Skip to content

Commit

Permalink
hourly elaboration
Browse files Browse the repository at this point in the history
  • Loading branch information
ftomei committed Jan 2, 2025
1 parent 94ec841 commit 2aa10e5
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 114 deletions.
13 changes: 8 additions & 5 deletions agrolib/climate/climate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -897,6 +897,7 @@ float loadHourlyVarSeries_SaveOutput(Crit3DMeteoPointsDbHandler *meteoPointsDbHa
int nrValidValues = 0;

// fills the missing initial output data
firstDateTimeDB.setTimeSpec(Qt::UTC);
int nrMissingHours = firstTime.secsTo(firstDateTimeDB) / 3600;
for (int i = 1; i <= nrMissingHours; i++)
{
Expand All @@ -919,7 +920,8 @@ float loadHourlyVarSeries_SaveOutput(Crit3DMeteoPointsDbHandler *meteoPointsDbHa
}

// fills the missing final output data
QDateTime lastDateTimeDB = firstDateTimeDB.addSecs(hourlyValues.size() * 3600);
int nrDataHours = int(hourlyValues.size()) -1;
QDateTime lastDateTimeDB = firstDateTimeDB.addSecs(nrDataHours * 3600);
nrMissingHours = lastDateTimeDB.secsTo(lastTime) / 3600;
for (int i = 1; i <= nrMissingHours; i++)
{
Expand Down Expand Up @@ -1074,6 +1076,7 @@ float loadHourlyVarSeries(Crit3DMeteoPointsDbHandler* meteoPointsDbHandler,
}

QDateTime currentDateTime = firstDateTimeDB;
currentDateTime.setTimeSpec(Qt::UTC);
for (unsigned int i = 0; i < hourlyValues.size(); i++)
{
quality::qualityType qualityT = qualityCheck.syntacticQualitySingleValue(variable, hourlyValues[i]);
Expand Down Expand Up @@ -2198,8 +2201,8 @@ bool preElaboration(Crit3DMeteoPointsDbHandler* meteoPointsDbHandler, Crit3DMete
case dailyLeafWetness:
{
if (loadHourlyVarSeries(meteoPointsDbHandler, meteoGridDbHandler, meteoPoint, isMeteoGrid, leafWetness,
QDateTime(startDate,QTime(1,0,0),Qt::UTC),
QDateTime(endDate.addDays(1),QTime(0,0,0),Qt::UTC), myError) > 0)
QDateTime(startDate, QTime(1,0,0), Qt::UTC),
QDateTime(endDate.addDays(1), QTime(0,0,0), Qt::UTC), myError) > 0)
{
myResult = elaborateDailyAggregatedVar(dailyLeafWetness, *meteoPoint, outputValues, percValue, meteoSettings);
}
Expand All @@ -2208,8 +2211,8 @@ bool preElaboration(Crit3DMeteoPointsDbHandler* meteoPointsDbHandler, Crit3DMete
case dailyTemperatureHoursAbove:
{
if (loadHourlyVarSeries(meteoPointsDbHandler, meteoGridDbHandler, meteoPoint, isMeteoGrid, airTemperature,
QDateTime(startDate,QTime(1,0,0),Qt::UTC),
QDateTime(endDate.addDays(1),QTime(0,0,0),Qt::UTC), myError) > 0)
QDateTime(startDate, QTime(1,0,0), Qt::UTC),
QDateTime(endDate.addDays(1), QTime(0,0,0), Qt::UTC), myError) > 0)
{
myResult = elaborateDailyAggregatedVar(dailyTemperatureHoursAbove, *meteoPoint, outputValues, percValue, meteoSettings);
}
Expand Down
81 changes: 40 additions & 41 deletions agrolib/dbMeteoGrid/dbMeteoGrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2445,7 +2445,7 @@ std::vector<float> Crit3DMeteoGridDbHandler::loadGridDailyVar(const QString &met
int varCode = getDailyVarCode(variable);
if (varCode == NODATA)
{
errorStr = "Variable not existing";
errorStr = "The variable does not exist in this meteo grid";
return dailyVarList;
}

Expand Down Expand Up @@ -2529,7 +2529,7 @@ std::vector<float> Crit3DMeteoGridDbHandler::exportAllDataVar(QString *errorStr,
idVar = getDailyVarCode(variable);
if (idVar == NODATA)
{
*errorStr = "Variable not existing";
*errorStr = "The variable does not exist in this meteo grid";
return allDataVarList;
}
tableName = _tableDaily.prefix + id + _tableDaily.postFix;
Expand All @@ -2543,7 +2543,7 @@ std::vector<float> Crit3DMeteoGridDbHandler::exportAllDataVar(QString *errorStr,
idVar = getHourlyVarCode(variable);
if (idVar == NODATA)
{
*errorStr = "Variable not existing";
*errorStr = "The variable does not exist in this meteo grid";
return allDataVarList;
}
tableName = _tableHourly.prefix + id + _tableHourly.postFix;
Expand Down Expand Up @@ -2615,7 +2615,7 @@ std::vector<float> Crit3DMeteoGridDbHandler::loadGridDailyVarFixedFields(const Q

if (varCode == NODATA)
{
errorStr = "Variable not existing";
errorStr = "The variable does not exist in this meteo grid";
return dailyVarList;
}

Expand Down Expand Up @@ -2700,7 +2700,7 @@ std::vector<float> Crit3DMeteoGridDbHandler::loadGridHourlyVar(meteoVariable var
int varCode = getHourlyVarCode(variable);
if (varCode == NODATA)
{
errorStr = "Variable not existing";
errorStr = "The variable does not exist in this meteo grid";
return hourlyVarList;
}

Expand All @@ -2711,54 +2711,53 @@ std::vector<float> Crit3DMeteoGridDbHandler::loadGridHourlyVar(meteoVariable var
}

QString statement = QString("SELECT * FROM `%1` WHERE VariableCode = '%2' AND `%3` >= '%4' AND `%3` <= '%5' ORDER BY `%3`")
.arg(tableH).arg(varCode).arg(_tableHourly.fieldTime,
firstTime.toString("yyyy-MM-dd hh:mm"), lastTime.toString("yyyy-MM-dd hh:mm"));
.arg(tableH).arg(varCode)
.arg(_tableHourly.fieldTime, firstTime.toString("yyyy-MM-dd hh:mm"), lastTime.toString("yyyy-MM-dd hh:mm"));
if(! qry.exec(statement) )
{
errorStr = qry.lastError().text();
return hourlyVarList;
}
else

while (qry.next())
{
while (qry.next())
if (firstRow)
{
if (firstRow)
if (! getValue(qry.value(_tableHourly.fieldTime), &firstDateTimeDB))
{
if (! getValue(qry.value(_tableHourly.fieldTime), &firstDateTimeDB))
{
errorStr = "Missing fieldTime";
return hourlyVarList;
}
errorStr = "Missing fieldTime";
return hourlyVarList;
}

if (! getValue(qry.value("Value"), &value))
{
errorStr = "Missing Value";
}
hourlyVarList.push_back(value);
previousDateTime = firstDateTimeDB;
firstRow = false;
if (! getValue(qry.value("Value"), &value))
{
errorStr = "Missing Value";
}
else
hourlyVarList.push_back(value);
previousDateTime = firstDateTimeDB;
firstRow = false;
}
else
{
if (! getValue(qry.value(_tableHourly.fieldTime), &dateTime))
{
if (! getValue(qry.value(_tableHourly.fieldTime), &dateTime))
{
errorStr = "Missing fieldTime";
return hourlyVarList;
}

int missingHours = previousDateTime.secsTo(dateTime) / 3600 - 1;
for (int i = 1; i <= missingHours; i++)
{
hourlyVarList.push_back(NODATA);
}
errorStr = "Missing fieldTime";
return hourlyVarList;
}

if (! getValue(qry.value("Value"), &value))
{
errorStr = "Missing Value";
}
int missingHours = previousDateTime.secsTo(dateTime) / 3600 - 1;
for (int i = 1; i <= missingHours; i++)
{
hourlyVarList.push_back(NODATA);
}

hourlyVarList.push_back(value);
previousDateTime = dateTime;
if (! getValue(qry.value("Value"), &value))
{
errorStr = "Missing Value";
}

hourlyVarList.push_back(value);
previousDateTime = dateTime;
}
}

Expand All @@ -2784,7 +2783,7 @@ std::vector<float> Crit3DMeteoGridDbHandler::loadGridHourlyVarFixedFields(meteoV

if (varCode == NODATA)
{
errorStr = "Variable not existing";
errorStr = "The variable does not exist in this meteo grid";
return hourlyVarList;
}

Expand Down
Loading

0 comments on commit 2aa10e5

Please sign in to comment.