From 6015ab629d431974ed23c7438b8638f8127075fe Mon Sep 17 00:00:00 2001 From: Gabriele Antolini Date: Tue, 31 Oct 2023 12:25:07 +0100 Subject: [PATCH 01/14] fixed step --- criteriaOutput/criteriaOutput.pro | 2 +- criteriaOutput/criteriaOutputProject.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/criteriaOutput/criteriaOutput.pro b/criteriaOutput/criteriaOutput.pro index 55d48f93d..99708ae78 100644 --- a/criteriaOutput/criteriaOutput.pro +++ b/criteriaOutput/criteriaOutput.pro @@ -59,7 +59,7 @@ HEADERS += \ # comment to compile without GDAL library -CONFIG += GDAL +#CONFIG += GDAL GDAL:{ DEFINES += GDAL diff --git a/criteriaOutput/criteriaOutputProject.cpp b/criteriaOutput/criteriaOutputProject.cpp index d02254c54..ef72541c8 100644 --- a/criteriaOutput/criteriaOutputProject.cpp +++ b/criteriaOutput/criteriaOutputProject.cpp @@ -440,7 +440,7 @@ int CriteriaOutputProject::precomputeDtx() logger.writeInfo("Compute dtx..."); QString idCase; - int step = compUnitList.size() * 0.01; + int step = MAXVALUE(compUnitList.size() * 0.01, 1); for (unsigned int i=0; i < compUnitList.size(); i++) { From 762f9193b95fb953681b9b533d8cd69bf5ded7cc Mon Sep 17 00:00:00 2001 From: Gabriele Antolini Date: Tue, 31 Oct 2023 12:25:53 +0100 Subject: [PATCH 02/14] fixed step --- criteriaOutput/criteriaOutput.pro | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/criteriaOutput/criteriaOutput.pro b/criteriaOutput/criteriaOutput.pro index 99708ae78..55d48f93d 100644 --- a/criteriaOutput/criteriaOutput.pro +++ b/criteriaOutput/criteriaOutput.pro @@ -59,7 +59,7 @@ HEADERS += \ # comment to compile without GDAL library -#CONFIG += GDAL +CONFIG += GDAL GDAL:{ DEFINES += GDAL From f40929c265e5ecb6e72169f657e8f8dfd63b4217 Mon Sep 17 00:00:00 2001 From: ftomei Date: Tue, 12 Dec 2023 20:02:08 +0100 Subject: [PATCH 03/14] fix netcdf dimension --- netcdfHandler/netcdfHandler.cpp | 180 ++++++++++++++++++++++++++------ netcdfHandler/netcdfHandler.h | 2 + 2 files changed, 149 insertions(+), 33 deletions(-) diff --git a/netcdfHandler/netcdfHandler.cpp b/netcdfHandler/netcdfHandler.cpp index 9a6331bbc..27538c6cc 100644 --- a/netcdfHandler/netcdfHandler.cpp +++ b/netcdfHandler/netcdfHandler.cpp @@ -127,6 +127,10 @@ void NetCDFHandler::clear() idTime = NODATA; idTimeBnds = NODATA; + indexTimeDim = NODATA; + indexYLonDim = NODATA; + indexXLatDim = NODATA; + isUTM = false; isLatLon = false; isRotatedLatLon = false; @@ -349,35 +353,40 @@ bool NetCDFHandler::readProperties(string fileName) int nrVarDimensions, nrVarAttributes; metadata << "\nDimensions: " << endl; - for (int i = 0; i < nrDimensions; i++) + for (int index = 0; index < nrDimensions; index++) { - nc_inq_dim(ncId, i, name, &length); + nc_inq_dim(ncId, index, name, &length); - dimensions.push_back(NetCDFVariable(name, i, NODATA)); + dimensions.push_back(NetCDFVariable(name, index, NODATA)); if (lowerCase(string(name)) == "time") { nrTime = int(length); + indexTimeDim = index; } else if (lowerCase(string(name)) == "x") { nrX = int(length); isUTM = true; + indexXLatDim = index; } else if (lowerCase(string(name)) == "y") { nrY = int(length); isUTM = true; + indexYLonDim = index; } else if (lowerCase(string(name)) == "lat" || lowerCase(string(name)) == "latitude") { nrLat = int(length); isLatLon = true; + indexXLatDim = index; } else if (lowerCase(string(name)) == "lon" || lowerCase(string(name)) == "longitude") { nrLon = int(length); isLatLon = true; + indexYLonDim = index; } else if (lowerCase(string(name)) == "rlat") { @@ -390,7 +399,7 @@ bool NetCDFHandler::readProperties(string fileName) isRotatedLatLon = true; } - metadata << i << " - " << name << "\t values: " << length << endl; + metadata << index << " - " << name << "\t values: " << length << endl; } if (isLatLon) @@ -529,7 +538,7 @@ bool NetCDFHandler::readProperties(string fileName) nc_get_att(ncId, v, attrName, &valueInt); // no data - if (lowerCase(string(attrName)) == "missing_value" || lowerCase(string(attrName)) == "nodata") + if (lowerCase(string(attrName)) == "missing_value" || lowerCase(string(attrName)) == "_fillvalue") { missingValue = double(valueInt); } @@ -541,7 +550,7 @@ bool NetCDFHandler::readProperties(string fileName) nc_get_att(ncId, v, attrName, &value); // no data - if (lowerCase(string(attrName)) == "missing_value" || lowerCase(string(attrName)) == "nodata") + if (lowerCase(string(attrName)) == "missing_value" || lowerCase(string(attrName)) == "_fillvalue") { missingValue = value; } @@ -704,25 +713,39 @@ bool NetCDFHandler::readProperties(string fileName) bool NetCDFHandler::exportDataSeries(int idVar, gis::Crit3DGeoPoint geoPoint, Crit3DTime seriesFirstTime, Crit3DTime seriesLastTime, stringstream *buffer) { - // check + // check dimensions if (! isTimeReadable()) { *buffer << "Wrong or missing time dimension!" << endl; return false; } - if (! isPointInside(geoPoint)) + if (indexTimeDim == NODATA || indexXLatDim == NODATA || indexYLonDim == NODATA) { - *buffer << "Wrong position!" << endl; + *buffer << "One dimension is missing: required (time, x, y) or (time, lon, lat)." << endl; + return false; + } + if (std::max(indexTimeDim, std::max(indexXLatDim, indexYLonDim)) > 2) + { + *buffer << "Wrong dimension index: greater than 3." << endl; return false; } - if (seriesFirstTime < getFirstTime() || seriesLastTime > getLastTime()) + // check variable + NetCDFVariable var = getVariableFromId(idVar); + if (var.getVarName() == "") { - *buffer << "Wrong time index!" << endl; + *buffer << "Wrong variable!" << endl; + return false; + } + + // check point + if (! isPointInside(geoPoint)) + { + *buffer << "Wrong position!" << endl; return false; } - // find row, col + // search row, col int row, col; if (isLatLon) { @@ -738,7 +761,14 @@ bool NetCDFHandler::exportDataSeries(int idVar, gis::Crit3DGeoPoint geoPoint, Cr row = (nrY -1) - row; } - // find time indexes + // check time indexes + if (seriesFirstTime < getFirstTime() || seriesLastTime > getLastTime()) + { + *buffer << "Wrong time index!" << endl; + return false; + } + + // search time indexes int t1 = NODATA; int t2 = NODATA; int i = 0; @@ -751,21 +781,13 @@ bool NetCDFHandler::exportDataSeries(int idVar, gis::Crit3DGeoPoint geoPoint, Cr i++; } - // check time + // check time range if (t1 == NODATA || t2 == NODATA) { *buffer << "Time out of range!" << endl; return false; } - // check variable - NetCDFVariable var = getVariableFromId(idVar); - if (var.getVarName() == "") - { - *buffer << "Wrong variable!" << endl; - return false; - } - *buffer << "variable: " << var.getVarName() << endl; // write position @@ -782,12 +804,12 @@ bool NetCDFHandler::exportDataSeries(int idVar, gis::Crit3DGeoPoint geoPoint, Cr // write data size_t* index = new size_t[3]; - index[1] = size_t(row); - index[2] = size_t(col); + index[indexYLonDim] = size_t(row); + index[indexXLatDim] = size_t(col); for (int t = t1; t <= t2; t++) { - index[0] = unsigned(t); + index[indexTimeDim] = unsigned(t); if (var.type == NC_DOUBLE) { double value; @@ -1049,16 +1071,11 @@ bool NetCDFHandler::writeData_NoTime(const gis::Crit3DRasterGrid& myDataGrid) } +// TODO: sistemare con dimensioni bool NetCDFHandler::extractVariableMap(int idVar, const Crit3DTime& myTime, std::string& errorStr) { // initialize - for (int row = 0; row < dataGrid.header->nrRows; row++) - { - for (int col = 0; col < dataGrid.header->nrCols; col++) - { - dataGrid.value[row][col] = NODATA; - } - } + dataGrid.emptyGrid(); // check variable NetCDFVariable currentVar = getVariableFromId(idVar); @@ -1100,7 +1117,7 @@ bool NetCDFHandler::extractVariableMap(int idVar, const Crit3DTime& myTime, std: // read data int retVal; long nrValues; - size_t start[] = {unsigned(timeIndex), 0, 0}; + size_t start[] = {size_t(timeIndex), 0, 0}; size_t count[] = {1, 1, 1}; if (isLatLon) { @@ -1181,6 +1198,103 @@ bool NetCDFHandler::extractVariableMap(int idVar, const Crit3DTime& myTime, std: } +bool NetCDFHandler::extractVariableMap2(int idVar, const Crit3DTime &myTime, std::string &errorStr) +{ + // initialize + dataGrid.emptyGrid(); + + // check dimensions + if (indexTimeDim == NODATA || indexXLatDim == NODATA || indexYLonDim == NODATA) + { + errorStr = "One dimension is missing: required (time, x, y) or (time, lon, lat)."; + return false; + } + if (std::max(indexTimeDim, std::max(indexXLatDim, indexYLonDim)) > 2) + { + errorStr = "Wrong dimension number: greater than 3."; + return false; + } + + // check variable + NetCDFVariable currentVar = getVariableFromId(idVar); + if (currentVar.getVarName() == "") + { + errorStr = "Wrong variable."; + return false; + } + + // check time + if (! isTimeReadable()) + { + errorStr = "Wrong Time dimension."; + return false; + } + + if (myTime < getFirstTime() || myTime > getLastTime()) + { + errorStr = "Time is out of range."; + return false; + } + + // search time index + long timeIndex = NODATA; + for (long i = 0; i < nrTime; i++) + { + if (getTime(i) == myTime) + { + timeIndex = i; + break; + } + } + if (timeIndex == NODATA) + { + errorStr = "No available time index."; + return false; + } + + // get data + size_t* index = new size_t[3]; + index[indexTimeDim] = size_t(timeIndex); + + for (int row = 0; row < dataGrid.header->nrRows; row++) + { + if (isYincreasing) + index[indexYLonDim] = size_t((nrLat-1) - row); + else + index[indexYLonDim] = size_t(row); + + for (int col = 0; col < dataGrid.header->nrCols; col++) + { + index[indexXLatDim] = size_t(col); + float value; + + if (currentVar.type == NC_DOUBLE) + { + double valueDouble; + nc_get_var1_double(ncId, idVar, index, &valueDouble); + value = float(valueDouble); + } + if (currentVar.type == NC_FLOAT) + { + nc_get_var1_float(ncId, idVar, index, &value); + } + if (currentVar.type <= NC_INT) + { + int valueInt; + nc_get_var1_int(ncId, idVar, index, &valueInt); + value = float(valueInt); + } + + dataGrid.value[row][col] = value; + } + } + + delete[] index; + + return true; +} + + gis::Crit3DRasterGrid* NetCDFHandler::getRaster() { return &dataGrid; diff --git a/netcdfHandler/netcdfHandler.h b/netcdfHandler/netcdfHandler.h index 1d8a284d9..6114307dc 100644 --- a/netcdfHandler/netcdfHandler.h +++ b/netcdfHandler/netcdfHandler.h @@ -27,6 +27,7 @@ private: int utmZone; long nrX, nrY, nrLat, nrLon, nrTime; + int indexTimeDim, indexYLonDim, indexXLatDim; int idTime, idTimeBnds, idX, idY, idLat, idLon; float *x, *y; @@ -99,6 +100,7 @@ bool readProperties(std::string fileName); bool exportDataSeries(int idVar, gis::Crit3DGeoPoint geoPoint, Crit3DTime seriesFirstTime, Crit3DTime seriesLastTime, std::stringstream *buffer); bool extractVariableMap(int idVar, const Crit3DTime &myTime, std::string &error); + bool extractVariableMap2(int idVar, const Crit3DTime &myTime, std::string &errorStr); bool createNewFile(std::string fileName); From 26686eef787130381171ef8ef2bc3b77c2ff7b17 Mon Sep 17 00:00:00 2001 From: ftomei Date: Thu, 14 Dec 2023 16:38:15 +0100 Subject: [PATCH 04/14] fix palette path --- criteriaOutput/criteriaOutputProject.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/criteriaOutput/criteriaOutputProject.cpp b/criteriaOutput/criteriaOutputProject.cpp index ef72541c8..861cb4215 100644 --- a/criteriaOutput/criteriaOutputProject.cpp +++ b/criteriaOutput/criteriaOutputProject.cpp @@ -668,7 +668,13 @@ int CriteriaOutputProject::createMaps() for (int i=0; i < inputField.size(); i++) { QString mapName = outputShapeFilePath + "/" + outputName[i]+ "." + mapFormat; - QString paletteName = mapPalettePath + "/" + paletteFileName[i]; + + QString paletteName = ""; + if (! mapPalettePath.isEmpty()) + { + paletteName = mapPalettePath + "/" + paletteFileName[i]; + } + logger.writeInfo("Write map: " + mapName); if (shapeToRaster(outputShapeFileName, inputField[i], mapCellSize, mapProjection, mapName, paletteName, projectError)) { From ab658bc6fb79591090b26d84711714241f15ab01 Mon Sep 17 00:00:00 2001 From: ftomei Date: Thu, 14 Dec 2023 19:39:26 +0100 Subject: [PATCH 05/14] fix palette --- .../criteriaAggregationVariable.cpp | 7 +- criteriaOutput/criteriaAggregationVariable.h | 2 +- criteriaOutput/criteriaOutputProject.cpp | 66 ++++++++++++------- criteriaOutput/criteriaOutputProject.h | 2 - 4 files changed, 47 insertions(+), 30 deletions(-) diff --git a/criteriaOutput/criteriaAggregationVariable.cpp b/criteriaOutput/criteriaAggregationVariable.cpp index 1250fcdd4..abd1d7329 100644 --- a/criteriaOutput/criteriaAggregationVariable.cpp +++ b/criteriaOutput/criteriaAggregationVariable.cpp @@ -44,6 +44,7 @@ bool CriteriaAggregationVariable::parserAggregationVariable(QString fileName, QS error = "missing output variable"; return false; } + // remove whitespace outputVarName.push_back(items[pos].toUpper().trimmed()); if (outputVarName.isEmpty()) @@ -58,9 +59,10 @@ bool CriteriaAggregationVariable::parserAggregationVariable(QString fileName, QS error = "missing input field (shape)"; return false; } + // remove whitespace - inputField.push_back(items[pos].toUpper().trimmed()); - if (inputField.isEmpty()) + inputFieldName.push_back(items[pos].toUpper().trimmed()); + if (inputFieldName.isEmpty()) { error = "missing input field"; return false; @@ -72,6 +74,7 @@ bool CriteriaAggregationVariable::parserAggregationVariable(QString fileName, QS error = "missing computation"; return false; } + // remove whitespace aggregationType.push_back(items[pos].toUpper().trimmed()); if (aggregationType.isEmpty()) diff --git a/criteriaOutput/criteriaAggregationVariable.h b/criteriaOutput/criteriaAggregationVariable.h index 26e8c87fa..c26a35a07 100644 --- a/criteriaOutput/criteriaAggregationVariable.h +++ b/criteriaOutput/criteriaAggregationVariable.h @@ -10,7 +10,7 @@ { public: QList outputVarName; - QList inputField; + QList inputFieldName; QList aggregationType; CriteriaAggregationVariable(); diff --git a/criteriaOutput/criteriaOutputProject.cpp b/criteriaOutput/criteriaOutputProject.cpp index 861cb4215..ec85098d6 100644 --- a/criteriaOutput/criteriaOutputProject.cpp +++ b/criteriaOutput/criteriaOutputProject.cpp @@ -611,8 +611,8 @@ int CriteriaOutputProject::createMaps() logger.writeInfo("MAPS"); // parser csv file mapListFileName - QList inputField; - QList outputName; + QList inputFieldName; + QList outputFileName; QList paletteFileName; QFile mapList(mapListFileName); if ( !mapList.open(QFile::ReadOnly | QFile::Text) ) @@ -623,51 +623,67 @@ int CriteriaOutputProject::createMaps() else { QTextStream in(&mapList); - //skip header + // skip header QString line = in.readLine(); - while (!in.atEnd()) + while (! in.atEnd()) { line = in.readLine(); QList items = line.split(","); - if (items.size() < REQUIREDMAPLISTCSVINFO) + + if (! mapPalettePath.isEmpty()) { - projectError = "invalid line in map list:\n" + line + "\n" - + "Required input field, output file name, palette file name."; - return ERROR_SETTINGS_MISSINGDATA; + if (items.size() < 3) + { + projectError = "invalid line in map list:\n" + line + "\n" + + "Required: input field name, output file name, palette file name."; + return ERROR_SETTINGS_MISSINGDATA; + } + } + else + { + if (items.size() < 2) + { + projectError = "invalid line in map list:\n" + line + "\n" + + "Required: input field name, output file name."; + return ERROR_SETTINGS_MISSINGDATA; + } } // input field (remove whitespace) - inputField.push_back(items[0].toUpper().trimmed()); - if (inputField.last().isEmpty()) + inputFieldName.push_back(items[0].toUpper().trimmed()); + if ( inputFieldName.last().isEmpty() ) { projectError = "missing shape input field in line:\n" + line; return ERROR_SETTINGS_MISSINGDATA; } - // output file name (remove whitespace) - outputName.push_back(items[1].toUpper().trimmed()); - if (outputName.last().isEmpty()) + // output file (remove whitespace) + outputFileName.push_back(items[1].toUpper().trimmed()); + if ( outputFileName.last().isEmpty() ) { projectError = "missing output map name in line:\n" + line; return ERROR_SETTINGS_MISSINGDATA; } - // palette file name (remove whitespace) - paletteFileName.push_back(items[2].toUpper().trimmed()); - if (paletteFileName.last().isEmpty()) + if (! mapPalettePath.isEmpty()) { - projectError = "missing palette file name in line:\n" + line; - return ERROR_SETTINGS_MISSINGDATA; + // palette file name (remove whitespace) + paletteFileName.push_back(items[2].toUpper().trimmed()); + if ( paletteFileName.last().isEmpty() ) + { + projectError = "missing palette file name in line:\n" + line; + return ERROR_SETTINGS_MISSINGDATA; + } } } } int rasterOK = 0; - for (int i=0; i < inputField.size(); i++) + for (int i=0; i < inputFieldName.size(); i++) { - QString mapName = outputShapeFilePath + "/" + outputName[i]+ "." + mapFormat; + QString mapName = outputShapeFilePath + "/" + outputFileName[i]+ "." + mapFormat; QString paletteName = ""; if (! mapPalettePath.isEmpty()) @@ -676,19 +692,19 @@ int CriteriaOutputProject::createMaps() } logger.writeInfo("Write map: " + mapName); - if (shapeToRaster(outputShapeFileName, inputField[i], mapCellSize, mapProjection, mapName, paletteName, projectError)) + if (shapeToRaster(outputShapeFileName, inputFieldName[i], mapCellSize, mapProjection, mapName, paletteName, projectError)) { rasterOK = rasterOK + 1; } } - if (rasterOK == inputField.size()) + if (rasterOK == inputFieldName.size()) { return CRIT1D_OK; } else { - int nRasterError = inputField.size() - rasterOK; + int nRasterError = inputFieldName.size() - rasterOK; projectError = QString::number(nRasterError) + " invalid raster - " + projectError; return ERROR_MAPS; } @@ -834,13 +850,13 @@ int CriteriaOutputProject::createAggregationFile() if (aggregationVariable.aggregationType[i] == "MAJORITY") { isOk = zonalStatisticsShapeMajority(shapeRef, shapeVal, matrix, vectorNull, - aggregationVariable.inputField[i].toStdString(), + aggregationVariable.inputFieldName[i].toStdString(), aggregationVariable.outputVarName[i].toStdString(), threshold, error); } else { - isOk = zonalStatisticsShape(shapeRef, shapeVal, matrix, vectorNull, aggregationVariable.inputField[i].toStdString(), + isOk = zonalStatisticsShape(shapeRef, shapeVal, matrix, vectorNull, aggregationVariable.inputFieldName[i].toStdString(), aggregationVariable.outputVarName[i].toStdString(), aggregationVariable.aggregationType[i].toStdString(), threshold, error); diff --git a/criteriaOutput/criteriaOutputProject.h b/criteriaOutput/criteriaOutputProject.h index db6010f9b..2eb4c496a 100644 --- a/criteriaOutput/criteriaOutputProject.h +++ b/criteriaOutput/criteriaOutputProject.h @@ -13,8 +13,6 @@ #include "shapeHandler.h" #include "crit3dDate.h" -#define REQUIREDMAPLISTCSVINFO 3 - #define ERROR_MISSINGPARAMETERS -900 #define ERROR_WRONGPARAMETER -901 From 45341f352e1e099ebaaad33f9551cb1b0653534e Mon Sep 17 00:00:00 2001 From: ftomei Date: Fri, 15 Dec 2023 19:04:43 +0100 Subject: [PATCH 06/14] fix check on last climate year --- criteriaOutput/criteriaOutputElaboration.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/criteriaOutput/criteriaOutputElaboration.cpp b/criteriaOutput/criteriaOutputElaboration.cpp index 4e721b302..5242487c5 100644 --- a/criteriaOutput/criteriaOutputElaboration.cpp +++ b/criteriaOutput/criteriaOutputElaboration.cpp @@ -313,7 +313,7 @@ int writeCsvOutputUnit(QString idCase, QString idCropClass, QSqlDatabase& dbData resultVector.clear(); QString varName = outputVariable.varName[i]; QString computation = outputVariable.computation[i]; - if (!computation.isEmpty()) + if (! computation.isEmpty()) { // nrDays is required, because the computation should be done between values into interval referenceDate+-nrDays if (outputVariable.nrDays[i].isEmpty()) @@ -506,10 +506,9 @@ int writeCsvOutputUnit(QString idCase, QString idCropClass, QSqlDatabase& dbData previousFirstDate, previousLastDate, irriRatio, resultVector, errorStr); if (queryResult == ERROR_DB_INCOMPLETE_DATA) { - // only first year can be incomplete, otherwise the comparison is not valid and can be terminated - if (year != climateFirstDate.year()) + // only first and last years can be incomplete, otherwise the comparison is not valid and can be terminated + if (year != climateFirstDate.year() && year != climateLastDate.year()) { - result = NODATA; skip = true; break; } @@ -526,6 +525,7 @@ int writeCsvOutputUnit(QString idCase, QString idCropClass, QSqlDatabase& dbData } year = year+1; } + resultVector.clear(); if (skip) { From 584a020bb6755c888b12450ce80d120daaeeff1a Mon Sep 17 00:00:00 2001 From: lauracosta Date: Wed, 20 Dec 2023 15:47:27 +0100 Subject: [PATCH 07/14] copy lat to meteoTemp --- climate/climate.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/climate/climate.cpp b/climate/climate.cpp index 33eb38bed..8b7e143fa 100644 --- a/climate/climate.cpp +++ b/climate/climate.cpp @@ -4974,6 +4974,7 @@ bool monthlyAggregateDataGrid(Crit3DMeteoGridDbHandler* meteoGridDbHandler, QDat meteoPointTemp->initializeObsDataM(nrMonths, firstDate.month(), firstDate.year()); // copy id to MPTemp meteoPointTemp->id = meteoGridDbHandler->meteoGrid()->meteoPointPointer(row,col)->id; + meteoPointTemp->latitude = meteoGridDbHandler->meteoGrid()->meteoPointPointer(row,col)->latitude; // meteoPointTemp should be init meteoPointTemp->nrObsDataDaysH = 0; meteoPointTemp->nrObsDataDaysD = 0; From 411cd7758b9efd72fcae77808f2ffa7fd6b633ad Mon Sep 17 00:00:00 2001 From: ftomei Date: Wed, 3 Jan 2024 18:34:18 +0100 Subject: [PATCH 08/14] fix set date --- dbMeteoGrid/dbMeteoGrid.cpp | 131 +++++++++++++++--------------------- dbMeteoGrid/dbMeteoGrid.h | 2 +- 2 files changed, 54 insertions(+), 79 deletions(-) diff --git a/dbMeteoGrid/dbMeteoGrid.cpp b/dbMeteoGrid/dbMeteoGrid.cpp index 1f93361f5..5940eb881 100644 --- a/dbMeteoGrid/dbMeteoGrid.cpp +++ b/dbMeteoGrid/dbMeteoGrid.cpp @@ -1440,15 +1440,14 @@ bool Crit3DMeteoGridDbHandler::updateGridDate(QString *myError) return false; } - _lastDailyDate.setDate(1800, 1, 1); - _firstDailyDate.setDate(7800, 12, 31); + QDate noDate = QDate(1800, 1, 1); - _lastHourlyDate.setDate(1800, 1, 1); - _firstHourlyDate.setDate(7800, 12, 31); - - _lastMonthlyDate.setDate(1800, 1, 1); - _firsMonthlytDate.setDate(7800, 12, 31); - QDate temp; + _lastDailyDate = noDate; + _firstDailyDate= noDate; + _lastHourlyDate = noDate; + _firstHourlyDate = noDate; + _lastMonthlyDate = noDate; + _firstMonthlyDate = noDate; QString tableD = _tableDaily.prefix + QString::fromStdString(id) + _tableDaily.postFix; QString tableH = _tableHourly.prefix + QString::fromStdString(id) + _tableHourly.postFix; @@ -1458,14 +1457,13 @@ bool Crit3DMeteoGridDbHandler::updateGridDate(QString *myError) if (_tableDaily.exists) { - QString statement = QString("SELECT MIN(%1) as minDate, MAX(%1) as maxDate FROM `%2`").arg(_tableDaily.fieldTime).arg(tableD); - if( !qry.exec(statement) ) + QString statement = QString("SELECT MIN(%1) as minDate, MAX(%1) as maxDate FROM `%2`").arg(_tableDaily.fieldTime, tableD); + if(! qry.exec(statement) ) { while( qry.lastError().nativeErrorCode() == tableNotFoundError && (col < _gridStructure.header().nrCols-1 || row < _gridStructure.header().nrRows-1)) { - if ( col < _gridStructure.header().nrCols-1) { col = col + 1; @@ -1482,9 +1480,8 @@ bool Crit3DMeteoGridDbHandler::updateGridDate(QString *myError) return false; } tableD = _tableDaily.prefix + QString::fromStdString(id) + _tableDaily.postFix; - tableH = _tableHourly.prefix + QString::fromStdString(id) + _tableHourly.postFix; - statement = QString("SELECT MIN(%1) as minDate, MAX(%1) as maxDate FROM `%2`").arg(_tableDaily.fieldTime).arg(tableD); + statement = QString("SELECT MIN(%1) as minDate, MAX(%1) as maxDate FROM `%2`").arg(_tableDaily.fieldTime, tableD); qry.exec(statement); } } @@ -1498,16 +1495,15 @@ bool Crit3DMeteoGridDbHandler::updateGridDate(QString *myError) { if (qry.next()) { + QDate temp; if (getValue(qry.value("minDate"), &temp)) { - if (temp < _firstDailyDate ) - _firstDailyDate = temp; + _firstDailyDate = temp; } if (getValue(qry.value("maxDate"), &temp)) { - if (temp > _lastDailyDate) - _lastDailyDate = temp; + _lastDailyDate = temp; } } else @@ -1520,12 +1516,12 @@ bool Crit3DMeteoGridDbHandler::updateGridDate(QString *myError) if (_tableHourly.exists) { - QString statement = QString("SELECT MIN(%1) as minDate, MAX(%1) as maxDate FROM `%2`").arg(_tableHourly.fieldTime).arg(tableH); - if( !qry.exec(statement) ) + tableH = _tableHourly.prefix + QString::fromStdString(id) + _tableHourly.postFix; + QString statement = QString("SELECT MIN(%1) as minDate, MAX(%1) as maxDate FROM `%2`").arg(_tableHourly.fieldTime, tableH); + if(! qry.exec(statement) ) { while( qry.lastError().nativeErrorCode() == tableNotFoundError) { - if ( col < _gridStructure.header().nrCols-1) { col = col + 1; @@ -1536,7 +1532,7 @@ bool Crit3DMeteoGridDbHandler::updateGridDate(QString *myError) col = 0; } - if (!_meteoGrid->findFirstActiveMeteoPoint(&id, &row, &col)) + if (! _meteoGrid->findFirstActiveMeteoPoint(&id, &row, &col)) { *myError = "active cell not found"; return false; @@ -1544,7 +1540,7 @@ bool Crit3DMeteoGridDbHandler::updateGridDate(QString *myError) tableH = _tableHourly.prefix + QString::fromStdString(id) + _tableHourly.postFix; - statement = QString("SELECT MIN(%1) as minDate, MAX(%1) as maxDate FROM `%2`").arg(_tableHourly.fieldTime).arg(tableH); + statement = QString("SELECT MIN(%1) as minDate, MAX(%1) as maxDate FROM `%2`").arg(_tableHourly.fieldTime, tableH); qry.exec(statement); } } @@ -1558,16 +1554,16 @@ bool Crit3DMeteoGridDbHandler::updateGridDate(QString *myError) { if (qry.next()) { + QDate temp; if (getValue(qry.value("minDate"), &temp)) { - if (temp < _firstHourlyDate) - _firstHourlyDate = temp; + _firstHourlyDate = temp; } if (getValue(qry.value("maxDate"), &temp)) { - if (temp > _lastHourlyDate) - _lastHourlyDate = temp; + // the last hourly day is always incomplete, there is just 00.00 value + _lastHourlyDate = temp.addDays(-1); } } else @@ -1580,14 +1576,12 @@ bool Crit3DMeteoGridDbHandler::updateGridDate(QString *myError) if (_tableMonthly.exists) { - QString table = "MonthlyData"; - QString statement = QString("CREATE TABLE IF NOT EXISTS `%1`" "(PragaYear smallint(4) UNSIGNED, PragaMonth tinyint(2) UNSIGNED, PointCode CHAR(5), " "VariableCode tinyint(3) UNSIGNED, Value float(6,1), PRIMARY KEY(PragaYear,PragaMonth,PointCode,VariableCode))").arg(table); - if( !qry.exec(statement) ) + if(! qry.exec(statement) ) { *myError = qry.lastError().text(); return false; @@ -1597,7 +1591,7 @@ bool Crit3DMeteoGridDbHandler::updateGridDate(QString *myError) int maxPragaYear; int minPragaMonth; int maxPragaMonth; - statement = QString("SELECT MIN(%1) as minYear, MAX(%1) as maxYear FROM `%2`").arg("PragaYear").arg(tableM); + statement = QString("SELECT MIN(%1) as minYear, MAX(%1) as maxYear FROM `%2`").arg("PragaYear", tableM); qry.exec(statement); if ( qry.lastError().type() != QSqlError::NoError ) @@ -1618,7 +1612,7 @@ bool Crit3DMeteoGridDbHandler::updateGridDate(QString *myError) return false; } } - statement = QString("SELECT MIN(%1) as minMonth FROM `%2` WHERE PragaYear=%3 ").arg("PragaMonth").arg(tableM).arg(minPragaYear); + statement = QString("SELECT MIN(%1) as minMonth FROM `%2` WHERE PragaYear=%3 ").arg("PragaMonth", tableM).arg(minPragaYear); qry.exec(statement); if ( qry.lastError().type() != QSqlError::NoError ) @@ -1639,7 +1633,7 @@ bool Crit3DMeteoGridDbHandler::updateGridDate(QString *myError) } } - statement = QString("SELECT MAX(%1) as maxMonth FROM `%2` WHERE PragaYear=%3 ").arg("PragaMonth").arg(tableM).arg(maxPragaYear); + statement = QString("SELECT MAX(%1) as maxMonth FROM `%2` WHERE PragaYear=%3 ").arg("PragaMonth", tableM).arg(maxPragaYear); qry.exec(statement); if ( qry.lastError().type() != QSqlError::NoError ) @@ -1664,60 +1658,41 @@ bool Crit3DMeteoGridDbHandler::updateGridDate(QString *myError) minPragaMonth != NODATA && maxPragaMonth != NODATA) { _lastMonthlyDate.setDate(maxPragaYear, maxPragaMonth, 1); - _firsMonthlytDate.setDate(minPragaYear, minPragaMonth, 1); + _firstMonthlyDate.setDate(minPragaYear, minPragaMonth, 1); } } - // the last hourly day is always incomplete, there is just 00.00 value - if (_lastHourlyDate != QDate(1800,1,1)) _lastHourlyDate = _lastHourlyDate.addDays(-1); - - if (_firstDailyDate < _firstHourlyDate) + // FIRST DATE + _firstDate = noDate; + if (_firstDailyDate != noDate) { - if (_tableMonthly.exists && _firsMonthlytDate != QDate(7800, 12, 31) && _firsMonthlytDate < _firstDailyDate) - { - _firstDate = _firsMonthlytDate; - } - else - { - _firstDate = _firstDailyDate; - } + _firstDate = _firstDailyDate; } - else + if (_firstHourlyDate != noDate && (_firstDate == noDate || _firstHourlyDate < _firstDate)) { - if (_tableMonthly.exists && _firsMonthlytDate != QDate(7800, 12, 31) && _firsMonthlytDate < _firstHourlyDate) - { - _firstDate = _firsMonthlytDate; - } - else - { - _firstDate = _firstHourlyDate; - } + _firstDate = _firstHourlyDate; + } + if (_firstMonthlyDate != noDate && (_firstDate == noDate || _firstMonthlyDate < _firstDate)) + { + _firstDate = _firstMonthlyDate; } - if (_lastDailyDate > _lastHourlyDate) + // LAST DATE + _lastDate = noDate; + if (_lastDailyDate != noDate) { - if (_tableMonthly.exists && _lastMonthlyDate != QDate(1800, 1, 1) && _lastMonthlyDate > _lastDailyDate) - { - _lastDate = _lastMonthlyDate; - } - else - { - _lastDate = _lastDailyDate; - } + _lastDate = _lastDailyDate; } - else + if (_lastHourlyDate != noDate && (_lastDate == noDate || _lastHourlyDate > _lastDate)) { - if (_tableMonthly.exists && _lastMonthlyDate != QDate(1800, 1, 1) && _lastMonthlyDate > _lastHourlyDate) - { - _lastDate = _lastMonthlyDate; - } - else - { - _lastDate = _lastHourlyDate; - } + _lastDate = _lastHourlyDate; + } + if (_lastMonthlyDate != noDate && (_lastDate == noDate || _lastMonthlyDate > _lastDate)) + { + _lastDate = _lastMonthlyDate; } - if (_firstDate > _lastDate) + if (_firstDate == noDate || _lastDate == noDate) { *myError = "Missing data!"; return false; @@ -3415,7 +3390,7 @@ bool Crit3DMeteoGridDbHandler::saveCellCurrentGridHourlyFF(QString& errorStr, QS QDate Crit3DMeteoGridDbHandler::getFirstDailyDate() const { - if (_firstDailyDate.year() == 7800) + if (_firstDailyDate.year() == 1800) { return QDate(); // return null date } @@ -3433,7 +3408,7 @@ QDate Crit3DMeteoGridDbHandler::getLastDailyDate() const QDate Crit3DMeteoGridDbHandler::getFirstHourlyDate() const { - if (_firstHourlyDate.year() == 7800) + if (_firstHourlyDate.year() == 1800) { return QDate(); // return null date } @@ -3451,11 +3426,11 @@ QDate Crit3DMeteoGridDbHandler::getLastHourlyDate() const QDate Crit3DMeteoGridDbHandler::getFirsMonthlytDate() const { - if (_firsMonthlytDate.year() == 7800) + if (_firstMonthlyDate.year() == 1800) { return QDate(); // return null date } - return _firsMonthlytDate; + return _firstMonthlyDate; } QDate Crit3DMeteoGridDbHandler::getLastMonthlyDate() const @@ -3471,7 +3446,7 @@ bool Crit3DMeteoGridDbHandler::idDailyList(QString *myError, QList* idM { QSqlQuery qry(_db); - QString statement = QString("SHOW TABLES LIKE '%1%%2'").arg(_tableDaily.prefix).arg(_tableDaily.postFix); + QString statement = QString("SHOW TABLES LIKE '%1%%2'").arg(_tableDaily.prefix, _tableDaily.postFix); if( !qry.exec(statement) ) { *myError = qry.lastError().text(); diff --git a/dbMeteoGrid/dbMeteoGrid.h b/dbMeteoGrid/dbMeteoGrid.h index 8bbf6fb0b..0b71833bb 100644 --- a/dbMeteoGrid/dbMeteoGrid.h +++ b/dbMeteoGrid/dbMeteoGrid.h @@ -184,7 +184,7 @@ QDate _lastDailyDate; QDate _firstHourlyDate; QDate _lastHourlyDate; - QDate _firsMonthlytDate; + QDate _firstMonthlyDate; QDate _lastMonthlyDate; TXMLTable _tableDaily; From 1ecf17463841597cc9f14068f1113eb9aa4b1921 Mon Sep 17 00:00:00 2001 From: ftomei Date: Wed, 3 Jan 2024 19:09:26 +0100 Subject: [PATCH 09/14] fix set date --- dbMeteoGrid/dbMeteoGrid.cpp | 67 +++++++++++++++++++++++++------------ dbMeteoGrid/dbMeteoGrid.h | 6 ++-- 2 files changed, 48 insertions(+), 25 deletions(-) diff --git a/dbMeteoGrid/dbMeteoGrid.cpp b/dbMeteoGrid/dbMeteoGrid.cpp index 5940eb881..e5c752a5b 100644 --- a/dbMeteoGrid/dbMeteoGrid.cpp +++ b/dbMeteoGrid/dbMeteoGrid.cpp @@ -1702,9 +1702,9 @@ bool Crit3DMeteoGridDbHandler::updateGridDate(QString *myError) } -bool Crit3DMeteoGridDbHandler::loadGridDailyData(QString &errorStr, const QString &meteoPoint, const QDate &first, const QDate &last) +bool Crit3DMeteoGridDbHandler::loadGridDailyData(QString &myError, const QString &meteoPoint, const QDate &firstDate, const QDate &lastDate) { - errorStr = ""; + myError = ""; QSqlQuery qry(_db); QString tableD = _tableDaily.prefix + meteoPoint + _tableDaily.postFix; @@ -1712,28 +1712,34 @@ bool Crit3DMeteoGridDbHandler::loadGridDailyData(QString &errorStr, const QStrin unsigned row, col; if ( !_meteoGrid->findMeteoPointFromId(&row, &col, meteoPoint.toStdString()) ) { - errorStr = "Missing MeteoPoint id"; + myError = "Missing MeteoPoint id"; return false; } - int numberOfDays = first.daysTo(last) + 1; - _meteoGrid->meteoPointPointer(row, col)->initializeObsDataD(numberOfDays, getCrit3DDate(first)); + int numberOfDays = firstDate.daysTo(lastDate) + 1; + _meteoGrid->meteoPointPointer(row, col)->initializeObsDataD(numberOfDays, getCrit3DDate(firstDate)); + + if (firstDate > _lastDailyDate || lastDate < _firstDailyDate) + { + myError = "missing data"; + return false; + } QString statement; - if (first == last) + if (firstDate == lastDate) { - statement = QString("SELECT * FROM `%1` WHERE %2 = '%3'").arg(tableD, _tableDaily.fieldTime, first.toString("yyyy-MM-dd")); + statement = QString("SELECT * FROM `%1` WHERE %2 = '%3'").arg(tableD, _tableDaily.fieldTime, firstDate.toString("yyyy-MM-dd")); } else { statement = QString("SELECT * FROM `%1` WHERE %2 >= '%3' AND %2 <= '%4' ORDER BY %2") - .arg(tableD, _tableDaily.fieldTime, first.toString("yyyy-MM-dd"), last.toString("yyyy-MM-dd")); + .arg(tableD, _tableDaily.fieldTime, firstDate.toString("yyyy-MM-dd"), lastDate.toString("yyyy-MM-dd")); } qry.prepare(statement); if(! qry.exec()) { - errorStr = qry.lastError().text(); + myError = qry.lastError().text(); return false; } @@ -1745,13 +1751,13 @@ bool Crit3DMeteoGridDbHandler::loadGridDailyData(QString &errorStr, const QStrin { if (! getValue(qry.value(_tableDaily.fieldTime), &date)) { - errorStr = "Missing " + _tableDaily.fieldTime; + myError = "Missing " + _tableDaily.fieldTime; return false; } if (! getValue(qry.value("VariableCode"), &varCode)) { - errorStr = "Missing VariableCode"; + myError = "Missing VariableCode"; return false; } @@ -1763,7 +1769,10 @@ bool Crit3DMeteoGridDbHandler::loadGridDailyData(QString &errorStr, const QStrin meteoVariable variable = getDailyVarEnum(varCode); if (! _meteoGrid->meteoPointPointer(row, col)->setMeteoPointValueD(getCrit3DDate(date), variable, value)) + { + myError = "Error in setMeteoPointValueD"; return false; + } } return true; @@ -1893,7 +1902,7 @@ bool Crit3DMeteoGridDbHandler::loadGridDailyDataFixedFields(QString &myError, QS } -bool Crit3DMeteoGridDbHandler::loadGridHourlyData(QString &myError, QString meteoPoint, QDateTime first, QDateTime last) +bool Crit3DMeteoGridDbHandler::loadGridHourlyData(QString &myError, QString meteoPoint, QDateTime firstDate, QDateTime lastDate) { myError = ""; @@ -1912,11 +1921,18 @@ bool Crit3DMeteoGridDbHandler::loadGridHourlyData(QString &myError, QString mete return false; } - int numberOfDays = first.date().daysTo(last.date()); - _meteoGrid->meteoPointPointer(row, col)->initializeObsDataH(1, numberOfDays, getCrit3DDate(first.date())); + int numberOfDays = firstDate.date().daysTo(lastDate.date()); + _meteoGrid->meteoPointPointer(row, col)->initializeObsDataH(1, numberOfDays, getCrit3DDate(firstDate.date())); + + if (firstDate.date() > _lastHourlyDate || lastDate.date() < _firstHourlyDate) + { + myError = "missing data"; + return false; + } QString statement = QString("SELECT * FROM `%1` WHERE `%2` >= '%3' AND `%2` <= '%4' ORDER BY `%2`") - .arg(tableH).arg(_tableHourly.fieldTime).arg(first.toString("yyyy-MM-dd hh:mm")).arg(last.toString("yyyy-MM-dd hh:mm")); + .arg(tableH, _tableHourly.fieldTime, firstDate.toString("yyyy-MM-dd hh:mm"), + lastDate.toString("yyyy-MM-dd hh:mm") ); if( !qry.exec(statement) ) { @@ -1953,6 +1969,7 @@ bool Crit3DMeteoGridDbHandler::loadGridHourlyData(QString &myError, QString mete return true; } + bool Crit3DMeteoGridDbHandler::loadGridHourlyDataEnsemble(QString &myError, QString meteoPoint, int memberNr, QDateTime first, QDateTime last) { myError = ""; @@ -2078,7 +2095,7 @@ bool Crit3DMeteoGridDbHandler::loadGridHourlyDataFixedFields(QString &myError, Q return true; } -bool Crit3DMeteoGridDbHandler::loadGridMonthlyData(QString &myError, QString meteoPoint, QDate first, QDate last) +bool Crit3DMeteoGridDbHandler::loadGridMonthlyData(QString &myError, QString meteoPoint, QDate firstDate, QDate lastDate) { myError = ""; @@ -2094,8 +2111,8 @@ bool Crit3DMeteoGridDbHandler::loadGridMonthlyData(QString &myError, QString met unsigned col; // set day to 1 to better comparison - first.setDate(first.year(), first.month(), 1); - last.setDate(last.year(), last.month(), 1); + firstDate.setDate(firstDate.year(), firstDate.month(), 1); + lastDate.setDate(lastDate.year(), lastDate.month(), 1); if (!_meteoGrid->findMeteoPointFromId(&row, &col, meteoPoint.toStdString()) ) { @@ -2103,10 +2120,16 @@ bool Crit3DMeteoGridDbHandler::loadGridMonthlyData(QString &myError, QString met return false; } - int numberOfMonths = (last.year()-first.year())*12 + last.month() - (first.month()-1); - _meteoGrid->meteoPointPointer(row,col)->initializeObsDataM(numberOfMonths, first.month(), first.year()); + int numberOfMonths = (lastDate.year()-firstDate.year())*12 + lastDate.month() - (firstDate.month()-1); + _meteoGrid->meteoPointPointer(row,col)->initializeObsDataM(numberOfMonths, firstDate.month(), firstDate.year()); + + if (firstDate > _lastMonthlyDate || lastDate < _firstMonthlyDate) + { + myError = "missing data"; + return false; + } - QString statement = QString("SELECT * FROM `%1` WHERE `PragaYear` BETWEEN %2 AND %3 AND PointCode = '%4' ORDER BY `PragaYear`").arg(table).arg(first.year()).arg(last.year()).arg(meteoPoint); + QString statement = QString("SELECT * FROM `%1` WHERE `PragaYear` BETWEEN %2 AND %3 AND PointCode = '%4' ORDER BY `PragaYear`").arg(table).arg(firstDate.year()).arg(lastDate.year()).arg(meteoPoint); if( !qry.exec(statement) ) { myError = qry.lastError().text(); @@ -2129,7 +2152,7 @@ bool Crit3DMeteoGridDbHandler::loadGridMonthlyData(QString &myError, QString met } date.setDate(year,month, 1); - if (date < first || date > last) + if (date < firstDate || date > lastDate) { continue; } diff --git a/dbMeteoGrid/dbMeteoGrid.h b/dbMeteoGrid/dbMeteoGrid.h index 0b71833bb..76de1594d 100644 --- a/dbMeteoGrid/dbMeteoGrid.h +++ b/dbMeteoGrid/dbMeteoGrid.h @@ -112,13 +112,13 @@ bool loadIdMeteoProperties(QString *myError, QString idMeteo); bool updateGridDate(QString *myError); - bool loadGridDailyData(QString &errorStr, const QString &meteoPoint, const QDate &first, const QDate &last); + bool loadGridDailyData(QString &myError, const QString &meteoPoint, const QDate &firstDate, const QDate &lastDate); bool loadGridDailyDataFixedFields(QString &myError, QString meteoPoint, QDate first, QDate last); bool loadGridDailyDataEnsemble(QString &myError, QString meteoPoint, int memberNr, QDate first, QDate last); - bool loadGridHourlyData(QString &myError, QString meteoPoint, QDateTime first, QDateTime last); + bool loadGridHourlyData(QString &myError, QString meteoPoint, QDateTime firstDate, QDateTime lastDate); bool loadGridHourlyDataFixedFields(QString &myError, QString meteoPoint, QDateTime first, QDateTime last); bool loadGridHourlyDataEnsemble(QString &myError, QString meteoPoint, int memberNr, QDateTime first, QDateTime last); - bool loadGridMonthlyData(QString &myError, QString meteoPoint, QDate first, QDate last); + bool loadGridMonthlyData(QString &myError, QString meteoPoint, QDate firstDate, QDate lastDate); std::vector loadGridDailyVar(QString *myError, QString meteoPoint, meteoVariable variable, QDate first, QDate last, QDate *firstDateDB); std::vector loadGridDailyVarFixedFields(QString *myError, QString meteoPoint, meteoVariable variable, QDate first, QDate last, QDate* firstDateDB); From 2b2efcb9149661b20ed1b6ddfefc3bc9f98b43bc Mon Sep 17 00:00:00 2001 From: ftomei Date: Wed, 3 Jan 2024 19:28:08 +0100 Subject: [PATCH 10/14] blanck --- pragaProject/pragaProject.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pragaProject/pragaProject.cpp b/pragaProject/pragaProject.cpp index 5d32bc411..9a73c6ec5 100644 --- a/pragaProject/pragaProject.cpp +++ b/pragaProject/pragaProject.cpp @@ -2437,6 +2437,7 @@ bool PragaProject::interpolationMeteoGrid(meteoVariable myVar, frequencyType myF return true; } + bool PragaProject::dbMeteoPointDataCount(QDate myFirstDate, QDate myLastDate, meteoVariable myVar, QString dataset, std::vector &myCounter) { frequencyType myFreq = getVarFrequency(myVar); @@ -2496,11 +2497,10 @@ bool PragaProject::dbMeteoPointDataCount(QDate myFirstDate, QDate myLastDate, me if (modality == MODE_GUI) closeProgressBar(); - - return true; } + bool PragaProject::dbMeteoGridMissingData(QDate myFirstDate, QDate myLastDate, meteoVariable myVar, QList &dateList, QList &idList) { frequencyType myFreq = getVarFrequency(myVar); @@ -2767,6 +2767,7 @@ void PragaProject::deleteSynchWidget() synchronicityWidget = nullptr; } + void PragaProject::showPointStatisticsWidgetGrid(std::string id) { logInfoGUI("Loading data..."); From 132e447ffb0961c8b3ce1b7f216699c55902c60b Mon Sep 17 00:00:00 2001 From: ftomei Date: Thu, 4 Jan 2024 15:55:44 +0100 Subject: [PATCH 11/14] fix interpolate and save grid --- dbMeteoGrid/dbMeteoGrid.cpp | 35 ++++++++++++++++++----------------- dbMeteoGrid/dbMeteoGrid.h | 2 +- pragaProject/pragaProject.cpp | 3 +++ project/project.cpp | 8 ++++---- 4 files changed, 26 insertions(+), 22 deletions(-) diff --git a/dbMeteoGrid/dbMeteoGrid.cpp b/dbMeteoGrid/dbMeteoGrid.cpp index e5c752a5b..b02c54154 100644 --- a/dbMeteoGrid/dbMeteoGrid.cpp +++ b/dbMeteoGrid/dbMeteoGrid.cpp @@ -1420,12 +1420,12 @@ bool Crit3DMeteoGridDbHandler::loadIdMeteoProperties(QString *myError, QString i } -bool Crit3DMeteoGridDbHandler::updateGridDate(QString *myError) +bool Crit3DMeteoGridDbHandler::updateMeteoGridDate(QString &myError) { QList tableList = _db.tables(QSql::Tables); if (tableList.size() <= 1) { - *myError = "No data."; + myError = "No data."; return false; } @@ -1436,7 +1436,7 @@ bool Crit3DMeteoGridDbHandler::updateGridDate(QString *myError) if (!_meteoGrid->findFirstActiveMeteoPoint(&id, &row, &col)) { - *myError = "No active cells."; + myError = "No active cells."; return false; } @@ -1476,7 +1476,7 @@ bool Crit3DMeteoGridDbHandler::updateGridDate(QString *myError) if (!_meteoGrid->findFirstActiveMeteoPoint(&id, &row, &col)) { - *myError = "active cell not found"; + myError = "active cell not found"; return false; } tableD = _tableDaily.prefix + QString::fromStdString(id) + _tableDaily.postFix; @@ -1488,7 +1488,7 @@ bool Crit3DMeteoGridDbHandler::updateGridDate(QString *myError) if ( qry.lastError().type() != QSqlError::NoError ) { - *myError = qry.lastError().text(); + myError = qry.lastError().text(); return false; } else @@ -1508,7 +1508,7 @@ bool Crit3DMeteoGridDbHandler::updateGridDate(QString *myError) } else { - *myError = "Daily time field not found: " + _tableDaily.fieldTime; + myError = "Daily time field not found: " + _tableDaily.fieldTime; return false; } } @@ -1534,7 +1534,7 @@ bool Crit3DMeteoGridDbHandler::updateGridDate(QString *myError) if (! _meteoGrid->findFirstActiveMeteoPoint(&id, &row, &col)) { - *myError = "active cell not found"; + myError = "active cell not found"; return false; } @@ -1547,7 +1547,7 @@ bool Crit3DMeteoGridDbHandler::updateGridDate(QString *myError) if ( qry.lastError().type() != QSqlError::NoError && qry.lastError().nativeErrorCode() != tableNotFoundError) { - *myError = qry.lastError().text(); + myError = qry.lastError().text(); return false; } else @@ -1568,7 +1568,7 @@ bool Crit3DMeteoGridDbHandler::updateGridDate(QString *myError) } else { - *myError = "Hourly time field not found: " + _tableHourly.fieldTime; + myError = "Hourly time field not found: " + _tableHourly.fieldTime; return false; } } @@ -1583,7 +1583,7 @@ bool Crit3DMeteoGridDbHandler::updateGridDate(QString *myError) if(! qry.exec(statement) ) { - *myError = qry.lastError().text(); + myError = qry.lastError().text(); return false; } @@ -1596,7 +1596,7 @@ bool Crit3DMeteoGridDbHandler::updateGridDate(QString *myError) if ( qry.lastError().type() != QSqlError::NoError ) { - *myError = qry.lastError().text(); + myError = qry.lastError().text(); return false; } else @@ -1608,7 +1608,7 @@ bool Crit3DMeteoGridDbHandler::updateGridDate(QString *myError) } else { - *myError = "PragaYear field not found"; + myError = "PragaYear field not found"; return false; } } @@ -1617,7 +1617,7 @@ bool Crit3DMeteoGridDbHandler::updateGridDate(QString *myError) if ( qry.lastError().type() != QSqlError::NoError ) { - *myError = qry.lastError().text(); + myError = qry.lastError().text(); return false; } else @@ -1628,7 +1628,7 @@ bool Crit3DMeteoGridDbHandler::updateGridDate(QString *myError) } else { - *myError = "PragaMonth field not found"; + myError = "PragaMonth field not found"; return false; } } @@ -1638,7 +1638,7 @@ bool Crit3DMeteoGridDbHandler::updateGridDate(QString *myError) if ( qry.lastError().type() != QSqlError::NoError ) { - *myError = qry.lastError().text(); + myError = qry.lastError().text(); return false; } else @@ -1649,7 +1649,7 @@ bool Crit3DMeteoGridDbHandler::updateGridDate(QString *myError) } else { - *myError = "PragaMonth field not found"; + myError = "PragaMonth field not found"; return false; } } @@ -1694,7 +1694,7 @@ bool Crit3DMeteoGridDbHandler::updateGridDate(QString *myError) if (_firstDate == noDate || _lastDate == noDate) { - *myError = "Missing data!"; + myError = "Missing data."; return false; } @@ -3128,6 +3128,7 @@ bool Crit3DMeteoGridDbHandler::saveGridData(QString *myError, QDateTime firstTim return true; } + bool Crit3DMeteoGridDbHandler::saveGridHourlyData(QString *myError, QDateTime firstDate, QDateTime lastDate, QList meteoVariableList) { std::string id; diff --git a/dbMeteoGrid/dbMeteoGrid.h b/dbMeteoGrid/dbMeteoGrid.h index 76de1594d..4e6fb9ab5 100644 --- a/dbMeteoGrid/dbMeteoGrid.h +++ b/dbMeteoGrid/dbMeteoGrid.h @@ -110,7 +110,7 @@ bool newCellProperties(QString *myError); bool writeCellProperties(QString *myError, int nRow, int nCol); bool loadIdMeteoProperties(QString *myError, QString idMeteo); - bool updateGridDate(QString *myError); + bool updateMeteoGridDate(QString &myError); bool loadGridDailyData(QString &myError, const QString &meteoPoint, const QDate &firstDate, const QDate &lastDate); bool loadGridDailyDataFixedFields(QString &myError, QString meteoPoint, QDate first, QDate last); diff --git a/pragaProject/pragaProject.cpp b/pragaProject/pragaProject.cpp index 5d32bc411..5a1de8e87 100644 --- a/pragaProject/pragaProject.cpp +++ b/pragaProject/pragaProject.cpp @@ -2245,6 +2245,9 @@ bool PragaProject::interpolationMeteoGridPeriod(QDate dateIni, QDate dateFin, QL if (nrDaysLoading == NODATA) nrDaysLoading = dateIni.daysTo(dateFin)+1; + if (nrDaysSaving == NODATA || nrDaysSaving > nrDaysLoading) + nrDaysSaving = nrDaysLoading; + while (myDate <= dateFin) { countDaysSaving++; diff --git a/project/project.cpp b/project/project.cpp index 958122551..ef03a51e9 100644 --- a/project/project.cpp +++ b/project/project.cpp @@ -1306,9 +1306,9 @@ bool Project::loadMeteoGridDB(QString xmlName) if (! this->meteoGridDbHandler->meteoGrid()->createRasterGrid()) return false; - if (!meteoGridDbHandler->updateGridDate(&errorString)) + if (!meteoGridDbHandler->updateMeteoGridDate(errorString)) { - logInfoGUI("updateGridDate: " + errorString); + logInfoGUI("Error in updateMeteoGridDate: " + errorString); } if (loadGridDataAtStart || ! meteoPointsLoaded) @@ -1345,9 +1345,9 @@ bool Project::newMeteoGridDB(QString xmlName) if (! this->meteoGridDbHandler->meteoGrid()->createRasterGrid()) return false; - if (!meteoGridDbHandler->updateGridDate(&errorString)) + if (!meteoGridDbHandler->updateMeteoGridDate(errorString)) { - logInfoGUI("updateGridDate: " + errorString); + logInfoGUI("Error in updateMeteoGridDate: " + errorString); } if (loadGridDataAtStart || ! meteoPointsLoaded) From 328abb1ab20ca570f3d3fb8e287e80fe0a00d63f Mon Sep 17 00:00:00 2001 From: ftomei Date: Thu, 4 Jan 2024 16:22:42 +0100 Subject: [PATCH 12/14] fix warnings --- climate/climate.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/climate/climate.cpp b/climate/climate.cpp index 8b7e143fa..1ed4aef04 100644 --- a/climate/climate.cpp +++ b/climate/climate.cpp @@ -1835,12 +1835,11 @@ bool elaborateDailyAggrVarFromDailyFromStartDate(meteoVariable myVar, Crit3DMete return true; else return false; - } + bool aggregatedHourlyToDaily(meteoVariable myVar, Crit3DMeteoPoint* meteoPoint, Crit3DDate dateIni, Crit3DDate dateFin, Crit3DMeteoSettings *meteoSettings) { - Crit3DDate date; std::vector values; float value, dailyValue; @@ -5009,13 +5008,12 @@ bool monthlyAggregateDataGrid(Crit3DMeteoGridDbHandler* meteoGridDbHandler, QDat return dataSaved; } + int computeAnnualSeriesOnPointFromDaily(QString *myError, Crit3DMeteoPointsDbHandler* meteoPointsDbHandler, Crit3DMeteoGridDbHandler* meteoGridDbHandler, Crit3DMeteoPoint* meteoPointTemp, Crit3DClimate* clima, bool isMeteoGrid, bool isAnomaly, Crit3DMeteoSettings* meteoSettings, std::vector &outputValues, bool dataAlreadyLoaded) { int validYears = 0; - meteoComputation elabMeteoComp = getMeteoCompFromString(MapMeteoComputation, clima->elab1().toStdString()); - if (clima->param1IsClimate()) { clima->param1(); @@ -5289,11 +5287,10 @@ void computeClimateOnDailyData(Crit3DMeteoPoint meteoPoint, meteoVariable var, Q } } + void setMpValues(Crit3DMeteoPoint meteoPointGet, Crit3DMeteoPoint* meteoPointSet, QDate myDate, meteoVariable myVar, Crit3DMeteoSettings* meteoSettings) { - bool automaticETP = meteoSettings->getAutomaticET0HS(); - bool automaticTmed = meteoSettings->getAutomaticTavg(); Crit3DQuality qualityCheck; switch(myVar) @@ -5407,9 +5404,9 @@ void setMpValues(Crit3DMeteoPoint meteoPointGet, Crit3DMeteoPoint* meteoPointSet break; } } - } + meteoComputation getMeteoCompFromString(std::map map, std::string value) { From 47c9908af242e06b5c04888d5ff2ff59089fe4bb Mon Sep 17 00:00:00 2001 From: ftomei Date: Thu, 4 Jan 2024 17:06:52 +0100 Subject: [PATCH 13/14] rename pragaStart --- project/project.cpp | 2 +- project/project.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/project/project.cpp b/project/project.cpp index ef03a51e9..b262434e4 100644 --- a/project/project.cpp +++ b/project/project.cpp @@ -3012,7 +3012,7 @@ bool Project::createDefaultProject(QString fileName) } -bool Project::start(QString appPath) +bool Project::pragaStart(QString appPath) { if (appPath.right(1) != "/") appPath += "/"; setApplicationPath(appPath); diff --git a/project/project.h b/project/project.h index 5f312fe16..25627ad8f 100644 --- a/project/project.h +++ b/project/project.h @@ -159,7 +159,7 @@ void saveRadiationParameters(); void saveProxies(); - bool start(QString appPath); + bool pragaStart(QString appPath); bool loadProject(); bool loadProjectSettings(QString settingsFileName); bool loadParameters(QString parametersFileName); From c39da3cf4e4154d3a0046ceca85e22bfdf46f183 Mon Sep 17 00:00:00 2001 From: ftomei Date: Thu, 4 Jan 2024 17:13:26 +0100 Subject: [PATCH 14/14] rename start --- project/project.cpp | 2 +- project/project.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/project/project.cpp b/project/project.cpp index b262434e4..ef03a51e9 100644 --- a/project/project.cpp +++ b/project/project.cpp @@ -3012,7 +3012,7 @@ bool Project::createDefaultProject(QString fileName) } -bool Project::pragaStart(QString appPath) +bool Project::start(QString appPath) { if (appPath.right(1) != "/") appPath += "/"; setApplicationPath(appPath); diff --git a/project/project.h b/project/project.h index 25627ad8f..5f312fe16 100644 --- a/project/project.h +++ b/project/project.h @@ -159,7 +159,7 @@ void saveRadiationParameters(); void saveProxies(); - bool pragaStart(QString appPath); + bool start(QString appPath); bool loadProject(); bool loadProjectSettings(QString settingsFileName); bool loadParameters(QString parametersFileName);