Commit 893ea95c authored by Béla Wiegel's avatar Béla Wiegel Committed by Gerrit Erichsen
Browse files

Update current working state

parent 3b4c198a
......@@ -520,7 +520,7 @@ void CharLGui::onPreferencesAction()
void CharLGui::onPlantDataReaderAction()
{
PlantDataReaderDialog * dialog = new PlantDataReaderDialog(m_modelLocations, m_modelNodes, this);
PlantDataReaderDialog * dialog = new PlantDataReaderDialog(m_modelLocations, m_modelNodes, m_modelWind, this);
dialog->setTableModel(PlantDataReaderDialog::Conventional, m_modelConventional);
dialog->setTableModel(PlantDataReaderDialog::Storage, m_modelStorage);
dialog->setTableModel(PlantDataReaderDialog::Wind, m_modelWind);
......
......@@ -233,6 +233,10 @@ QVariant LocationsTableModel::data(const QModelIndex &index, int role) const
{
return QVariant("Not set");
}
else if (role == Qt::UserRole)
{
return m_data[index.row()]->getNodeID();
}
else
{
int id = m_data[index.row()]->getNodeID();
......
#include "PlantDataReaderDialog.h"
#include <PolygonCalculations.h>
#include <QFileDialog>
#include <QHBoxLayout>
#include <QMessageBox>
#include <QThreadPool>
PlantDataReaderDialog::PlantDataReaderDialog(LocationsTableModel * locationsTableModel, NodesTableModel * nodesTableModel, QWidget * parent) : QDialog(parent),
PlantDataReaderDialog::PlantDataReaderDialog(
LocationsTableModel * locationsTableModel,
NodesTableModel * nodesTableModel,
WindTableModel * windTableModel,
QWidget * parent) : QDialog(parent),
m_locationsTableModel(locationsTableModel),
m_nodesTableModel(nodesTableModel)
m_nodesTableModel(nodesTableModel),
m_windTableModel(windTableModel)
{
// fill plant selector combo box
m_cboPlantType = new QComboBox();
......@@ -16,7 +22,7 @@ PlantDataReaderDialog::PlantDataReaderDialog(LocationsTableModel * locationsTabl
m_cboPlantType->insertItem(Wind, "Wind Turbines");
m_cboPlantType->insertItem(Solar, "PV Modules");
// gui stuff
// GUI
m_btnSelectFile = new QPushButton("Select File");
m_btnSelectFile->setWhatsThis(
"<b>Hint</b>: Column seperated is a semicolon (;). Decimal separator is a point (.)"
......@@ -25,10 +31,13 @@ PlantDataReaderDialog::PlantDataReaderDialog(LocationsTableModel * locationsTabl
m_lblFilePath = new QLabel("Please select a file...");
m_btnProcessFile = new QPushButton("Create table items");
m_btnProcessFile->setEnabled(false);
m_btnOPSDData = new QPushButton("OPSD Data");
m_btnOPSDData->setEnabled(false);
// make connection
connect(m_btnSelectFile, &QPushButton::clicked, this, &PlantDataReaderDialog::fileDialog);
connect(m_btnProcessFile, &QPushButton::clicked, this, &PlantDataReaderDialog::processFile);
connect(m_btnOPSDData, &QPushButton::clicked, this, &PlantDataReaderDialog::processOPSDWindData);
// generate layout
QHBoxLayout * lyoFileSelection = new QHBoxLayout();
......@@ -37,15 +46,18 @@ PlantDataReaderDialog::PlantDataReaderDialog(LocationsTableModel * locationsTabl
lyoFileSelection->addWidget(m_lblFilePath);
lyoFileSelection->addStretch();
QHBoxLayout * lyoBtns = new QHBoxLayout();
lyoBtns->addWidget(m_btnOPSDData);
lyoBtns->addWidget(m_btnProcessFile);
QVBoxLayout * lyoMain = new QVBoxLayout();
lyoMain->addLayout(lyoFileSelection);
lyoMain->addWidget(m_btnProcessFile);
lyoMain->addLayout(lyoBtns);
lyoMain->addStretch();
setLayout(lyoMain);
// temporary
// processOPSDWindData();
// LonLatToAGS();
}
......@@ -66,11 +78,13 @@ void PlantDataReaderDialog::fileDialog()
{
m_lblFilePath->setText("No file selected.");
m_btnProcessFile->setEnabled(false);
m_btnOPSDData->setEnabled(false);
}
else
{
m_lblFilePath->setText(m_filePath);
m_btnProcessFile->setEnabled(true);
m_btnOPSDData->setEnabled(true);
}
}
......@@ -98,7 +112,7 @@ void PlantDataReaderDialog::processFile()
}
QString csvHeaderStr = QString::fromUtf8(file.readLine());
csvHeaderStr = csvHeaderStr.remove("\r\n");
csvHeaderStr = csvHeaderStr.simplified();
QList<QString> csvHeader = csvHeaderStr.split(';');
AbstractPlantTableModel * tableModel = m_tableModels.value(plantType);
......@@ -160,8 +174,8 @@ void PlantDataReaderDialog::processFile()
// match power plant to node via locations
const NodesTableItem * nodeItem;
const LocationsTableItem * locationItem;
const NodesTableItem * nodeItem = nullptr;
const LocationsTableItem * locationItem = nullptr;
int locationID = -1;
int csvIndexAGS = csvHeader.indexOf("ags");
......@@ -198,6 +212,9 @@ void PlantDataReaderDialog::processFile()
}
}
float minDistance = static_cast<float>(1e30);
int minDistanceIndex = -1;
// check if lat and lon fields are available
if (!found && csvIndexLat != -1 && csvIndexLon != -1)
{
......@@ -218,14 +235,25 @@ void PlantDataReaderDialog::processFile()
for (int i = 0; i < m_locationsTableModel->rowCount(); i++)
indices << i;
float distance = static_cast<float>(1e30);
for (int index : indices)
{
if (static_cast<const LocationsTableItem*>(m_locationsTableModel->getItem(index))
->getMapPolygon().containsPoint(plantCoordinates, Qt::WindingFill))
const LocationsTableItem * locationItem_temp = static_cast<const LocationsTableItem*>(m_locationsTableModel->getItem(index));
// calculate distance
QPointF diff = VectorCalculations::differenceVectorENU(plantCoordinates, locationItem_temp->getLonLat(), plantCoordinates);
distance = VectorCalculations::norm(diff);
if (distance < minDistance)
{
minDistance = distance;
minDistanceIndex = index;
}
if (locationItem_temp->getMapPolygon().containsPoint(plantCoordinates, Qt::WindingFill))
{
// match
locationID = index;
locationItem = static_cast<const LocationsTableItem*>(m_locationsTableModel->getItem(index));
locationItem = locationItem_temp;
nodeItem = static_cast<const NodesTableItem*>(m_nodesTableModel->getItem(locationItem->getNodeID()));
found = true;
......@@ -236,6 +264,14 @@ void PlantDataReaderDialog::processFile()
}
}
if (found == false && minDistanceIndex >= 0 && minDistance < 1e5) // max 100 km distance
{
found = true;
locationID = minDistanceIndex;
locationItem = static_cast<const LocationsTableItem*>(m_locationsTableModel->getItem(minDistanceIndex));
nodeItem = static_cast<const NodesTableItem*>(m_nodesTableModel->getItem(locationItem->getNodeID()));
}
// continue only if location (and corresponding node) are found
if (found && nodeItem != nullptr && locationItem != nullptr)
{
......@@ -249,7 +285,7 @@ void PlantDataReaderDialog::processFile()
}
ConfigTableItem configTableItem;
configTableItem.setSelectionProducer(fileRow);
configTableItem.setSelectionProducer(fileRow - 1);
configTableItem.setSelectionLocation(locationID);
// set max_power, min_power and step_power
......@@ -312,21 +348,48 @@ void PlantDataReaderDialog::processFile()
qDebug() << " " << locationDataString;
}
}
if (minDistanceIndex >= 0 && locationItem != nullptr)
{
qDebug(" assigned min distance location index %d: %s", minDistanceIndex, locationItem->getName().toStdString().c_str());
qDebug(" with distance of %f km", minDistance / 1000);
qDebug(" coorinates %s", locationDataString.toStdString().c_str());
}
}
}
bool secondIsLower(const pair<double,double> & a, const pair<double,double> & b)
{
return a.second < b.second;
}
void PlantDataReaderDialog::processOPSDWindData()
{
QList<float> turbinePower = QList<float>({7580, 4500, 5000, 4600, 10000, 500, 1000, 1540, 2000, 3050, 3000, 4200});
qSort(turbinePower.begin(), turbinePower.end());
// debug
float processedPower = 0;
float assignedPower = 0;
QList<float> turbinePower;
for (int i = 0; i < m_windTableModel->rowCount(); i++)
{
const WindTableItem * item = static_cast<const WindTableItem *>(m_windTableModel->getItem(i));
QVector<std::pair<double,double>> curve = item->getPowerCurve();
qSort(curve.begin(), curve.end(), secondIsLower);
turbinePower.append(static_cast<float>(curve.last().second));
qDebug() << curve.last().second;
}
QList<float> turbinePowerSorted = QList<float>(turbinePower);
qSort(turbinePowerSorted.begin(), turbinePowerSorted.end());
QList<float> powerClasses;
powerClasses << 0;
for (int i = 0; i < turbinePower.size() - 1; i++)
for (int i = 0; i < turbinePowerSorted.size() - 1; i++)
{
powerClasses << (turbinePower[i] + turbinePower[i + 1]) / 2;
powerClasses << (turbinePowerSorted[i] + turbinePowerSorted[i + 1]) / 2;
}
QFile file("D:/Locations_Nodes_Plants/OPSD_20190626_Wind.csv");
QFile file(m_filePath);
file.open(QIODevice::ReadOnly);
QString csvHeaderStr = QString::fromUtf8(file.readLine());
......@@ -345,7 +408,13 @@ void PlantDataReaderDialog::processOPSDWindData()
QList<QString> csvData = csvDataStr.split(';');
QString AGS = csvData[indexAGS];
// fill up to length of 8
while (AGS.size() < 8)
AGS = "0" + AGS;
float power = csvData[indexPower].toFloat(); // [MW]
processedPower += power;
power *= 1000; // [kW]
int powerClass = 0;
......@@ -365,16 +434,58 @@ void PlantDataReaderDialog::processOPSDWindData()
}
file.close();
// write result to csv
// write data to ConfigTableModel in corresponding Node
for (int locationID = 0; locationID < m_locationsTableModel->rowCount(); locationID++)
{
const LocationsTableItem * locationItem = static_cast<const LocationsTableItem *>(m_locationsTableModel->getItem(locationID));
if (powerPerClassinAGS.contains(locationItem->getAGS()))
{
const NodesTableItem * nodeItem = static_cast<const NodesTableItem *>(m_nodesTableModel->getItem(locationItem->getNodeID()));
if (nodeItem == nullptr)
continue;
ConfigTableModel * configModel = const_cast<NodesTableItem*>(nodeItem)->getWindTablePtr();
for (int turbineIndex = 0; turbineIndex < powerPerClassinAGS[locationItem->getAGS()].size(); turbineIndex++)
{
int turbineID = turbinePower.indexOf(turbinePowerSorted[turbineIndex]);
if (powerPerClassinAGS[locationItem->getAGS()][turbineID] == 0)
continue;
ConfigTableItem configTableItem;
// set producer ID (wind turbine) and locationID
configTableItem.setSelectionProducer(turbineID);
configTableItem.setSelectionLocation(locationID);
configTableItem.setStepSizePower(0);
// set max_power, min_power and step_power
configTableItem.setMaxPower(static_cast<double>(powerPerClassinAGS[locationItem->getAGS()][turbineID]));
configTableItem.setMinPower(configTableItem.getMaxPower());
assignedPower += configTableItem.getMaxPower();
configModel->addItem(configTableItem);
}
}
}
qDebug() << processedPower;
qDebug() << assignedPower;
// skip csv writing
return;
// --- write result to csv ----------------------------------------------------------------------------------------
QFile result("D:/Locations_Nodes_Plants/WindPowerClasses.csv");
QTextStream stream(&result);
result.open(QIODevice::WriteOnly);
stream << "AGS;";
for (int i = 0; i < turbinePower.size(); i++)
for (int i = 0; i < turbinePowerSorted.size(); i++)
{
stream << QString::number(turbinePower[i]).toInt();
if (i < turbinePower.size() - 1)
stream << QString::number(turbinePowerSorted[i]).toInt();
if (i < turbinePowerSorted.size() - 1)
stream << ";";
}
stream << endl;
......
......@@ -12,11 +12,16 @@
#include "Models/AbstractPlantTableModel.h"
#include "Models/LocationsTableModel.h"
#include "Models/NodesTableModel.h"
#include <Models/WindTableModel.h>
class PlantDataReaderDialog : public QDialog
{
public:
PlantDataReaderDialog(LocationsTableModel * locationsTableModel, NodesTableModel * nodesTableModel, QWidget * parent = 0);
PlantDataReaderDialog(
LocationsTableModel * locationsTableModel,
NodesTableModel * nodesTableModel,
WindTableModel * windTableModel,
QWidget * parent = nullptr);
enum PlantType {
Conventional,
......@@ -30,12 +35,14 @@ public:
private slots:
void fileDialog();
void processFile();
void processOPSDWindData();
private:
QHash<PlantType, AbstractPlantTableModel*> m_tableModels;
LocationsTableModel * m_locationsTableModel;
NodesTableModel * m_nodesTableModel;
WindTableModel * m_windTableModel;
// GUI
QComboBox * m_cboPlantType;
......@@ -44,9 +51,9 @@ private:
* m_btnProcessFile;
QLabel * m_lblFilePath;
QString m_filePath;
QPushButton * m_btnOPSDData;
// temporary
void processOPSDWindData();
void LonLatToAGS();
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment