##// END OF EJS Templates
Merge branch 'feature/AcqBasedOnPreviousRequest' into develop
perrinel -
r815:3edf24abad73 merge
parent child
Show More
@@ -48,15 +48,17 SqpRange computeSynchroRangeRequested(const SqpRange &varRange, const SqpRange &
48 break;
48 break;
49 }
49 }
50 case AcquisitionZoomType::PanRight: {
50 case AcquisitionZoomType::PanRight: {
51 auto deltaLeft = graphRange.m_TStart - oldGraphRange.m_TStart;
51 auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd;
52 auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd;
52 varRangeRequested.m_TStart += deltaRight;
53 varRangeRequested.m_TStart += deltaLeft;
53 varRangeRequested.m_TEnd += deltaRight;
54 varRangeRequested.m_TEnd += deltaRight;
54 break;
55 break;
55 }
56 }
56 case AcquisitionZoomType::PanLeft: {
57 case AcquisitionZoomType::PanLeft: {
57 auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart;
58 auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart;
59 auto deltaRight = oldGraphRange.m_TEnd - graphRange.m_TEnd;
58 varRangeRequested.m_TStart -= deltaLeft;
60 varRangeRequested.m_TStart -= deltaLeft;
59 varRangeRequested.m_TEnd -= deltaLeft;
61 varRangeRequested.m_TEnd -= deltaRight;
60 break;
62 break;
61 }
63 }
62 case AcquisitionZoomType::Unknown: {
64 case AcquisitionZoomType::Unknown: {
@@ -117,6 +119,8 struct VariableController::VariableControllerPrivate {
117 void updateVariableRequest(QUuid varRequestId);
119 void updateVariableRequest(QUuid varRequestId);
118 void cancelVariableRequest(QUuid varRequestId);
120 void cancelVariableRequest(QUuid varRequestId);
119
121
122 SqpRange getLastRequestedRange(QUuid varId);
123
120 QMutex m_WorkingMutex;
124 QMutex m_WorkingMutex;
121 /// Variable model. The VariableController has the ownership
125 /// Variable model. The VariableController has the ownership
122 VariableModel *m_VariableModel;
126 VariableModel *m_VariableModel;
@@ -549,15 +553,19 AcquisitionZoomType VariableController::getZoomType(const SqpRange &range, const
549 // t1.m_TStart <= t2.m_TStart && t2.m_TEnd <= t1.m_TEnd
553 // t1.m_TStart <= t2.m_TStart && t2.m_TEnd <= t1.m_TEnd
550 auto zoomType = AcquisitionZoomType::Unknown;
554 auto zoomType = AcquisitionZoomType::Unknown;
551 if (range.m_TStart <= oldRange.m_TStart && oldRange.m_TEnd <= range.m_TEnd) {
555 if (range.m_TStart <= oldRange.m_TStart && oldRange.m_TEnd <= range.m_TEnd) {
556 qCCritical(LOG_VariableController()) << "zoomtype: ZoomOut";
552 zoomType = AcquisitionZoomType::ZoomOut;
557 zoomType = AcquisitionZoomType::ZoomOut;
553 }
558 }
554 else if (range.m_TStart > oldRange.m_TStart && range.m_TEnd > oldRange.m_TEnd) {
559 else if (range.m_TStart > oldRange.m_TStart && range.m_TEnd > oldRange.m_TEnd) {
560 qCCritical(LOG_VariableController()) << "zoomtype: PanRight";
555 zoomType = AcquisitionZoomType::PanRight;
561 zoomType = AcquisitionZoomType::PanRight;
556 }
562 }
557 else if (range.m_TStart < oldRange.m_TStart && range.m_TEnd < oldRange.m_TEnd) {
563 else if (range.m_TStart < oldRange.m_TStart && range.m_TEnd < oldRange.m_TEnd) {
564 qCCritical(LOG_VariableController()) << "zoomtype: PanLeft";
558 zoomType = AcquisitionZoomType::PanLeft;
565 zoomType = AcquisitionZoomType::PanLeft;
559 }
566 }
560 else if (range.m_TStart > oldRange.m_TStart && oldRange.m_TEnd > range.m_TEnd) {
567 else if (range.m_TStart > oldRange.m_TStart && oldRange.m_TEnd > range.m_TEnd) {
568 qCCritical(LOG_VariableController()) << "zoomtype: ZoomIn";
561 zoomType = AcquisitionZoomType::ZoomIn;
569 zoomType = AcquisitionZoomType::ZoomIn;
562 }
570 }
563 else {
571 else {
@@ -570,59 +578,70 void VariableController::VariableControllerPrivate::processRequest(std::shared_p
570 const SqpRange &rangeRequested,
578 const SqpRange &rangeRequested,
571 QUuid varRequestId)
579 QUuid varRequestId)
572 {
580 {
573
574 // TODO: protect at
575 auto varRequest = VariableRequest{};
581 auto varRequest = VariableRequest{};
576 auto varId = m_VariableToIdentifierMap.at(var);
577
582
578 auto varStrategyRangesRequested
583 auto it = m_VariableToIdentifierMap.find(var);
579 = m_VariableCacheStrategy->computeRange(var->range(), rangeRequested);
584 if (it != m_VariableToIdentifierMap.cend()) {
580
585
581 auto notInCacheRangeList = QVector<SqpRange>{varStrategyRangesRequested.second};
586 auto varId = it->second;
582 auto inCacheRangeList = QVector<SqpRange>{};
587
583 if (m_VarIdToVarRequestIdQueueMap.find(varId) == m_VarIdToVarRequestIdQueueMap.cend()) {
588 auto oldRange = getLastRequestedRange(varId);
584 notInCacheRangeList = var->provideNotInCacheRangeList(varStrategyRangesRequested.second);
589
585 inCacheRangeList = var->provideInCacheRangeList(varStrategyRangesRequested.second);
590 // check for update oldRange to the last request range.
586 }
591 if (oldRange == INVALID_RANGE) {
592 oldRange = var->range();
593 }
587
594
588 if (!notInCacheRangeList.empty()) {
595 auto varStrategyRangesRequested
589 varRequest.m_RangeRequested = varStrategyRangesRequested.first;
596 = m_VariableCacheStrategy->computeRange(oldRange, rangeRequested);
590 varRequest.m_CacheRangeRequested = varStrategyRangesRequested.second;
591
597
592 // store VarRequest
598 auto notInCacheRangeList = QVector<SqpRange>{varStrategyRangesRequested.second};
593 storeVariableRequest(varId, varRequestId, varRequest);
599 auto inCacheRangeList = QVector<SqpRange>{};
600 if (m_VarIdToVarRequestIdQueueMap.find(varId) == m_VarIdToVarRequestIdQueueMap.cend()) {
601 notInCacheRangeList
602 = var->provideNotInCacheRangeList(varStrategyRangesRequested.second);
603 inCacheRangeList = var->provideInCacheRangeList(varStrategyRangesRequested.second);
604 }
594
605
595 auto varProvider = m_VariableToProviderMap.at(var);
606 if (!notInCacheRangeList.empty()) {
596 if (varProvider != nullptr) {
607 varRequest.m_RangeRequested = varStrategyRangesRequested.first;
597 auto varRequestIdCanceled = m_VariableAcquisitionWorker->pushVariableRequest(
608 varRequest.m_CacheRangeRequested = varStrategyRangesRequested.second;
598 varRequestId, varId, varStrategyRangesRequested.first,
609
599 varStrategyRangesRequested.second,
610 // store VarRequest
600 DataProviderParameters{std::move(notInCacheRangeList), var->metadata()},
611 storeVariableRequest(varId, varRequestId, varRequest);
601 varProvider);
612
613 auto varProvider = m_VariableToProviderMap.at(var);
614 if (varProvider != nullptr) {
615 auto varRequestIdCanceled = m_VariableAcquisitionWorker->pushVariableRequest(
616 varRequestId, varId, varStrategyRangesRequested.first,
617 varStrategyRangesRequested.second,
618 DataProviderParameters{std::move(notInCacheRangeList), var->metadata()},
619 varProvider);
620
621 if (!varRequestIdCanceled.isNull()) {
622 qCDebug(LOG_VariableAcquisitionWorker()) << tr("vsarRequestIdCanceled: ")
623 << varRequestIdCanceled;
624 cancelVariableRequest(varRequestIdCanceled);
625 }
626 }
627 else {
628 qCCritical(LOG_VariableController())
629 << "Impossible to provide data with a null provider";
630 }
602
631
603 if (!varRequestIdCanceled.isNull()) {
632 if (!inCacheRangeList.empty()) {
604 qCDebug(LOG_VariableAcquisitionWorker()) << tr("vsarRequestIdCanceled: ")
633 emit q->updateVarDisplaying(var, inCacheRangeList.first());
605 << varRequestIdCanceled;
606 cancelVariableRequest(varRequestIdCanceled);
607 }
634 }
608 }
635 }
609 else {
636 else {
610 qCCritical(LOG_VariableController())
637 varRequest.m_RangeRequested = varStrategyRangesRequested.first;
611 << "Impossible to provide data with a null provider";
638 varRequest.m_CacheRangeRequested = varStrategyRangesRequested.second;
612 }
639 // store VarRequest
613
640 storeVariableRequest(varId, varRequestId, varRequest);
614 if (!inCacheRangeList.empty()) {
641 acceptVariableRequest(
615 emit q->updateVarDisplaying(var, inCacheRangeList.first());
642 varId, var->dataSeries()->subDataSeries(varStrategyRangesRequested.second));
616 }
643 }
617 }
644 }
618 else {
619 varRequest.m_RangeRequested = varStrategyRangesRequested.first;
620 varRequest.m_CacheRangeRequested = varStrategyRangesRequested.second;
621 // store VarRequest
622 storeVariableRequest(varId, varRequestId, varRequest);
623 acceptVariableRequest(varId,
624 var->dataSeries()->subDataSeries(varStrategyRangesRequested.second));
625 }
626 }
645 }
627
646
628 std::shared_ptr<Variable>
647 std::shared_ptr<Variable>
@@ -838,3 +857,40 void VariableController::VariableControllerPrivate::cancelVariableRequest(QUuid
838 }
857 }
839 }
858 }
840 }
859 }
860
861 SqpRange VariableController::VariableControllerPrivate::getLastRequestedRange(QUuid varId)
862 {
863 auto lastRangeRequested = SqpRange{INVALID_RANGE};
864 auto varIdToVarRequestIdQueueMapIt = m_VarIdToVarRequestIdQueueMap.find(varId);
865 if (varIdToVarRequestIdQueueMapIt != m_VarIdToVarRequestIdQueueMap.cend()) {
866 auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second;
867 auto varRequestId = varRequestIdQueue.back();
868 auto varRequestIdToVarIdVarRequestMapIt
869 = m_VarRequestIdToVarIdVarRequestMap.find(varRequestId);
870 if (varRequestIdToVarIdVarRequestMapIt != m_VarRequestIdToVarIdVarRequestMap.cend()) {
871 auto &varIdToVarRequestMap = varRequestIdToVarIdVarRequestMapIt->second;
872 auto varIdToVarRequestMapIt = varIdToVarRequestMap.find(varId);
873 if (varIdToVarRequestMapIt != varIdToVarRequestMap.cend()) {
874 auto &varRequest = varIdToVarRequestMapIt->second;
875 lastRangeRequested = varRequest.m_RangeRequested;
876 }
877 else {
878 qCDebug(LOG_VariableController())
879 << tr("Impossible to getLastRequestedRange of a unknown variable id attached "
880 "to a variableRequestId")
881 << varRequestId << varId;
882 }
883 }
884 else {
885 qCCritical(LOG_VariableController())
886 << tr("Impossible to getLastRequestedRange of a unknown variableRequestId")
887 << varRequestId;
888 }
889 }
890 else {
891 qDebug(LOG_VariableController())
892 << tr("Impossible to getLastRequestedRange of a unknown variable id") << varId;
893 }
894
895 return lastRangeRequested;
896 }
@@ -171,20 +171,10 private slots:
171 void testSync();
171 void testSync();
172 };
172 };
173
173
174 void TestVariableSync::testSync_data()
174 namespace {
175 {
176 // ////////////// //
177 // Test structure //
178 // ////////////// //
179
180 QTest::addColumn<QUuid>("syncId");
181 QTest::addColumn<SqpRange>("initialRange");
182 QTest::addColumn<Iterations>("iterations");
183
184 // ////////// //
185 // Test cases //
186 // ////////// //
187
175
176 void testSyncCase1()
177 {
188 // Id used to synchronize variables in the controller
178 // Id used to synchronize variables in the controller
189 auto syncId = QUuid::createUuid();
179 auto syncId = QUuid::createUuid();
190
180
@@ -254,7 +244,86 void TestVariableSync::testSync_data()
254 // Zoom out
244 // Zoom out
255 moveVar0(range({12, 0}, {18, 0}), range({11, 0}, {17, 0}));
245 moveVar0(range({12, 0}, {18, 0}), range({11, 0}, {17, 0}));
256
246
257 QTest::newRow("sync1") << syncId << initialRange << std::move(iterations);
247 QTest::newRow("sync1") << syncId << initialRange << std::move(iterations) << 200;
248 }
249
250 void testSyncCase2()
251 {
252 // Id used to synchronize variables in the controller
253 auto syncId = QUuid::createUuid();
254
255 /// Generates a range according to a start time and a end time (the date is the same)
256 auto dateTime = [](int year, int month, int day, int hours, int minutes, int seconds) {
257 return DateUtils::secondsSinceEpoch(
258 QDateTime{{year, month, day}, QTime{hours, minutes, seconds}, Qt::UTC});
259 };
260
261 auto initialRange = SqpRange{dateTime(2017, 1, 1, 12, 0, 0), dateTime(2017, 1, 1, 13, 0, 0)};
262
263 Iterations iterations{};
264 // Creates variables var0 and var1
265 iterations.push_back({std::make_shared<Create>(0), {{0, initialRange}}});
266 iterations.push_back({std::make_shared<Create>(1), {{0, initialRange}, {1, initialRange}}});
267
268 // Adds variables into the sync group (ranges don't need to be tested here)
269 iterations.push_back({std::make_shared<Synchronize>(0, syncId)});
270 iterations.push_back({std::make_shared<Synchronize>(1, syncId)});
271
272
273 // Moves var0 through several operations:
274 // - range of var0 changes
275 // - range or var1 changes according to the previous shift (one hour)
276 auto moveVar0 = [&iterations](const auto &var0NewRange) {
277 iterations.push_back(
278 {std::make_shared<Move>(0, var0NewRange), {{0, var0NewRange}, {1, var0NewRange}}});
279 };
280 moveVar0(SqpRange{dateTime(2017, 1, 1, 12, 0, 0), dateTime(2017, 1, 1, 13, 0, 0)});
281 moveVar0(SqpRange{dateTime(2017, 1, 1, 14, 0, 0), dateTime(2017, 1, 1, 15, 0, 0)});
282 moveVar0(SqpRange{dateTime(2017, 1, 1, 8, 0, 0), dateTime(2017, 1, 1, 9, 0, 0)});
283 // moveVar0(SqpRange{dateTime(2017, 1, 1, 7, 30, 0), dateTime(2017, 1, 1, 9, 30, 0)});
284 moveVar0(SqpRange{dateTime(2017, 1, 1, 2, 0, 0), dateTime(2017, 1, 1, 4, 0, 0)});
285 moveVar0(SqpRange{dateTime(2017, 1, 1, 6, 0, 0), dateTime(2017, 1, 1, 8, 0, 0)});
286
287 moveVar0(SqpRange{dateTime(2017, 1, 10, 6, 0, 0), dateTime(2017, 1, 15, 8, 0, 0)});
288 moveVar0(SqpRange{dateTime(2017, 1, 17, 6, 0, 0), dateTime(2017, 1, 25, 8, 0, 0)});
289 moveVar0(SqpRange{dateTime(2017, 1, 2, 6, 0, 0), dateTime(2017, 1, 8, 8, 0, 0)});
290
291 moveVar0(SqpRange{dateTime(2017, 4, 10, 6, 0, 0), dateTime(2017, 6, 15, 8, 0, 0)});
292 moveVar0(SqpRange{dateTime(2017, 1, 17, 6, 0, 0), dateTime(2017, 2, 25, 8, 0, 0)});
293 moveVar0(SqpRange{dateTime(2017, 7, 2, 6, 0, 0), dateTime(2017, 10, 8, 8, 0, 0)});
294 moveVar0(SqpRange{dateTime(2017, 4, 10, 6, 0, 0), dateTime(2017, 6, 15, 8, 0, 0)});
295 moveVar0(SqpRange{dateTime(2017, 1, 17, 6, 0, 0), dateTime(2017, 2, 25, 8, 0, 0)});
296 moveVar0(SqpRange{dateTime(2017, 7, 2, 6, 0, 0), dateTime(2017, 10, 8, 8, 0, 0)});
297 moveVar0(SqpRange{dateTime(2017, 4, 10, 6, 0, 0), dateTime(2017, 6, 15, 8, 0, 0)});
298 moveVar0(SqpRange{dateTime(2017, 1, 17, 6, 0, 0), dateTime(2017, 2, 25, 8, 0, 0)});
299 moveVar0(SqpRange{dateTime(2017, 7, 2, 6, 0, 0), dateTime(2017, 10, 8, 8, 0, 0)});
300 moveVar0(SqpRange{dateTime(2017, 4, 10, 6, 0, 0), dateTime(2017, 6, 15, 8, 0, 0)});
301 moveVar0(SqpRange{dateTime(2017, 1, 17, 6, 0, 0), dateTime(2017, 2, 25, 8, 0, 0)});
302 moveVar0(SqpRange{dateTime(2017, 7, 2, 6, 0, 0), dateTime(2017, 10, 8, 8, 0, 0)});
303
304
305 QTest::newRow("sync2") << syncId << initialRange << iterations << 4000;
306 // QTest::newRow("sync3") << syncId << initialRange << iterations << 5000;
307 }
308 }
309
310 void TestVariableSync::testSync_data()
311 {
312 // ////////////// //
313 // Test structure //
314 // ////////////// //
315
316 QTest::addColumn<QUuid>("syncId");
317 QTest::addColumn<SqpRange>("initialRange");
318 QTest::addColumn<Iterations>("iterations");
319 QTest::addColumn<int>("operationDelay");
320
321 // ////////// //
322 // Test cases //
323 // ////////// //
324
325 testSyncCase1();
326 testSyncCase2();
258 }
327 }
259
328
260 void TestVariableSync::testSync()
329 void TestVariableSync::testSync()
@@ -271,15 +340,8 void TestVariableSync::testSync()
271 // Synchronization group used
340 // Synchronization group used
272 variableController.onAddSynchronizationGroupId(syncId);
341 variableController.onAddSynchronizationGroupId(syncId);
273
342
274 // For each iteration:
343 auto validateRanges = [&variableController](const auto &expectedRanges) {
275 // - execute operation
344 for (const auto &expectedRangeEntry : expectedRanges) {
276 // - compare the variables' state to the expected states
277 QFETCH(Iterations, iterations);
278 for (const auto &iteration : iterations) {
279 iteration.m_Operation->exec(variableController);
280 QTest::qWait(OPERATION_DELAY);
281
282 for (const auto &expectedRangeEntry : iteration.m_ExpectedRanges) {
283 auto variableIndex = expectedRangeEntry.first;
345 auto variableIndex = expectedRangeEntry.first;
284 auto expectedRange = expectedRangeEntry.second;
346 auto expectedRange = expectedRangeEntry.second;
285
347
@@ -297,12 +359,31 void TestVariableSync::testSync()
297
359
298 auto it = dataSeries->xAxisRange(range.m_TStart, range.m_TEnd);
360 auto it = dataSeries->xAxisRange(range.m_TStart, range.m_TEnd);
299 auto expectedValues = values(range);
361 auto expectedValues = values(range);
362 qInfo() << std::distance(it.first, it.second) << expectedValues.size();
300 QVERIFY(std::equal(it.first, it.second, expectedValues.cbegin(), expectedValues.cend(),
363 QVERIFY(std::equal(it.first, it.second, expectedValues.cbegin(), expectedValues.cend(),
301 [](const auto &dataSeriesIt, const auto &expectedValue) {
364 [](const auto &dataSeriesIt, const auto &expectedValue) {
302 return dataSeriesIt.value() == expectedValue;
365 return dataSeriesIt.value() == expectedValue;
303 }));
366 }));
304 }
367 }
368 };
369
370 // For each iteration:
371 // - execute operation
372 // - compare the variables' state to the expected states
373 QFETCH(Iterations, iterations);
374 QFETCH(int, operationDelay);
375 for (const auto &iteration : iterations) {
376 iteration.m_Operation->exec(variableController);
377 QTest::qWait(operationDelay);
378
379 validateRanges(iteration.m_ExpectedRanges);
380 }
381
382 for (const auto &iteration : iterations) {
383 iteration.m_Operation->exec(variableController);
305 }
384 }
385 QTest::qWait(operationDelay);
386 validateRanges(iterations.back().m_ExpectedRanges);
306 }
387 }
307
388
308 QTEST_MAIN(TestVariableSync)
389 QTEST_MAIN(TestVariableSync)
@@ -153,8 +153,9 VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<V
153 }
153 }
154 case AcquisitionZoomType::PanRight: {
154 case AcquisitionZoomType::PanRight: {
155 qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: PanRight");
155 qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: PanRight");
156 auto deltaLeft = graphRange.m_TStart - oldGraphRange.m_TStart;
156 auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd;
157 auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd;
157 graphChildRange.m_TStart += deltaRight;
158 graphChildRange.m_TStart += deltaLeft;
158 graphChildRange.m_TEnd += deltaRight;
159 graphChildRange.m_TEnd += deltaRight;
159 qCDebug(LOG_VisualizationZoneWidget())
160 qCDebug(LOG_VisualizationZoneWidget())
160 << tr("TORM: dt") << graphRange.m_TEnd - graphRange.m_TStart;
161 << tr("TORM: dt") << graphRange.m_TEnd - graphRange.m_TStart;
@@ -163,8 +164,9 VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<V
163 case AcquisitionZoomType::PanLeft: {
164 case AcquisitionZoomType::PanLeft: {
164 qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: PanLeft");
165 qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: PanLeft");
165 auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart;
166 auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart;
167 auto deltaRight = oldGraphRange.m_TEnd - graphRange.m_TEnd;
166 graphChildRange.m_TStart -= deltaLeft;
168 graphChildRange.m_TStart -= deltaLeft;
167 graphChildRange.m_TEnd -= deltaLeft;
169 graphChildRange.m_TEnd -= deltaRight;
168 break;
170 break;
169 }
171 }
170 case AcquisitionZoomType::Unknown: {
172 case AcquisitionZoomType::Unknown: {
@@ -26,6 +26,11 public:
26 void requestDataAborting(QUuid acqIdentifier) override;
26 void requestDataAborting(QUuid acqIdentifier) override;
27
27
28
28
29 /// Provide data
30 std::shared_ptr<IDataSeries> provideDataSeries(const SqpRange &dataRangeRequested,
31 const QVariantHash &data);
32
33
29 private:
34 private:
30 std::shared_ptr<IDataSeries>
35 std::shared_ptr<IDataSeries>
31 retrieveData(QUuid acqIdentifier, const SqpRange &dataRangeRequested, const QVariantHash &data);
36 retrieveData(QUuid acqIdentifier, const SqpRange &dataRangeRequested, const QVariantHash &data);
@@ -145,8 +145,9 std::shared_ptr<IDataSeries> CosinusProvider::retrieveData(QUuid acqIdentifier,
145 progress = currentProgress;
145 progress = currentProgress;
146
146
147 emit dataProvidedProgress(acqIdentifier, progress);
147 emit dataProvidedProgress(acqIdentifier, progress);
148 qCInfo(LOG_CosinusProvider()) << "TORM: CosinusProvider::retrieveData"
148 qCDebug(LOG_CosinusProvider()) << "TORM: CosinusProvider::retrieveData"
149 << QThread::currentThread()->objectName() << progress;
149 << QThread::currentThread()->objectName()
150 << progress;
150 // NOTE: Try to use multithread if possible
151 // NOTE: Try to use multithread if possible
151 }
152 }
152 }
153 }
@@ -199,3 +200,14 void CosinusProvider::requestDataAborting(QUuid acqIdentifier)
199 << tr("Aborting progression of inexistant identifier detected !!!");
200 << tr("Aborting progression of inexistant identifier detected !!!");
200 }
201 }
201 }
202 }
203
204 std::shared_ptr<IDataSeries> CosinusProvider::provideDataSeries(const SqpRange &dataRangeRequested,
205 const QVariantHash &data)
206 {
207 auto uid = QUuid::createUuid();
208 m_VariableToEnableProvider[uid] = true;
209 auto dataSeries = this->retrieveData(uid, dataRangeRequested, data);
210
211 m_VariableToEnableProvider.remove(uid);
212 return dataSeries;
213 }
@@ -24,9 +24,6 const auto TESTS_RESOURCES_PATH = QFileInfo{
24 /// Format of dates in data files
24 /// Format of dates in data files
25 const auto DATETIME_FORMAT = QStringLiteral("yyyy/MM/dd hh:mm:ss:zzz");
25 const auto DATETIME_FORMAT = QStringLiteral("yyyy/MM/dd hh:mm:ss:zzz");
26
26
27 /// Delay after each operation on the variable before validating it (in ms)
28 const auto OPERATION_DELAY = 250;
29
30 /**
27 /**
31 * Verifies that the data in the candidate series are identical to the data in the reference series
28 * Verifies that the data in the candidate series are identical to the data in the reference series
32 * in a specific range
29 * in a specific range
@@ -45,6 +42,9 bool checkDataSeries(std::shared_ptr<IDataSeries> candidate, const SqpRange &ran
45
42
46 auto referenceIt = reference->xAxisRange(range.m_TStart, range.m_TEnd);
43 auto referenceIt = reference->xAxisRange(range.m_TStart, range.m_TEnd);
47
44
45 qInfo() << "candidateSize" << std::distance(candidate->cbegin(), candidate->cend());
46 qInfo() << "refSize" << std::distance(referenceIt.first, referenceIt.second);
47
48 return std::equal(candidate->cbegin(), candidate->cend(), referenceIt.first, referenceIt.second,
48 return std::equal(candidate->cbegin(), candidate->cend(), referenceIt.first, referenceIt.second,
49 [](const auto &it1, const auto &it2) {
49 [](const auto &it1, const auto &it2) {
50 // - milliseconds precision for time
50 // - milliseconds precision for time
@@ -54,29 +54,6 bool checkDataSeries(std::shared_ptr<IDataSeries> candidate, const SqpRange &ran
54 });
54 });
55 }
55 }
56
56
57 /// Generates the data series from the reading of a data stream
58 std::shared_ptr<IDataSeries> readDataStream(QTextStream &stream)
59 {
60 std::vector<double> xAxisData, valuesData;
61
62 QString line{};
63 while (stream.readLineInto(&line)) {
64 // Separates date (x-axis data) to value data
65 auto splitLine = line.split('\t');
66 if (splitLine.size() == 2) {
67 // Converts datetime to double
68 auto dateTime = QDateTime::fromString(splitLine[0], DATETIME_FORMAT);
69 dateTime.setTimeSpec(Qt::UTC);
70 xAxisData.push_back(DateUtils::secondsSinceEpoch(dateTime));
71
72 valuesData.push_back(splitLine[1].toDouble());
73 }
74 }
75
76 return std::make_shared<ScalarSeries>(std::move(xAxisData), std::move(valuesData),
77 Unit{{}, true}, Unit{});
78 }
79
80 } // namespace
57 } // namespace
81
58
82 /**
59 /**
@@ -99,8 +76,9 void TestCosinusAcquisition::testAcquisition_data()
99 // Test structure //
76 // Test structure //
100 // ////////////// //
77 // ////////////// //
101
78
102 QTest::addColumn<QString>("dataFilename"); // File containing expected data of acquisitions
79 QTest::addColumn<SqpRange>("referenceRange"); // Range for generating reference series
103 QTest::addColumn<SqpRange>("initialRange"); // First acquisition
80 QTest::addColumn<SqpRange>("initialRange"); // First acquisition
81 QTest::addColumn<int>("operationDelay"); // Acquisitions to make
104 QTest::addColumn<std::vector<SqpRange> >("operations"); // Acquisitions to make
82 QTest::addColumn<std::vector<SqpRange> >("operations"); // Acquisitions to make
105
83
106 // ////////// //
84 // ////////// //
@@ -113,8 +91,8 void TestCosinusAcquisition::testAcquisition_data()
113 };
91 };
114
92
115 QTest::newRow("cosinus")
93 QTest::newRow("cosinus")
116 << "Cosinus_100Hz_20170101_1200_20170101_1300.txt"
94 << SqpRange{dateTime(2017, 1, 1, 12, 0, 0), dateTime(2017, 1, 1, 13, 0, 0)}
117 << SqpRange{dateTime(2017, 1, 1, 12, 30, 0), dateTime(2017, 1, 1, 12, 35, 1)}
95 << SqpRange{dateTime(2017, 1, 1, 12, 30, 0), dateTime(2017, 1, 1, 12, 35, 1)} << 250
118 << std::vector<SqpRange>{
96 << std::vector<SqpRange>{
119 // Pan (jump) left
97 // Pan (jump) left
120 SqpRange{dateTime(2017, 1, 1, 12, 45, 0), dateTime(2017, 1, 1, 12, 50, 0)},
98 SqpRange{dateTime(2017, 1, 1, 12, 45, 0), dateTime(2017, 1, 1, 12, 50, 0)},
@@ -130,55 +108,78 void TestCosinusAcquisition::testAcquisition_data()
130 SqpRange{dateTime(2017, 1, 1, 12, 17, 30), dateTime(2017, 1, 1, 12, 19, 30)},
108 SqpRange{dateTime(2017, 1, 1, 12, 17, 30), dateTime(2017, 1, 1, 12, 19, 30)},
131 // Zoom out
109 // Zoom out
132 SqpRange{dateTime(2017, 1, 1, 12, 12, 30), dateTime(2017, 1, 1, 12, 24, 30)}};
110 SqpRange{dateTime(2017, 1, 1, 12, 12, 30), dateTime(2017, 1, 1, 12, 24, 30)}};
111
112 QTest::newRow("cosinus_big")
113 << SqpRange{dateTime(2017, 1, 1, 1, 0, 0), dateTime(2017, 1, 5, 13, 0, 0)}
114 << SqpRange{dateTime(2017, 1, 2, 6, 30, 0), dateTime(2017, 1, 2, 18, 30, 0)} << 5000
115 << std::vector<SqpRange>{
116 // Pan (jump) left
117 SqpRange{dateTime(2017, 1, 1, 13, 30, 0), dateTime(2017, 1, 1, 18, 30, 0)},
118 // Pan (jump) right
119 SqpRange{dateTime(2017, 1, 3, 4, 30, 0), dateTime(2017, 1, 3, 10, 30, 0)},
120 // Pan (overlay) right
121 SqpRange{dateTime(2017, 1, 3, 8, 30, 0), dateTime(2017, 1, 3, 12, 30, 0)},
122 // Pan (overlay) left
123 SqpRange{dateTime(2017, 1, 2, 8, 30, 0), dateTime(2017, 1, 3, 10, 30, 0)},
124 // Pan (overlay) left
125 SqpRange{dateTime(2017, 1, 1, 12, 30, 0), dateTime(2017, 1, 3, 5, 30, 0)},
126 // Zoom in
127 SqpRange{dateTime(2017, 1, 2, 2, 30, 0), dateTime(2017, 1, 2, 8, 30, 0)},
128 // Zoom out
129 SqpRange{dateTime(2017, 1, 1, 14, 30, 0), dateTime(2017, 1, 3, 12, 30, 0)}};
133 }
130 }
134
131
135 void TestCosinusAcquisition::testAcquisition()
132 void TestCosinusAcquisition::testAcquisition()
136 {
133 {
137 // Retrieves data file
134 // Retrieves reference range
138 QFETCH(QString, dataFilename);
135 QFETCH(SqpRange, referenceRange);
139
136 CosinusProvider referenceProvider{};
140 auto dataFilePath = QFileInfo{TESTS_RESOURCES_PATH, dataFilename}.absoluteFilePath();
137 auto dataSeries = referenceProvider.provideDataSeries(
141 QFile dataFile{dataFilePath};
138 referenceRange, {{COSINUS_TYPE_KEY, "scalar"}, {COSINUS_FREQUENCY_KEY, 100.}});
142
139
143 if (dataFile.open(QFile::ReadOnly)) {
140 auto end = dataSeries->cend() - 1;
144 // Generates data series to compare with
141 qInfo() << dataSeries->nbPoints() << dataSeries->cbegin()->x() << end->x();
145 QTextStream dataStream{&dataFile};
142
146 auto dataSeries = readDataStream(dataStream);
143 /// Lambda used to validate a variable at each step
147
144 auto validateVariable
148 /// Lambda used to validate a variable at each step
145 = [dataSeries](std::shared_ptr<Variable> variable, const SqpRange &range) {
149 auto validateVariable = [dataSeries](std::shared_ptr<Variable> variable,
146 // Checks that the variable's range has changed
150 const SqpRange &range) {
147 QCOMPARE(variable->range(), range);
151 // Checks that the variable's range has changed
148
152 QCOMPARE(variable->range(), range);
149 // Checks the variable's data series
153
150 QVERIFY(checkDataSeries(variable->dataSeries(), variable->cacheRange(), dataSeries));
154 // Checks the variable's data series
151 };
155 QVERIFY(checkDataSeries(variable->dataSeries(), variable->cacheRange(), dataSeries));
152
156 };
153 // Creates variable
157
154 QFETCH(SqpRange, initialRange);
158 // Creates variable
155 sqpApp->timeController().onTimeToUpdate(initialRange);
159 QFETCH(SqpRange, initialRange);
156 auto provider = std::make_shared<CosinusProvider>();
160 sqpApp->timeController().onTimeToUpdate(initialRange);
157 auto variable = sqpApp->variableController().createVariable(
161 auto provider = std::make_shared<CosinusProvider>();
158 "MMS", {{COSINUS_TYPE_KEY, "scalar"}, {COSINUS_FREQUENCY_KEY, 100.}}, provider);
162 auto variable = sqpApp->variableController().createVariable(
159
163 "MMS", {{COSINUS_TYPE_KEY, "scalar"}, {COSINUS_FREQUENCY_KEY, 100.}}, provider);
160 QFETCH(int, operationDelay);
164
161 QTest::qWait(operationDelay);
165 QTest::qWait(OPERATION_DELAY);
162 validateVariable(variable, initialRange);
166 validateVariable(variable, initialRange);
163
167
164 // Makes operations on the variable
168 // Makes operations on the variable
165 QFETCH(std::vector<SqpRange>, operations);
169 QFETCH(std::vector<SqpRange>, operations);
166 for (const auto &operation : operations) {
170 for (const auto &operation : operations) {
167 // Asks request on the variable and waits during its execution
171 // Asks request on the variable and waits during its execution
168 sqpApp->variableController().onRequestDataLoading({variable}, operation, variable->range(),
172 sqpApp->variableController().onRequestDataLoading({variable}, operation,
169 true);
173 variable->range(), true);
170
174
171 QTest::qWait(operationDelay);
175 QTest::qWait(OPERATION_DELAY);
172 validateVariable(variable, operation);
176 validateVariable(variable, operation);
177 }
178 }
173 }
179 else {
174
180 QFAIL("Can't read input data file");
175
176 for (const auto &operation : operations) {
177 // Asks request on the variable and waits during its execution
178 sqpApp->variableController().onRequestDataLoading({variable}, operation, variable->range(),
179 true);
181 }
180 }
181 QTest::qWait(operationDelay);
182 validateVariable(variable, operations.back());
182 }
183 }
183
184
184 int main(int argc, char *argv[])
185 int main(int argc, char *argv[])
General Comments 3
Under Review
author

Auto status change to "Under Review"

Approved
author

Status change > Approved

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