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