diff --git a/agrolib/climate/dbClimate.cpp b/agrolib/climate/dbClimate.cpp index 0161a200f..45604879d 100644 --- a/agrolib/climate/dbClimate.cpp +++ b/agrolib/climate/dbClimate.cpp @@ -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* listElab) +bool getClimateFieldsFromTable(QSqlDatabase db, QString *myError, QString climateTable, QList* 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); @@ -418,7 +418,7 @@ bool selectAllElab(QSqlDatabase db, QString *myError, QString table, QListappend(elab); + fieldList->append(elab); found = true; } else @@ -431,7 +431,7 @@ bool selectAllElab(QSqlDatabase db, QString *myError, QString table, QList* climateTables) +bool getClimateTables(QSqlDatabase db, QString *myError, QList* climateTables) { QSqlQuery qry(db); QString table; diff --git a/agrolib/climate/dbClimate.h b/agrolib/climate/dbClimate.h index 3d0f9990e..fd5ace45b 100644 --- a/agrolib/climate/dbClimate.h +++ b/agrolib/climate/dbClimate.h @@ -5,6 +5,10 @@ #include #endif + #ifndef _VECTOR_ + #include + #endif + bool saveDailyElab(QSqlDatabase db, QString *myError, QString id, std::vector allResults, QString elab); bool saveDecadalElab(QSqlDatabase db, QString *myError, QString id, std::vector allResults, QString elab); bool saveMonthlyElab(QSqlDatabase db, QString *myError, QString id, std::vector allResults, QString elab); @@ -12,9 +16,9 @@ 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* listElab); + bool getClimateFieldsFromTable(QSqlDatabase db, QString *myError, QString climateTable, QList* fieldList); bool selectVarElab(QSqlDatabase db, QString *myError, QString table, QString variable, QList* listElab); - bool showClimateTables(QSqlDatabase db, QString *myError, QList* climateTables); + bool getClimateTables(QSqlDatabase db, QString *myError, QList* climateTables); bool deleteElab(QSqlDatabase db, QString *myError, QString table, QString elab); diff --git a/agrolib/dbMeteoGrid/dbMeteoGrid.cpp b/agrolib/dbMeteoGrid/dbMeteoGrid.cpp index 8f07d0ce8..f102bfe46 100644 --- a/agrolib/dbMeteoGrid/dbMeteoGrid.cpp +++ b/agrolib/dbMeteoGrid/dbMeteoGrid.cpp @@ -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) ) { diff --git a/agrolib/pragaProject/dialogAnomaly.cpp b/agrolib/pragaProject/dialogAnomaly.cpp index aa1896123..f5d5fa270 100644 --- a/agrolib/pragaProject/dialogAnomaly.cpp +++ b/agrolib/pragaProject/dialogAnomaly.cpp @@ -560,7 +560,7 @@ void DialogAnomaly::AnomalyFillClimateDbList(QComboBox* dbList) { QList 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"); } diff --git a/agrolib/pragaProject/dialogMeteoComputation.cpp b/agrolib/pragaProject/dialogMeteoComputation.cpp index 23ace396e..39ddce591 100644 --- a/agrolib/pragaProject/dialogMeteoComputation.cpp +++ b/agrolib/pragaProject/dialogMeteoComputation.cpp @@ -1091,7 +1091,7 @@ void DialogMeteoComputation::readParameter(int state) climateDbElabList.setVisible(true); adjustSize(); QList climateTables; - if (! showClimateTables(myProject.clima->db(), &myError, &climateTables) ) + if (! getClimateTables(myProject.clima->db(), &myError, &climateTables) ) { climateDbElabList.addItem("No saved elaborations found"); } diff --git a/agrolib/pragaProject/pragaProject.cpp b/agrolib/pragaProject/pragaProject.cpp index 6d913e4cb..3121da984 100644 --- a/agrolib/pragaProject/pragaProject.cpp +++ b/agrolib/pragaProject/pragaProject.cpp @@ -574,7 +574,7 @@ bool PragaProject::showClimateFields(bool isMeteoGrid, QList* climateDb } QList climateTables; - if ( !showClimateTables(db, &errorString, &climateTables) ) + if ( !getClimateTables(db, &errorString, &climateTables) ) { errorString = "No climate tables"; return false; @@ -583,7 +583,7 @@ bool PragaProject::showClimateFields(bool isMeteoGrid, QList* climateDb { for (int i=0; i < climateTables.size(); i++) { - selectAllElab(db, &errorString, climateTables[i], climateDbElab); + getClimateFieldsFromTable(db, &errorString, climateTables[i], climateDbElab); } if (climateDbElab->isEmpty()) { @@ -1316,14 +1316,12 @@ bool PragaProject::downloadDailyDataArkimet(QList 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); @@ -1398,7 +1396,7 @@ bool PragaProject::downloadHourlyDataArkimet(QList variables, QDate sta } } - int index, nrPoints = 0; + int index = 0; QString id, dataset; QList datasetList; QList> idList; @@ -1408,8 +1406,6 @@ bool PragaProject::downloadHourlyDataArkimet(QList variables, QDate sta { if (!isSelection || meteoPoints[i].selected) { - nrPoints ++; - id = QString::fromStdString(meteoPoints[i].id); dataset = QString::fromStdString(meteoPoints[i].dataset); @@ -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 climateTables; + QList 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(); diff --git a/agrolib/pragaProject/pragaProject.h b/agrolib/pragaProject/pragaProject.h index 95b6ed833..4d5db5cbc 100644 --- a/agrolib/pragaProject/pragaProject.h +++ b/agrolib/pragaProject/pragaProject.h @@ -152,7 +152,8 @@ bool getGriddingTasks(std::vector &timeCreation, std::vector &dateStart, std::vector &dateEnd, std::vector &users, std::vector ¬es); 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 diff --git a/agrolib/pragaProject/pragaShell.cpp b/agrolib/pragaProject/pragaShell.cpp index 658b2bfca..7ffbbdf58 100644 --- a/agrolib/pragaProject/pragaShell.cpp +++ b/agrolib/pragaProject/pragaShell.cpp @@ -16,6 +16,7 @@ QList 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"); @@ -123,7 +124,12 @@ int PragaProject::executePragaCommand(QList 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") { @@ -940,7 +946,7 @@ int pragaShell(PragaProject* myProject) return true; } */ - int cmdComputeClimaFromXMLSaveOnDB(PragaProject* myProject, QList argumentList) + int cmdComputeClimatePointsXML(PragaProject* myProject, QList argumentList) { if (argumentList.size() < 2) { @@ -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; } diff --git a/agrolib/pragaProject/pragaShell.h b/agrolib/pragaProject/pragaShell.h index cc4ff03ab..2b0b58c4d 100644 --- a/agrolib/pragaProject/pragaShell.h +++ b/agrolib/pragaProject/pragaShell.h @@ -20,7 +20,8 @@ int cmdGridAggregationOnZones(PragaProject* myProject, QList argumentList); int cmdMonthlyIntegrationVariablesGrid(PragaProject* myProject, QList argumentList); int cmdExportDailyGridToRaster(PragaProject* myProject, QList argumentList); - int cmdComputeClimaFromXMLSaveOnDB(PragaProject* myProject, QList argumentList); + int cmdComputeClimatePointsXML(PragaProject* myProject, QList argumentList); + int cmdCleanClimatePoint(PragaProject* myProject); int cmdDroughtIndexPoint(PragaProject* myProject, QList argumentList); int cmdSaveLogDataProceduresGrid(PragaProject* myProject, QList argumentList); //bool cmdLoadForecast(PragaProject* myProject, QList argumentList);