##// END OF EJS Templates
Fixes compilation
Alexandre Leroux -
r943:e9b5130d9068
parent child
Show More
@@ -1,385 +1,387
1 #include "AmdaResultParserHelper.h"
1 #include "AmdaResultParserHelper.h"
2
2
3 #include <Common/DateUtils.h>
3 #include <Common/DateUtils.h>
4 #include <Common/SortUtils.h>
4 #include <Common/SortUtils.h>
5
5
6 #include <Data/ScalarSeries.h>
6 #include <Data/ScalarSeries.h>
7 #include <Data/SpectrogramSeries.h>
7 #include <Data/SpectrogramSeries.h>
8 #include <Data/Unit.h>
8 #include <Data/Unit.h>
9 #include <Data/VectorSeries.h>
9 #include <Data/VectorSeries.h>
10
10
11 #include <QtCore/QDateTime>
11 #include <QtCore/QDateTime>
12 #include <QtCore/QRegularExpression>
12 #include <QtCore/QRegularExpression>
13
13
14 #include <functional>
15
14 Q_LOGGING_CATEGORY(LOG_AmdaResultParserHelper, "AmdaResultParserHelper")
16 Q_LOGGING_CATEGORY(LOG_AmdaResultParserHelper, "AmdaResultParserHelper")
15
17
16 namespace {
18 namespace {
17
19
18 // ///////// //
20 // ///////// //
19 // Constants //
21 // Constants //
20 // ///////// //
22 // ///////// //
21
23
22 /// Separator between values in a result line
24 /// Separator between values in a result line
23 const auto RESULT_LINE_SEPARATOR = QRegularExpression{QStringLiteral("\\s+")};
25 const auto RESULT_LINE_SEPARATOR = QRegularExpression{QStringLiteral("\\s+")};
24
26
25 /// Format for dates in result files
27 /// Format for dates in result files
26 const auto DATE_FORMAT = QStringLiteral("yyyy-MM-ddThh:mm:ss.zzz");
28 const auto DATE_FORMAT = QStringLiteral("yyyy-MM-ddThh:mm:ss.zzz");
27
29
28 // /////// //
30 // /////// //
29 // Methods //
31 // Methods //
30 // /////// //
32 // /////// //
31
33
32 /**
34 /**
33 * Checks that the properties contain a specific unit and that this unit is valid
35 * Checks that the properties contain a specific unit and that this unit is valid
34 * @param properties the properties map in which to search unit
36 * @param properties the properties map in which to search unit
35 * @param key the key to search for the unit in the properties
37 * @param key the key to search for the unit in the properties
36 * @param errorMessage the error message to log in case the unit is invalid
38 * @param errorMessage the error message to log in case the unit is invalid
37 * @return true if the unit is valid, false it it's invalid or was not found in the properties
39 * @return true if the unit is valid, false it it's invalid or was not found in the properties
38 */
40 */
39 bool checkUnit(const Properties &properties, const QString &key, const QString &errorMessage)
41 bool checkUnit(const Properties &properties, const QString &key, const QString &errorMessage)
40 {
42 {
41 auto unit = properties.value(key).value<Unit>();
43 auto unit = properties.value(key).value<Unit>();
42 if (unit.m_Name.isEmpty()) {
44 if (unit.m_Name.isEmpty()) {
43 qCWarning(LOG_AmdaResultParserHelper()) << errorMessage;
45 qCWarning(LOG_AmdaResultParserHelper()) << errorMessage;
44 return false;
46 return false;
45 }
47 }
46
48
47 return true;
49 return true;
48 }
50 }
49
51
50 QDateTime dateTimeFromString(const QString &stringDate) noexcept
52 QDateTime dateTimeFromString(const QString &stringDate) noexcept
51 {
53 {
52 #if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0)
54 #if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0)
53 return QDateTime::fromString(stringDate, Qt::ISODateWithMs);
55 return QDateTime::fromString(stringDate, Qt::ISODateWithMs);
54 #else
56 #else
55 return QDateTime::fromString(stringDate, DATE_FORMAT);
57 return QDateTime::fromString(stringDate, DATE_FORMAT);
56 #endif
58 #endif
57 }
59 }
58
60
59 /// Converts a string date to a double date
61 /// Converts a string date to a double date
60 /// @return a double that represents the date in seconds, NaN if the string date can't be converted
62 /// @return a double that represents the date in seconds, NaN if the string date can't be converted
61 double doubleDate(const QString &stringDate) noexcept
63 double doubleDate(const QString &stringDate) noexcept
62 {
64 {
63 // Format: yyyy-MM-ddThh:mm:ss.zzz
65 // Format: yyyy-MM-ddThh:mm:ss.zzz
64 auto dateTime = dateTimeFromString(stringDate);
66 auto dateTime = dateTimeFromString(stringDate);
65 dateTime.setTimeSpec(Qt::UTC);
67 dateTime.setTimeSpec(Qt::UTC);
66 return dateTime.isValid() ? DateUtils::secondsSinceEpoch(dateTime)
68 return dateTime.isValid() ? DateUtils::secondsSinceEpoch(dateTime)
67 : std::numeric_limits<double>::quiet_NaN();
69 : std::numeric_limits<double>::quiet_NaN();
68 }
70 }
69
71
70 /**
72 /**
71 * Reads a line from the AMDA file and tries to extract a x-axis data and value data from it
73 * Reads a line from the AMDA file and tries to extract a x-axis data and value data from it
72 * @param xAxisData the vector in which to store the x-axis data extracted
74 * @param xAxisData the vector in which to store the x-axis data extracted
73 * @param valuesData the vector in which to store the value extracted
75 * @param valuesData the vector in which to store the value extracted
74 * @param line the line to read to extract the property
76 * @param line the line to read to extract the property
75 * @param valuesIndexes indexes of insertion of read values. For example, if the line contains three
77 * @param valuesIndexes indexes of insertion of read values. For example, if the line contains three
76 * columns of values, and valuesIndexes are {2, 0, 1}, the value of the third column will be read
78 * columns of values, and valuesIndexes are {2, 0, 1}, the value of the third column will be read
77 * and inserted first, then the value of the first column, and finally the value of the second
79 * and inserted first, then the value of the first column, and finally the value of the second
78 * column.
80 * column.
79 * @param fillValue value that tags an invalid data. For example, if fillValue is -1 and a read
81 * @param fillValue value that tags an invalid data. For example, if fillValue is -1 and a read
80 * value is -1, then this value is considered as invalid and converted to NaN
82 * value is -1, then this value is considered as invalid and converted to NaN
81 */
83 */
82 void tryReadResult(std::vector<double> &xAxisData, std::vector<double> &valuesData,
84 void tryReadResult(std::vector<double> &xAxisData, std::vector<double> &valuesData,
83 const QString &line, const std::vector<int> &valuesIndexes,
85 const QString &line, const std::vector<int> &valuesIndexes,
84 double fillValue = std::numeric_limits<double>::quiet_NaN())
86 double fillValue = std::numeric_limits<double>::quiet_NaN())
85 {
87 {
86 auto lineData = line.split(RESULT_LINE_SEPARATOR, QString::SkipEmptyParts);
88 auto lineData = line.split(RESULT_LINE_SEPARATOR, QString::SkipEmptyParts);
87
89
88 // Checks that the line contains expected number of values + x-axis value
90 // Checks that the line contains expected number of values + x-axis value
89 if (lineData.size() == valuesIndexes.size() + 1) {
91 if (lineData.size() == valuesIndexes.size() + 1) {
90 // X : the data is converted from date to double (in secs)
92 // X : the data is converted from date to double (in secs)
91 auto x = doubleDate(lineData.at(0));
93 auto x = doubleDate(lineData.at(0));
92
94
93 // Adds result only if x is valid. Then, if value is invalid, it is set to NaN
95 // Adds result only if x is valid. Then, if value is invalid, it is set to NaN
94 if (!std::isnan(x)) {
96 if (!std::isnan(x)) {
95 xAxisData.push_back(x);
97 xAxisData.push_back(x);
96
98
97 // Values
99 // Values
98 for (auto valueIndex : valuesIndexes) {
100 for (auto valueIndex : valuesIndexes) {
99 bool valueOk;
101 bool valueOk;
100 // we use valueIndex + 1 to skip column 0 (x-axis value)
102 // we use valueIndex + 1 to skip column 0 (x-axis value)
101 auto value = lineData.at(valueIndex + 1).toDouble(&valueOk);
103 auto value = lineData.at(valueIndex + 1).toDouble(&valueOk);
102
104
103 if (!valueOk) {
105 if (!valueOk) {
104 qCWarning(LOG_AmdaResultParserHelper())
106 qCWarning(LOG_AmdaResultParserHelper())
105 << QObject::tr(
107 << QObject::tr(
106 "Value from (line %1, column %2) is invalid and will be "
108 "Value from (line %1, column %2) is invalid and will be "
107 "converted to NaN")
109 "converted to NaN")
108 .arg(line, valueIndex);
110 .arg(line, valueIndex);
109 value = std::numeric_limits<double>::quiet_NaN();
111 value = std::numeric_limits<double>::quiet_NaN();
110 }
112 }
111
113
112 // Handles fill value
114 // Handles fill value
113 if (!std::isnan(fillValue) && !std::isnan(value) && fillValue == value) {
115 if (!std::isnan(fillValue) && !std::isnan(value) && fillValue == value) {
114 value = std::numeric_limits<double>::quiet_NaN();
116 value = std::numeric_limits<double>::quiet_NaN();
115 }
117 }
116
118
117 valuesData.push_back(value);
119 valuesData.push_back(value);
118 }
120 }
119 }
121 }
120 else {
122 else {
121 qCWarning(LOG_AmdaResultParserHelper())
123 qCWarning(LOG_AmdaResultParserHelper())
122 << QObject::tr("Can't retrieve results from line %1: x is invalid").arg(line);
124 << QObject::tr("Can't retrieve results from line %1: x is invalid").arg(line);
123 }
125 }
124 }
126 }
125 else {
127 else {
126 qCWarning(LOG_AmdaResultParserHelper())
128 qCWarning(LOG_AmdaResultParserHelper())
127 << QObject::tr("Can't retrieve results from line %1: invalid line").arg(line);
129 << QObject::tr("Can't retrieve results from line %1: invalid line").arg(line);
128 }
130 }
129 }
131 }
130
132
131 /**
133 /**
132 * Reads a line from the AMDA file and tries to extract a property from it
134 * Reads a line from the AMDA file and tries to extract a property from it
133 * @param properties the properties map in which to put the property extracted from the line
135 * @param properties the properties map in which to put the property extracted from the line
134 * @param key the key to which the property is added in the properties map
136 * @param key the key to which the property is added in the properties map
135 * @param line the line to read to extract the property
137 * @param line the line to read to extract the property
136 * @param regex the expected regex to extract the property. If the line matches this regex, the
138 * @param regex the expected regex to extract the property. If the line matches this regex, the
137 * property is generated
139 * property is generated
138 * @param fun the function used to generate the property
140 * @param fun the function used to generate the property
139 * @return true if the property could be generated, false if the line does not match the regex, or
141 * @return true if the property could be generated, false if the line does not match the regex, or
140 * if a property has already been generated for the key
142 * if a property has already been generated for the key
141 */
143 */
142 template <typename GeneratePropertyFun>
144 template <typename GeneratePropertyFun>
143 bool tryReadProperty(Properties &properties, const QString &key, const QString &line,
145 bool tryReadProperty(Properties &properties, const QString &key, const QString &line,
144 const QRegularExpression &regex, GeneratePropertyFun fun)
146 const QRegularExpression &regex, GeneratePropertyFun fun)
145 {
147 {
146 if (properties.contains(key)) {
148 if (properties.contains(key)) {
147 return false;
149 return false;
148 }
150 }
149
151
150 auto match = regex.match(line);
152 auto match = regex.match(line);
151 if (match.hasMatch()) {
153 if (match.hasMatch()) {
152 properties.insert(key, fun(match));
154 properties.insert(key, fun(match));
153 }
155 }
154
156
155 return match.hasMatch();
157 return match.hasMatch();
156 }
158 }
157
159
158 /**
160 /**
159 * Reads a line from the AMDA file and tries to extract a double from it
161 * Reads a line from the AMDA file and tries to extract a double from it
160 * @sa tryReadProperty()
162 * @sa tryReadProperty()
161 */
163 */
162 bool tryReadDouble(Properties &properties, const QString &key, const QString &line,
164 bool tryReadDouble(Properties &properties, const QString &key, const QString &line,
163 const QRegularExpression &regex)
165 const QRegularExpression &regex)
164 {
166 {
165 return tryReadProperty(properties, key, line, regex, [](const auto &match) {
167 return tryReadProperty(properties, key, line, regex, [](const auto &match) {
166 bool ok;
168 bool ok;
167
169
168 // If the value can't be converted to double, it is set to NaN
170 // If the value can't be converted to double, it is set to NaN
169 auto doubleValue = match.captured(1).toDouble(&ok);
171 auto doubleValue = match.captured(1).toDouble(&ok);
170 if (!ok) {
172 if (!ok) {
171 doubleValue = std::numeric_limits<double>::quiet_NaN();
173 doubleValue = std::numeric_limits<double>::quiet_NaN();
172 }
174 }
173
175
174 return QVariant::fromValue(doubleValue);
176 return QVariant::fromValue(doubleValue);
175 });
177 });
176 }
178 }
177
179
178 /**
180 /**
179 * Reads a line from the AMDA file and tries to extract a vector of doubles from it
181 * Reads a line from the AMDA file and tries to extract a vector of doubles from it
180 * @param sep the separator of double values in the line
182 * @param sep the separator of double values in the line
181 * @sa tryReadProperty()
183 * @sa tryReadProperty()
182 */
184 */
183 bool tryReadDoubles(Properties &properties, const QString &key, const QString &line,
185 bool tryReadDoubles(Properties &properties, const QString &key, const QString &line,
184 const QRegularExpression &regex, const QString &sep = QStringLiteral(","))
186 const QRegularExpression &regex, const QString &sep = QStringLiteral(","))
185 {
187 {
186 return tryReadProperty(properties, key, line, regex, [sep](const auto &match) {
188 return tryReadProperty(properties, key, line, regex, [sep](const auto &match) {
187 std::vector<double> doubleValues{};
189 std::vector<double> doubleValues{};
188
190
189 // If the value can't be converted to double, it is set to NaN
191 // If the value can't be converted to double, it is set to NaN
190 auto values = match.captured(1).split(sep);
192 auto values = match.captured(1).split(sep);
191 for (auto value : values) {
193 for (auto value : values) {
192 bool ok;
194 bool ok;
193
195
194 auto doubleValue = value.toDouble(&ok);
196 auto doubleValue = value.toDouble(&ok);
195 if (!ok) {
197 if (!ok) {
196 doubleValue = std::numeric_limits<double>::quiet_NaN();
198 doubleValue = std::numeric_limits<double>::quiet_NaN();
197 }
199 }
198
200
199 doubleValues.push_back(doubleValue);
201 doubleValues.push_back(doubleValue);
200 }
202 }
201
203
202 return QVariant::fromValue(doubleValues);
204 return QVariant::fromValue(doubleValues);
203 });
205 });
204 }
206 }
205
207
206 /**
208 /**
207 * Reads a line from the AMDA file and tries to extract a unit from it
209 * Reads a line from the AMDA file and tries to extract a unit from it
208 * @sa tryReadProperty()
210 * @sa tryReadProperty()
209 */
211 */
210 bool tryReadUnit(Properties &properties, const QString &key, const QString &line,
212 bool tryReadUnit(Properties &properties, const QString &key, const QString &line,
211 const QRegularExpression &regex, bool timeUnit = false)
213 const QRegularExpression &regex, bool timeUnit = false)
212 {
214 {
213 return tryReadProperty(properties, key, line, regex, [timeUnit](const auto &match) {
215 return tryReadProperty(properties, key, line, regex, [timeUnit](const auto &match) {
214 return QVariant::fromValue(Unit{match.captured(1), timeUnit});
216 return QVariant::fromValue(Unit{match.captured(1), timeUnit});
215 });
217 });
216 }
218 }
217
219
218 } // namespace
220 } // namespace
219
221
220 // ////////////////// //
222 // ////////////////// //
221 // ScalarParserHelper //
223 // ScalarParserHelper //
222 // ////////////////// //
224 // ////////////////// //
223
225
224 bool ScalarParserHelper::checkProperties()
226 bool ScalarParserHelper::checkProperties()
225 {
227 {
226 return checkUnit(m_Properties, X_AXIS_UNIT_PROPERTY,
228 return checkUnit(m_Properties, X_AXIS_UNIT_PROPERTY,
227 QObject::tr("The x-axis unit could not be found in the file"));
229 QObject::tr("The x-axis unit could not be found in the file"));
228 }
230 }
229
231
230 std::shared_ptr<IDataSeries> ScalarParserHelper::createSeries()
232 std::shared_ptr<IDataSeries> ScalarParserHelper::createSeries()
231 {
233 {
232 return std::make_shared<ScalarSeries>(std::move(m_XAxisData), std::move(m_ValuesData),
234 return std::make_shared<ScalarSeries>(std::move(m_XAxisData), std::move(m_ValuesData),
233 m_Properties.value(X_AXIS_UNIT_PROPERTY).value<Unit>(),
235 m_Properties.value(X_AXIS_UNIT_PROPERTY).value<Unit>(),
234 m_Properties.value(VALUES_UNIT_PROPERTY).value<Unit>());
236 m_Properties.value(VALUES_UNIT_PROPERTY).value<Unit>());
235 }
237 }
236
238
237 void ScalarParserHelper::readPropertyLine(const QString &line)
239 void ScalarParserHelper::readPropertyLine(const QString &line)
238 {
240 {
239 tryReadUnit(m_Properties, X_AXIS_UNIT_PROPERTY, line, DEFAULT_X_AXIS_UNIT_REGEX, true);
241 tryReadUnit(m_Properties, X_AXIS_UNIT_PROPERTY, line, DEFAULT_X_AXIS_UNIT_REGEX, true);
240 }
242 }
241
243
242 void ScalarParserHelper::readResultLine(const QString &line)
244 void ScalarParserHelper::readResultLine(const QString &line)
243 {
245 {
244 tryReadResult(m_XAxisData, m_ValuesData, line, valuesIndexes());
246 tryReadResult(m_XAxisData, m_ValuesData, line, valuesIndexes());
245 }
247 }
246
248
247 std::vector<int> ScalarParserHelper::valuesIndexes() const
249 std::vector<int> ScalarParserHelper::valuesIndexes() const
248 {
250 {
249 // Only one value to read
251 // Only one value to read
250 static auto result = std::vector<int>{0};
252 static auto result = std::vector<int>{0};
251 return result;
253 return result;
252 }
254 }
253
255
254 // /////////////////////// //
256 // /////////////////////// //
255 // SpectrogramParserHelper //
257 // SpectrogramParserHelper //
256 // /////////////////////// //
258 // /////////////////////// //
257
259
258 bool SpectrogramParserHelper::checkProperties()
260 bool SpectrogramParserHelper::checkProperties()
259 {
261 {
260 // Generates y-axis data from bands extracted (take the middle of the intervals)
262 // Generates y-axis data from bands extracted (take the middle of the intervals)
261 auto minBands = m_Properties.value(MIN_BANDS_PROPERTY).value<std::vector<double> >();
263 auto minBands = m_Properties.value(MIN_BANDS_PROPERTY).value<std::vector<double> >();
262 auto maxBands = m_Properties.value(MAX_BANDS_PROPERTY).value<std::vector<double> >();
264 auto maxBands = m_Properties.value(MAX_BANDS_PROPERTY).value<std::vector<double> >();
263
265
264 if (minBands.size() != maxBands.size()) {
266 if (minBands.size() != maxBands.size()) {
265 qCWarning(LOG_AmdaResultParserHelper()) << QObject::tr(
267 qCWarning(LOG_AmdaResultParserHelper()) << QObject::tr(
266 "Can't generate y-axis data from bands extracted: bands intervals are invalid");
268 "Can't generate y-axis data from bands extracted: bands intervals are invalid");
267 return false;
269 return false;
268 }
270 }
269
271
270 std::transform(
272 std::transform(
271 minBands.begin(), minBands.end(), maxBands.begin(), std::back_inserter(m_YAxisData),
273 minBands.begin(), minBands.end(), maxBands.begin(), std::back_inserter(m_YAxisData),
272 [](const auto &minValue, const auto &maxValue) { return (minValue + maxValue) / 2.; });
274 [](const auto &minValue, const auto &maxValue) { return (minValue + maxValue) / 2.; });
273
275
274 // Generates values indexes, i.e. the order in which each value will be retrieved (in ascending
276 // Generates values indexes, i.e. the order in which each value will be retrieved (in ascending
275 // order of the associated bands)
277 // order of the associated bands)
276 m_ValuesIndexes = SortUtils::sortPermutation(m_YAxisData, std::less<double>());
278 m_ValuesIndexes = SortUtils::sortPermutation(m_YAxisData, std::less<double>());
277
279
278 // Sorts y-axis data accoding to the ascending order
280 // Sorts y-axis data accoding to the ascending order
279 m_YAxisData = SortUtils::sort(m_YAxisData, 1, m_ValuesIndexes);
281 m_YAxisData = SortUtils::sort(m_YAxisData, 1, m_ValuesIndexes);
280
282
281 // Sets fill value
283 // Sets fill value
282 m_FillValue = m_Properties.value(FILL_VALUE_PROPERTY).value<double>();
284 m_FillValue = m_Properties.value(FILL_VALUE_PROPERTY).value<double>();
283
285
284 /// @todo: handle min/max samplings?
286 /// @todo: handle min/max samplings?
285
287
286 return true;
288 return true;
287 }
289 }
288
290
289 std::shared_ptr<IDataSeries> SpectrogramParserHelper::createSeries()
291 std::shared_ptr<IDataSeries> SpectrogramParserHelper::createSeries()
290 {
292 {
291 return std::make_shared<SpectrogramSeries>(
293 return std::make_shared<SpectrogramSeries>(
292 std::move(m_XAxisData), std::move(m_YAxisData), std::move(m_ValuesData),
294 std::move(m_XAxisData), std::move(m_YAxisData), std::move(m_ValuesData),
293 Unit{"t", true}, // x-axis unit is always a time unit
295 Unit{"t", true}, // x-axis unit is always a time unit
294 m_Properties.value(Y_AXIS_UNIT_PROPERTY).value<Unit>(),
296 m_Properties.value(Y_AXIS_UNIT_PROPERTY).value<Unit>(),
295 m_Properties.value(VALUES_UNIT_PROPERTY).value<Unit>());
297 m_Properties.value(VALUES_UNIT_PROPERTY).value<Unit>());
296 }
298 }
297
299
298 void SpectrogramParserHelper::readPropertyLine(const QString &line)
300 void SpectrogramParserHelper::readPropertyLine(const QString &line)
299 {
301 {
300 // Set of functions to test on the line to generate a property. If a function is valid (i.e. a
302 // Set of functions to test on the line to generate a property. If a function is valid (i.e. a
301 // property has been generated for the line), the line is treated as processed and the other
303 // property has been generated for the line), the line is treated as processed and the other
302 // functions are not called
304 // functions are not called
303 std::vector<std::function<bool()> > functions{
305 std::vector<std::function<bool()> > functions{
304 // values unit
306 // values unit
305 [&] {
307 [&] {
306 return tryReadUnit(m_Properties, VALUES_UNIT_PROPERTY, line,
308 return tryReadUnit(m_Properties, VALUES_UNIT_PROPERTY, line,
307 SPECTROGRAM_VALUES_UNIT_REGEX);
309 SPECTROGRAM_VALUES_UNIT_REGEX);
308 },
310 },
309 // y-axis unit
311 // y-axis unit
310 [&] {
312 [&] {
311 return tryReadUnit(m_Properties, Y_AXIS_UNIT_PROPERTY, line,
313 return tryReadUnit(m_Properties, Y_AXIS_UNIT_PROPERTY, line,
312 SPECTROGRAM_Y_AXIS_UNIT_REGEX);
314 SPECTROGRAM_Y_AXIS_UNIT_REGEX);
313 },
315 },
314 // min sampling
316 // min sampling
315 [&] {
317 [&] {
316 return tryReadDouble(m_Properties, MIN_SAMPLING_PROPERTY, line,
318 return tryReadDouble(m_Properties, MIN_SAMPLING_PROPERTY, line,
317 SPECTROGRAM_MIN_SAMPLING_REGEX);
319 SPECTROGRAM_MIN_SAMPLING_REGEX);
318 },
320 },
319 // max sampling
321 // max sampling
320 [&] {
322 [&] {
321 return tryReadDouble(m_Properties, MAX_SAMPLING_PROPERTY, line,
323 return tryReadDouble(m_Properties, MAX_SAMPLING_PROPERTY, line,
322 SPECTROGRAM_MAX_SAMPLING_REGEX);
324 SPECTROGRAM_MAX_SAMPLING_REGEX);
323 },
325 },
324 // fill value
326 // fill value
325 [&] {
327 [&] {
326 return tryReadDouble(m_Properties, FILL_VALUE_PROPERTY, line,
328 return tryReadDouble(m_Properties, FILL_VALUE_PROPERTY, line,
327 SPECTROGRAM_FILL_VALUE_REGEX);
329 SPECTROGRAM_FILL_VALUE_REGEX);
328 },
330 },
329 // min bounds of each band
331 // min bounds of each band
330 [&] {
332 [&] {
331 return tryReadDoubles(m_Properties, MIN_BANDS_PROPERTY, line,
333 return tryReadDoubles(m_Properties, MIN_BANDS_PROPERTY, line,
332 SPECTROGRAM_MIN_BANDS_REGEX);
334 SPECTROGRAM_MIN_BANDS_REGEX);
333 },
335 },
334 // max bounds of each band
336 // max bounds of each band
335 [&] {
337 [&] {
336 return tryReadDoubles(m_Properties, MAX_BANDS_PROPERTY, line,
338 return tryReadDoubles(m_Properties, MAX_BANDS_PROPERTY, line,
337 SPECTROGRAM_MAX_BANDS_REGEX);
339 SPECTROGRAM_MAX_BANDS_REGEX);
338 }};
340 }};
339
341
340 for (auto function : functions) {
342 for (auto function : functions) {
341 // Stops at the first function that is valid
343 // Stops at the first function that is valid
342 if (function()) {
344 if (function()) {
343 return;
345 return;
344 }
346 }
345 }
347 }
346 }
348 }
347
349
348 void SpectrogramParserHelper::readResultLine(const QString &line)
350 void SpectrogramParserHelper::readResultLine(const QString &line)
349 {
351 {
350 tryReadResult(m_XAxisData, m_ValuesData, line, m_ValuesIndexes, m_FillValue);
352 tryReadResult(m_XAxisData, m_ValuesData, line, m_ValuesIndexes, m_FillValue);
351 }
353 }
352
354
353 // ////////////////// //
355 // ////////////////// //
354 // VectorParserHelper //
356 // VectorParserHelper //
355 // ////////////////// //
357 // ////////////////// //
356
358
357 bool VectorParserHelper::checkProperties()
359 bool VectorParserHelper::checkProperties()
358 {
360 {
359 return checkUnit(m_Properties, X_AXIS_UNIT_PROPERTY,
361 return checkUnit(m_Properties, X_AXIS_UNIT_PROPERTY,
360 QObject::tr("The x-axis unit could not be found in the file"));
362 QObject::tr("The x-axis unit could not be found in the file"));
361 }
363 }
362
364
363 std::shared_ptr<IDataSeries> VectorParserHelper::createSeries()
365 std::shared_ptr<IDataSeries> VectorParserHelper::createSeries()
364 {
366 {
365 return std::make_shared<VectorSeries>(std::move(m_XAxisData), std::move(m_ValuesData),
367 return std::make_shared<VectorSeries>(std::move(m_XAxisData), std::move(m_ValuesData),
366 m_Properties.value(X_AXIS_UNIT_PROPERTY).value<Unit>(),
368 m_Properties.value(X_AXIS_UNIT_PROPERTY).value<Unit>(),
367 m_Properties.value(VALUES_UNIT_PROPERTY).value<Unit>());
369 m_Properties.value(VALUES_UNIT_PROPERTY).value<Unit>());
368 }
370 }
369
371
370 void VectorParserHelper::readPropertyLine(const QString &line)
372 void VectorParserHelper::readPropertyLine(const QString &line)
371 {
373 {
372 tryReadUnit(m_Properties, X_AXIS_UNIT_PROPERTY, line, DEFAULT_X_AXIS_UNIT_REGEX, true);
374 tryReadUnit(m_Properties, X_AXIS_UNIT_PROPERTY, line, DEFAULT_X_AXIS_UNIT_REGEX, true);
373 }
375 }
374
376
375 void VectorParserHelper::readResultLine(const QString &line)
377 void VectorParserHelper::readResultLine(const QString &line)
376 {
378 {
377 tryReadResult(m_XAxisData, m_ValuesData, line, valuesIndexes());
379 tryReadResult(m_XAxisData, m_ValuesData, line, valuesIndexes());
378 }
380 }
379
381
380 std::vector<int> VectorParserHelper::valuesIndexes() const
382 std::vector<int> VectorParserHelper::valuesIndexes() const
381 {
383 {
382 // 3 values to read, in order in the file (x, y, z)
384 // 3 values to read, in order in the file (x, y, z)
383 static auto result = std::vector<int>{0, 1, 2};
385 static auto result = std::vector<int>{0, 1, 2};
384 return result;
386 return result;
385 }
387 }
General Comments 0
You need to be logged in to leave comments. Login now