##// END OF EJS Templates
Implement progression for AmdaProvider.
perrinel -
r695:22c6ca1df132
parent child
Show More
@@ -18,6 +18,7 class QNetworkRequest;
18 18 * @brief The AmdaProvider class is an example of how a data provider can generate data
19 19 */
20 20 class SCIQLOP_AMDA_EXPORT AmdaProvider : public IDataProvider {
21 Q_OBJECT
21 22 public:
22 23 explicit AmdaProvider();
23 24 std::shared_ptr<IDataProvider> clone() const override;
@@ -27,7 +28,8 public:
27 28 void requestDataAborting(QUuid acqIdentifier) override;
28 29
29 30 private slots:
30 void onReplyDownloadProgress(QUuid, const QNetworkRequest &, double progress);
31 void onReplyDownloadProgress(QUuid acqIdentifier,
32 std::shared_ptr<QNetworkRequest> networkRequest, double progress);
31 33
32 34 private:
33 35 void retrieveData(QUuid token, const SqpRange &dateTime, const QVariantHash &data);
@@ -29,11 +29,6 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
37 32 /// Formats a time to a date that can be passed in URL
38 33 QString dateFormat(double sqpRange) noexcept
39 34 {
@@ -61,16 +56,17 AmdaProvider::AmdaProvider()
61 56 qCDebug(LOG_AmdaProvider()) << tr("AmdaProvider::AmdaProvider") << QThread::currentThread();
62 57 if (auto app = sqpApp) {
63 58 auto &networkController = app->networkController();
64 connect(this, SIGNAL(requestConstructed(QNetworkRequest, QUuid,
59 connect(this, SIGNAL(requestConstructed(std::shared_ptr<QNetworkRequest>, QUuid,
65 60 std::function<void(QNetworkReply *, QUuid)>)),
66 61 &networkController,
67 SLOT(onProcessRequested(QNetworkRequest, QUuid,
62 SLOT(onProcessRequested(std::shared_ptr<QNetworkRequest>, QUuid,
68 63 std::function<void(QNetworkReply *, QUuid)>)));
69 64
70 65
71 66 connect(&sqpApp->networkController(),
72 SIGNAL(replyDownloadProgress(QUuid, const QNetworkRequest &, double)), this,
73 SLOT(onReplyDownloadProgress(QUuid, const QNetworkRequest &, double)));
67 SIGNAL(replyDownloadProgress(QUuid, std::shared_ptr<QNetworkRequest>, double)),
68 this,
69 SLOT(onReplyDownloadProgress(QUuid, std::shared_ptr<QNetworkRequest>, double)));
74 70 }
75 71 }
76 72
@@ -103,16 +99,17 void AmdaProvider::requestDataAborting(QUuid acqIdentifier)
103 99 }
104 100
105 101 void AmdaProvider::onReplyDownloadProgress(QUuid acqIdentifier,
106 const QNetworkRequest &networkRequest, double progress)
102 std::shared_ptr<QNetworkRequest> networkRequest,
103 double progress)
107 104 {
108 qCCritical(LOG_AmdaProvider()) << tr("onReplyDownloadProgress") << progress;
105 qCDebug(LOG_AmdaProvider()) << tr("onReplyDownloadProgress") << acqIdentifier
106 << networkRequest.get() << progress;
109 107 auto acqIdToRequestProgressMapIt = m_AcqIdToRequestProgressMap.find(acqIdentifier);
110 108 if (acqIdToRequestProgressMapIt != m_AcqIdToRequestProgressMap.end()) {
111 109
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(); };
110 qCDebug(LOG_AmdaProvider()) << tr("1 onReplyDownloadProgress found") << progress;
111 auto requestPtr = networkRequest;
112 auto findRequest = [requestPtr](const auto &entry) { return requestPtr == entry.first; };
116 113
117 114 auto &requestProgressMap = acqIdToRequestProgressMapIt->second;
118 115 auto requestProgressMapEnd = requestProgressMap.end();
@@ -123,13 +120,13 void AmdaProvider::onReplyDownloadProgress(QUuid acqIdentifier,
123 120 requestProgressMapIt->second = progress;
124 121 }
125 122 else {
126 qCCritical(LOG_AmdaProvider()) << tr("Can't retrieve Request in progress");
123 qCCritical(LOG_AmdaProvider()) << tr("Can't retrieve Request in progress")
124 << acqIdentifier << networkRequest.get() << progress;
127 125 }
128 126 }
129 127
130 128 acqIdToRequestProgressMapIt = m_AcqIdToRequestProgressMap.find(acqIdentifier);
131 129 if (acqIdToRequestProgressMapIt != m_AcqIdToRequestProgressMap.end()) {
132 qCCritical(LOG_AmdaProvider()) << tr("2 onReplyDownloadProgress") << progress;
133 130 double finalProgress = 0.0;
134 131
135 132 auto &requestProgressMap = acqIdToRequestProgressMapIt->second;
@@ -137,13 +134,16 void AmdaProvider::onReplyDownloadProgress(QUuid acqIdentifier,
137 134
138 135 for (auto requestProgress : requestProgressMap) {
139 136 finalProgress += requestProgress.second;
137 qCDebug(LOG_AmdaProvider()) << tr("current final progress without freq:")
138 << finalProgress << requestProgress.second;
140 139 }
141 140
142 141 if (fraq > 0) {
143 142 finalProgress = finalProgress / fraq;
144 143 }
145 144
146 qCCritical(LOG_AmdaProvider()) << tr("2 onReplyDownloadProgress") << finalProgress;
145 qCDebug(LOG_AmdaProvider()) << tr("2 onReplyDownloadProgress final progress") << fraq
146 << finalProgress;
147 147 emit dataProvidedProgress(acqIdentifier, finalProgress);
148 148 }
149 149 else {
@@ -173,7 +173,7 void AmdaProvider::retrieveData(QUuid token, const SqpRange &dateTime, const QVa
173 173 auto endDate = dateFormat(dateTime.m_TEnd);
174 174
175 175 auto url = QUrl{QString{AMDA_URL_FORMAT}.arg(startDate, endDate, productId)};
176 qCInfo(LOG_AmdaProvider()) << tr("TORM AmdaProvider::retrieveData url:") << url;
176 qCDebug(LOG_AmdaProvider()) << tr("TORM AmdaProvider::retrieveData url:") << url;
177 177 auto tempFile = std::make_shared<QTemporaryFile>();
178 178
179 179 // LAMBDA
@@ -216,10 +216,10 void AmdaProvider::retrieveData(QUuid token, const SqpRange &dateTime, const QVa
216 216
217 217 // Creates destination file
218 218 if (tempFile->open()) {
219 // Executes request
219 // Executes request and store the request for progression
220 220 auto request = std::make_shared<QNetworkRequest>(downloadFileUrl);
221 221 updateRequestProgress(dataId, request, 0.0);
222 emit requestConstructed(*request.get(), dataId, httpDownloadFinished);
222 emit requestConstructed(request, dataId, httpDownloadFinished);
223 223 }
224 224 }
225 225 else {
@@ -232,9 +232,10 void AmdaProvider::retrieveData(QUuid token, const SqpRange &dateTime, const QVa
232 232 // //////////////// //
233 233
234 234 auto request = std::make_shared<QNetworkRequest>(url);
235 qCDebug(LOG_AmdaProvider()) << tr("First Request creation") << request.get();
235 236 updateRequestProgress(token, request, 0.0);
236 237
237 emit requestConstructed(*request.get(), token, httpFinishedLambda);
238 emit requestConstructed(request, token, httpFinishedLambda);
238 239 }
239 240
240 241 void AmdaProvider::updateRequestProgress(QUuid acqIdentifier,
@@ -246,12 +247,18 void AmdaProvider::updateRequestProgress(QUuid acqIdentifier,
246 247 auto requestProgressMapIt = requestProgressMap.find(request);
247 248 if (requestProgressMapIt != requestProgressMap.end()) {
248 249 requestProgressMapIt->second = progress;
250 qCDebug(LOG_AmdaProvider()) << tr("updateRequestProgress new progress for request")
251 << acqIdentifier << request.get() << progress;
249 252 }
250 253 else {
254 qCDebug(LOG_AmdaProvider()) << tr("updateRequestProgress new request") << acqIdentifier
255 << request.get() << progress;
251 256 acqIdToRequestProgressMapIt->second.insert(std::make_pair(request, progress));
252 257 }
253 258 }
254 259 else {
260 qCDebug(LOG_AmdaProvider()) << tr("updateRequestProgress new acqIdentifier")
261 << acqIdentifier << request.get() << progress;
255 262 auto requestProgressMap = std::map<std::shared_ptr<QNetworkRequest>, double>{};
256 263 requestProgressMap.insert(std::make_pair(request, progress));
257 264 m_AcqIdToRequestProgressMap.insert(
General Comments 2
You need to be logged in to leave comments. Login now