##// END OF EJS Templates
Add sleep to permits AMDA to wait 1 sec between each request
perrinel -
r587:40f1a68a746c
parent child
Show More
@@ -1,168 +1,168
1 #include "AmdaProvider.h"
1 #include "AmdaProvider.h"
2 #include "AmdaDefs.h"
2 #include "AmdaDefs.h"
3 #include "AmdaResultParser.h"
3 #include "AmdaResultParser.h"
4
4
5 #include <Common/DateUtils.h>
5 #include <Common/DateUtils.h>
6 #include <Data/DataProviderParameters.h>
6 #include <Data/DataProviderParameters.h>
7 #include <Network/NetworkController.h>
7 #include <Network/NetworkController.h>
8 #include <SqpApplication.h>
8 #include <SqpApplication.h>
9 #include <Variable/Variable.h>
9 #include <Variable/Variable.h>
10
10
11 #include <QNetworkAccessManager>
11 #include <QNetworkAccessManager>
12 #include <QNetworkReply>
12 #include <QNetworkReply>
13 #include <QTemporaryFile>
13 #include <QTemporaryFile>
14 #include <QThread>
14 #include <QThread>
15
15
16 Q_LOGGING_CATEGORY(LOG_AmdaProvider, "AmdaProvider")
16 Q_LOGGING_CATEGORY(LOG_AmdaProvider, "AmdaProvider")
17
17
18 namespace {
18 namespace {
19
19
20 /// URL format for a request on AMDA server. The parameters are as follows:
20 /// URL format for a request on AMDA server. The parameters are as follows:
21 /// - %1: start date
21 /// - %1: start date
22 /// - %2: end date
22 /// - %2: end date
23 /// - %3: parameter id
23 /// - %3: parameter id
24 const auto AMDA_URL_FORMAT = QStringLiteral(
24 const auto AMDA_URL_FORMAT = QStringLiteral(
25 "http://amda.irap.omp.eu/php/rest/"
25 "http://amda.irap.omp.eu/php/rest/"
26 "getParameter.php?startTime=%1&stopTime=%2&parameterID=%3&outputFormat=ASCII&"
26 "getParameter.php?startTime=%1&stopTime=%2&parameterID=%3&outputFormat=ASCII&"
27 "timeFormat=ISO8601&gzip=0");
27 "timeFormat=ISO8601&gzip=0");
28
28
29 /// Dates format passed in the URL (e.g 2013-09-23T09:00)
29 /// Dates format passed in the URL (e.g 2013-09-23T09:00)
30 const auto AMDA_TIME_FORMAT = QStringLiteral("yyyy-MM-ddThh:mm:ss");
30 const auto AMDA_TIME_FORMAT = QStringLiteral("yyyy-MM-ddThh:mm:ss");
31
31
32 /// Formats a time to a date that can be passed in URL
32 /// Formats a time to a date that can be passed in URL
33 QString dateFormat(double sqpRange) noexcept
33 QString dateFormat(double sqpRange) noexcept
34 {
34 {
35 auto dateTime = DateUtils::dateTime(sqpRange);
35 auto dateTime = DateUtils::dateTime(sqpRange);
36 return dateTime.toString(AMDA_TIME_FORMAT);
36 return dateTime.toString(AMDA_TIME_FORMAT);
37 }
37 }
38
38
39 AmdaResultParser::ValueType valueType(const QString &valueType)
39 AmdaResultParser::ValueType valueType(const QString &valueType)
40 {
40 {
41 if (valueType == QStringLiteral("scalar")) {
41 if (valueType == QStringLiteral("scalar")) {
42 return AmdaResultParser::ValueType::SCALAR;
42 return AmdaResultParser::ValueType::SCALAR;
43 }
43 }
44 else if (valueType == QStringLiteral("vector")) {
44 else if (valueType == QStringLiteral("vector")) {
45 return AmdaResultParser::ValueType::VECTOR;
45 return AmdaResultParser::ValueType::VECTOR;
46 }
46 }
47 else {
47 else {
48 return AmdaResultParser::ValueType::UNKNOWN;
48 return AmdaResultParser::ValueType::UNKNOWN;
49 }
49 }
50 }
50 }
51
51
52 } // namespace
52 } // namespace
53
53
54 AmdaProvider::AmdaProvider()
54 AmdaProvider::AmdaProvider()
55 {
55 {
56 qCDebug(LOG_AmdaProvider()) << tr("AmdaProvider::AmdaProvider") << QThread::currentThread();
56 qCDebug(LOG_AmdaProvider()) << tr("AmdaProvider::AmdaProvider") << QThread::currentThread();
57 if (auto app = sqpApp) {
57 if (auto app = sqpApp) {
58 auto &networkController = app->networkController();
58 auto &networkController = app->networkController();
59 connect(this, SIGNAL(requestConstructed(QNetworkRequest, QUuid,
59 connect(this, SIGNAL(requestConstructed(QNetworkRequest, QUuid,
60 std::function<void(QNetworkReply *, QUuid)>)),
60 std::function<void(QNetworkReply *, QUuid)>)),
61 &networkController,
61 &networkController,
62 SLOT(onProcessRequested(QNetworkRequest, QUuid,
62 SLOT(onProcessRequested(QNetworkRequest, QUuid,
63 std::function<void(QNetworkReply *, QUuid)>)));
63 std::function<void(QNetworkReply *, QUuid)>)));
64
64
65
65
66 connect(&sqpApp->networkController(), SIGNAL(replyDownloadProgress(QUuid, double)), this,
66 connect(&sqpApp->networkController(), SIGNAL(replyDownloadProgress(QUuid, double)), this,
67 SIGNAL(dataProvidedProgress(QUuid, double)));
67 SIGNAL(dataProvidedProgress(QUuid, double)));
68 }
68 }
69 }
69 }
70
70
71 void AmdaProvider::requestDataLoading(QUuid acqIdentifier, const DataProviderParameters &parameters)
71 void AmdaProvider::requestDataLoading(QUuid acqIdentifier, const DataProviderParameters &parameters)
72 {
72 {
73 // NOTE: Try to use multithread if possible
73 // NOTE: Try to use multithread if possible
74 const auto times = parameters.m_Times;
74 const auto times = parameters.m_Times;
75 const auto data = parameters.m_Data;
75 const auto data = parameters.m_Data;
76 for (const auto &dateTime : qAsConst(times)) {
76 for (const auto &dateTime : qAsConst(times)) {
77 this->retrieveData(acqIdentifier, dateTime, data);
77 this->retrieveData(acqIdentifier, dateTime, data);
78
78
79 // TORM
79 // TORM when AMDA will support quick asynchrone request
80 // QThread::msleep(200);
80 QThread::msleep(1000);
81 }
81 }
82 }
82 }
83
83
84 void AmdaProvider::requestDataAborting(QUuid acqIdentifier)
84 void AmdaProvider::requestDataAborting(QUuid acqIdentifier)
85 {
85 {
86 if (auto app = sqpApp) {
86 if (auto app = sqpApp) {
87 auto &networkController = app->networkController();
87 auto &networkController = app->networkController();
88 networkController.onReplyCanceled(acqIdentifier);
88 networkController.onReplyCanceled(acqIdentifier);
89 }
89 }
90 }
90 }
91
91
92 void AmdaProvider::retrieveData(QUuid token, const SqpRange &dateTime, const QVariantHash &data)
92 void AmdaProvider::retrieveData(QUuid token, const SqpRange &dateTime, const QVariantHash &data)
93 {
93 {
94 // Retrieves product ID from data: if the value is invalid, no request is made
94 // Retrieves product ID from data: if the value is invalid, no request is made
95 auto productId = data.value(AMDA_XML_ID_KEY).toString();
95 auto productId = data.value(AMDA_XML_ID_KEY).toString();
96 if (productId.isNull()) {
96 if (productId.isNull()) {
97 qCCritical(LOG_AmdaProvider()) << tr("Can't retrieve data: unknown product id");
97 qCCritical(LOG_AmdaProvider()) << tr("Can't retrieve data: unknown product id");
98 return;
98 return;
99 }
99 }
100 qCDebug(LOG_AmdaProvider()) << tr("AmdaProvider::retrieveData") << dateTime;
100 qCDebug(LOG_AmdaProvider()) << tr("AmdaProvider::retrieveData") << dateTime;
101
101
102 // Retrieves the data type that determines whether the expected format for the result file is
102 // Retrieves the data type that determines whether the expected format for the result file is
103 // scalar, vector...
103 // scalar, vector...
104 auto productValueType = valueType(data.value(AMDA_DATA_TYPE_KEY).toString());
104 auto productValueType = valueType(data.value(AMDA_DATA_TYPE_KEY).toString());
105
105
106 // /////////// //
106 // /////////// //
107 // Creates URL //
107 // Creates URL //
108 // /////////// //
108 // /////////// //
109
109
110 auto startDate = dateFormat(dateTime.m_TStart);
110 auto startDate = dateFormat(dateTime.m_TStart);
111 auto endDate = dateFormat(dateTime.m_TEnd);
111 auto endDate = dateFormat(dateTime.m_TEnd);
112
112
113 auto url = QUrl{QString{AMDA_URL_FORMAT}.arg(startDate, endDate, productId)};
113 auto url = QUrl{QString{AMDA_URL_FORMAT}.arg(startDate, endDate, productId)};
114 qCInfo(LOG_AmdaProvider()) << tr("TORM AmdaProvider::retrieveData url:") << url;
114 qCInfo(LOG_AmdaProvider()) << tr("TORM AmdaProvider::retrieveData url:") << url;
115 auto tempFile = std::make_shared<QTemporaryFile>();
115 auto tempFile = std::make_shared<QTemporaryFile>();
116
116
117 // LAMBDA
117 // LAMBDA
118 auto httpDownloadFinished = [this, dateTime, tempFile,
118 auto httpDownloadFinished = [this, dateTime, tempFile,
119 productValueType](QNetworkReply *reply, QUuid dataId) noexcept {
119 productValueType](QNetworkReply *reply, QUuid dataId) noexcept {
120
120
121 // Don't do anything if the reply was abort
121 // Don't do anything if the reply was abort
122 if (reply->error() != QNetworkReply::OperationCanceledError) {
122 if (reply->error() != QNetworkReply::OperationCanceledError) {
123
123
124 if (tempFile) {
124 if (tempFile) {
125 auto replyReadAll = reply->readAll();
125 auto replyReadAll = reply->readAll();
126 if (!replyReadAll.isEmpty()) {
126 if (!replyReadAll.isEmpty()) {
127 tempFile->write(replyReadAll);
127 tempFile->write(replyReadAll);
128 }
128 }
129 tempFile->close();
129 tempFile->close();
130
130
131 // Parse results file
131 // Parse results file
132 if (auto dataSeries
132 if (auto dataSeries
133 = AmdaResultParser::readTxt(tempFile->fileName(), productValueType)) {
133 = AmdaResultParser::readTxt(tempFile->fileName(), productValueType)) {
134 emit dataProvided(dataId, dataSeries, dateTime);
134 emit dataProvided(dataId, dataSeries, dateTime);
135 }
135 }
136 else {
136 else {
137 /// @todo ALX : debug
137 /// @todo ALX : debug
138 }
138 }
139 }
139 }
140 }
140 }
141
141
142 };
142 };
143 auto httpFinishedLambda
143 auto httpFinishedLambda
144 = [this, httpDownloadFinished, tempFile](QNetworkReply *reply, QUuid dataId) noexcept {
144 = [this, httpDownloadFinished, tempFile](QNetworkReply *reply, QUuid dataId) noexcept {
145
145
146 // Don't do anything if the reply was abort
146 // Don't do anything if the reply was abort
147 if (reply->error() != QNetworkReply::OperationCanceledError) {
147 if (reply->error() != QNetworkReply::OperationCanceledError) {
148 auto downloadFileUrl = QUrl{QString{reply->readAll()}};
148 auto downloadFileUrl = QUrl{QString{reply->readAll()}};
149
149
150
150
151 qCInfo(LOG_AmdaProvider())
151 qCInfo(LOG_AmdaProvider())
152 << tr("TORM AmdaProvider::retrieveData downloadFileUrl:") << downloadFileUrl;
152 << tr("TORM AmdaProvider::retrieveData downloadFileUrl:") << downloadFileUrl;
153 // Executes request for downloading file //
153 // Executes request for downloading file //
154
154
155 // Creates destination file
155 // Creates destination file
156 if (tempFile->open()) {
156 if (tempFile->open()) {
157 // Executes request
157 // Executes request
158 emit requestConstructed(QNetworkRequest{downloadFileUrl}, dataId,
158 emit requestConstructed(QNetworkRequest{downloadFileUrl}, dataId,
159 httpDownloadFinished);
159 httpDownloadFinished);
160 }
160 }
161 }
161 }
162 };
162 };
163
163
164 // //////////////// //
164 // //////////////// //
165 // Executes request //
165 // Executes request //
166 // //////////////// //
166 // //////////////// //
167 emit requestConstructed(QNetworkRequest{url}, token, httpFinishedLambda);
167 emit requestConstructed(QNetworkRequest{url}, token, httpFinishedLambda);
168 }
168 }
General Comments 3
Under Review
author

