Skip to content

Commit

Permalink
Merge commit '8ec2281350d6dbf7fa2f588ffbe479018d8dfa61'
Browse files Browse the repository at this point in the history
  • Loading branch information
ftomei committed Nov 22, 2023
2 parents 5681c0a + 8ec2281 commit 1c7628f
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 37 deletions.
73 changes: 40 additions & 33 deletions agrolib/dbMeteoGrid/dbMeteoGrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,6 @@ QString Crit3DMeteoGridDbHandler::getDailyVarField(meteoVariable meteoGridDailyV

meteoVariable Crit3DMeteoGridDbHandler::getDailyVarEnum(int varCode)
{

if (varCode == NODATA)
{
return noMeteoVar;
Expand All @@ -791,6 +790,7 @@ meteoVariable Crit3DMeteoGridDbHandler::getDailyVarEnum(int varCode)
return noMeteoVar;
}


meteoVariable Crit3DMeteoGridDbHandler::getDailyVarFieldEnum(QString varField)
{

Expand Down Expand Up @@ -1724,64 +1724,71 @@ bool Crit3DMeteoGridDbHandler::updateGridDate(QString *myError)
}

return true;

}


bool Crit3DMeteoGridDbHandler::loadGridDailyData(QString &myError, QString meteoPoint, QDate first, QDate last)
bool Crit3DMeteoGridDbHandler::loadGridDailyData(QString &errorStr, const QString &meteoPoint, const QDate &first, const QDate &last)
{
myError = "";
errorStr = "";

QSqlQuery qry(_db);
QString tableD = _tableDaily.prefix + meteoPoint + _tableDaily.postFix;
QDate date;
int varCode;
float value;

unsigned row, col;

if ( !_meteoGrid->findMeteoPointFromId(&row, &col, meteoPoint.toStdString()) )
{
myError = "Missing MeteoPoint id";
errorStr = "Missing MeteoPoint id";
return false;
}

int numberOfDays = first.daysTo(last) + 1;
_meteoGrid->meteoPointPointer(row,col)->initializeObsDataD(numberOfDays, getCrit3DDate(first));
_meteoGrid->meteoPointPointer(row, col)->initializeObsDataD(numberOfDays, getCrit3DDate(first));

QString 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"));
QString statement;
if (first == last)
{
statement = QString("SELECT * FROM `%1` WHERE %2 = '%3'").arg(tableD, _tableDaily.fieldTime, first.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"));
}
qry.prepare(statement);
if( !qry.exec())

if(! qry.exec())
{
myError = qry.lastError().text();
errorStr = qry.lastError().text();
return false;
}
else

int varCode;
float value;
QDate date;

while (qry.next())
{
while (qry.next())
if (! getValue(qry.value(_tableDaily.fieldTime), &date))
{
if (!getValue(qry.value(_tableDaily.fieldTime), &date))
{
myError = "Missing fieldTime";
return false;
}
errorStr = "Missing " + _tableDaily.fieldTime;
return false;
}

if (!getValue(qry.value("VariableCode"), &varCode))
{
myError = "Missing VariableCode";
return false;
}
if (! getValue(qry.value("VariableCode"), &varCode))
{
errorStr = "Missing VariableCode";
return false;
}

if (!getValue(qry.value("Value"), &value))
{
myError = "Missing Value";
}
if (! getValue(qry.value("Value"), &value))
{
// no data
}

meteoVariable variable = getDailyVarEnum(varCode);
meteoVariable variable = getDailyVarEnum(varCode);

if (! _meteoGrid->meteoPointPointer(row,col)->setMeteoPointValueD(getCrit3DDate(date), variable, value))
return false;
}
if (! _meteoGrid->meteoPointPointer(row, col)->setMeteoPointValueD(getCrit3DDate(date), variable, value))
return false;
}

return true;
Expand Down
2 changes: 1 addition & 1 deletion agrolib/dbMeteoGrid/dbMeteoGrid.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
bool loadIdMeteoProperties(QString *myError, QString idMeteo);
bool updateGridDate(QString *myError);

bool loadGridDailyData(QString &myError, QString meteoPoint, QDate first, QDate last);
bool loadGridDailyData(QString &errorStr, const QString &meteoPoint, const QDate &first, const QDate &last);
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);
Expand Down
7 changes: 4 additions & 3 deletions agrolib/project/project.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "project.h"
#include "dbMeteoGrid.h"
#include "commonConstants.h"
#include "basicMath.h"
#include "spatialControl.h"
Expand Down Expand Up @@ -1503,22 +1504,22 @@ bool Project::loadMeteoGridDailyData(QDate firstDate, QDate lastDate, bool showI
int memberNr = 1;
if (this->meteoGridDbHandler->loadGridDailyDataEnsemble(errorString, QString::fromStdString(id), memberNr, firstDate, lastDate))
{
count = count + 1;
count++;
}
}
else
{
if (this->meteoGridDbHandler->loadGridDailyData(errorString, QString::fromStdString(id), firstDate, lastDate))
{
count = count + 1;
count++;
}
}
}
else
{
if (this->meteoGridDbHandler->loadGridDailyDataFixedFields(errorString, QString::fromStdString(id), firstDate, lastDate))
{
count = count + 1;
count++;
}
}
}
Expand Down

0 comments on commit 1c7628f

Please sign in to comment.