##// END OF EJS Templates
Fix bug in synchro for operation (jump + rescaling)
perrinel -
r814:1fc2e26b3db5
parent child
Show More
@@ -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: {
@@ -551,15 +553,19 AcquisitionZoomType VariableController::getZoomType(const SqpRange &range, const
551 553 // t1.m_TStart <= t2.m_TStart && t2.m_TEnd <= t1.m_TEnd
552 554 auto zoomType = AcquisitionZoomType::Unknown;
553 555 if (range.m_TStart <= oldRange.m_TStart && oldRange.m_TEnd <= range.m_TEnd) {
556 qCCritical(LOG_VariableController()) << "zoomtype: ZoomOut";
554 557 zoomType = AcquisitionZoomType::ZoomOut;
555 558 }
556 559 else if (range.m_TStart > oldRange.m_TStart && range.m_TEnd > oldRange.m_TEnd) {
560 qCCritical(LOG_VariableController()) << "zoomtype: PanRight";
557 561 zoomType = AcquisitionZoomType::PanRight;
558 562 }
559 563 else if (range.m_TStart < oldRange.m_TStart && range.m_TEnd < oldRange.m_TEnd) {
564 qCCritical(LOG_VariableController()) << "zoomtype: PanLeft";
560 565 zoomType = AcquisitionZoomType::PanLeft;
561 566 }
562 567 else if (range.m_TStart > oldRange.m_TStart && oldRange.m_TEnd > range.m_TEnd) {
568 qCCritical(LOG_VariableController()) << "zoomtype: ZoomIn";
563 569 zoomType = AcquisitionZoomType::ZoomIn;
564 570 }
565 571 else {
@@ -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 += 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: {
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