##// END OF EJS Templates
Improve cosinus tests with:...
perrinel -
r808:5353ec1e417b
parent child
Show More
@@ -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 }
@@ -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
79 QTest::addColumn<SqpRange>("referenceRange"); // Range for generating reference series
103 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,24 +108,41 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};
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.}});
142 139
143 if (dataFile.open(QFile::ReadOnly)) {
144 // Generates data series to compare with
145 QTextStream dataStream{&dataFile};
146 auto dataSeries = readDataStream(dataStream);
140 auto end = dataSeries->cend() - 1;
141 qInfo() << dataSeries->nbPoints() << dataSeries->cbegin()->x() << end->x();
147 142
148 143 /// Lambda used to validate a variable at each step
149 auto validateVariable = [dataSeries](std::shared_ptr<Variable> variable,
150 const SqpRange &range) {
144 auto validateVariable
145 = [dataSeries](std::shared_ptr<Variable> variable, const SqpRange &range) {
151 146 // Checks that the variable's range has changed
152 147 QCOMPARE(variable->range(), range);
153 148
@@ -162,23 +157,29 void TestCosinusAcquisition::testAcquisition()
162 157 auto variable = sqpApp->variableController().createVariable(
163 158 "MMS", {{COSINUS_TYPE_KEY, "scalar"}, {COSINUS_FREQUENCY_KEY, 100.}}, provider);
164 159
165 QTest::qWait(OPERATION_DELAY);
160 QFETCH(int, operationDelay);
161 QTest::qWait(operationDelay);
166 162 validateVariable(variable, initialRange);
167 163
168 164 // Makes operations on the variable
169 165 QFETCH(std::vector<SqpRange>, operations);
170 166 for (const auto &operation : operations) {
171 167 // Asks request on the variable and waits during its execution
172 sqpApp->variableController().onRequestDataLoading({variable}, operation,
173 variable->range(), true);
168 sqpApp->variableController().onRequestDataLoading({variable}, operation, variable->range(),
169 true);
174 170
175 QTest::qWait(OPERATION_DELAY);
171 QTest::qWait(operationDelay);
176 172 validateVariable(variable, operation);
177 173 }
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);
178 180 }
179 else {
180 QFAIL("Can't read input data file");
181 }
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