@@ -73,6 +73,9 public: | |||||
73 | std::shared_ptr<IDataSeries> createSeries() override; |
|
73 | std::shared_ptr<IDataSeries> createSeries() override; | |
74 | void readPropertyLine(const QString &line) override; |
|
74 | void readPropertyLine(const QString &line) override; | |
75 | void readResultLine(const QString &line) override; |
|
75 | void readResultLine(const QString &line) override; | |
|
76 | ||||
|
77 | private: | |||
|
78 | Properties m_Properties{}; | |||
76 | }; |
|
79 | }; | |
77 |
|
80 | |||
78 | /** |
|
81 | /** |
@@ -154,6 +154,54 bool tryReadProperty(Properties &properties, const QString &key, const QString & | |||||
154 | } |
|
154 | } | |
155 |
|
155 | |||
156 | /** |
|
156 | /** | |
|
157 | * Reads a line from the AMDA file and tries to extract a double from it | |||
|
158 | * @sa tryReadProperty() | |||
|
159 | */ | |||
|
160 | bool tryReadDouble(Properties &properties, const QString &key, const QString &line, | |||
|
161 | const QRegularExpression ®ex) | |||
|
162 | { | |||
|
163 | return tryReadProperty(properties, key, line, regex, [](const auto &match) { | |||
|
164 | bool ok; | |||
|
165 | ||||
|
166 | // If the value can't be converted to double, it is set to NaN | |||
|
167 | auto doubleValue = match.captured(1).toDouble(&ok); | |||
|
168 | if (!ok) { | |||
|
169 | doubleValue = std::numeric_limits<double>::quiet_NaN(); | |||
|
170 | } | |||
|
171 | ||||
|
172 | return QVariant::fromValue(doubleValue); | |||
|
173 | }); | |||
|
174 | } | |||
|
175 | ||||
|
176 | /** | |||
|
177 | * Reads a line from the AMDA file and tries to extract a vector of doubles from it | |||
|
178 | * @param sep the separator of double values in the line | |||
|
179 | * @sa tryReadProperty() | |||
|
180 | */ | |||
|
181 | bool tryReadDoubles(Properties &properties, const QString &key, const QString &line, | |||
|
182 | const QRegularExpression ®ex, const QString &sep = QStringLiteral(",")) | |||
|
183 | { | |||
|
184 | return tryReadProperty(properties, key, line, regex, [sep](const auto &match) { | |||
|
185 | std::vector<double> doubleValues{}; | |||
|
186 | ||||
|
187 | // If the value can't be converted to double, it is set to NaN | |||
|
188 | auto values = match.captured(1).split(sep); | |||
|
189 | for (auto value : values) { | |||
|
190 | bool ok; | |||
|
191 | ||||
|
192 | auto doubleValue = value.toDouble(&ok); | |||
|
193 | if (!ok) { | |||
|
194 | doubleValue = std::numeric_limits<double>::quiet_NaN(); | |||
|
195 | } | |||
|
196 | ||||
|
197 | doubleValues.push_back(doubleValue); | |||
|
198 | } | |||
|
199 | ||||
|
200 | return QVariant::fromValue(doubleValues); | |||
|
201 | }); | |||
|
202 | } | |||
|
203 | ||||
|
204 | /** | |||
157 | * Reads a line from the AMDA file and tries to extract a unit from it |
|
205 | * Reads a line from the AMDA file and tries to extract a unit from it | |
158 | * @sa tryReadProperty() |
|
206 | * @sa tryReadProperty() | |
159 | */ |
|
207 | */ | |
@@ -207,7 +255,17 std::vector<int> ScalarParserHelper::valuesIndexes() const | |||||
207 |
|
255 | |||
208 | bool SpectrogramParserHelper::checkProperties() |
|
256 | bool SpectrogramParserHelper::checkProperties() | |
209 | { |
|
257 | { | |
210 | /// @todo ALX |
|
258 | // Generates y-axis data from bands extracted (take the middle of the intervals) | |
|
259 | auto minBands = m_Properties.value(MIN_BANDS_PROPERTY).value<std::vector<double> >(); | |||
|
260 | auto maxBands = m_Properties.value(MAX_BANDS_PROPERTY).value<std::vector<double> >(); | |||
|
261 | ||||
|
262 | if (minBands.size() != maxBands.size()) { | |||
|
263 | qCWarning(LOG_AmdaResultParserHelper()) << QObject::tr( | |||
|
264 | "Can't generate y-axis data from bands extracted: bands intervals are invalid"); | |||
|
265 | return false; | |||
|
266 | } | |||
|
267 | ||||
|
268 | return true; | |||
211 | } |
|
269 | } | |
212 |
|
270 | |||
213 | std::shared_ptr<IDataSeries> SpectrogramParserHelper::createSeries() |
|
271 | std::shared_ptr<IDataSeries> SpectrogramParserHelper::createSeries() | |
@@ -217,7 +275,52 std::shared_ptr<IDataSeries> SpectrogramParserHelper::createSeries() | |||||
217 |
|
275 | |||
218 | void SpectrogramParserHelper::readPropertyLine(const QString &line) |
|
276 | void SpectrogramParserHelper::readPropertyLine(const QString &line) | |
219 | { |
|
277 | { | |
220 | /// @todo ALX |
|
278 | // Set of functions to test on the line to generate a property. If a function is valid (i.e. a | |
|
279 | // property has been generated for the line), the line is treated as processed and the other | |||
|
280 | // functions are not called | |||
|
281 | std::vector<std::function<bool()> > functions{ | |||
|
282 | // values unit | |||
|
283 | [&] { | |||
|
284 | return tryReadUnit(m_Properties, VALUES_UNIT_PROPERTY, line, | |||
|
285 | SPECTROGRAM_VALUES_UNIT_REGEX); | |||
|
286 | }, | |||
|
287 | // y-axis unit | |||
|
288 | [&] { | |||
|
289 | return tryReadUnit(m_Properties, Y_AXIS_UNIT_PROPERTY, line, | |||
|
290 | SPECTROGRAM_Y_AXIS_UNIT_REGEX); | |||
|
291 | }, | |||
|
292 | // min sampling | |||
|
293 | [&] { | |||
|
294 | return tryReadDouble(m_Properties, MIN_SAMPLING_PROPERTY, line, | |||
|
295 | SPECTROGRAM_MIN_SAMPLING_REGEX); | |||
|
296 | }, | |||
|
297 | // max sampling | |||
|
298 | [&] { | |||
|
299 | return tryReadDouble(m_Properties, MAX_SAMPLING_PROPERTY, line, | |||
|
300 | SPECTROGRAM_MAX_SAMPLING_REGEX); | |||
|
301 | }, | |||
|
302 | // fill value | |||
|
303 | [&] { | |||
|
304 | return tryReadDouble(m_Properties, FILL_VALUE_PROPERTY, line, | |||
|
305 | SPECTROGRAM_FILL_VALUE_REGEX); | |||
|
306 | }, | |||
|
307 | // min bounds of each band | |||
|
308 | [&] { | |||
|
309 | return tryReadDoubles(m_Properties, MIN_BANDS_PROPERTY, line, | |||
|
310 | SPECTROGRAM_MIN_BANDS_REGEX); | |||
|
311 | }, | |||
|
312 | // max bounds of each band | |||
|
313 | [&] { | |||
|
314 | return tryReadDoubles(m_Properties, MAX_BANDS_PROPERTY, line, | |||
|
315 | SPECTROGRAM_MAX_BANDS_REGEX); | |||
|
316 | }}; | |||
|
317 | ||||
|
318 | for (auto function : functions) { | |||
|
319 | // Stops at the first function that is valid | |||
|
320 | if (function()) { | |||
|
321 | return; | |||
|
322 | } | |||
|
323 | } | |||
221 | } |
|
324 | } | |
222 |
|
325 | |||
223 | void SpectrogramParserHelper::readResultLine(const QString &line) |
|
326 | void SpectrogramParserHelper::readResultLine(const QString &line) |
General Comments 0
You need to be logged in to leave comments.
Login now