##// 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 46 /// ... - Units : m/s - ...
47 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 52 /// Regex to find end time of data in a line for a spectrogram
50 53 extern const QRegularExpression SPECTROGRAM_END_TIME_REGEX;
51 54
@@ -11,9 +11,17 const QString X_AXIS_UNIT_PROPERTY = QStringLiteral("xAxisUnit");
11 11 const QString Y_AXIS_UNIT_PROPERTY = QStringLiteral("yAxisUnit");
12 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 20 const QRegularExpression DEFAULT_X_AXIS_UNIT_REGEX
15 21 = QRegularExpression{QStringLiteral("-\\s*Units\\s*:\\s*(.+?)\\s*-")};
16 22
23 const QRegularExpression ALTERNATIVE_X_AXIS_UNIT_REGEX = PARAMETER_UNITS_REGEX;
24
17 25 const QRegularExpression SPECTROGRAM_END_TIME_REGEX
18 26 = QRegularExpression{QStringLiteral("\\s*INTERVAL_STOP\\s*:\\s*(.*)")};
19 27
@@ -38,5 +46,4 const QRegularExpression SPECTROGRAM_START_TIME_REGEX
38 46 const QRegularExpression SPECTROGRAM_Y_AXIS_UNIT_REGEX
39 47 = QRegularExpression{QStringLiteral("\\s*PARAMETER_TABLE_UNITS\\[0\\]\\s*:\\s*(.*)")};
40 48
41 const QRegularExpression SPECTROGRAM_VALUES_UNIT_REGEX
42 = QRegularExpression{QStringLiteral("\\s*PARAMETER_UNITS\\s*:\\s*(.*)")};
49 const QRegularExpression SPECTROGRAM_VALUES_UNIT_REGEX = PARAMETER_UNITS_REGEX;
@@ -136,7 +136,7 void tryReadResult(std::vector<double> &xAxisData, std::vector<double> &valuesDa
136 136 * @param properties the properties map in which to put the property extracted from the line
137 137 * @param key the key to which the property is added in the properties map
138 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 140 * property is generated
141 141 * @param fun the function used to generate the property
142 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 145 template <typename GeneratePropertyFun>
146 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 149 if (properties.contains(key)) {
150 150 return false;
151 151 }
152 152
153 auto match = regex.match(line);
154 if (match.hasMatch()) {
153 // Searches for a match among all possible regexes
154 auto hasMatch = false;
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) {
155 160 properties.insert(key, fun(match));
156 161 }
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 169 * @sa tryReadProperty()
164 170 */
165 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 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 181 * @sa tryReadProperty()
176 182 */
177 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 187 bool ok;
182 188
183 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 202 * @sa tryReadProperty()
197 203 */
198 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 209 std::vector<double> doubleValues{};
203 210
204 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 230 * @sa tryReadProperty()
224 231 */
225 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 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 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 265 void ScalarParserHelper::readResultLine(const QString &line)
@@ -321,46 +329,46 void SpectrogramParserHelper::readPropertyLine(const QString &line)
321 329 // values unit
322 330 [&] {
323 331 return tryReadUnit(m_Properties, VALUES_UNIT_PROPERTY, line,
324 SPECTROGRAM_VALUES_UNIT_REGEX);
332 {SPECTROGRAM_VALUES_UNIT_REGEX});
325 333 },
326 334 // y-axis unit
327 335 [&] {
328 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 339 // min sampling
332 340 [&] {
333 341 return tryReadDouble(m_Properties, MIN_SAMPLING_PROPERTY, line,
334 SPECTROGRAM_MIN_SAMPLING_REGEX);
342 {SPECTROGRAM_MIN_SAMPLING_REGEX});
335 343 },
336 344 // max sampling
337 345 [&] {
338 346 return tryReadDouble(m_Properties, MAX_SAMPLING_PROPERTY, line,
339 SPECTROGRAM_MAX_SAMPLING_REGEX);
347 {SPECTROGRAM_MAX_SAMPLING_REGEX});
340 348 },
341 349 // fill value
342 350 [&] {
343 351 return tryReadDouble(m_Properties, FILL_VALUE_PROPERTY, line,
344 SPECTROGRAM_FILL_VALUE_REGEX);
352 {SPECTROGRAM_FILL_VALUE_REGEX});
345 353 },
346 354 // min bounds of each band
347 355 [&] {
348 356 return tryReadDoubles(m_Properties, MIN_BANDS_PROPERTY, line,
349 SPECTROGRAM_MIN_BANDS_REGEX);
357 {SPECTROGRAM_MIN_BANDS_REGEX});
350 358 },
351 359 // max bounds of each band
352 360 [&] {
353 361 return tryReadDoubles(m_Properties, MAX_BANDS_PROPERTY, line,
354 SPECTROGRAM_MAX_BANDS_REGEX);
362 {SPECTROGRAM_MAX_BANDS_REGEX});
355 363 },
356 364 // start time of data
357 365 [&] {
358 366 return tryReadDate(m_Properties, START_TIME_PROPERTY, line,
359 SPECTROGRAM_START_TIME_REGEX);
367 {SPECTROGRAM_START_TIME_REGEX});
360 368 },
361 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 374 for (auto function : functions) {
@@ -407,7 +415,8 std::shared_ptr<IDataSeries> VectorParserHelper::createSeries()
407 415
408 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 422 void VectorParserHelper::readResultLine(const QString &line)
General Comments 0
You need to be logged in to leave comments. Login now