@@ -4,6 +4,7 | |||
|
4 | 4 | |
|
5 | 5 | #include <QDateTime> |
|
6 | 6 | #include <QFile> |
|
7 | #include <QRegularExpression> | |
|
7 | 8 | |
|
8 | 9 | Q_LOGGING_CATEGORY(LOG_AmdaResultParser, "AmdaResultParser") |
|
9 | 10 | |
@@ -12,6 +13,13 namespace { | |||
|
12 | 13 | /// Format for dates in result files |
|
13 | 14 | const auto DATE_FORMAT = QStringLiteral("yyyy-MM-ddThh:mm:ss.zzz"); |
|
14 | 15 | |
|
16 | /// Regex to find unit in a line. Examples of valid lines: | |
|
17 | /// ... - Units : nT - ... | |
|
18 | /// ... -Units:nT- ... | |
|
19 | /// ... -Units: mΒ²- ... | |
|
20 | /// ... - Units : m/s - ... | |
|
21 | const auto UNIT_REGEX = QRegularExpression{QStringLiteral("-\\s*Units\\s*:\\s*(.+?)\\s*-")}; | |
|
22 | ||
|
15 | 23 | /// @todo ALX |
|
16 | 24 | double doubleDate(const QString &stringDate) noexcept |
|
17 | 25 | { |
@@ -19,6 +27,34 double doubleDate(const QString &stringDate) noexcept | |||
|
19 | 27 | return dateTime.toMSecsSinceEpoch() / 1000.; |
|
20 | 28 | } |
|
21 | 29 | |
|
30 | /** | |
|
31 | * Reads stream to retrieve x-axis unit | |
|
32 | * @param stream the stream to read | |
|
33 | * @return the unit that has been read in the stream, a default unit (time unit with no label) if an | |
|
34 | * error occured during reading | |
|
35 | */ | |
|
36 | Unit readXAxisUnit(QTextStream &stream) | |
|
37 | { | |
|
38 | QString line{}; | |
|
39 | ||
|
40 | if (stream.readLineInto(&line)) { | |
|
41 | auto match = UNIT_REGEX.match(line); | |
|
42 | if (match.hasMatch()) { | |
|
43 | return Unit{match.captured(1), true}; | |
|
44 | } | |
|
45 | else { | |
|
46 | qCWarning(LOG_AmdaResultParser()) | |
|
47 | << QObject::tr("Can't read unit: invalid line %1").arg(line); | |
|
48 | } | |
|
49 | } | |
|
50 | else { | |
|
51 | qCWarning(LOG_AmdaResultParser()) << QObject::tr("Can't read unit: end of file"); | |
|
52 | } | |
|
53 | ||
|
54 | // Error cases | |
|
55 | return Unit{{}, true}; | |
|
56 | } | |
|
57 | ||
|
22 | 58 | } // namespace |
|
23 | 59 | |
|
24 | 60 | std::shared_ptr<IDataSeries> AmdaResultParser::readTxt(const QString &filePath) noexcept |
@@ -37,12 +73,16 std::shared_ptr<IDataSeries> AmdaResultParser::readTxt(const QString &filePath) | |||
|
37 | 73 | |
|
38 | 74 | QTextStream stream{&file}; |
|
39 | 75 | |
|
40 |
// Ignore |
|
|
41 | stream.readLine(); | |
|
76 | // Ignore first two lines (comments lines) | |
|
42 | 77 | stream.readLine(); |
|
43 | 78 | stream.readLine(); |
|
44 | 79 | |
|
45 | 80 | QString line{}; |
|
81 | ||
|
82 | // Reads x-axis unit | |
|
83 | auto xAxisUnit = readXAxisUnit(stream); | |
|
84 | ||
|
85 | // Reads results | |
|
46 | 86 | auto lineRegex = QRegExp{QStringLiteral("\\s+")}; |
|
47 | 87 | while (stream.readLineInto(&line)) { |
|
48 | 88 | auto lineData = line.split(lineRegex, QString::SkipEmptyParts); |
@@ -58,7 +98,6 std::shared_ptr<IDataSeries> AmdaResultParser::readTxt(const QString &filePath) | |||
|
58 | 98 | } |
|
59 | 99 | } |
|
60 | 100 | |
|
61 | /// @todo ALX : handle units | |
|
62 | return std::make_shared<ScalarSeries>(std::move(xData), std::move(valuesData), Unit{"nT", true}, | |
|
101 | return std::make_shared<ScalarSeries>(std::move(xData), std::move(valuesData), xAxisUnit, | |
|
63 | 102 | Unit{}); |
|
64 | 103 | } |
General Comments 0
You need to be logged in to leave comments.
Login now