##// END OF EJS Templates
Adds read compatibility for local AMDA server...
Alexandre Leroux -
r1121:98220c931c83
parent child
Show More
@@ -46,6 +46,9 extern const QString VALUES_UNIT_PROPERTY;
46 /// ... - Units : m/s - ...
46 /// ... - Units : m/s - ...
47 extern const QRegularExpression DEFAULT_X_AXIS_UNIT_REGEX;
47 extern const QRegularExpression DEFAULT_X_AXIS_UNIT_REGEX;
48
48
49 /// Alternative regex to find x-axis unit in a line
50 extern const QRegularExpression ALTERNATIVE_X_AXIS_UNIT_REGEX;
51
49 /// Regex to find end time of data in a line for a spectrogram
52 /// Regex to find end time of data in a line for a spectrogram
50 extern const QRegularExpression SPECTROGRAM_END_TIME_REGEX;
53 extern const QRegularExpression SPECTROGRAM_END_TIME_REGEX;
51
54
@@ -11,9 +11,17 const QString X_AXIS_UNIT_PROPERTY = QStringLiteral("xAxisUnit");
11 const QString Y_AXIS_UNIT_PROPERTY = QStringLiteral("yAxisUnit");
11 const QString Y_AXIS_UNIT_PROPERTY = QStringLiteral("yAxisUnit");
12 const QString VALUES_UNIT_PROPERTY = QStringLiteral("valuesUnit");
12 const QString VALUES_UNIT_PROPERTY = QStringLiteral("valuesUnit");
13
13
14 namespace {
15
16 const auto PARAMETER_UNITS_REGEX
17 = QRegularExpression{QStringLiteral("\\s*PARAMETER_UNITS\\s*:\\s*(.*)")};
18 }
19
14 const QRegularExpression DEFAULT_X_AXIS_UNIT_REGEX
20 const QRegularExpression DEFAULT_X_AXIS_UNIT_REGEX
15 = QRegularExpression{QStringLiteral("-\\s*Units\\s*:\\s*(.+?)\\s*-")};
21 = QRegularExpression{QStringLiteral("-\\s*Units\\s*:\\s*(.+?)\\s*-")};
16
22
23 const QRegularExpression ALTERNATIVE_X_AXIS_UNIT_REGEX = PARAMETER_UNITS_REGEX;
24
17 const QRegularExpression SPECTROGRAM_END_TIME_REGEX
25 const QRegularExpression SPECTROGRAM_END_TIME_REGEX
18 = QRegularExpression{QStringLiteral("\\s*INTERVAL_STOP\\s*:\\s*(.*)")};
26 = QRegularExpression{QStringLiteral("\\s*INTERVAL_STOP\\s*:\\s*(.*)")};
19
27
@@ -38,5 +46,4 const QRegularExpression SPECTROGRAM_START_TIME_REGEX
38 const QRegularExpression SPECTROGRAM_Y_AXIS_UNIT_REGEX
46 const QRegularExpression SPECTROGRAM_Y_AXIS_UNIT_REGEX
39 = QRegularExpression{QStringLiteral("\\s*PARAMETER_TABLE_UNITS\\[0\\]\\s*:\\s*(.*)")};
47 = QRegularExpression{QStringLiteral("\\s*PARAMETER_TABLE_UNITS\\[0\\]\\s*:\\s*(.*)")};
40
48
41 const QRegularExpression SPECTROGRAM_VALUES_UNIT_REGEX
49 const QRegularExpression SPECTROGRAM_VALUES_UNIT_REGEX = PARAMETER_UNITS_REGEX;
42 = QRegularExpression{QStringLiteral("\\s*PARAMETER_UNITS\\s*:\\s*(.*)")};
@@ -136,7 +136,7 void tryReadResult(std::vector<double> &xAxisData, std::vector<double> &valuesDa
136 * @param properties the properties map in which to put the property extracted from the line
136 * @param properties the properties map in which to put the property extracted from the line
137 * @param key the key to which the property is added in the properties map
137 * @param key the key to which the property is added in the properties map
138 * @param line the line to read to extract the property
138 * @param line the line to read to extract the property
139 * @param regex the expected regex to extract the property. If the line matches this regex, the
139 * @param regexes the expected regexes to extract the property. If the line matches one regex, the
140 * property is generated
140 * property is generated
141 * @param fun the function used to generate the property
141 * @param fun the function used to generate the property
142 * @return true if the property could be generated, false if the line does not match the regex, or
142 * @return true if the property could be generated, false if the line does not match the regex, or
@@ -144,18 +144,24 void tryReadResult(std::vector<double> &xAxisData, std::vector<double> &valuesDa
144 */
144 */
145 template <typename GeneratePropertyFun>
145 template <typename GeneratePropertyFun>
146 bool tryReadProperty(Properties &properties, const QString &key, const QString &line,
146 bool tryReadProperty(Properties &properties, const QString &key, const QString &line,
147 const QRegularExpression &regex, GeneratePropertyFun fun)
147 const std::vector<QRegularExpression> &regexes, GeneratePropertyFun fun)
148 {
148 {
149 if (properties.contains(key)) {
149 if (properties.contains(key)) {
150 return false;
150 return false;
151 }
151 }
152
152
153 auto match = regex.match(line);
153 // Searches for a match among all possible regexes
154 if (match.hasMatch()) {
154 auto hasMatch = false;
155 properties.insert(key, fun(match));
155 for (auto regexIt = regexes.cbegin(), end = regexes.cend(); regexIt != end && !hasMatch;
156 ++regexIt) {
157 auto match = regexIt->match(line);
158 auto hasMatch = match.hasMatch();
159 if (hasMatch) {
160 properties.insert(key, fun(match));
161 }
156 }
162 }
157
163
158 return match.hasMatch();
164 return hasMatch;
159 }
165 }
160
166
161 /**
167 /**
@@ -163,9 +169,9 bool tryReadProperty(Properties &properties, const QString &key, const QString &
163 * @sa tryReadProperty()
169 * @sa tryReadProperty()
164 */
170 */
165 bool tryReadDate(Properties &properties, const QString &key, const QString &line,
171 bool tryReadDate(Properties &properties, const QString &key, const QString &line,
166 const QRegularExpression &regex, bool timeUnit = false)
172 const std::vector<QRegularExpression> &regexes, bool timeUnit = false)
167 {
173 {
168 return tryReadProperty(properties, key, line, regex, [timeUnit](const auto &match) {
174 return tryReadProperty(properties, key, line, regexes, [timeUnit](const auto &match) {
169 return QVariant::fromValue(doubleDate(match.captured(1)));
175 return QVariant::fromValue(doubleDate(match.captured(1)));
170 });
176 });
171 }
177 }
@@ -175,9 +181,9 bool tryReadDate(Properties &properties, const QString &key, const QString &line
175 * @sa tryReadProperty()
181 * @sa tryReadProperty()
176 */
182 */
177 bool tryReadDouble(Properties &properties, const QString &key, const QString &line,
183 bool tryReadDouble(Properties &properties, const QString &key, const QString &line,
178 const QRegularExpression &regex)
184 const std::vector<QRegularExpression> &regexes)
179 {
185 {
180 return tryReadProperty(properties, key, line, regex, [](const auto &match) {
186 return tryReadProperty(properties, key, line, regexes, [](const auto &match) {
181 bool ok;
187 bool ok;
182
188
183 // If the value can't be converted to double, it is set to NaN
189 // If the value can't be converted to double, it is set to NaN
@@ -196,9 +202,10 bool tryReadDouble(Properties &properties, const QString &key, const QString &li
196 * @sa tryReadProperty()
202 * @sa tryReadProperty()
197 */
203 */
198 bool tryReadDoubles(Properties &properties, const QString &key, const QString &line,
204 bool tryReadDoubles(Properties &properties, const QString &key, const QString &line,
199 const QRegularExpression &regex, const QString &sep = QStringLiteral(","))
205 const std::vector<QRegularExpression> &regexes,
206 const QString &sep = QStringLiteral(","))
200 {
207 {
201 return tryReadProperty(properties, key, line, regex, [sep](const auto &match) {
208 return tryReadProperty(properties, key, line, regexes, [sep](const auto &match) {
202 std::vector<double> doubleValues{};
209 std::vector<double> doubleValues{};
203
210
204 // If the value can't be converted to double, it is set to NaN
211 // If the value can't be converted to double, it is set to NaN
@@ -223,9 +230,9 bool tryReadDoubles(Properties &properties, const QString &key, const QString &l
223 * @sa tryReadProperty()
230 * @sa tryReadProperty()
224 */
231 */
225 bool tryReadUnit(Properties &properties, const QString &key, const QString &line,
232 bool tryReadUnit(Properties &properties, const QString &key, const QString &line,
226 const QRegularExpression &regex, bool timeUnit = false)
233 const std::vector<QRegularExpression> &regexes, bool timeUnit = false)
227 {
234 {
228 return tryReadProperty(properties, key, line, regex, [timeUnit](const auto &match) {
235 return tryReadProperty(properties, key, line, regexes, [timeUnit](const auto &match) {
229 return QVariant::fromValue(Unit{match.captured(1), timeUnit});
236 return QVariant::fromValue(Unit{match.captured(1), timeUnit});
230 });
237 });
231 }
238 }
@@ -251,7 +258,8 std::shared_ptr<IDataSeries> ScalarParserHelper::createSeries()
251
258
252 void ScalarParserHelper::readPropertyLine(const QString &line)
259 void ScalarParserHelper::readPropertyLine(const QString &line)
253 {
260 {
254 tryReadUnit(m_Properties, X_AXIS_UNIT_PROPERTY, line, DEFAULT_X_AXIS_UNIT_REGEX, true);
261 tryReadUnit(m_Properties, X_AXIS_UNIT_PROPERTY, line,
262 {DEFAULT_X_AXIS_UNIT_REGEX, ALTERNATIVE_X_AXIS_UNIT_REGEX}, true);
255 }
263 }
256
264
257 void ScalarParserHelper::readResultLine(const QString &line)
265 void ScalarParserHelper::readResultLine(const QString &line)
@@ -321,46 +329,46 void SpectrogramParserHelper::readPropertyLine(const QString &line)
321 // values unit
329 // values unit
322 [&] {
330 [&] {
323 return tryReadUnit(m_Properties, VALUES_UNIT_PROPERTY, line,
331 return tryReadUnit(m_Properties, VALUES_UNIT_PROPERTY, line,
324 SPECTROGRAM_VALUES_UNIT_REGEX);
332 {SPECTROGRAM_VALUES_UNIT_REGEX});
325 },
333 },
326 // y-axis unit
334 // y-axis unit
327 [&] {
335 [&] {
328 return tryReadUnit(m_Properties, Y_AXIS_UNIT_PROPERTY, line,
336 return tryReadUnit(m_Properties, Y_AXIS_UNIT_PROPERTY, line,
329 SPECTROGRAM_Y_AXIS_UNIT_REGEX);
337 {SPECTROGRAM_Y_AXIS_UNIT_REGEX});
330 },
338 },
331 // min sampling
339 // min sampling
332 [&] {
340 [&] {
333 return tryReadDouble(m_Properties, MIN_SAMPLING_PROPERTY, line,
341 return tryReadDouble(m_Properties, MIN_SAMPLING_PROPERTY, line,
334 SPECTROGRAM_MIN_SAMPLING_REGEX);
342 {SPECTROGRAM_MIN_SAMPLING_REGEX});
335 },
343 },
336 // max sampling
344 // max sampling
337 [&] {
345 [&] {
338 return tryReadDouble(m_Properties, MAX_SAMPLING_PROPERTY, line,
346 return tryReadDouble(m_Properties, MAX_SAMPLING_PROPERTY, line,
339 SPECTROGRAM_MAX_SAMPLING_REGEX);
347 {SPECTROGRAM_MAX_SAMPLING_REGEX});
340 },
348 },
341 // fill value
349 // fill value
342 [&] {
350 [&] {
343 return tryReadDouble(m_Properties, FILL_VALUE_PROPERTY, line,
351 return tryReadDouble(m_Properties, FILL_VALUE_PROPERTY, line,
344 SPECTROGRAM_FILL_VALUE_REGEX);
352 {SPECTROGRAM_FILL_VALUE_REGEX});
345 },
353 },
346 // min bounds of each band
354 // min bounds of each band
347 [&] {
355 [&] {
348 return tryReadDoubles(m_Properties, MIN_BANDS_PROPERTY, line,
356 return tryReadDoubles(m_Properties, MIN_BANDS_PROPERTY, line,
349 SPECTROGRAM_MIN_BANDS_REGEX);
357 {SPECTROGRAM_MIN_BANDS_REGEX});
350 },
358 },
351 // max bounds of each band
359 // max bounds of each band
352 [&] {
360 [&] {
353 return tryReadDoubles(m_Properties, MAX_BANDS_PROPERTY, line,
361 return tryReadDoubles(m_Properties, MAX_BANDS_PROPERTY, line,
354 SPECTROGRAM_MAX_BANDS_REGEX);
362 {SPECTROGRAM_MAX_BANDS_REGEX});
355 },
363 },
356 // start time of data
364 // start time of data
357 [&] {
365 [&] {
358 return tryReadDate(m_Properties, START_TIME_PROPERTY, line,
366 return tryReadDate(m_Properties, START_TIME_PROPERTY, line,
359 SPECTROGRAM_START_TIME_REGEX);
367 {SPECTROGRAM_START_TIME_REGEX});
360 },
368 },
361 // end time of data
369 // end time of data
362 [&] {
370 [&] {
363 return tryReadDate(m_Properties, END_TIME_PROPERTY, line, SPECTROGRAM_END_TIME_REGEX);
371 return tryReadDate(m_Properties, END_TIME_PROPERTY, line, {SPECTROGRAM_END_TIME_REGEX});
364 }};
372 }};
365
373
366 for (auto function : functions) {
374 for (auto function : functions) {
@@ -407,7 +415,8 std::shared_ptr<IDataSeries> VectorParserHelper::createSeries()
407
415
408 void VectorParserHelper::readPropertyLine(const QString &line)
416 void VectorParserHelper::readPropertyLine(const QString &line)
409 {
417 {
410 tryReadUnit(m_Properties, X_AXIS_UNIT_PROPERTY, line, DEFAULT_X_AXIS_UNIT_REGEX, true);
418 tryReadUnit(m_Properties, X_AXIS_UNIT_PROPERTY, line,
419 {DEFAULT_X_AXIS_UNIT_REGEX, ALTERNATIVE_X_AXIS_UNIT_REGEX}, true);
411 }
420 }
412
421
413 void VectorParserHelper::readResultLine(const QString &line)
422 void VectorParserHelper::readResultLine(const QString &line)
General Comments 0
You need to be logged in to leave comments. Login now