##// END OF EJS Templates
Improve cosinus tests with:...
perrinel -
r808:5353ec1e417b
parent child
Show More
@@ -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 0
You need to be logged in to leave comments. Login now