##// END OF EJS Templates
Reads x-axis unit in result file
Alexandre Leroux -
r393:dc7f981a773b
parent child
Show More
@@ -4,6 +4,7
4
4
5 #include <QDateTime>
5 #include <QDateTime>
6 #include <QFile>
6 #include <QFile>
7 #include <QRegularExpression>
7
8
8 Q_LOGGING_CATEGORY(LOG_AmdaResultParser, "AmdaResultParser")
9 Q_LOGGING_CATEGORY(LOG_AmdaResultParser, "AmdaResultParser")
9
10
@@ -12,6 +13,13 namespace {
12 /// Format for dates in result files
13 /// Format for dates in result files
13 const auto DATE_FORMAT = QStringLiteral("yyyy-MM-ddThh:mm:ss.zzz");
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 /// @todo ALX
23 /// @todo ALX
16 double doubleDate(const QString &stringDate) noexcept
24 double doubleDate(const QString &stringDate) noexcept
17 {
25 {
@@ -19,6 +27,34 double doubleDate(const QString &stringDate) noexcept
19 return dateTime.toMSecsSinceEpoch() / 1000.;
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 } // namespace
58 } // namespace
23
59
24 std::shared_ptr<IDataSeries> AmdaResultParser::readTxt(const QString &filePath) noexcept
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 QTextStream stream{&file};
74 QTextStream stream{&file};
39
75
40 // Ignore comment lines (3 lines)
76 // Ignore first two lines (comments lines)
41 stream.readLine();
42 stream.readLine();
77 stream.readLine();
43 stream.readLine();
78 stream.readLine();
44
79
45 QString line{};
80 QString line{};
81
82 // Reads x-axis unit
83 auto xAxisUnit = readXAxisUnit(stream);
84
85 // Reads results
46 auto lineRegex = QRegExp{QStringLiteral("\\s+")};
86 auto lineRegex = QRegExp{QStringLiteral("\\s+")};
47 while (stream.readLineInto(&line)) {
87 while (stream.readLineInto(&line)) {
48 auto lineData = line.split(lineRegex, QString::SkipEmptyParts);
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
101 return std::make_shared<ScalarSeries>(std::move(xData), std::move(valuesData), xAxisUnit,
62 return std::make_shared<ScalarSeries>(std::move(xData), std::move(valuesData), Unit{"nT", true},
63 Unit{});
102 Unit{});
64 }
103 }
General Comments 0
You need to be logged in to leave comments. Login now