##// END OF EJS Templates
Merge pull request 306 from SciQLop-fork develop...
perrinel -
r820:0b4649618604 merge
parent child
Show More
@@ -68,6 +68,12 public:
68 68 QVector<SqpRange> provideInCacheRangeList(const SqpRange &range) const noexcept;
69 69 void mergeDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept;
70 70
71 static QVector<SqpRange> provideNotInCacheRangeList(const SqpRange &oldRange,
72 const SqpRange &nextRange);
73
74 static QVector<SqpRange> provideInCacheRangeList(const SqpRange &oldRange,
75 const SqpRange &nextRange);
76
71 77 signals:
72 78 void updated();
73 79
@@ -83,7 +83,7 signals:
83 83 public slots:
84 84 /// Request the data loading of the variable whithin range
85 85 void onRequestDataLoading(QVector<std::shared_ptr<Variable> > variables, const SqpRange &range,
86 const SqpRange &oldRange, bool synchronise);
86 bool synchronise);
87 87 /**
88 88 * Creates a new variable and adds it to the model
89 89 * @param name the name of the new variable
@@ -138,7 +138,6 void Variable::setCacheRange(const SqpRange &cacheRange) noexcept
138 138 impl->lockWrite();
139 139 if (cacheRange != impl->m_CacheRange) {
140 140 impl->m_CacheRange = cacheRange;
141 impl->purgeDataSeries();
142 141 }
143 142 impl->unlock();
144 143 }
@@ -174,6 +173,7 void Variable::mergeDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept
174 173 impl->unlock();
175 174 }
176 175
176
177 177 std::shared_ptr<IDataSeries> Variable::dataSeries() const noexcept
178 178 {
179 179 impl->lockRead();
@@ -285,7 +285,7 QVector<SqpRange> Variable::provideInCacheRangeList(const SqpRange &range) const
285 285
286 286 if (impl->m_CacheRange != INVALID_RANGE) {
287 287
288 if (this->intersect(range)) {
288 if (this->cacheIntersect(range)) {
289 289 if (range.m_TStart <= impl->m_CacheRange.m_TStart
290 290 && range.m_TEnd >= impl->m_CacheRange.m_TStart
291 291 && range.m_TEnd < impl->m_CacheRange.m_TEnd) {
@@ -313,3 +313,76 QVector<SqpRange> Variable::provideInCacheRangeList(const SqpRange &range) const
313 313
314 314 return inCache;
315 315 }
316
317
318 QVector<SqpRange> Variable::provideNotInCacheRangeList(const SqpRange &oldRange,
319 const SqpRange &nextRange)
320 {
321
322 // This code assume that cach in contigue. Can return 0, 1 or 2 SqpRange
323 auto notInCache = QVector<SqpRange>{};
324 if (oldRange != INVALID_RANGE) {
325
326 if (!oldRange.contains(nextRange)) {
327 if (nextRange.m_TEnd <= oldRange.m_TStart || nextRange.m_TStart >= oldRange.m_TEnd) {
328 notInCache << nextRange;
329 }
330 else if (nextRange.m_TStart < oldRange.m_TStart
331 && nextRange.m_TEnd <= oldRange.m_TEnd) {
332 notInCache << SqpRange{nextRange.m_TStart, oldRange.m_TStart};
333 }
334 else if (nextRange.m_TStart < oldRange.m_TStart && nextRange.m_TEnd > oldRange.m_TEnd) {
335 notInCache << SqpRange{nextRange.m_TStart, oldRange.m_TStart}
336 << SqpRange{oldRange.m_TEnd, nextRange.m_TEnd};
337 }
338 else if (nextRange.m_TStart < oldRange.m_TEnd) {
339 notInCache << SqpRange{oldRange.m_TEnd, nextRange.m_TEnd};
340 }
341 else {
342 qCCritical(LOG_Variable()) << tr("Detection of unknown case.")
343 << QThread::currentThread();
344 }
345 }
346 }
347 else {
348 notInCache << nextRange;
349 }
350
351 return notInCache;
352 }
353
354 QVector<SqpRange> Variable::provideInCacheRangeList(const SqpRange &oldRange,
355 const SqpRange &nextRange)
356 {
357 // This code assume that cach is contigue. Can return 0 or 1 SqpRange
358
359 auto inCache = QVector<SqpRange>{};
360
361 if (oldRange != INVALID_RANGE) {
362
363 if (oldRange.intersect(nextRange)) {
364 if (nextRange.m_TStart <= oldRange.m_TStart && nextRange.m_TEnd >= oldRange.m_TStart
365 && nextRange.m_TEnd < oldRange.m_TEnd) {
366 inCache << SqpRange{oldRange.m_TStart, nextRange.m_TEnd};
367 }
368
369 else if (nextRange.m_TStart >= oldRange.m_TStart
370 && nextRange.m_TEnd <= oldRange.m_TEnd) {
371 inCache << nextRange;
372 }
373 else if (nextRange.m_TStart > oldRange.m_TStart && nextRange.m_TEnd > oldRange.m_TEnd) {
374 inCache << SqpRange{nextRange.m_TStart, oldRange.m_TEnd};
375 }
376 else if (nextRange.m_TStart <= oldRange.m_TStart
377 && nextRange.m_TEnd >= oldRange.m_TEnd) {
378 inCache << oldRange;
379 }
380 else {
381 qCCritical(LOG_Variable()) << tr("Detection of unknown case.")
382 << QThread::currentThread();
383 }
384 }
385 }
386
387 return inCache;
388 }
@@ -32,6 +32,10 struct VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate {
32 32 /// Remove the current request and execute the next one if exist
33 33 void updateToNextRequest(QUuid vIdentifier);
34 34
35 /// Remove and/or abort all AcqRequest in link with varRequestId
36 void cancelVarRequest(QUuid varRequestId);
37 void removeAcqRequest(QUuid acqRequestId);
38
35 39 QMutex m_WorkingMutex;
36 40 QReadWriteLock m_Lock;
37 41
@@ -67,7 +71,8 QUuid VariableAcquisitionWorker::pushVariableRequest(QUuid varRequestId, QUuid v
67 71
68 72 // Request creation
69 73 auto acqRequest = AcquisitionRequest{};
70 qCInfo(LOG_VariableAcquisitionWorker()) << tr("TpushVariableRequest ") << vIdentifier;
74 qCDebug(LOG_VariableAcquisitionWorker()) << tr("PushVariableRequest ") << vIdentifier
75 << varRequestId;
71 76 acqRequest.m_VarRequestId = varRequestId;
72 77 acqRequest.m_vIdentifier = vIdentifier;
73 78 acqRequest.m_DataProviderParameters = parameters;
@@ -85,15 +90,19 QUuid VariableAcquisitionWorker::pushVariableRequest(QUuid varRequestId, QUuid v
85 90 auto it = impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.find(vIdentifier);
86 91 if (it != impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.cend()) {
87 92 // A current request already exists, we can replace the next one
88 auto nextAcqId = it->second.second;
89 auto acqIdentifierToAcqRequestMapIt = impl->m_AcqIdentifierToAcqRequestMap.find(nextAcqId);
93 auto oldAcqId = it->second.second;
94 auto acqIdentifierToAcqRequestMapIt = impl->m_AcqIdentifierToAcqRequestMap.find(oldAcqId);
90 95 if (acqIdentifierToAcqRequestMapIt != impl->m_AcqIdentifierToAcqRequestMap.cend()) {
91 auto request = acqIdentifierToAcqRequestMapIt->second;
92 varRequestIdCanceled = request.m_VarRequestId;
96 auto oldAcqRequest = acqIdentifierToAcqRequestMapIt->second;
97 varRequestIdCanceled = oldAcqRequest.m_VarRequestId;
93 98 }
94 99
95 100 it->second.second = acqRequest.m_AcqIdentifier;
96 101 impl->unlock();
102
103 // remove old acqIdentifier from the worker
104 impl->cancelVarRequest(varRequestIdCanceled);
105 // impl->m_AcqIdentifierToAcqRequestMap.erase(oldAcqId);
97 106 }
98 107 else {
99 108 // First request for the variable, it must be stored and executed
@@ -122,10 +131,7 void VariableAcquisitionWorker::abortProgressRequested(QUuid vIdentifier)
122 131 impl->unlock();
123 132
124 133 // Remove the current request from the worker
125
126 impl->lockWrite();
127 134 impl->updateToNextRequest(vIdentifier);
128 impl->unlock();
129 135
130 136 // notify the request aborting to the provider
131 137 request.m_Provider->requestDataAborting(currentAcqId);
@@ -221,22 +227,28 void VariableAcquisitionWorker::onVariableDataAcquired(QUuid acqIdentifier,
221 227 // if the counter is 0, we can return data then run the next request if it exists and
222 228 // removed the finished request
223 229 if (acqRequest.m_Size == acqRequest.m_Progression) {
230 auto varId = acqRequest.m_vIdentifier;
231 auto rangeRequested = acqRequest.m_RangeRequested;
232 auto cacheRangeRequested = acqRequest.m_CacheRangeRequested;
224 233 // Return the data
225 234 aIdToADPVit = impl->m_AcqIdentifierToAcqDataPacketVectorMap.find(acqIdentifier);
226 235 if (aIdToADPVit != impl->m_AcqIdentifierToAcqDataPacketVectorMap.cend()) {
227 emit dataProvided(acqRequest.m_vIdentifier, acqRequest.m_RangeRequested,
228 acqRequest.m_CacheRangeRequested, aIdToADPVit->second);
236 emit dataProvided(varId, rangeRequested, cacheRangeRequested, aIdToADPVit->second);
229 237 }
238 impl->unlock();
230 239
231 240 // Update to the next request
232 241 impl->updateToNextRequest(acqRequest.m_vIdentifier);
233 242 }
243 else {
244 impl->unlock();
245 }
234 246 }
235 247 else {
248 impl->unlock();
236 249 qCWarning(LOG_VariableAcquisitionWorker())
237 250 << tr("Impossible to retrieve AcquisitionRequest for the incoming data.");
238 251 }
239 impl->unlock();
240 252 }
241 253
242 254 void VariableAcquisitionWorker::onExecuteRequest(QUuid acqIdentifier)
@@ -296,27 +308,109 void VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate::removeVariable
296 308 void VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate::updateToNextRequest(
297 309 QUuid vIdentifier)
298 310 {
311 lockRead();
299 312 auto it = m_VIdentifierToCurrrentAcqIdNextIdPairMap.find(vIdentifier);
300 313 if (it != m_VIdentifierToCurrrentAcqIdNextIdPairMap.cend()) {
301 314 if (it->second.second.isNull()) {
315 unlock();
302 316 // There is no next request, we can remove the variable request
303 317 removeVariableRequest(vIdentifier);
304 318 }
305 319 else {
306 320 auto acqIdentifierToRemove = it->second.first;
307 321 // Move the next request to the current request
308 it->second.first = it->second.second;
322 auto nextRequestId = it->second.second;
323 it->second.first = nextRequestId;
309 324 it->second.second = QUuid();
325 unlock();
310 326 // Remove AcquisitionRequest and results;
327 lockWrite();
311 328 m_AcqIdentifierToAcqRequestMap.erase(acqIdentifierToRemove);
312 329 m_AcqIdentifierToAcqDataPacketVectorMap.erase(acqIdentifierToRemove);
330 unlock();
313 331 // Execute the current request
314 332 QMetaObject::invokeMethod(q, "onExecuteRequest", Qt::QueuedConnection,
315 Q_ARG(QUuid, it->second.first));
333 Q_ARG(QUuid, nextRequestId));
316 334 }
317 335 }
318 336 else {
337 unlock();
319 338 qCCritical(LOG_VariableAcquisitionWorker())
320 339 << tr("Impossible to execute the acquisition on an unfound variable ");
321 340 }
322 341 }
342
343 void VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate::cancelVarRequest(
344 QUuid varRequestId)
345 {
346 qCDebug(LOG_VariableAcquisitionWorker())
347 << "VariableAcquisitionWorkerPrivate::cancelVarRequest 0";
348 lockRead();
349 // get all AcqIdentifier in link with varRequestId
350 QVector<QUuid> acqIdsToRm;
351 auto cend = m_AcqIdentifierToAcqRequestMap.cend();
352 for (auto it = m_AcqIdentifierToAcqRequestMap.cbegin(); it != cend; ++it) {
353 if (it->second.m_VarRequestId == varRequestId) {
354 acqIdsToRm << it->first;
355 }
356 }
357 unlock();
358 // run aborting or removing of acqIdsToRm
359
360 for (auto acqId : acqIdsToRm) {
361 removeAcqRequest(acqId);
362 }
363 qCDebug(LOG_VariableAcquisitionWorker())
364 << "VariableAcquisitionWorkerPrivate::cancelVarRequest end";
365 }
366
367 void VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate::removeAcqRequest(
368 QUuid acqRequestId)
369 {
370 qCDebug(LOG_VariableAcquisitionWorker())
371 << "VariableAcquisitionWorkerPrivate::removeAcqRequest";
372 QUuid vIdentifier;
373 std::shared_ptr<IDataProvider> provider;
374 lockRead();
375 auto acqIt = m_AcqIdentifierToAcqRequestMap.find(acqRequestId);
376 if (acqIt != m_AcqIdentifierToAcqRequestMap.cend()) {
377 vIdentifier = acqIt->second.m_vIdentifier;
378 provider = acqIt->second.m_Provider;
379
380 auto it = m_VIdentifierToCurrrentAcqIdNextIdPairMap.find(vIdentifier);
381 if (it != m_VIdentifierToCurrrentAcqIdNextIdPairMap.cend()) {
382 if (it->second.first == acqRequestId) {
383 // acqRequest is currently running -> let's aborting it
384 unlock();
385
386 // Remove the current request from the worker
387 updateToNextRequest(vIdentifier);
388
389 // notify the request aborting to the provider
390 provider->requestDataAborting(acqRequestId);
391 }
392 else if (it->second.second == acqRequestId) {
393 it->second.second = QUuid();
394 unlock();
395 }
396 else {
397 unlock();
398 }
399 }
400 else {
401 unlock();
402 }
403 }
404 else {
405 unlock();
406 }
407
408 lockWrite();
409
410 m_AcqIdentifierToAcqDataPacketVectorMap.erase(acqRequestId);
411 m_AcqIdentifierToAcqRequestMap.erase(acqRequestId);
412
413 unlock();
414 qCDebug(LOG_VariableAcquisitionWorker())
415 << "VariableAcquisitionWorkerPrivate::removeAcqRequest END";
416 }
@@ -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 += deltaRight;
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 -= deltaLeft;
61 varRangeRequested.m_TEnd -= deltaRight;
60 62 break;
61 63 }
62 64 case AcquisitionZoomType::Unknown: {
@@ -103,9 +105,6 struct VariableController::VariableControllerPrivate {
103 105 void processRequest(std::shared_ptr<Variable> var, const SqpRange &rangeRequested,
104 106 QUuid varRequestId);
105 107
106 QVector<SqpRange> provideNotInCacheDateTimeList(std::shared_ptr<Variable> variable,
107 const SqpRange &dateTime);
108
109 108 std::shared_ptr<Variable> findVariable(QUuid vIdentifier);
110 109 std::shared_ptr<IDataSeries>
111 110 retrieveDataSeries(const QVector<AcquisitionDataPacket> acqDataPacketVector);
@@ -117,6 +116,8 struct VariableController::VariableControllerPrivate {
117 116 void updateVariableRequest(QUuid varRequestId);
118 117 void cancelVariableRequest(QUuid varRequestId);
119 118
119 SqpRange getLastRequestedRange(QUuid varId);
120
120 121 QMutex m_WorkingMutex;
121 122 /// Variable model. The VariableController has the ownership
122 123 VariableModel *m_VariableModel;
@@ -295,22 +296,24 VariableController::createVariable(const QString &name, const QVariantHash &meta
295 296
296 297 void VariableController::onDateTimeOnSelection(const SqpRange &dateTime)
297 298 {
298 // TODO check synchronisation and Rescale
299 // NOTE: Even if acquisition request is aborting, the graphe range will be changed
299 300 qCDebug(LOG_VariableController()) << "VariableController::onDateTimeOnSelection"
300 301 << QThread::currentThread()->objectName();
301 302 auto selectedRows = impl->m_VariableSelectionModel->selectedRows();
302 auto varRequestId = QUuid::createUuid();
303 auto variables = QVector<std::shared_ptr<Variable> >{};
303 304
304 305 for (const auto &selectedRow : qAsConst(selectedRows)) {
305 306 if (auto selectedVariable = impl->m_VariableModel->variable(selectedRow.row())) {
306 selectedVariable->setRange(dateTime);
307 impl->processRequest(selectedVariable, dateTime, varRequestId);
307 variables << selectedVariable;
308 308
309 309 // notify that rescale operation has to be done
310 310 emit rangeChanged(selectedVariable, dateTime);
311 311 }
312 312 }
313 impl->updateVariableRequest(varRequestId);
313
314 if (!variables.isEmpty()) {
315 this->onRequestDataLoading(variables, dateTime, true);
316 }
314 317 }
315 318
316 319 void VariableController::onDataProvided(QUuid vIdentifier, const SqpRange &rangeRequested,
@@ -455,8 +458,7 void VariableController::desynchronize(std::shared_ptr<Variable> variable,
455 458 }
456 459
457 460 void VariableController::onRequestDataLoading(QVector<std::shared_ptr<Variable> > variables,
458 const SqpRange &range, const SqpRange &oldRange,
459 bool synchronise)
461 const SqpRange &range, bool synchronise)
460 462 {
461 463 // NOTE: oldRange isn't really necessary since oldRange == variable->range().
462 464
@@ -549,19 +551,23 AcquisitionZoomType VariableController::getZoomType(const SqpRange &range, const
549 551 // t1.m_TStart <= t2.m_TStart && t2.m_TEnd <= t1.m_TEnd
550 552 auto zoomType = AcquisitionZoomType::Unknown;
551 553 if (range.m_TStart <= oldRange.m_TStart && oldRange.m_TEnd <= range.m_TEnd) {
554 qCDebug(LOG_VariableController()) << "zoomtype: ZoomOut";
552 555 zoomType = AcquisitionZoomType::ZoomOut;
553 556 }
554 557 else if (range.m_TStart > oldRange.m_TStart && range.m_TEnd > oldRange.m_TEnd) {
558 qCDebug(LOG_VariableController()) << "zoomtype: PanRight";
555 559 zoomType = AcquisitionZoomType::PanRight;
556 560 }
557 561 else if (range.m_TStart < oldRange.m_TStart && range.m_TEnd < oldRange.m_TEnd) {
562 qCDebug(LOG_VariableController()) << "zoomtype: PanLeft";
558 563 zoomType = AcquisitionZoomType::PanLeft;
559 564 }
560 565 else if (range.m_TStart > oldRange.m_TStart && oldRange.m_TEnd > range.m_TEnd) {
566 qCDebug(LOG_VariableController()) << "zoomtype: ZoomIn";
561 567 zoomType = AcquisitionZoomType::ZoomIn;
562 568 }
563 569 else {
564 qCCritical(LOG_VariableController()) << "getZoomType: Unknown type detected";
570 qCDebug(LOG_VariableController()) << "getZoomType: Unknown type detected";
565 571 }
566 572 return zoomType;
567 573 }
@@ -570,59 +576,67 void VariableController::VariableControllerPrivate::processRequest(std::shared_p
570 576 const SqpRange &rangeRequested,
571 577 QUuid varRequestId)
572 578 {
573
574 // TODO: protect at
575 579 auto varRequest = VariableRequest{};
576 auto varId = m_VariableToIdentifierMap.at(var);
577 580
578 auto varStrategyRangesRequested
579 = m_VariableCacheStrategy->computeRange(var->range(), rangeRequested);
581 auto it = m_VariableToIdentifierMap.find(var);
582 if (it != m_VariableToIdentifierMap.cend()) {
580 583
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 }
584 auto varId = it->second;
587 585
588 if (!notInCacheRangeList.empty()) {
589 varRequest.m_RangeRequested = varStrategyRangesRequested.first;
590 varRequest.m_CacheRangeRequested = varStrategyRangesRequested.second;
586 auto oldRange = getLastRequestedRange(varId);
591 587
592 // store VarRequest
593 storeVariableRequest(varId, varRequestId, varRequest);
588 // check for update oldRange to the last request range.
589 if (oldRange == INVALID_RANGE) {
590 oldRange = var->range();
591 }
594 592
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);
593 auto varStrategyRangesRequested
594 = m_VariableCacheStrategy->computeRange(oldRange, rangeRequested);
595
596 auto notInCacheRangeList
597 = Variable::provideNotInCacheRangeList(oldRange, varStrategyRangesRequested.second);
598 auto inCacheRangeList
599 = Variable::provideInCacheRangeList(oldRange, varStrategyRangesRequested.second);
600
601 if (!notInCacheRangeList.empty()) {
602 varRequest.m_RangeRequested = varStrategyRangesRequested.first;
603 varRequest.m_CacheRangeRequested = varStrategyRangesRequested.second;
604
605 // store VarRequest
606 storeVariableRequest(varId, varRequestId, varRequest);
607
608 auto varProvider = m_VariableToProviderMap.at(var);
609 if (varProvider != nullptr) {
610 auto varRequestIdCanceled = m_VariableAcquisitionWorker->pushVariableRequest(
611 varRequestId, varId, varStrategyRangesRequested.first,
612 varStrategyRangesRequested.second,
613 DataProviderParameters{std::move(notInCacheRangeList), var->metadata()},
614 varProvider);
615
616 if (!varRequestIdCanceled.isNull()) {
617 qCInfo(LOG_VariableAcquisitionWorker()) << tr("varRequestIdCanceled: ")
618 << varRequestIdCanceled;
619 cancelVariableRequest(varRequestIdCanceled);
620 }
621 }
622 else {
623 qCCritical(LOG_VariableController())
624 << "Impossible to provide data with a null provider";
625 }
602 626
603 if (!varRequestIdCanceled.isNull()) {
604 qCDebug(LOG_VariableAcquisitionWorker()) << tr("vsarRequestIdCanceled: ")
605 << varRequestIdCanceled;
606 cancelVariableRequest(varRequestIdCanceled);
627 if (!inCacheRangeList.empty()) {
628 emit q->updateVarDisplaying(var, inCacheRangeList.first());
607 629 }
608 630 }
609 631 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());
632 varRequest.m_RangeRequested = varStrategyRangesRequested.first;
633 varRequest.m_CacheRangeRequested = varStrategyRangesRequested.second;
634 // store VarRequest
635 storeVariableRequest(varId, varRequestId, varRequest);
636 acceptVariableRequest(
637 varId, var->dataSeries()->subDataSeries(varStrategyRangesRequested.second));
616 638 }
617 639 }
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 640 }
627 641
628 642 std::shared_ptr<Variable>
@@ -784,26 +798,22 void VariableController::VariableControllerPrivate::updateVariableRequest(QUuid
784 798 var->setRange(varRequest.m_RangeRequested);
785 799 var->setCacheRange(varRequest.m_CacheRangeRequested);
786 800 qCDebug(LOG_VariableController()) << tr("1: onDataProvided")
787 << varRequest.m_RangeRequested;
788 qCDebug(LOG_VariableController()) << tr("2: onDataProvided")
801 << varRequest.m_RangeRequested
789 802 << varRequest.m_CacheRangeRequested;
803 qCDebug(LOG_VariableController()) << tr("2: onDataProvided var points before")
804 << var->nbPoints()
805 << varRequest.m_DataSeries->nbPoints();
790 806 var->mergeDataSeries(varRequest.m_DataSeries);
791 qCDebug(LOG_VariableController()) << tr("3: onDataProvided");
807 qCDebug(LOG_VariableController()) << tr("3: onDataProvided var points after")
808 << var->nbPoints();
792 809
793 /// @todo MPL: confirm
794 // Variable update is notified only if there is no pending request for it
795 // if
796 // (m_VarIdToVarRequestIdQueueMap.count(varIdToVarRequestMapIt->first)
797 // == 0) {
798 810 emit var->updated();
799 // }
800 811 }
801 812 else {
802 813 qCCritical(LOG_VariableController())
803 814 << tr("Impossible to update data to a null variable");
804 815 }
805 816 }
806
807 817 // cleaning varRequestId
808 818 qCDebug(LOG_VariableController()) << tr("0: erase REQUEST in MAP ?")
809 819 << m_VarRequestIdToVarIdVarRequestMap.size();
@@ -832,9 +842,48 void VariableController::VariableControllerPrivate::cancelVariableRequest(QUuid
832 842 if (varRequestIdQueue.empty()) {
833 843 varIdToVarRequestIdQueueMapIt
834 844 = m_VarIdToVarRequestIdQueueMap.erase(varIdToVarRequestIdQueueMapIt);
845
846 // Recompute if there is any next request based on the removed request.
835 847 }
836 848 else {
837 849 ++varIdToVarRequestIdQueueMapIt;
838 850 }
839 851 }
840 852 }
853
854 SqpRange VariableController::VariableControllerPrivate::getLastRequestedRange(QUuid varId)
855 {
856 auto lastRangeRequested = SqpRange{INVALID_RANGE};
857 auto varIdToVarRequestIdQueueMapIt = m_VarIdToVarRequestIdQueueMap.find(varId);
858 if (varIdToVarRequestIdQueueMapIt != m_VarIdToVarRequestIdQueueMap.cend()) {
859 auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second;
860 auto varRequestId = varRequestIdQueue.back();
861 auto varRequestIdToVarIdVarRequestMapIt
862 = m_VarRequestIdToVarIdVarRequestMap.find(varRequestId);
863 if (varRequestIdToVarIdVarRequestMapIt != m_VarRequestIdToVarIdVarRequestMap.cend()) {
864 auto &varIdToVarRequestMap = varRequestIdToVarIdVarRequestMapIt->second;
865 auto varIdToVarRequestMapIt = varIdToVarRequestMap.find(varId);
866 if (varIdToVarRequestMapIt != varIdToVarRequestMap.cend()) {
867 auto &varRequest = varIdToVarRequestMapIt->second;
868 lastRangeRequested = varRequest.m_RangeRequested;
869 }
870 else {
871 qCDebug(LOG_VariableController())
872 << tr("Impossible to getLastRequestedRange of a unknown variable id attached "
873 "to a variableRequestId")
874 << varRequestId << varId;
875 }
876 }
877 else {
878 qCCritical(LOG_VariableController())
879 << tr("Impossible to getLastRequestedRange of a unknown variableRequestId")
880 << varRequestId;
881 }
882 }
883 else {
884 qDebug(LOG_VariableController())
885 << tr("Impossible to getLastRequestedRange of a unknown variable id") << varId;
886 }
887
888 return lastRangeRequested;
889 }
@@ -105,8 +105,7 struct Move : public IOperation {
105 105 void exec(VariableController &variableController) const override
106 106 {
107 107 if (auto variable = variableController.variableModel()->variable(m_Index)) {
108 variableController.onRequestDataLoading({variable}, m_NewRange, variable->range(),
109 !m_Shift);
108 variableController.onRequestDataLoading({variable}, m_NewRange, !m_Shift);
110 109 }
111 110 }
112 111
@@ -171,20 +170,10 private slots:
171 170 void testSync();
172 171 };
173 172
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 // ////////// //
173 namespace {
187 174
175 void testSyncCase1()
176 {
188 177 // Id used to synchronize variables in the controller
189 178 auto syncId = QUuid::createUuid();
190 179
@@ -254,7 +243,86 void TestVariableSync::testSync_data()
254 243 // Zoom out
255 244 moveVar0(range({12, 0}, {18, 0}), range({11, 0}, {17, 0}));
256 245
257 QTest::newRow("sync1") << syncId << initialRange << std::move(iterations);
246 QTest::newRow("sync1") << syncId << initialRange << std::move(iterations) << 200;
247 }
248
249 void testSyncCase2()
250 {
251 // Id used to synchronize variables in the controller
252 auto syncId = QUuid::createUuid();
253
254 /// Generates a range according to a start time and a end time (the date is the same)
255 auto dateTime = [](int year, int month, int day, int hours, int minutes, int seconds) {
256 return DateUtils::secondsSinceEpoch(
257 QDateTime{{year, month, day}, QTime{hours, minutes, seconds}, Qt::UTC});
258 };
259
260 auto initialRange = SqpRange{dateTime(2017, 1, 1, 12, 0, 0), dateTime(2017, 1, 1, 13, 0, 0)};
261
262 Iterations iterations{};
263 // Creates variables var0 and var1
264 iterations.push_back({std::make_shared<Create>(0), {{0, initialRange}}});
265 iterations.push_back({std::make_shared<Create>(1), {{0, initialRange}, {1, initialRange}}});
266
267 // Adds variables into the sync group (ranges don't need to be tested here)
268 iterations.push_back({std::make_shared<Synchronize>(0, syncId)});
269 iterations.push_back({std::make_shared<Synchronize>(1, syncId)});
270
271
272 // Moves var0 through several operations:
273 // - range of var0 changes
274 // - range or var1 changes according to the previous shift (one hour)
275 auto moveVar0 = [&iterations](const auto &var0NewRange) {
276 iterations.push_back(
277 {std::make_shared<Move>(0, var0NewRange), {{0, var0NewRange}, {1, var0NewRange}}});
278 };
279 moveVar0(SqpRange{dateTime(2017, 1, 1, 12, 0, 0), dateTime(2017, 1, 1, 13, 0, 0)});
280 moveVar0(SqpRange{dateTime(2017, 1, 1, 14, 0, 0), dateTime(2017, 1, 1, 15, 0, 0)});
281 moveVar0(SqpRange{dateTime(2017, 1, 1, 8, 0, 0), dateTime(2017, 1, 1, 9, 0, 0)});
282 // moveVar0(SqpRange{dateTime(2017, 1, 1, 7, 30, 0), dateTime(2017, 1, 1, 9, 30, 0)});
283 moveVar0(SqpRange{dateTime(2017, 1, 1, 2, 0, 0), dateTime(2017, 1, 1, 4, 0, 0)});
284 moveVar0(SqpRange{dateTime(2017, 1, 1, 6, 0, 0), dateTime(2017, 1, 1, 8, 0, 0)});
285
286 moveVar0(SqpRange{dateTime(2017, 1, 10, 6, 0, 0), dateTime(2017, 1, 15, 8, 0, 0)});
287 moveVar0(SqpRange{dateTime(2017, 1, 17, 6, 0, 0), dateTime(2017, 1, 25, 8, 0, 0)});
288 moveVar0(SqpRange{dateTime(2017, 1, 2, 6, 0, 0), dateTime(2017, 1, 8, 8, 0, 0)});
289
290 moveVar0(SqpRange{dateTime(2017, 4, 10, 6, 0, 0), dateTime(2017, 6, 15, 8, 0, 0)});
291 moveVar0(SqpRange{dateTime(2017, 1, 17, 6, 0, 0), dateTime(2017, 2, 25, 8, 0, 0)});
292 moveVar0(SqpRange{dateTime(2017, 7, 2, 6, 0, 0), dateTime(2017, 10, 8, 8, 0, 0)});
293 moveVar0(SqpRange{dateTime(2017, 4, 10, 6, 0, 0), dateTime(2017, 6, 15, 8, 0, 0)});
294 moveVar0(SqpRange{dateTime(2017, 1, 17, 6, 0, 0), dateTime(2017, 2, 25, 8, 0, 0)});
295 moveVar0(SqpRange{dateTime(2017, 7, 2, 6, 0, 0), dateTime(2017, 10, 8, 8, 0, 0)});
296 moveVar0(SqpRange{dateTime(2017, 4, 10, 6, 0, 0), dateTime(2017, 6, 15, 8, 0, 0)});
297 moveVar0(SqpRange{dateTime(2017, 1, 17, 6, 0, 0), dateTime(2017, 2, 25, 8, 0, 0)});
298 moveVar0(SqpRange{dateTime(2017, 7, 2, 6, 0, 0), dateTime(2017, 10, 8, 8, 0, 0)});
299 moveVar0(SqpRange{dateTime(2017, 4, 10, 6, 0, 0), dateTime(2017, 6, 15, 8, 0, 0)});
300 moveVar0(SqpRange{dateTime(2017, 1, 17, 6, 0, 0), dateTime(2017, 2, 25, 8, 0, 0)});
301 moveVar0(SqpRange{dateTime(2017, 7, 2, 6, 0, 0), dateTime(2017, 10, 8, 8, 0, 0)});
302
303
304 QTest::newRow("sync2") << syncId << initialRange << iterations << 4000;
305 // QTest::newRow("sync3") << syncId << initialRange << iterations << 5000;
306 }
307 }
308
309 void TestVariableSync::testSync_data()
310 {
311 // ////////////// //
312 // Test structure //
313 // ////////////// //
314
315 QTest::addColumn<QUuid>("syncId");
316 QTest::addColumn<SqpRange>("initialRange");
317 QTest::addColumn<Iterations>("iterations");
318 QTest::addColumn<int>("operationDelay");
319
320 // ////////// //
321 // Test cases //
322 // ////////// //
323
324 testSyncCase1();
325 testSyncCase2();
258 326 }
259 327
260 328 void TestVariableSync::testSync()
@@ -271,15 +339,8 void TestVariableSync::testSync()
271 339 // Synchronization group used
272 340 variableController.onAddSynchronizationGroupId(syncId);
273 341
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) {
342 auto validateRanges = [&variableController](const auto &expectedRanges) {
343 for (const auto &expectedRangeEntry : expectedRanges) {
283 344 auto variableIndex = expectedRangeEntry.first;
284 345 auto expectedRange = expectedRangeEntry.second;
285 346
@@ -297,12 +358,31 void TestVariableSync::testSync()
297 358
298 359 auto it = dataSeries->xAxisRange(range.m_TStart, range.m_TEnd);
299 360 auto expectedValues = values(range);
361 qInfo() << std::distance(it.first, it.second) << expectedValues.size();
300 362 QVERIFY(std::equal(it.first, it.second, expectedValues.cbegin(), expectedValues.cend(),
301 363 [](const auto &dataSeriesIt, const auto &expectedValue) {
302 364 return dataSeriesIt.value() == expectedValue;
303 365 }));
304 366 }
367 };
368
369 // For each iteration:
370 // - execute operation
371 // - compare the variables' state to the expected states
372 QFETCH(Iterations, iterations);
373 QFETCH(int, operationDelay);
374 for (const auto &iteration : iterations) {
375 iteration.m_Operation->exec(variableController);
376 QTest::qWait(operationDelay);
377
378 validateRanges(iteration.m_ExpectedRanges);
379 }
380
381 for (const auto &iteration : iterations) {
382 iteration.m_Operation->exec(variableController);
305 383 }
384 QTest::qWait(operationDelay);
385 validateRanges(iterations.back().m_ExpectedRanges);
306 386 }
307 387
308 388 QTEST_MAIN(TestVariableSync)
@@ -39,7 +39,6 public:
39 39 /// Removes a variable from the graph
40 40 void removeVariable(std::shared_ptr<Variable> variable) noexcept;
41 41
42 void setRange(std::shared_ptr<Variable> variable, const SqpRange &range);
43 42 void setYRange(const SqpRange &range);
44 43 SqpRange graphRange() const noexcept;
45 44 void setGraphRange(const SqpRange &range);
@@ -54,7 +53,7 public:
54 53 signals:
55 54 void synchronize(const SqpRange &range, const SqpRange &oldRange);
56 55 void requestDataLoading(QVector<std::shared_ptr<Variable> > variable, const SqpRange &range,
57 const SqpRange &oldRange, bool synchronise);
56 bool synchronise);
58 57
59 58 /// Signal emitted when the variable is about to be removed from the graph
60 59 void variableAboutToBeRemoved(std::shared_ptr<Variable> var);
@@ -119,14 +119,11 void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable, S
119 119
120 120 connect(variable.get(), SIGNAL(updated()), this, SLOT(onDataCacheVariableUpdated()));
121 121
122 auto varRange = variable->range();
123
124 122 this->enableAcquisition(false);
125 123 this->setGraphRange(range);
126 124 this->enableAcquisition(true);
127 125
128 emit requestDataLoading(QVector<std::shared_ptr<Variable> >() << variable, range, varRange,
129 false);
126 emit requestDataLoading(QVector<std::shared_ptr<Variable> >() << variable, range, false);
130 127
131 128 emit variableAdded(variable);
132 129 }
@@ -155,17 +152,6 void VisualizationGraphWidget::removeVariable(std::shared_ptr<Variable> variable
155 152 ui->widget->replot();
156 153 }
157 154
158 void VisualizationGraphWidget::setRange(std::shared_ptr<Variable> variable, const SqpRange &range)
159 {
160 // Note: in case of different axes that depends on variable, we could start with a code like
161 // that:
162 // auto componentsIt = impl->m_VariableToPlotMultiMap.equal_range(variable);
163 // for (auto it = componentsIt.first; it != componentsIt.second;) {
164 // }
165 ui->widget->xAxis->setRange(range.m_TStart, range.m_TEnd);
166 ui->widget->replot();
167 }
168
169 155 void VisualizationGraphWidget::setYRange(const SqpRange &range)
170 156 {
171 157 ui->widget->yAxis->setRange(range.m_TStart, range.m_TEnd);
@@ -282,7 +268,7 void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1, const QCPRange
282 268 it != end; it = impl->m_VariableToPlotMultiMap.upper_bound(it->first)) {
283 269 variableUnderGraphVector.push_back(it->first);
284 270 }
285 emit requestDataLoading(std::move(variableUnderGraphVector), graphRange, oldGraphRange,
271 emit requestDataLoading(std::move(variableUnderGraphVector), graphRange,
286 272 !impl->m_IsCalibration);
287 273
288 274 if (!impl->m_IsCalibration) {
@@ -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 += deltaRight;
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 -= deltaLeft;
169 graphChildRange.m_TEnd -= deltaRight;
168 170 break;
169 171 }
170 172 case AcquisitionZoomType::Unknown: {
@@ -59,7 +59,9 void RescaleAxeOperation::visit(VisualizationGraphWidget *graphWidget)
59 59 if (graphWidget) {
60 60 // If the widget contains the variable, rescale it
61 61 if (impl->m_Variable && graphWidget->contains(*impl->m_Variable)) {
62 graphWidget->setRange(impl->m_Variable, impl->m_Range);
62 graphWidget->enableAcquisition(false);
63 graphWidget->setGraphRange(impl->m_Range);
64 graphWidget->enableAcquisition(true);
63 65 }
64 66 }
65 67 else {
@@ -123,8 +123,7 void TestAmdaAcquisition::testAcquisition()
123 123
124 124 auto nextSqpR
125 125 = SqpRange{DateUtils::secondsSinceEpoch(tStart), DateUtils::secondsSinceEpoch(tEnd)};
126 vc.onRequestDataLoading(QVector<std::shared_ptr<Variable> >{} << var, nextSqpR,
127 var->range(), true);
126 vc.onRequestDataLoading(QVector<std::shared_ptr<Variable> >{} << var, nextSqpR, true);
128 127
129 128 QEventLoop loop;
130 129 QTimer::singleShot(timeToWaitMs, &loop, &QEventLoop::quit);
@@ -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 qCInfo(LOG_CosinusProvider()) << "TORM: CosinusProvider::retrieveData"
149 << QThread::currentThread()->objectName() << progress;
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 }
@@ -179,7 +180,6 void CosinusProvider::requestDataLoading(QUuid acqIdentifier,
179 180 for (const auto &dateTime : qAsConst(times)) {
180 181 if (m_VariableToEnableProvider[acqIdentifier]) {
181 182 auto scalarSeries = this->retrieveData(acqIdentifier, dateTime, parameters.m_Data);
182 qCDebug(LOG_CosinusProvider()) << "TORM: CosinusProvider::dataProvided";
183 183 emit dataProvided(acqIdentifier, scalarSeries, dateTime);
184 184 }
185 185 }
@@ -187,7 +187,6 void CosinusProvider::requestDataLoading(QUuid acqIdentifier,
187 187
188 188 void CosinusProvider::requestDataAborting(QUuid acqIdentifier)
189 189 {
190 // TODO: Add Mutex
191 190 qCDebug(LOG_CosinusProvider()) << "CosinusProvider::requestDataAborting" << acqIdentifier
192 191 << QThread::currentThread()->objectName();
193 192 auto it = m_VariableToEnableProvider.find(acqIdentifier);
@@ -195,7 +194,18 void CosinusProvider::requestDataAborting(QUuid acqIdentifier)
195 194 it.value() = false;
196 195 }
197 196 else {
198 qCWarning(LOG_CosinusProvider())
197 qCDebug(LOG_CosinusProvider())
199 198 << tr("Aborting progression of inexistant identifier detected !!!");
200 199 }
201 200 }
201
202 std::shared_ptr<IDataSeries> CosinusProvider::provideDataSeries(const SqpRange &dataRangeRequested,
203 const QVariantHash &data)
204 {
205 auto uid = QUuid::createUuid();
206 m_VariableToEnableProvider[uid] = true;
207 auto dataSeries = this->retrieveData(uid, dataRangeRequested, data);
208
209 m_VariableToEnableProvider.remove(uid);
210 return dataSeries;
211 }
@@ -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,76 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 data file
138 QFETCH(QString, dataFilename);
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 sqpApp->timeController().onTimeToUpdate(initialRange);
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, true);
169
170 QTest::qWait(operationDelay);
171 validateVariable(variable, operation);
178 172 }
179 else {
180 QFAIL("Can't read input data file");
173
174
175 for (const auto &operation : operations) {
176 // Asks request on the variable and waits during its execution
177 sqpApp->variableController().onRequestDataLoading({variable}, operation, true);
181 178 }
179 QTest::qWait(operationDelay);
180 validateVariable(variable, operations.back());
182 181 }
183 182
184 183 int main(int argc, char *argv[])
General Comments 0
You need to be logged in to leave comments. Login now