From a6f250cc335f365f17fe6b19c0dad231f15b6e36 2017-08-17 08:24:20 From: Alexandre Leroux Date: 2017-08-17 08:24:20 Subject: [PATCH] Reads variable metadata to get the data type The data type is then parsed to determine the value type expected when reading result file --- diff --git a/plugins/amda/include/AmdaDefs.h b/plugins/amda/include/AmdaDefs.h index 4189ea9..5ae3b9d 100644 --- a/plugins/amda/include/AmdaDefs.h +++ b/plugins/amda/include/AmdaDefs.h @@ -9,6 +9,7 @@ // Relevant keys in JSON file extern const QString AMDA_COMPONENT_KEY; +extern const QString AMDA_DATA_TYPE_KEY; extern const QString AMDA_PRODUCT_KEY; extern const QString AMDA_ROOT_KEY; extern const QString AMDA_XML_ID_KEY; diff --git a/plugins/amda/src/AmdaDefs.cpp b/plugins/amda/src/AmdaDefs.cpp index f90f076..63cd914 100644 --- a/plugins/amda/src/AmdaDefs.cpp +++ b/plugins/amda/src/AmdaDefs.cpp @@ -1,6 +1,7 @@ #include "AmdaDefs.h" const QString AMDA_COMPONENT_KEY = QStringLiteral("component"); +const QString AMDA_DATA_TYPE_KEY = QStringLiteral("dataType"); const QString AMDA_PRODUCT_KEY = QStringLiteral("parameter"); const QString AMDA_ROOT_KEY = QStringLiteral("dataCenter"); const QString AMDA_XML_ID_KEY = QStringLiteral("xml:id"); diff --git a/plugins/amda/src/AmdaProvider.cpp b/plugins/amda/src/AmdaProvider.cpp index baa2b00..a320b84 100644 --- a/plugins/amda/src/AmdaProvider.cpp +++ b/plugins/amda/src/AmdaProvider.cpp @@ -36,6 +36,19 @@ QString dateFormat(double sqpRange) noexcept return dateTime.toString(AMDA_TIME_FORMAT); } +AmdaResultParser::ValueType valueType(const QString &valueType) +{ + if (valueType == QStringLiteral("scalar")) { + return AmdaResultParser::ValueType::SCALAR; + } + else if (valueType == QStringLiteral("vector")) { + return AmdaResultParser::ValueType::VECTOR; + } + else { + return AmdaResultParser::ValueType::UNKNOWN; + } +} + } // namespace AmdaProvider::AmdaProvider() @@ -86,6 +99,10 @@ void AmdaProvider::retrieveData(QUuid token, const SqpRange &dateTime, const QVa } qCDebug(LOG_AmdaProvider()) << tr("AmdaProvider::retrieveData") << dateTime; + // Retrieves the data type that determines whether the expected format for the result file is + // scalar, vector... + auto productValueType = valueType(data.value(AMDA_DATA_TYPE_KEY).toString()); + // /////////// // // Creates URL // // /////////// // @@ -98,30 +115,31 @@ void AmdaProvider::retrieveData(QUuid token, const SqpRange &dateTime, const QVa auto tempFile = std::make_shared(); // LAMBDA - auto httpDownloadFinished - = [this, dateTime, tempFile](QNetworkReply *reply, QUuid dataId) noexcept { - - // Don't do anything if the reply was abort - if (reply->error() != QNetworkReply::OperationCanceledError) { - - if (tempFile) { - auto replyReadAll = reply->readAll(); - if (!replyReadAll.isEmpty()) { - tempFile->write(replyReadAll); - } - tempFile->close(); - - // Parse results file - if (auto dataSeries = AmdaResultParser::readTxt(tempFile->fileName())) { - emit dataProvided(dataId, dataSeries, dateTime); - } - else { - /// @todo ALX : debug - } - } - } - - }; + auto httpDownloadFinished = [this, dateTime, tempFile, + productValueType](QNetworkReply *reply, QUuid dataId) noexcept { + + // Don't do anything if the reply was abort + if (reply->error() != QNetworkReply::OperationCanceledError) { + + if (tempFile) { + auto replyReadAll = reply->readAll(); + if (!replyReadAll.isEmpty()) { + tempFile->write(replyReadAll); + } + tempFile->close(); + + // Parse results file + if (auto dataSeries + = AmdaResultParser::readTxt(tempFile->fileName(), productValueType)) { + emit dataProvided(dataId, dataSeries, dateTime); + } + else { + /// @todo ALX : debug + } + } + } + + }; auto httpFinishedLambda = [this, httpDownloadFinished, tempFile](QNetworkReply *reply, QUuid dataId) noexcept {