Pull request updated. Auto status change to "Under Review"

Changed commits:
  * 1 added
  * 0 removed

Changed files:
  * M core/include/Data/AcquisitionRequest.h
  * M core/include/Variable/VariableAcquisitionWorker.h
  * M core/include/Variable/VariableCacheStrategy.h
  * M core/include/Variable/VariableController.h
  * M core/src/Variable/VariableAcquisitionWorker.cpp
  * M core/src/Variable/VariableCacheStrategy.cpp
  * M core/src/Variable/VariableController.cpp
  * M gui/src/Visualization/VisualizationZoneWidget.cpp
  * M plugins/amda/include/AmdaPlugin.h
  * M plugins/amda/src/AmdaProvider.cpp
  * M plugins/amda/tests/TestAmdaAcquisition.cpp
  * M plugins/mockplugin/include/MockPlugin.h
  * R COPYING
  * R app/src/MainWindow.cpp
  * R app/ui/MainWindow.ui
  * R cmake/sciqlop_package_qt.cmake
  * R core/include/Common/DateUtils.h
  * R core/include/Common/MetaTypes.h
  * R core/include/Common/SortUtils.h
  * R core/include/CoreGlobal.h
  * R core/include/Data/AcquisitionDataPacket.h
  * R core/include/Data/ArrayData.h
  * R core/include/Data/DataProviderParameters.h
  * R core/include/Data/DataSeries.h
  * R core/include/Data/DataSeriesIterator.h
  * R core/include/Data/IDataProvider.h
  * R core/include/Data/IDataSeries.h
  * R core/include/Data/ScalarSeries.h
  * R core/include/Data/SqpRange.h
  * R core/include/Data/VectorSeries.h
  * R core/include/DataSource/DataSourceItemAction.h
  * R core/include/Network/NetworkController.h
  * R core/include/Plugin/PluginManager.h
  * R core/include/Settings/ISqpSettingsBindable.h
  * R core/include/Settings/SqpSettingsDefs.h
  * R core/include/Time/TimeController.h
  * R core/include/Variable/Variable.h
  * R core/include/Variable/VariableCacheController.h
  * R core/include/Variable/VariableModel.h
  * R core/include/Variable/VariableSynchronizationGroup.h
  * R core/include/Visualization/VisualizationController.h
  * R core/src/Common/DateUtils.cpp
  * R core/src/Data/DataSeriesIterator.cpp
  * R core/src/Data/ScalarSeries.cpp
  * R core/src/Data/VectorSeries.cpp
  * R core/src/DataSource/DataSourceItemAction.cpp
  * R core/src/Network/NetworkController.cpp
  * R core/src/Plugin/PluginManager.cpp
  * R core/src/Settings/SqpSettingsDefs.cpp
  * R core/src/Time/TimeController.cpp
  * R core/src/Variable/Variable.cpp
  * R core/src/Variable/VariableCacheController.cpp
  * R core/src/Variable/VariableModel.cpp
  * R core/src/Variable/VariableSynchronizationGroup.cpp
  * R core/src/Visualization/VisualizationController.cpp
  * R core/tests/Data/TestDataSeries.cpp
  * R core/tests/Data/TestOneDimArrayData.cpp
  * R core/tests/Data/TestTwoDimArrayData.cpp
  * R core/tests/Variable/TestVariable.cpp
  * R core/tests/Variable/TestVariableCacheController.cpp
  * R gui/include/Common/ColorUtils.h
  * R gui/include/DataSource/DataSourceTreeWidgetHelper.h
  * R gui/include/DataSource/DataSourceTreeWidgetItem.h
  * R gui/include/DataSource/DataSourceWidget.h
  * R gui/include/Settings/SqpSettingsDialog.h
  * R gui/include/Settings/SqpSettingsGeneralWidget.h
  * R gui/include/SidePane/SqpSidePane.h
  * R gui/include/TimeWidget/TimeWidget.h
  * R gui/include/Variable/VariableInspectorWidget.h
  * R gui/include/Variable/VariableMenuHeaderWidget.h
  * R gui/include/Visualization/IVariableContainer.h
  * R gui/include/Visualization/IVisualizationWidget.h
  * R gui/include/Visualization/IVisualizationWidgetVisitor.h
  * R gui/include/Visualization/VisualizationDefs.h
  * R gui/include/Visualization/VisualizationGraphHelper.h
  * R gui/include/Visualization/VisualizationGraphRenderingDelegate.h
  * R gui/include/Visualization/VisualizationGraphWidget.h
  * R gui/include/Visualization/VisualizationTabWidget.h
  * R gui/include/Visualization/VisualizationWidget.h
  * R gui/include/Visualization/VisualizationZoneWidget.h
  * R gui/include/Visualization/operations/GenerateVariableMenuOperation.h
  * R gui/include/Visualization/operations/MenuBuilder.h
  * R gui/include/Visualization/operations/RemoveVariableOperation.h
  * R gui/include/Visualization/operations/RescaleAxeOperation.h
  * R gui/include/Visualization/qcustomplot.h
  * R gui/resources/icones/dataSourceComponent.png
  * R gui/resources/icones/dataSourceNode.png
  * R gui/resources/icones/dataSourceProduct.png
  * R gui/resources/icones/dataSourceRoot.png
  * R gui/resources/icones/delete.png
  * R gui/resources/icones/next.png
  * R gui/resources/icones/openInspector.png
  * R gui/resources/icones/plot.png
  * R gui/resources/icones/previous.png
  * R gui/resources/icones/sciqlop2PNG_1024.png
  * R gui/resources/icones/unplot.png
  * R gui/resources/sqpguiresources.qrc
  * R gui/src/Common/ColorUtils.cpp
  * R gui/src/DataSource/DataSourceTreeWidgetHelper.cpp
  * R gui/src/DataSource/DataSourceTreeWidgetItem.cpp
  * R gui/src/DataSource/DataSourceWidget.cpp
  * R gui/src/Settings/SqpSettingsDialog.cpp
  * R gui/src/Settings/SqpSettingsGeneralWidget.cpp
  * R gui/src/SidePane/SqpSidePane.cpp
  * R gui/src/TimeWidget/TimeWidget.cpp
  * R gui/src/Variable/VariableInspectorWidget.cpp
  * R gui/src/Variable/VariableMenuHeaderWidget.cpp
  * R gui/src/Visualization/VisualizationGraphHelper.cpp
  * R gui/src/Visualization/VisualizationGraphRenderingDelegate.cpp
  * R gui/src/Visualization/VisualizationGraphWidget.cpp
  * R gui/src/Visualization/VisualizationTabWidget.cpp
  * R gui/src/Visualization/VisualizationWidget.cpp
  * R gui/src/Visualization/operations/GenerateVariableMenuOperation.cpp
  * R gui/src/Visualization/operations/MenuBuilder.cpp
  * R gui/src/Visualization/operations/RemoveVariableOperation.cpp
  * R gui/src/Visualization/operations/RescaleAxeOperation.cpp
  * R gui/src/Visualization/qcustomplot.cpp
  * R gui/ui/DataSource/DataSourceWidget.ui
  * R gui/ui/Settings/SqpSettingsDialog.ui
  * R gui/ui/Settings/SqpSettingsGeneralWidget.ui
  * R gui/ui/SidePane/SqpSidePane.ui
  * R gui/ui/TimeWidget/TimeWidget.ui
  * R gui/ui/Variable/VariableInspectorWidget.ui
  * R gui/ui/Variable/VariableMenuHeaderWidget.ui
  * R gui/ui/Visualization/VisualizationGraphWidget.ui
  * R gui/ui/Visualization/VisualizationTabWidget.ui
  * R gui/ui/Visualization/VisualizationWidget.ui
  * R gui/ui/Visualization/VisualizationZoneWidget.ui
  * R gui/vera-exclusions/exclusions.txt
  * R plugin/CMakeLists.txt
  * R plugin/cmake/Findsciqlop-plugin.cmake
  * R plugin/include/Plugin/IPlugin.h
  * R plugins/amda/CMakeLists.txt
  * R plugins/amda/cmake/Findsciqlop-amda.cmake
  * R plugins/amda/include/AmdaDefs.h
  * R plugins/amda/include/AmdaGlobal.h
  * R plugins/amda/include/AmdaParser.h
  * R plugins/amda/include/AmdaProvider.h
  * R plugins/amda/include/AmdaResultParser.h
  * R plugins/amda/resources/amda.json
  * R plugins/amda/resources/amdaresources.qrc
  * R plugins/amda/resources/samples/AmdaSample.json
  * R plugins/amda/resources/samples/AmdaSampleV2.json
  * R plugins/amda/src/AmdaDefs.cpp
  * R plugins/amda/src/AmdaParser.cpp
  * R plugins/amda/src/AmdaPlugin.cpp
  * R plugins/amda/src/AmdaResultParser.cpp
  * R plugins/amda/tests-resources/TestAmdaAcquisition/AmdaData-2012-01-01-12-00-00_2012-01-03-12-00-00.txt
  * R plugins/amda/tests-resources/TestAmdaParser/TwoRootsFile.json
  * R plugins/amda/tests-resources/TestAmdaParser/ValidFile1.json
  * R plugins/amda/tests-resources/TestAmdaParser/WrongRootKey.json
  * R plugins/amda/tests-resources/TestAmdaParser/WrongRootType.json
  * R plugins/amda/tests-resources/TestAmdaResultParser/FileNotFound.txt
  * R plugins/amda/tests-resources/TestAmdaResultParser/NaNValue.txt
  * R plugins/amda/tests-resources/TestAmdaResultParser/NaNX.txt
  * R plugins/amda/tests-resources/TestAmdaResultParser/NoUnit.txt
  * R plugins/amda/tests-resources/TestAmdaResultParser/TooManyValues.txt
  * R plugins/amda/tests-resources/TestAmdaResultParser/ValidScalar1.txt
  * R plugins/amda/tests-resources/TestAmdaResultParser/ValidVector1.txt
  * R plugins/amda/tests-resources/TestAmdaResultParser/WrongDate.txt
  * R plugins/amda/tests-resources/TestAmdaResultParser/WrongUnit.txt
  * R plugins/amda/tests-resources/TestAmdaResultParser/WrongValue.txt
  * R plugins/amda/tests/TestAmdaParser.cpp
  * R plugins/amda/tests/TestAmdaResultParser.cpp
  * R plugins/mockplugin/CMakeLists.txt
  * R plugins/mockplugin/cmake/Findsciqlop-mockplugin.cmake
  * R plugins/mockplugin/include/CosinusProvider.h
  * R plugins/mockplugin/include/MockPluginGlobal.h
  * R plugins/mockplugin/resources/mockplugin.json
  * R plugins/mockplugin/src/CosinusProvider.cpp
  * R plugins/mockplugin/src/MockPlugin.cpp
  * R README.md
  * R app/CMakeLists.txt
  * R app/include/MainWindow.h
  * R app/src/Main.cpp
  * R app/vera-exclusions/exclusions.txt
  * R cmake/sciqlop.cmake
  * R cmake/sciqlop_applications.cmake
  * R cmake/sciqlop_package.cmake
  * R cmake/sciqlop_params.cmake
  * R core/CMakeLists.txt
  * R core/include/Common/spimpl.h
  * R core/include/DataSource/DataSourceController.h
  * R core/include/DataSource/DataSourceItem.h
  * R core/src/DataSource/DataSourceController.cpp
  * R core/src/DataSource/DataSourceItem.cpp
  * R core/tests/DataSource/TestDataSourceController.cpp
  * R core/vera-exclusions/exclusions.txt
  * R formatting/cmake/use_clangformat.cmake
  * R formatting/vera-exclusions/exclusions.txt
  * R gui/CMakeLists.txt
  * R gui/include/SqpApplication.h
  * R gui/src/SqpApplication.cpp
  * R LICENSE
  * R app/src/mainwindow.cpp
  * R app/src/mainwindow.ui
Approved
author

Status change > Approved

You need to be logged in to leave comments. Login now