@@ -21,6 +21,7 struct AcquisitionRequest { | |||
|
21 | 21 | { |
|
22 | 22 | m_AcqIdentifier = QUuid::createUuid(); |
|
23 | 23 | m_Size = 0; |
|
24 | m_Progression = 0; | |
|
24 | 25 | } |
|
25 | 26 | |
|
26 | 27 | QUuid m_VarRequestId; |
@@ -30,6 +31,7 struct AcquisitionRequest { | |||
|
30 | 31 | SqpRange m_RangeRequested; |
|
31 | 32 | SqpRange m_CacheRangeRequested; |
|
32 | 33 | int m_Size; |
|
34 | int m_Progression; | |
|
33 | 35 | std::shared_ptr<IDataProvider> m_Provider; |
|
34 | 36 | }; |
|
35 | 37 |
@@ -36,7 +36,8 public slots: | |||
|
36 | 36 | |
|
37 | 37 | signals: |
|
38 | 38 | void replyFinished(QNetworkReply *reply, QUuid identifier); |
|
39 |
void replyDownloadProgress(QUuid identifier, |
|
|
39 | void replyDownloadProgress(QUuid identifier, const QNetworkRequest &networkRequest, | |
|
40 | double progress); | |
|
40 | 41 | |
|
41 | 42 | private: |
|
42 | 43 | void waitForFinish(); |
@@ -42,7 +42,7 void NetworkController::onProcessRequested(const QNetworkRequest &request, QUuid | |||
|
42 | 42 | impl->m_NetworkReplyToVariableId[reply] = identifier; |
|
43 | 43 | impl->unlock(); |
|
44 | 44 | |
|
45 | auto onReplyFinished = [reply, this, identifier, callback]() { | |
|
45 | auto onReplyFinished = [request, reply, this, identifier, callback]() { | |
|
46 | 46 | |
|
47 | 47 | qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyFinished") |
|
48 | 48 | << QThread::currentThread() << reply; |
@@ -57,14 +57,14 void NetworkController::onProcessRequested(const QNetworkRequest &request, QUuid | |||
|
57 | 57 | callback(reply, identifier); |
|
58 | 58 | reply->deleteLater(); |
|
59 | 59 | |
|
60 | emit this->replyDownloadProgress(identifier, 0); | |
|
60 | emit this->replyDownloadProgress(identifier, request, 0); | |
|
61 | 61 | } |
|
62 | 62 | |
|
63 | 63 | qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyFinished END") |
|
64 | 64 | << QThread::currentThread() << reply; |
|
65 | 65 | }; |
|
66 | 66 | |
|
67 | auto onReplyProgress = [reply, this](qint64 bytesRead, qint64 totalBytes) { | |
|
67 | auto onReplyProgress = [reply, request, this](qint64 bytesRead, qint64 totalBytes) { | |
|
68 | 68 | |
|
69 | 69 | double progress = (bytesRead * 100.0) / totalBytes; |
|
70 | 70 | qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyProgress") << progress |
@@ -73,7 +73,7 void NetworkController::onProcessRequested(const QNetworkRequest &request, QUuid | |||
|
73 | 73 | auto it = impl->m_NetworkReplyToVariableId.find(reply); |
|
74 | 74 | impl->unlock(); |
|
75 | 75 | if (it != impl->m_NetworkReplyToVariableId.cend()) { |
|
76 | emit this->replyDownloadProgress(it->second, progress); | |
|
76 | emit this->replyDownloadProgress(it->second, request, progress); | |
|
77 | 77 | } |
|
78 | 78 | qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyProgress END") |
|
79 | 79 | << QThread::currentThread() << reply; |
@@ -12,6 +12,8 | |||
|
12 | 12 | #include <QReadWriteLock> |
|
13 | 13 | #include <QThread> |
|
14 | 14 | |
|
15 | #include <cmath> | |
|
16 | ||
|
15 | 17 | Q_LOGGING_CATEGORY(LOG_VariableAcquisitionWorker, "VariableAcquisitionWorker") |
|
16 | 18 | |
|
17 | 19 | struct VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate { |
@@ -106,15 +108,45 void VariableAcquisitionWorker::abortProgressRequested(QUuid vIdentifier) | |||
|
106 | 108 | void VariableAcquisitionWorker::onVariableRetrieveDataInProgress(QUuid acqIdentifier, |
|
107 | 109 | double progress) |
|
108 | 110 | { |
|
109 | // TODO | |
|
111 | impl->lockRead(); | |
|
112 | auto aIdToARit = impl->m_AcqIdentifierToAcqRequestMap.find(acqIdentifier); | |
|
113 | if (aIdToARit != impl->m_AcqIdentifierToAcqRequestMap.cend()) { | |
|
114 | auto currentPartSize = (aIdToARit->second.m_Size != 0) ? 100 / aIdToARit->second.m_Size : 0; | |
|
115 | ||
|
116 | auto currentPartProgress | |
|
117 | = std::isnan(progress) ? 0.0 : (progress * currentPartSize) / 100.0; | |
|
118 | auto currentAlreadyProgress = aIdToARit->second.m_Progression * currentPartSize; | |
|
119 | ||
|
120 | qCInfo(LOG_VariableAcquisitionWorker()) << tr("TORM: progress :") << progress; | |
|
121 | qCInfo(LOG_VariableAcquisitionWorker()) << tr("TORM: onVariableRetrieveDataInProgress A:") | |
|
122 | << aIdToARit->second.m_Progression | |
|
123 | << aIdToARit->second.m_Size; | |
|
124 | qCInfo(LOG_VariableAcquisitionWorker()) << tr("TORM: onVariableRetrieveDataInProgress B:") | |
|
125 | << currentPartSize; | |
|
126 | qCInfo(LOG_VariableAcquisitionWorker()) << tr("TORM: onVariableRetrieveDataInProgress C:") | |
|
127 | << currentPartProgress; | |
|
128 | qCInfo(LOG_VariableAcquisitionWorker()) << tr("TORM: onVariableRetrieveDataInProgress D:") | |
|
129 | << currentAlreadyProgress; | |
|
130 | qCInfo(LOG_VariableAcquisitionWorker()) << tr("TORM: onVariableRetrieveDataInProgress E:") | |
|
131 | << currentAlreadyProgress + currentPartProgress | |
|
132 | << "\n"; | |
|
133 | ||
|
134 | auto finalProgression = currentAlreadyProgress + currentPartProgress; | |
|
135 | emit variableRequestInProgress(aIdToARit->second.m_vIdentifier, finalProgression); | |
|
136 | ||
|
137 | if (finalProgression == 100.0) { | |
|
138 | emit variableRequestInProgress(aIdToARit->second.m_vIdentifier, 0.0); | |
|
139 | } | |
|
140 | } | |
|
141 | impl->unlock(); | |
|
110 | 142 | } |
|
111 | 143 | |
|
112 | 144 | void VariableAcquisitionWorker::onVariableDataAcquired(QUuid acqIdentifier, |
|
113 | 145 | std::shared_ptr<IDataSeries> dataSeries, |
|
114 | 146 | SqpRange dataRangeAcquired) |
|
115 | 147 | { |
|
116 |
qC |
|
|
117 |
|
|
|
148 | qCInfo(LOG_VariableAcquisitionWorker()) << tr("TORM: onVariableDataAcquired on range ") | |
|
149 | << acqIdentifier << dataRangeAcquired; | |
|
118 | 150 | impl->lockWrite(); |
|
119 | 151 | auto aIdToARit = impl->m_AcqIdentifierToAcqRequestMap.find(acqIdentifier); |
|
120 | 152 | if (aIdToARit != impl->m_AcqIdentifierToAcqRequestMap.cend()) { |
@@ -137,11 +169,11 void VariableAcquisitionWorker::onVariableDataAcquired(QUuid acqIdentifier, | |||
|
137 | 169 | |
|
138 | 170 | // Decrement the counter of the request |
|
139 | 171 | auto &acqRequest = aIdToARit->second; |
|
140 |
acqRequest.m_ |
|
|
172 | acqRequest.m_Progression = acqRequest.m_Progression + 1; | |
|
141 | 173 | |
|
142 | 174 | // if the counter is 0, we can return data then run the next request if it exists and |
|
143 | 175 | // removed the finished request |
|
144 |
if (acqRequest.m_Size == |
|
|
176 | if (acqRequest.m_Size == acqRequest.m_Progression) { | |
|
145 | 177 | // Return the data |
|
146 | 178 | aIdToADPVit = impl->m_AcqIdentifierToAcqDataPacketVectorMap.find(acqIdentifier); |
|
147 | 179 | if (aIdToADPVit != impl->m_AcqIdentifierToAcqDataPacketVectorMap.cend()) { |
@@ -192,6 +224,7 void VariableAcquisitionWorker::onExecuteRequest(QUuid acqIdentifier) | |||
|
192 | 224 | if (it != impl->m_AcqIdentifierToAcqRequestMap.cend()) { |
|
193 | 225 | auto request = it->second; |
|
194 | 226 | impl->unlock(); |
|
227 | emit variableRequestInProgress(request.m_vIdentifier, 0.1); | |
|
195 | 228 | request.m_Provider->requestDataLoading(acqIdentifier, request.m_DataProviderParameters); |
|
196 | 229 | } |
|
197 | 230 | else { |
@@ -290,6 +290,8 void VariableController::onDataProvided(QUuid vIdentifier, const SqpRange &range | |||
|
290 | 290 | |
|
291 | 291 | void VariableController::onVariableRetrieveDataInProgress(QUuid identifier, double progress) |
|
292 | 292 | { |
|
293 | qCInfo(LOG_VariableController()) << "TORM: ariableController::onVariableRetrieveDataInProgress" | |
|
294 | << QThread::currentThread()->objectName() << progress; | |
|
293 | 295 | if (auto var = impl->findVariable(identifier)) { |
|
294 | 296 | impl->m_VariableModel->setDataProgress(var, progress); |
|
295 | 297 | } |
@@ -86,8 +86,8 void TestTwoDimArrayData::testCtor_data() | |||
|
86 | 86 | << true << Container{{1., 2., 3., 4., 5.}, |
|
87 | 87 | {6., 7., 8., 9., 10.}, |
|
88 | 88 | {11., 12., 13., 14., 15.}}; |
|
89 | QTest::newRow("invalidInput (invalid data size") | |
|
90 | << InputData{{1., 2., 3., 4., 5., 6., 7.}, 3} << false << Container{{}, {}, {}}; | |
|
89 | QTest::newRow("invalidInput (invalid data size") << InputData{{1., 2., 3., 4., 5., 6., 7.}, 3} | |
|
90 | << false << Container{{}, {}, {}}; | |
|
91 | 91 | QTest::newRow("invalidInput (less than two components") |
|
92 | 92 | << flatten(Container{{1., 2., 3., 4., 5.}}) << false << Container{{}, {}, {}}; |
|
93 | 93 | } |
@@ -7,10 +7,12 | |||
|
7 | 7 | |
|
8 | 8 | #include <QLoggingCategory> |
|
9 | 9 | |
|
10 | #include <map> | |
|
10 | 11 | |
|
11 | 12 | Q_DECLARE_LOGGING_CATEGORY(LOG_AmdaProvider) |
|
12 | 13 | |
|
13 | 14 | class QNetworkReply; |
|
15 | class QNetworkRequest; | |
|
14 | 16 | |
|
15 | 17 | /** |
|
16 | 18 | * @brief The AmdaProvider class is an example of how a data provider can generate data |
@@ -23,8 +25,17 public: | |||
|
23 | 25 | |
|
24 | 26 | void requestDataAborting(QUuid acqIdentifier) override; |
|
25 | 27 | |
|
28 | private slots: | |
|
29 | void onReplyDownloadProgress(QUuid, const QNetworkRequest &, double progress); | |
|
30 | ||
|
26 | 31 | private: |
|
27 | 32 | void retrieveData(QUuid token, const SqpRange &dateTime, const QVariantHash &data); |
|
33 | ||
|
34 | void updateRequestProgress(QUuid acqIdentifier, std::shared_ptr<QNetworkRequest> request, | |
|
35 | double progress); | |
|
36 | ||
|
37 | std::map<QUuid, std::map<std::shared_ptr<QNetworkRequest>, double> > | |
|
38 | m_AcqIdToRequestProgressMap; | |
|
28 | 39 | }; |
|
29 | 40 | |
|
30 | 41 | #endif // SCIQLOP_AMDAPROVIDER_H |
@@ -29,6 +29,11 const auto AMDA_URL_FORMAT = QStringLiteral( | |||
|
29 | 29 | /// Dates format passed in the URL (e.g 2013-09-23T09:00) |
|
30 | 30 | const auto AMDA_TIME_FORMAT = QStringLiteral("yyyy-MM-ddThh:mm:ss"); |
|
31 | 31 | |
|
32 | // struct AmdaProgression { | |
|
33 | // QUuid acqIdentifier; | |
|
34 | // std::map<QNetworkRequest, double> m_RequestId; | |
|
35 | //}; | |
|
36 | ||
|
32 | 37 | /// Formats a time to a date that can be passed in URL |
|
33 | 38 | QString dateFormat(double sqpRange) noexcept |
|
34 | 39 | { |
@@ -63,8 +68,9 AmdaProvider::AmdaProvider() | |||
|
63 | 68 | std::function<void(QNetworkReply *, QUuid)>))); |
|
64 | 69 | |
|
65 | 70 | |
|
66 |
connect(&sqpApp->networkController(), |
|
|
67 |
SIGNAL( |
|
|
71 | connect(&sqpApp->networkController(), | |
|
72 | SIGNAL(replyDownloadProgress(QUuid, const QNetworkRequest &, double)), this, | |
|
73 | SLOT(onReplyDownloadProgress(QUuid, const QNetworkRequest &, double))); | |
|
68 | 74 | } |
|
69 | 75 | } |
|
70 | 76 | |
@@ -76,6 +82,7 void AmdaProvider::requestDataLoading(QUuid acqIdentifier, const DataProviderPar | |||
|
76 | 82 | for (const auto &dateTime : qAsConst(times)) { |
|
77 | 83 | this->retrieveData(acqIdentifier, dateTime, data); |
|
78 | 84 | |
|
85 | ||
|
79 | 86 | // TORM when AMDA will support quick asynchrone request |
|
80 | 87 | QThread::msleep(1000); |
|
81 | 88 | } |
@@ -89,6 +96,55 void AmdaProvider::requestDataAborting(QUuid acqIdentifier) | |||
|
89 | 96 | } |
|
90 | 97 | } |
|
91 | 98 | |
|
99 | void AmdaProvider::onReplyDownloadProgress(QUuid acqIdentifier, | |
|
100 | const QNetworkRequest &networkRequest, double progress) | |
|
101 | { | |
|
102 | qCCritical(LOG_AmdaProvider()) << tr("onReplyDownloadProgress") << progress; | |
|
103 | auto acqIdToRequestProgressMapIt = m_AcqIdToRequestProgressMap.find(acqIdentifier); | |
|
104 | if (acqIdToRequestProgressMapIt != m_AcqIdToRequestProgressMap.end()) { | |
|
105 | ||
|
106 | qCCritical(LOG_AmdaProvider()) << tr("1 onReplyDownloadProgress") << progress; | |
|
107 | auto requestPtr = &networkRequest; | |
|
108 | auto findRequest | |
|
109 | = [requestPtr](const auto &entry) { return requestPtr == entry.first.get(); }; | |
|
110 | ||
|
111 | auto &requestProgressMap = acqIdToRequestProgressMapIt->second; | |
|
112 | auto requestProgressMapEnd = requestProgressMap.end(); | |
|
113 | auto requestProgressMapIt | |
|
114 | = std::find_if(requestProgressMap.begin(), requestProgressMapEnd, findRequest); | |
|
115 | ||
|
116 | if (requestProgressMapIt != requestProgressMapEnd) { | |
|
117 | requestProgressMapIt->second = progress; | |
|
118 | } | |
|
119 | else { | |
|
120 | qCCritical(LOG_AmdaProvider()) << tr("Can't retrieve Request in progress"); | |
|
121 | } | |
|
122 | } | |
|
123 | ||
|
124 | acqIdToRequestProgressMapIt = m_AcqIdToRequestProgressMap.find(acqIdentifier); | |
|
125 | if (acqIdToRequestProgressMapIt != m_AcqIdToRequestProgressMap.end()) { | |
|
126 | qCCritical(LOG_AmdaProvider()) << tr("2 onReplyDownloadProgress") << progress; | |
|
127 | double finalProgress = 0.0; | |
|
128 | ||
|
129 | auto &requestProgressMap = acqIdToRequestProgressMapIt->second; | |
|
130 | auto fraq = requestProgressMap.size(); | |
|
131 | ||
|
132 | for (auto requestProgress : requestProgressMap) { | |
|
133 | finalProgress += requestProgress.second; | |
|
134 | } | |
|
135 | ||
|
136 | if (fraq > 0) { | |
|
137 | finalProgress = finalProgress / fraq; | |
|
138 | } | |
|
139 | ||
|
140 | qCCritical(LOG_AmdaProvider()) << tr("2 onReplyDownloadProgress") << finalProgress; | |
|
141 | emit dataProvidedProgress(acqIdentifier, finalProgress); | |
|
142 | } | |
|
143 | else { | |
|
144 | emit dataProvidedProgress(acqIdentifier, 0.0); | |
|
145 | } | |
|
146 | } | |
|
147 | ||
|
92 | 148 | void AmdaProvider::retrieveData(QUuid token, const SqpRange &dateTime, const QVariantHash &data) |
|
93 | 149 | { |
|
94 | 150 | // Retrieves product ID from data: if the value is invalid, no request is made |
@@ -137,6 +193,7 void AmdaProvider::retrieveData(QUuid token, const SqpRange &dateTime, const QVa | |||
|
137 | 193 | /// @todo ALX : debug |
|
138 | 194 | } |
|
139 | 195 | } |
|
196 | m_AcqIdToRequestProgressMap.erase(dataId); | |
|
140 | 197 | } |
|
141 | 198 | |
|
142 | 199 | }; |
@@ -147,7 +204,6 void AmdaProvider::retrieveData(QUuid token, const SqpRange &dateTime, const QVa | |||
|
147 | 204 | if (reply->error() != QNetworkReply::OperationCanceledError) { |
|
148 | 205 | auto downloadFileUrl = QUrl{QString{reply->readAll()}}; |
|
149 | 206 | |
|
150 | ||
|
151 | 207 | qCInfo(LOG_AmdaProvider()) |
|
152 | 208 | << tr("TORM AmdaProvider::retrieveData downloadFileUrl:") << downloadFileUrl; |
|
153 | 209 | // Executes request for downloading file // |
@@ -155,14 +211,44 void AmdaProvider::retrieveData(QUuid token, const SqpRange &dateTime, const QVa | |||
|
155 | 211 | // Creates destination file |
|
156 | 212 | if (tempFile->open()) { |
|
157 | 213 | // Executes request |
|
158 |
|
|
|
159 | httpDownloadFinished); | |
|
214 | auto request = std::make_shared<QNetworkRequest>(downloadFileUrl); | |
|
215 | updateRequestProgress(dataId, request, 0.0); | |
|
216 | emit requestConstructed(*request.get(), dataId, httpDownloadFinished); | |
|
160 | 217 | } |
|
161 | 218 | } |
|
219 | else { | |
|
220 | m_AcqIdToRequestProgressMap.erase(dataId); | |
|
221 | } | |
|
162 | 222 | }; |
|
163 | 223 | |
|
164 | 224 | // //////////////// // |
|
165 | 225 | // Executes request // |
|
166 | 226 | // //////////////// // |
|
167 | emit requestConstructed(QNetworkRequest{url}, token, httpFinishedLambda); | |
|
227 | ||
|
228 | auto request = std::make_shared<QNetworkRequest>(url); | |
|
229 | updateRequestProgress(token, request, 0.0); | |
|
230 | ||
|
231 | emit requestConstructed(*request.get(), token, httpFinishedLambda); | |
|
232 | } | |
|
233 | ||
|
234 | void AmdaProvider::updateRequestProgress(QUuid acqIdentifier, | |
|
235 | std::shared_ptr<QNetworkRequest> request, double progress) | |
|
236 | { | |
|
237 | auto acqIdToRequestProgressMapIt = m_AcqIdToRequestProgressMap.find(acqIdentifier); | |
|
238 | if (acqIdToRequestProgressMapIt != m_AcqIdToRequestProgressMap.end()) { | |
|
239 | auto &requestProgressMap = acqIdToRequestProgressMapIt->second; | |
|
240 | auto requestProgressMapIt = requestProgressMap.find(request); | |
|
241 | if (requestProgressMapIt != requestProgressMap.end()) { | |
|
242 | requestProgressMapIt->second = progress; | |
|
243 | } | |
|
244 | else { | |
|
245 | acqIdToRequestProgressMapIt->second.insert(std::make_pair(request, progress)); | |
|
246 | } | |
|
247 | } | |
|
248 | else { | |
|
249 | auto requestProgressMap = std::map<std::shared_ptr<QNetworkRequest>, double>{}; | |
|
250 | requestProgressMap.insert(std::make_pair(request, progress)); | |
|
251 | m_AcqIdToRequestProgressMap.insert( | |
|
252 | std::make_pair(acqIdentifier, std::move(requestProgressMap))); | |
|
253 | } | |
|
168 | 254 | } |
@@ -52,6 +52,9 std::shared_ptr<IDataSeries> CosinusProvider::retrieveData(QUuid acqIdentifier, | |||
|
52 | 52 | progress = currentProgress; |
|
53 | 53 | |
|
54 | 54 | emit dataProvidedProgress(acqIdentifier, progress); |
|
55 | qCInfo(LOG_CosinusProvider()) << "TORM: CosinusProvider::retrieveData" | |
|
56 | << QThread::currentThread()->objectName() << progress; | |
|
57 | // NOTE: Try to use multithread if possible | |
|
55 | 58 | } |
|
56 | 59 | } |
|
57 | 60 | else { |
@@ -62,8 +65,10 std::shared_ptr<IDataSeries> CosinusProvider::retrieveData(QUuid acqIdentifier, | |||
|
62 | 65 | } |
|
63 | 66 | } |
|
64 | 67 | } |
|
65 | emit dataProvidedProgress(acqIdentifier, 0.0); | |
|
66 | ||
|
68 | if (progress != 100) { | |
|
69 | // We can close progression beacause all data has been retrieved | |
|
70 | emit dataProvidedProgress(acqIdentifier, 100); | |
|
71 | } | |
|
67 | 72 | return std::make_shared<ScalarSeries>(std::move(xAxisData), std::move(valuesData), |
|
68 | 73 | Unit{QStringLiteral("t"), true}, Unit{}); |
|
69 | 74 | } |
General Comments 0
You need to be logged in to leave comments.
Login now