Skip to content

Commit

Permalink
Merge commit '4906e67d91785353533cae2d58af54bf2d054a35'
Browse files Browse the repository at this point in the history
  • Loading branch information
ftomei committed Sep 7, 2023
2 parents a5ff29f + 4906e67 commit 9e6737e
Show file tree
Hide file tree
Showing 8 changed files with 371 additions and 281 deletions.
241 changes: 130 additions & 111 deletions agrolib/criteriaOutput/criteriaOutputElaboration.cpp

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions agrolib/criteriaOutput/criteriaOutputElaboration.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,23 @@
int computeAllDtxUnit(QSqlDatabase db, QString idCase, QString &error);

int computeAllDtxPeriod(QSqlDatabase db, QString idCase, unsigned int period,
std::vector<double> &dtx, QString &error);
std::vector<double> &dtx, QString &errorStr);

bool writeDtxToDB(QSqlDatabase db, QString idCase, std::vector<double> &dt30,
std::vector<double> &dt90, std::vector<double> &dt180, QString &error);
std::vector<double> &dt90, std::vector<double> &dt180, QString &errorStr);

int writeCsvOutputUnit(QString idCase, QString idCropClass, QSqlDatabase &dbData, QSqlDatabase &dbCrop,
QSqlDatabase &dbHistoricalData, QDate dateComputation,
CriteriaOutputVariable outputVariable, QString csvFileName, QString &error);
CriteriaOutputVariable outputVariable, QString csvFileName, QString &errorStr);

int selectSimpleVar(QSqlDatabase &db, QString idCase, QString varName, QString computation, QDate firstDate,
QDate lastDate, float irriRatio, std::vector<float> &resVector, QString &error);
QDate lastDate, float irriRatio, std::vector<float> &resultVector, QString &errorStr);

int computeDTX(QSqlDatabase &db, QString idCase, int period, QString computation, QDate firstDate,
QDate lastDate, std::vector<float> &resVector, QString &error);
QDate lastDate, std::vector<float> &resultVector, QString &errorStr);

int writeCsvAggrFromShape(Crit3DShapeHandler &refShapeFile, QString csvFileName, QDate dateComputation,
QList<QString> outputVarName, QString shapeField, QString &error);
QList<QString> outputVarName, QString shapeField, QString &errorStr);

int orderCsvByField(QString csvFileName, QString field, QString &error);

Expand Down
41 changes: 35 additions & 6 deletions agrolib/criteriaOutput/criteriaOutputProject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include <QtSql>
#include <iostream>
#include <math.h>


CriteriaOutputProject::CriteriaOutputProject()
Expand Down Expand Up @@ -267,7 +268,12 @@ bool CriteriaOutputProject::readSettings()
dbCropName = QDir::cleanPath(path + dbCropName);
}

dbHistoricalDataName = projectSettings->value("db_data_historical","").toString();
dbHistoricalDataName = projectSettings->value("db_data_climate","").toString();
if (dbHistoricalDataName == "")
{
dbHistoricalDataName = projectSettings->value("db_data_historical","").toString();
}

if (dbHistoricalDataName.left(1) == ".")
{
dbHistoricalDataName = QDir::cleanPath(path + dbHistoricalDataName);
Expand Down Expand Up @@ -403,23 +409,32 @@ int CriteriaOutputProject::precomputeDtx()
return ERROR_READ_UNITS;
}
logger.writeInfo("Query result: " + QString::number(compUnitList.size()) + " distinct computational units.");



logger.writeInfo("Compute dtx...");

QString idCase;
int step = compUnitList.size() * 0.01;

for (unsigned int i=0; i < compUnitList.size(); i++)
{
idCase = compUnitList[i].idCase;
logger.writeInfo(QString::number(i) + " ID CASE: " + idCase);

int myResult = computeAllDtxUnit(dbHistoricalData, idCase, projectError);
if (myResult != CRIT1D_OK)
{
projectError = "ID CASE: " + idCase + "\n" + projectError;
return myResult;
}

// counter
if (i % step == 0)
{
int percentage = round(i * 100.0 / compUnitList.size());
std::cout << percentage << "..";
}
if (i == compUnitList.size()-1)
{
std::cout << "100\n";
}
}

return CRIT1D_OK;
Expand Down Expand Up @@ -454,12 +469,15 @@ int CriteriaOutputProject::createCsvFile()
// write output
QString idCase;
QString idCropClass;
int step = compUnitList.size() * 0.01;

for (unsigned int i=0; i < compUnitList.size(); i++)
{
idCase = compUnitList[i].idCase;
idCropClass = compUnitList[i].idCropClass;

myResult = writeCsvOutputUnit(idCase, idCropClass, dbData, dbCrop, dbHistoricalData, dateComputation, outputVariable, outputCsvFileName, projectError);
myResult = writeCsvOutputUnit(idCase, idCropClass, dbData, dbCrop, dbHistoricalData,
dateComputation, outputVariable, outputCsvFileName, projectError);
if (myResult != CRIT1D_OK)
{
if (QFile(outputCsvFileName).exists())
Expand All @@ -468,6 +486,17 @@ int CriteriaOutputProject::createCsvFile()
}
return myResult;
}

// counter
if (i % step == 0)
{
int percentage = round(i * 100.0 / compUnitList.size());
std::cout << percentage << "..";
}
if (i == compUnitList.size()-1)
{
std::cout << "100\n";
}
}

return CRIT1D_OK;
Expand Down
Loading

0 comments on commit 9e6737e

Please sign in to comment.