@@ -48,15 +48,17 SqpRange computeSynchroRangeRequested(const SqpRange &varRange, const SqpRange & | |||
|
48 | 48 | break; |
|
49 | 49 | } |
|
50 | 50 | case AcquisitionZoomType::PanRight: { |
|
51 | auto deltaLeft = graphRange.m_TStart - oldGraphRange.m_TStart; | |
|
51 | 52 | auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd; |
|
52 |
varRangeRequested.m_TStart += delta |
|
|
53 | varRangeRequested.m_TStart += deltaLeft; | |
|
53 | 54 | varRangeRequested.m_TEnd += deltaRight; |
|
54 | 55 | break; |
|
55 | 56 | } |
|
56 | 57 | case AcquisitionZoomType::PanLeft: { |
|
57 | 58 | auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart; |
|
59 | auto deltaRight = oldGraphRange.m_TEnd - graphRange.m_TEnd; | |
|
58 | 60 | varRangeRequested.m_TStart -= deltaLeft; |
|
59 |
varRangeRequested.m_TEnd -= delta |
|
|
61 | varRangeRequested.m_TEnd -= deltaRight; | |
|
60 | 62 | break; |
|
61 | 63 | } |
|
62 | 64 | case AcquisitionZoomType::Unknown: { |
@@ -117,6 +119,8 struct VariableController::VariableControllerPrivate { | |||
|
117 | 119 | void updateVariableRequest(QUuid varRequestId); |
|
118 | 120 | void cancelVariableRequest(QUuid varRequestId); |
|
119 | 121 | |
|
122 | SqpRange getLastRequestedRange(QUuid varId); | |
|
123 | ||
|
120 | 124 | QMutex m_WorkingMutex; |
|
121 | 125 | /// Variable model. The VariableController has the ownership |
|
122 | 126 | VariableModel *m_VariableModel; |
@@ -549,15 +553,19 AcquisitionZoomType VariableController::getZoomType(const SqpRange &range, const | |||
|
549 | 553 | // t1.m_TStart <= t2.m_TStart && t2.m_TEnd <= t1.m_TEnd |
|
550 | 554 | auto zoomType = AcquisitionZoomType::Unknown; |
|
551 | 555 | if (range.m_TStart <= oldRange.m_TStart && oldRange.m_TEnd <= range.m_TEnd) { |
|
556 | qCCritical(LOG_VariableController()) << "zoomtype: ZoomOut"; | |
|
552 | 557 | zoomType = AcquisitionZoomType::ZoomOut; |
|
553 | 558 | } |
|
554 | 559 | else if (range.m_TStart > oldRange.m_TStart && range.m_TEnd > oldRange.m_TEnd) { |
|
560 | qCCritical(LOG_VariableController()) << "zoomtype: PanRight"; | |
|
555 | 561 | zoomType = AcquisitionZoomType::PanRight; |
|
556 | 562 | } |
|
557 | 563 | else if (range.m_TStart < oldRange.m_TStart && range.m_TEnd < oldRange.m_TEnd) { |
|
564 | qCCritical(LOG_VariableController()) << "zoomtype: PanLeft"; | |
|
558 | 565 | zoomType = AcquisitionZoomType::PanLeft; |
|
559 | 566 | } |
|
560 | 567 | else if (range.m_TStart > oldRange.m_TStart && oldRange.m_TEnd > range.m_TEnd) { |
|
568 | qCCritical(LOG_VariableController()) << "zoomtype: ZoomIn"; | |
|
561 | 569 | zoomType = AcquisitionZoomType::ZoomIn; |
|
562 | 570 | } |
|
563 | 571 | else { |
@@ -570,59 +578,70 void VariableController::VariableControllerPrivate::processRequest(std::shared_p | |||
|
570 | 578 | const SqpRange &rangeRequested, |
|
571 | 579 | QUuid varRequestId) |
|
572 | 580 | { |
|
573 | ||
|
574 | // TODO: protect at | |
|
575 | 581 | auto varRequest = VariableRequest{}; |
|
576 | auto varId = m_VariableToIdentifierMap.at(var); | |
|
577 | 582 | |
|
578 | auto varStrategyRangesRequested | |
|
579 | = m_VariableCacheStrategy->computeRange(var->range(), rangeRequested); | |
|
583 | auto it = m_VariableToIdentifierMap.find(var); | |
|
584 | if (it != m_VariableToIdentifierMap.cend()) { | |
|
580 | 585 | |
|
581 | auto notInCacheRangeList = QVector<SqpRange>{varStrategyRangesRequested.second}; | |
|
582 | auto inCacheRangeList = QVector<SqpRange>{}; | |
|
583 | if (m_VarIdToVarRequestIdQueueMap.find(varId) == m_VarIdToVarRequestIdQueueMap.cend()) { | |
|
584 | notInCacheRangeList = var->provideNotInCacheRangeList(varStrategyRangesRequested.second); | |
|
585 | inCacheRangeList = var->provideInCacheRangeList(varStrategyRangesRequested.second); | |
|
586 | } | |
|
586 | auto varId = it->second; | |
|
587 | ||
|
588 | auto oldRange = getLastRequestedRange(varId); | |
|
589 | ||
|
590 | // check for update oldRange to the last request range. | |
|
591 | if (oldRange == INVALID_RANGE) { | |
|
592 | oldRange = var->range(); | |
|
593 | } | |
|
587 | 594 | |
|
588 | if (!notInCacheRangeList.empty()) { | |
|
589 | varRequest.m_RangeRequested = varStrategyRangesRequested.first; | |
|
590 | varRequest.m_CacheRangeRequested = varStrategyRangesRequested.second; | |
|
595 | auto varStrategyRangesRequested | |
|
596 | = m_VariableCacheStrategy->computeRange(oldRange, rangeRequested); | |
|
591 | 597 | |
|
592 | // store VarRequest | |
|
593 | storeVariableRequest(varId, varRequestId, varRequest); | |
|
598 | auto notInCacheRangeList = QVector<SqpRange>{varStrategyRangesRequested.second}; | |
|
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); | |
|
596 | if (varProvider != nullptr) { | |
|
597 | auto varRequestIdCanceled = m_VariableAcquisitionWorker->pushVariableRequest( | |
|
598 | varRequestId, varId, varStrategyRangesRequested.first, | |
|
599 | varStrategyRangesRequested.second, | |
|
600 | DataProviderParameters{std::move(notInCacheRangeList), var->metadata()}, | |
|
601 | varProvider); | |
|
606 | if (!notInCacheRangeList.empty()) { | |
|
607 | varRequest.m_RangeRequested = varStrategyRangesRequested.first; | |
|
608 | varRequest.m_CacheRangeRequested = varStrategyRangesRequested.second; | |
|
609 | ||
|
610 | // store VarRequest | |
|
611 | storeVariableRequest(varId, varRequestId, varRequest); | |
|
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 (! |
|
|
604 | qCDebug(LOG_VariableAcquisitionWorker()) << tr("vsarRequestIdCanceled: ") | |
|
605 | << varRequestIdCanceled; | |
|
606 | cancelVariableRequest(varRequestIdCanceled); | |
|
632 | if (!inCacheRangeList.empty()) { | |
|
633 | emit q->updateVarDisplaying(var, inCacheRangeList.first()); | |
|
607 | 634 | } |
|
608 | 635 | } |
|
609 | 636 | else { |
|
610 | qCCritical(LOG_VariableController()) | |
|
611 | << "Impossible to provide data with a null provider"; | |
|
612 | } | |
|
613 | ||
|
614 | if (!inCacheRangeList.empty()) { | |
|
615 | emit q->updateVarDisplaying(var, inCacheRangeList.first()); | |
|
637 | varRequest.m_RangeRequested = varStrategyRangesRequested.first; | |
|
638 | varRequest.m_CacheRangeRequested = varStrategyRangesRequested.second; | |
|
639 | // store VarRequest | |
|
640 | storeVariableRequest(varId, varRequestId, varRequest); | |
|
641 | acceptVariableRequest( | |
|
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 | 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 | 171 | void testSync(); |
|
172 | 172 | }; |
|
173 | 173 | |
|
174 | void TestVariableSync::testSync_data() | |
|
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 | // ////////// // | |
|
174 | namespace { | |
|
187 | 175 | |
|
176 | void testSyncCase1() | |
|
177 | { | |
|
188 | 178 | // Id used to synchronize variables in the controller |
|
189 | 179 | auto syncId = QUuid::createUuid(); |
|
190 | 180 | |
@@ -254,7 +244,86 void TestVariableSync::testSync_data() | |||
|
254 | 244 | // Zoom out |
|
255 | 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 | 329 | void TestVariableSync::testSync() |
@@ -271,15 +340,8 void TestVariableSync::testSync() | |||
|
271 | 340 | // Synchronization group used |
|
272 | 341 | variableController.onAddSynchronizationGroupId(syncId); |
|
273 | 342 | |
|
274 | // For each iteration: | |
|
275 | // - execute operation | |
|
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) { | |
|
343 | auto validateRanges = [&variableController](const auto &expectedRanges) { | |
|
344 | for (const auto &expectedRangeEntry : expectedRanges) { | |
|
283 | 345 | auto variableIndex = expectedRangeEntry.first; |
|
284 | 346 | auto expectedRange = expectedRangeEntry.second; |
|
285 | 347 | |
@@ -297,12 +359,31 void TestVariableSync::testSync() | |||
|
297 | 359 | |
|
298 | 360 | auto it = dataSeries->xAxisRange(range.m_TStart, range.m_TEnd); |
|
299 | 361 | auto expectedValues = values(range); |
|
362 | qInfo() << std::distance(it.first, it.second) << expectedValues.size(); | |
|
300 | 363 | QVERIFY(std::equal(it.first, it.second, expectedValues.cbegin(), expectedValues.cend(), |
|
301 | 364 | [](const auto &dataSeriesIt, const auto &expectedValue) { |
|
302 | 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 | 389 | QTEST_MAIN(TestVariableSync) |
@@ -153,8 +153,9 VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<V | |||
|
153 | 153 | } |
|
154 | 154 | case AcquisitionZoomType::PanRight: { |
|
155 | 155 | qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: PanRight"); |
|
156 | auto deltaLeft = graphRange.m_TStart - oldGraphRange.m_TStart; | |
|
156 | 157 | auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd; |
|
157 |
graphChildRange.m_TStart += delta |
|
|
158 | graphChildRange.m_TStart += deltaLeft; | |
|
158 | 159 | graphChildRange.m_TEnd += deltaRight; |
|
159 | 160 | qCDebug(LOG_VisualizationZoneWidget()) |
|
160 | 161 | << tr("TORM: dt") << graphRange.m_TEnd - graphRange.m_TStart; |
@@ -163,8 +164,9 VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<V | |||
|
163 | 164 | case AcquisitionZoomType::PanLeft: { |
|
164 | 165 | qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: PanLeft"); |
|
165 | 166 | auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart; |
|
167 | auto deltaRight = oldGraphRange.m_TEnd - graphRange.m_TEnd; | |
|
166 | 168 | graphChildRange.m_TStart -= deltaLeft; |
|
167 |
graphChildRange.m_TEnd -= delta |
|
|
169 | graphChildRange.m_TEnd -= deltaRight; | |
|
168 | 170 | break; |
|
169 | 171 | } |
|
170 | 172 | case AcquisitionZoomType::Unknown: { |
@@ -26,6 +26,11 public: | |||
|
26 | 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 | 34 | private: |
|
30 | 35 | std::shared_ptr<IDataSeries> |
|
31 | 36 | retrieveData(QUuid acqIdentifier, const SqpRange &dataRangeRequested, const QVariantHash &data); |
@@ -145,8 +145,9 std::shared_ptr<IDataSeries> CosinusProvider::retrieveData(QUuid acqIdentifier, | |||
|
145 | 145 | progress = currentProgress; |
|
146 | 146 | |
|
147 | 147 | emit dataProvidedProgress(acqIdentifier, progress); |
|
148 |
qC |
|
|
149 |
<< QThread::currentThread()->objectName() |
|
|
148 | qCDebug(LOG_CosinusProvider()) << "TORM: CosinusProvider::retrieveData" | |
|
149 | << QThread::currentThread()->objectName() | |
|
150 | << progress; | |
|
150 | 151 | // NOTE: Try to use multithread if possible |
|
151 | 152 | } |
|
152 | 153 | } |
@@ -199,3 +200,14 void CosinusProvider::requestDataAborting(QUuid acqIdentifier) | |||
|
199 | 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 | 24 | /// Format of dates in data files |
|
25 | 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 | 28 | * Verifies that the data in the candidate series are identical to the data in the reference series |
|
32 | 29 | * in a specific range |
@@ -45,6 +42,9 bool checkDataSeries(std::shared_ptr<IDataSeries> candidate, const SqpRange &ran | |||
|
45 | 42 | |
|
46 | 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 | 48 | return std::equal(candidate->cbegin(), candidate->cend(), referenceIt.first, referenceIt.second, |
|
49 | 49 | [](const auto &it1, const auto &it2) { |
|
50 | 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 | 57 | } // namespace |
|
81 | 58 | |
|
82 | 59 | /** |
@@ -99,8 +76,9 void TestCosinusAcquisition::testAcquisition_data() | |||
|
99 | 76 | // Test structure // |
|
100 | 77 | // ////////////// // |
|
101 | 78 | |
|
102 | QTest::addColumn<QString>("dataFilename"); // File containing expected data of acquisitions | |
|
103 | QTest::addColumn<SqpRange>("initialRange"); // First acquisition | |
|
79 | QTest::addColumn<SqpRange>("referenceRange"); // Range for generating reference series | |
|
80 | QTest::addColumn<SqpRange>("initialRange"); // First acquisition | |
|
81 | QTest::addColumn<int>("operationDelay"); // Acquisitions to make | |
|
104 | 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 | 93 | QTest::newRow("cosinus") |
|
116 | << "Cosinus_100Hz_20170101_1200_20170101_1300.txt" | |
|
117 | << SqpRange{dateTime(2017, 1, 1, 12, 30, 0), dateTime(2017, 1, 1, 12, 35, 1)} | |
|
94 | << SqpRange{dateTime(2017, 1, 1, 12, 0, 0), dateTime(2017, 1, 1, 13, 0, 0)} | |
|
95 | << SqpRange{dateTime(2017, 1, 1, 12, 30, 0), dateTime(2017, 1, 1, 12, 35, 1)} << 250 | |
|
118 | 96 | << std::vector<SqpRange>{ |
|
119 | 97 | // Pan (jump) left |
|
120 | 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 | 108 | SqpRange{dateTime(2017, 1, 1, 12, 17, 30), dateTime(2017, 1, 1, 12, 19, 30)}, |
|
131 | 109 | // Zoom out |
|
132 | 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 | 132 | void TestCosinusAcquisition::testAcquisition() |
|
136 | 133 | { |
|
137 |
// Retrieves |
|
|
138 |
QFETCH( |
|
|
139 | ||
|
140 | auto dataFilePath = QFileInfo{TESTS_RESOURCES_PATH, dataFilename}.absoluteFilePath(); | |
|
141 | QFile dataFile{dataFilePath}; | |
|
142 | ||
|
143 | if (dataFile.open(QFile::ReadOnly)) { | |
|
144 | // Generates data series to compare with | |
|
145 | QTextStream dataStream{&dataFile}; | |
|
146 | auto dataSeries = readDataStream(dataStream); | |
|
147 | ||
|
148 | /// Lambda used to validate a variable at each step | |
|
149 | auto validateVariable = [dataSeries](std::shared_ptr<Variable> variable, | |
|
150 | const SqpRange &range) { | |
|
151 | // Checks that the variable's range has changed | |
|
152 | QCOMPARE(variable->range(), range); | |
|
153 | ||
|
154 | // Checks the variable's data series | |
|
155 | QVERIFY(checkDataSeries(variable->dataSeries(), variable->cacheRange(), dataSeries)); | |
|
156 | }; | |
|
157 | ||
|
158 | // Creates variable | |
|
159 | QFETCH(SqpRange, initialRange); | |
|
160 |
|
|
|
161 | auto provider = std::make_shared<CosinusProvider>(); | |
|
162 | auto variable = sqpApp->variableController().createVariable( | |
|
163 | "MMS", {{COSINUS_TYPE_KEY, "scalar"}, {COSINUS_FREQUENCY_KEY, 100.}}, provider); | |
|
164 | ||
|
165 | QTest::qWait(OPERATION_DELAY); | |
|
166 | validateVariable(variable, initialRange); | |
|
167 | ||
|
168 | // Makes operations on the variable | |
|
169 | QFETCH(std::vector<SqpRange>, operations); | |
|
170 | for (const auto &operation : operations) { | |
|
171 | // Asks request on the variable and waits during its execution | |
|
172 | sqpApp->variableController().onRequestDataLoading({variable}, operation, | |
|
173 | variable->range(), true); | |
|
174 | ||
|
175 | QTest::qWait(OPERATION_DELAY); | |
|
176 | validateVariable(variable, operation); | |
|
177 | } | |
|
134 | // Retrieves reference range | |
|
135 | QFETCH(SqpRange, referenceRange); | |
|
136 | CosinusProvider referenceProvider{}; | |
|
137 | auto dataSeries = referenceProvider.provideDataSeries( | |
|
138 | referenceRange, {{COSINUS_TYPE_KEY, "scalar"}, {COSINUS_FREQUENCY_KEY, 100.}}); | |
|
139 | ||
|
140 | auto end = dataSeries->cend() - 1; | |
|
141 | qInfo() << dataSeries->nbPoints() << dataSeries->cbegin()->x() << end->x(); | |
|
142 | ||
|
143 | /// Lambda used to validate a variable at each step | |
|
144 | auto validateVariable | |
|
145 | = [dataSeries](std::shared_ptr<Variable> variable, const SqpRange &range) { | |
|
146 | // Checks that the variable's range has changed | |
|
147 | QCOMPARE(variable->range(), range); | |
|
148 | ||
|
149 | // Checks the variable's data series | |
|
150 | QVERIFY(checkDataSeries(variable->dataSeries(), variable->cacheRange(), dataSeries)); | |
|
151 | }; | |
|
152 | ||
|
153 | // Creates variable | |
|
154 | QFETCH(SqpRange, initialRange); | |
|
155 | sqpApp->timeController().onTimeToUpdate(initialRange); | |
|
156 | auto provider = std::make_shared<CosinusProvider>(); | |
|
157 | auto variable = sqpApp->variableController().createVariable( | |
|
158 | "MMS", {{COSINUS_TYPE_KEY, "scalar"}, {COSINUS_FREQUENCY_KEY, 100.}}, provider); | |
|
159 | ||
|
160 | QFETCH(int, operationDelay); | |
|
161 | QTest::qWait(operationDelay); | |
|
162 | validateVariable(variable, initialRange); | |
|
163 | ||
|
164 | // Makes operations on the variable | |
|
165 | QFETCH(std::vector<SqpRange>, operations); | |
|
166 | for (const auto &operation : operations) { | |
|
167 | // Asks request on the variable and waits during its execution | |
|
168 | sqpApp->variableController().onRequestDataLoading({variable}, operation, variable->range(), | |
|
169 | true); | |
|
170 | ||
|
171 | QTest::qWait(operationDelay); | |
|
172 | validateVariable(variable, operation); | |
|
178 | 173 | } |
|
179 | else { | |
|
180 | QFAIL("Can't read input data file"); | |
|
174 | ||
|
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 | 185 | int main(int argc, char *argv[]) |
General Comments 0
You need to be logged in to leave comments.
Login now