##// END OF EJS Templates
Implementation of progression
perrinel -
r750:f189aafd213c
parent child
Show More
@@ -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, double progress);
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 qCDebug(LOG_VariableAcquisitionWorker()) << tr("onVariableDataAcquired on range ")
117 << acqIdentifier << dataRangeAcquired;
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_Size = acqRequest.m_Size - 1;
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 == 0) {
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()) {
@@ -184,6 +216,23 void VariableAcquisitionWorker::onVariableDataAcquired(QUuid acqIdentifier,
184 216 impl->unlock();
185 217 }
186 218
219 void VariableAcquisitionWorker::onExecuteRequest(QUuid acqIdentifier)
220 {
221 qCDebug(LOG_VariableAcquisitionWorker()) << tr("onExecuteRequest") << QThread::currentThread();
222 impl->lockRead();
223 auto it = impl->m_AcqIdentifierToAcqRequestMap.find(acqIdentifier);
224 if (it != impl->m_AcqIdentifierToAcqRequestMap.cend()) {
225 auto request = it->second;
226 impl->unlock();
227 emit variableRequestInProgress(request.m_vIdentifier, 0.1);
228 request.m_Provider->requestDataLoading(acqIdentifier, request.m_DataProviderParameters);
229 }
230 else {
231 impl->unlock();
232 // TODO log no acqIdentifier recognized
233 }
234 }
235
187 236 void VariableAcquisitionWorker::initialize()
188 237 {
189 238 qCDebug(LOG_VariableAcquisitionWorker()) << tr("VariableAcquisitionWorker init")
@@ -221,18 +270,18 void VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate::removeVariable
221 270 unlock();
222 271 }
223 272
224 void VariableAcquisitionWorker::onExecuteRequest(QUuid acqIdentifier)
225 {
226 qCDebug(LOG_VariableAcquisitionWorker()) << tr("onExecuteRequest") << QThread::currentThread();
227 impl->lockRead();
228 auto it = impl->m_AcqIdentifierToAcqRequestMap.find(acqIdentifier);
229 if (it != impl->m_AcqIdentifierToAcqRequestMap.cend()) {
230 auto request = it->second;
231 impl->unlock();
232 request.m_Provider->requestDataLoading(acqIdentifier, request.m_DataProviderParameters);
233 }
234 else {
235 impl->unlock();
236 // TODO log no acqIdentifier recognized
237 }
238 }
273 //void VariableAcquisitionWorker::onExecuteRequest(QUuid acqIdentifier)
274 //{
275 // qCDebug(LOG_VariableAcquisitionWorker()) << tr("onExecuteRequest") << QThread::currentThread();
276 // impl->lockRead();
277 // auto it = impl->m_AcqIdentifierToAcqRequestMap.find(acqIdentifier);
278 // if (it != impl->m_AcqIdentifierToAcqRequestMap.cend()) {
279 // auto request = it->second;
280 // impl->unlock();
281 // request.m_Provider->requestDataLoading(acqIdentifier, request.m_DataProviderParameters);
282 // }
283 // else {
284 // impl->unlock();
285 // // TODO log no acqIdentifier recognized
286 // }
287 //}
@@ -322,6 +322,8 void VariableController::onDataProvided(QUuid vIdentifier, const SqpRange &range
322 322
323 323 void VariableController::onVariableRetrieveDataInProgress(QUuid identifier, double progress)
324 324 {
325 qCInfo(LOG_VariableController()) << "TORM: ariableController::onVariableRetrieveDataInProgress"
326 << QThread::currentThread()->objectName() << progress;
325 327 if (auto var = impl->findVariable(identifier)) {
326 328 impl->m_VariableModel->setDataProgress(var, progress);
327 329 }
@@ -87,8 +87,8 void TestTwoDimArrayData::testCtor_data()
87 87 << true << Container{{1., 2., 3., 4., 5.},
88 88 {6., 7., 8., 9., 10.},
89 89 {11., 12., 13., 14., 15.}};
90 QTest::newRow("invalidInput (invalid data size")
91 << InputData{{1., 2., 3., 4., 5., 6., 7.}, 3} << false << Container{{}, {}, {}};
90 QTest::newRow("invalidInput (invalid data size") << InputData{{1., 2., 3., 4., 5., 6., 7.}, 3}
91 << false << Container{{}, {}, {}};
92 92 QTest::newRow("invalidInput (less than two components")
93 93 << flatten(Container{{1., 2., 3., 4., 5.}}) << false << Container{{}, {}, {}};
94 94 }
@@ -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
@@ -24,8 +26,17 public:
24 26
25 27 void requestDataAborting(QUuid acqIdentifier) override;
26 28
29 private slots:
30 void onReplyDownloadProgress(QUuid, const QNetworkRequest &, double progress);
31
27 32 private:
28 33 void retrieveData(QUuid token, const SqpRange &dateTime, const QVariantHash &data);
34
35 void updateRequestProgress(QUuid acqIdentifier, std::shared_ptr<QNetworkRequest> request,
36 double progress);
37
38 std::map<QUuid, std::map<std::shared_ptr<QNetworkRequest>, double> >
39 m_AcqIdToRequestProgressMap;
29 40 };
30 41
31 42 #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(), SIGNAL(replyDownloadProgress(QUuid, double)), this,
67 SIGNAL(dataProvidedProgress(QUuid, double)));
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
@@ -82,6 +88,7 void AmdaProvider::requestDataLoading(QUuid acqIdentifier, const DataProviderPar
82 88 for (const auto &dateTime : qAsConst(times)) {
83 89 this->retrieveData(acqIdentifier, dateTime, data);
84 90
91
85 92 // TORM when AMDA will support quick asynchrone request
86 93 QThread::msleep(1000);
87 94 }
@@ -95,6 +102,55 void AmdaProvider::requestDataAborting(QUuid acqIdentifier)
95 102 }
96 103 }
97 104
105 void AmdaProvider::onReplyDownloadProgress(QUuid acqIdentifier,
106 const QNetworkRequest &networkRequest, double progress)
107 {
108 qCCritical(LOG_AmdaProvider()) << tr("onReplyDownloadProgress") << progress;
109 auto acqIdToRequestProgressMapIt = m_AcqIdToRequestProgressMap.find(acqIdentifier);
110 if (acqIdToRequestProgressMapIt != m_AcqIdToRequestProgressMap.end()) {
111
112 qCCritical(LOG_AmdaProvider()) << tr("1 onReplyDownloadProgress") << progress;
113 auto requestPtr = &networkRequest;
114 auto findRequest
115 = [requestPtr](const auto &entry) { return requestPtr == entry.first.get(); };
116
117 auto &requestProgressMap = acqIdToRequestProgressMapIt->second;
118 auto requestProgressMapEnd = requestProgressMap.end();
119 auto requestProgressMapIt
120 = std::find_if(requestProgressMap.begin(), requestProgressMapEnd, findRequest);
121
122 if (requestProgressMapIt != requestProgressMapEnd) {
123 requestProgressMapIt->second = progress;
124 }
125 else {
126 qCCritical(LOG_AmdaProvider()) << tr("Can't retrieve Request in progress");
127 }
128 }
129
130 acqIdToRequestProgressMapIt = m_AcqIdToRequestProgressMap.find(acqIdentifier);
131 if (acqIdToRequestProgressMapIt != m_AcqIdToRequestProgressMap.end()) {
132 qCCritical(LOG_AmdaProvider()) << tr("2 onReplyDownloadProgress") << progress;
133 double finalProgress = 0.0;
134
135 auto &requestProgressMap = acqIdToRequestProgressMapIt->second;
136 auto fraq = requestProgressMap.size();
137
138 for (auto requestProgress : requestProgressMap) {
139 finalProgress += requestProgress.second;
140 }
141
142 if (fraq > 0) {
143 finalProgress = finalProgress / fraq;
144 }
145
146 qCCritical(LOG_AmdaProvider()) << tr("2 onReplyDownloadProgress") << finalProgress;
147 emit dataProvidedProgress(acqIdentifier, finalProgress);
148 }
149 else {
150 emit dataProvidedProgress(acqIdentifier, 0.0);
151 }
152 }
153
98 154 void AmdaProvider::retrieveData(QUuid token, const SqpRange &dateTime, const QVariantHash &data)
99 155 {
100 156 // Retrieves product ID from data: if the value is invalid, no request is made
@@ -143,6 +199,7 void AmdaProvider::retrieveData(QUuid token, const SqpRange &dateTime, const QVa
143 199 /// @todo ALX : debug
144 200 }
145 201 }
202 m_AcqIdToRequestProgressMap.erase(dataId);
146 203 }
147 204
148 205 };
@@ -153,7 +210,6 void AmdaProvider::retrieveData(QUuid token, const SqpRange &dateTime, const QVa
153 210 if (reply->error() != QNetworkReply::OperationCanceledError) {
154 211 auto downloadFileUrl = QUrl{QString{reply->readAll()}};
155 212
156
157 213 qCInfo(LOG_AmdaProvider())
158 214 << tr("TORM AmdaProvider::retrieveData downloadFileUrl:") << downloadFileUrl;
159 215 // Executes request for downloading file //
@@ -161,14 +217,44 void AmdaProvider::retrieveData(QUuid token, const SqpRange &dateTime, const QVa
161 217 // Creates destination file
162 218 if (tempFile->open()) {
163 219 // Executes request
164 emit requestConstructed(QNetworkRequest{downloadFileUrl}, dataId,
165 httpDownloadFinished);
220 auto request = std::make_shared<QNetworkRequest>(downloadFileUrl);
221 updateRequestProgress(dataId, request, 0.0);
222 emit requestConstructed(*request.get(), dataId, httpDownloadFinished);
166 223 }
167 224 }
225 else {
226 m_AcqIdToRequestProgressMap.erase(dataId);
227 }
168 228 };
169 229
170 230 // //////////////// //
171 231 // Executes request //
172 232 // //////////////// //
173 emit requestConstructed(QNetworkRequest{url}, token, httpFinishedLambda);
233
234 auto request = std::make_shared<QNetworkRequest>(url);
235 updateRequestProgress(token, request, 0.0);
236
237 emit requestConstructed(*request.get(), token, httpFinishedLambda);
238 }
239
240 void AmdaProvider::updateRequestProgress(QUuid acqIdentifier,
241 std::shared_ptr<QNetworkRequest> request, double progress)
242 {
243 auto acqIdToRequestProgressMapIt = m_AcqIdToRequestProgressMap.find(acqIdentifier);
244 if (acqIdToRequestProgressMapIt != m_AcqIdToRequestProgressMap.end()) {
245 auto &requestProgressMap = acqIdToRequestProgressMapIt->second;
246 auto requestProgressMapIt = requestProgressMap.find(request);
247 if (requestProgressMapIt != requestProgressMap.end()) {
248 requestProgressMapIt->second = progress;
249 }
250 else {
251 acqIdToRequestProgressMapIt->second.insert(std::make_pair(request, progress));
252 }
253 }
254 else {
255 auto requestProgressMap = std::map<std::shared_ptr<QNetworkRequest>, double>{};
256 requestProgressMap.insert(std::make_pair(request, progress));
257 m_AcqIdToRequestProgressMap.insert(
258 std::make_pair(acqIdentifier, std::move(requestProgressMap)));
259 }
174 260 }
@@ -59,6 +59,9 std::shared_ptr<IDataSeries> CosinusProvider::retrieveData(QUuid acqIdentifier,
59 59 progress = currentProgress;
60 60
61 61 emit dataProvidedProgress(acqIdentifier, progress);
62 qCInfo(LOG_CosinusProvider()) << "TORM: CosinusProvider::retrieveData"
63 << QThread::currentThread()->objectName() << progress;
64 // NOTE: Try to use multithread if possible
62 65 }
63 66 }
64 67 else {
@@ -69,8 +72,10 std::shared_ptr<IDataSeries> CosinusProvider::retrieveData(QUuid acqIdentifier,
69 72 }
70 73 }
71 74 }
72 emit dataProvidedProgress(acqIdentifier, 0.0);
73
75 if (progress != 100) {
76 // We can close progression beacause all data has been retrieved
77 emit dataProvidedProgress(acqIdentifier, 100);
78 }
74 79 return std::make_shared<ScalarSeries>(std::move(xAxisData), std::move(valuesData),
75 80 Unit{QStringLiteral("t"), true}, Unit{});
76 81 }
General Comments 0
You need to be logged in to leave comments. Login now