Skip to content

Commit

Permalink
Merge commit '7464e4c153690977e3cc5a2abca5865a793a1396'
Browse files Browse the repository at this point in the history
  • Loading branch information
ftomei committed Jan 17, 2024
2 parents 8cbac9c + 7464e4c commit b2a93fe
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 24 deletions.
8 changes: 4 additions & 4 deletions agrolib/climate/dbClimate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,14 +395,14 @@ bool selectVarElab(QSqlDatabase db, QString *myError, QString table, QString var
return found;
}

bool selectAllElab(QSqlDatabase db, QString *myError, QString table, QList<QString>* listElab)
bool getClimateFieldsFromTable(QSqlDatabase db, QString *myError, QString climateTable, QList<QString>* fieldList)
{
QSqlQuery qry(db);
QString elab;

bool found = false;

QString statement = QString("SELECT DISTINCT elab from `%1` ").arg(table);
QString statement = QString("SELECT DISTINCT elab from `%1` ").arg(climateTable);

qry.prepare(statement);

Expand All @@ -418,7 +418,7 @@ bool selectAllElab(QSqlDatabase db, QString *myError, QString table, QList<QStri
{
if (getValue(qry.value("elab"), &elab))
{
listElab->append(elab);
fieldList->append(elab);
found = true;
}
else
Expand All @@ -431,7 +431,7 @@ bool selectAllElab(QSqlDatabase db, QString *myError, QString table, QList<QStri
return found;
}

bool showClimateTables(QSqlDatabase db, QString *myError, QList<QString>* climateTables)
bool getClimateTables(QSqlDatabase db, QString *myError, QList<QString>* climateTables)
{
QSqlQuery qry(db);
QString table;
Expand Down
8 changes: 6 additions & 2 deletions agrolib/climate/dbClimate.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,20 @@
#include <QSqlDatabase>
#endif

#ifndef _VECTOR_
#include <vector>
#endif

bool saveDailyElab(QSqlDatabase db, QString *myError, QString id, std::vector<float> allResults, QString elab);
bool saveDecadalElab(QSqlDatabase db, QString *myError, QString id, std::vector<float> allResults, QString elab);
bool saveMonthlyElab(QSqlDatabase db, QString *myError, QString id, std::vector<float> allResults, QString elab);
bool saveSeasonalElab(QSqlDatabase db, QString *myError, QString id, std::vector<float> allResults, QString elab);
bool saveAnnualElab(QSqlDatabase db, QString *myError, QString id, float result, QString elab);
bool saveGenericElab(QSqlDatabase db, QString *myError, QString id, float result, QString elab);

bool selectAllElab(QSqlDatabase db, QString *myError, QString table, QList<QString>* listElab);
bool getClimateFieldsFromTable(QSqlDatabase db, QString *myError, QString climateTable, QList<QString>* fieldList);
bool selectVarElab(QSqlDatabase db, QString *myError, QString table, QString variable, QList<QString>* listElab);
bool showClimateTables(QSqlDatabase db, QString *myError, QList<QString>* climateTables);
bool getClimateTables(QSqlDatabase db, QString *myError, QList<QString>* climateTables);

bool deleteElab(QSqlDatabase db, QString *myError, QString table, QString elab);

Expand Down
4 changes: 2 additions & 2 deletions agrolib/dbMeteoGrid/dbMeteoGrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1262,8 +1262,8 @@ bool Crit3DMeteoGridDbHandler::newCellProperties(QString *myError)
QSqlQuery qry(_db);
QString table = "CellsProperties";
QString statement = QString("CREATE TABLE `%1`"
"(`Code` varchar(6) NOT NULL PRIMARY KEY, `SecondaryCode` TEXT, `Name` TEXT, "
"`Notes` TEXT, `Row` INT, `Col` INT, `X` DOUBLE(16,2) DEFAULT 0.00, `Y` DOUBLE(16,2) DEFAULT 0.00, `Height` DOUBLE(16,2) DEFAULT 0.00, `Active` INT)").arg(table);
"(`Code` varchar(6) NOT NULL PRIMARY KEY, `Name` varchar(50), "
"`Row` INT, `Col` INT, `X` DOUBLE(16,2) DEFAULT 0.00, `Y` DOUBLE(16,2) DEFAULT 0.00, `Height` DOUBLE(16,2) DEFAULT 0.00, `Active` INT)").arg(table);

if( !qry.exec(statement) )
{
Expand Down
2 changes: 1 addition & 1 deletion agrolib/pragaProject/dialogAnomaly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ void DialogAnomaly::AnomalyFillClimateDbList(QComboBox* dbList)
{
QList<QString> climateTables;
QString myError = myProject.errorString;
if (! showClimateTables(myProject.clima->db(), &myError, &climateTables) )
if (! getClimateTables(myProject.clima->db(), &myError, &climateTables) )
{
dbList->addItem("No saved elaborations found");
}
Expand Down
2 changes: 1 addition & 1 deletion agrolib/pragaProject/dialogMeteoComputation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1091,7 +1091,7 @@ void DialogMeteoComputation::readParameter(int state)
climateDbElabList.setVisible(true);
adjustSize();
QList<QString> climateTables;
if (! showClimateTables(myProject.clima->db(), &myError, &climateTables) )
if (! getClimateTables(myProject.clima->db(), &myError, &climateTables) )
{
climateDbElabList.addItem("No saved elaborations found");
}
Expand Down
50 changes: 41 additions & 9 deletions agrolib/pragaProject/pragaProject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ bool PragaProject::showClimateFields(bool isMeteoGrid, QList<QString>* climateDb
}
QList<QString> climateTables;

if ( !showClimateTables(db, &errorString, &climateTables) )
if ( !getClimateTables(db, &errorString, &climateTables) )
{
errorString = "No climate tables";
return false;
Expand All @@ -583,7 +583,7 @@ bool PragaProject::showClimateFields(bool isMeteoGrid, QList<QString>* climateDb
{
for (int i=0; i < climateTables.size(); i++)
{
selectAllElab(db, &errorString, climateTables[i], climateDbElab);
getClimateFieldsFromTable(db, &errorString, climateTables[i], climateDbElab);
}
if (climateDbElab->isEmpty())
{
Expand Down Expand Up @@ -1316,14 +1316,12 @@ bool PragaProject::downloadDailyDataArkimet(QList<QString> variables, bool prec0
return false;
}

int index, nrPoints = 0;
int index = 0;
bool isSelection = isSelectionPointsActive(meteoPoints, nrMeteoPoints);
for( int i=0; i < nrMeteoPoints; i++ )
{
if (!isSelection || meteoPoints[i].selected)
{
nrPoints ++;

id = QString::fromStdString(meteoPoints[i].id);
dataset = QString::fromStdString(meteoPoints[i].dataset);

Expand Down Expand Up @@ -1398,7 +1396,7 @@ bool PragaProject::downloadHourlyDataArkimet(QList<QString> variables, QDate sta
}
}

int index, nrPoints = 0;
int index = 0;
QString id, dataset;
QList<QString> datasetList;
QList<QList<QString>> idList;
Expand All @@ -1408,8 +1406,6 @@ bool PragaProject::downloadHourlyDataArkimet(QList<QString> variables, QDate sta
{
if (!isSelection || meteoPoints[i].selected)
{
nrPoints ++;

id = QString::fromStdString(meteoPoints[i].id);
dataset = QString::fromStdString(meteoPoints[i].dataset);

Expand Down Expand Up @@ -3634,7 +3630,43 @@ bool PragaProject::removeGriddingTask(QDateTime dateCreation, QString user, QDat
return true;
}

bool PragaProject::computeClimaFromXMLSaveOnDB(QString xmlName)
bool PragaProject::cleanClimatePoint()
{

QSqlDatabase db;

if (this->meteoPointsDbHandler == nullptr)
{
errorString = "Load meteo points";
return false;
}
db = this->meteoPointsDbHandler->getDb();

QList<QString> climateTables;
QList<QString> climateFields;

unsigned i,j;

if (getClimateTables(db, &errorString, &climateTables) )
{
for (i=0; i < climateTables.size(); i++)
{
climateFields.clear();
getClimateFieldsFromTable(db, &errorString, climateTables[i], &climateFields);

if (! climateFields.isEmpty())
{
for (j=0; j < climateFields.size(); j++)
if (! deleteElab(db, &errorString, climateTables[i].toLower(), climateFields[j]))
return false;
}
}
}

return true;
}

bool PragaProject::computeClimatePointXML(QString xmlName)
{

Crit3DElabList *listXMLElab = new Crit3DElabList();
Expand Down
3 changes: 2 additions & 1 deletion agrolib/pragaProject/pragaProject.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@
bool getGriddingTasks(std::vector<QDateTime> &timeCreation, std::vector<QDate> &dateStart, std::vector<QDate> &dateEnd,
std::vector<QString> &users, std::vector<QString> &notes);
bool removeGriddingTask(QDateTime dateCreation, QString user, QDate dateStart, QDate dateEnd);
bool computeClimaFromXMLSaveOnDB(QString xmlName);
bool computeClimatePointXML(QString xmlName);
bool cleanClimatePoint();
bool saveLogProceduresGrid(QString nameProc, QDate date);

#ifdef NETCDF
Expand Down
22 changes: 19 additions & 3 deletions agrolib/pragaProject/pragaShell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ QList<QString> getPragaCommandList()
cmdList.append("Download | Download");
cmdList.append("AggrOnZones | GridAggregationOnZones");
cmdList.append("ComputeClimate | ComputeClimaFromXMLSaveOnDB");
cmdList.append("CleanClimate | CleanClimate");
cmdList.append("Drought | ComputeDroughtIndexGrid");
cmdList.append("DroughtPoint | ComputeDroughtIndexPoint");
cmdList.append("GridAggr | GridAggregation");
Expand Down Expand Up @@ -123,7 +124,12 @@ int PragaProject::executePragaCommand(QList<QString> argumentList, bool* isComma
else if (command == "CLIMATE" || command == "COMPUTECLIMATE")
{
*isCommandFound = true;
return cmdComputeClimaFromXMLSaveOnDB(this, argumentList);
return cmdComputeClimatePointsXML(this, argumentList);
}
else if (command == "CLEANCLIM" || command == "CLEANCLIMATE")
{
*isCommandFound = true;
return cmdCleanClimatePoint(this);
}
else if (command == "DROUGHTINDEXPOINT" || command == "DROUGHTPOINT")
{
Expand Down Expand Up @@ -940,7 +946,7 @@ int pragaShell(PragaProject* myProject)
return true;
}
*/
int cmdComputeClimaFromXMLSaveOnDB(PragaProject* myProject, QList<QString> argumentList)
int cmdComputeClimatePointsXML(PragaProject* myProject, QList<QString> argumentList)
{
if (argumentList.size() < 2)
{
Expand All @@ -949,7 +955,17 @@ int pragaShell(PragaProject* myProject)
}

QString xmlName = myProject->getCompleteFileName(argumentList.at(1), PATH_PROJECT);
if (!myProject->computeClimaFromXMLSaveOnDB(xmlName))
if (!myProject->computeClimatePointXML(xmlName))
{
return PRAGA_ERROR;
}

return PRAGA_OK;
}

int cmdCleanClimatePoint(PragaProject* myProject)
{
if (!myProject->cleanClimatePoint())
{
return PRAGA_ERROR;
}
Expand Down
3 changes: 2 additions & 1 deletion agrolib/pragaProject/pragaShell.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
int cmdGridAggregationOnZones(PragaProject* myProject, QList<QString> argumentList);
int cmdMonthlyIntegrationVariablesGrid(PragaProject* myProject, QList<QString> argumentList);
int cmdExportDailyGridToRaster(PragaProject* myProject, QList<QString> argumentList);
int cmdComputeClimaFromXMLSaveOnDB(PragaProject* myProject, QList<QString> argumentList);
int cmdComputeClimatePointsXML(PragaProject* myProject, QList<QString> argumentList);
int cmdCleanClimatePoint(PragaProject* myProject);
int cmdDroughtIndexPoint(PragaProject* myProject, QList<QString> argumentList);
int cmdSaveLogDataProceduresGrid(PragaProject* myProject, QList<QString> argumentList);
//bool cmdLoadForecast(PragaProject* myProject, QList<QString> argumentList);
Expand Down

0 comments on commit b2a93fe

Please sign in to comment.