@@ -17,24 +17,38 namespace { | |||
|
17 | 17 | /// Message in result file when the file was not found on server |
|
18 | 18 | const auto FILE_NOT_FOUND_MESSAGE = QStringLiteral("Not Found"); |
|
19 | 19 | |
|
20 | /// Format for dates in result files | |
|
21 | const auto DATE_FORMAT = QStringLiteral("yyyy-MM-ddThh:mm:ss.zzz"); | |
|
22 | ||
|
23 | 20 | /// Separator between values in a result line |
|
24 | 21 | const auto RESULT_LINE_SEPARATOR = QRegularExpression{QStringLiteral("\\s+")}; |
|
25 | 22 | |
|
23 | /// Regex to find the header of the data in the file. This header indicates the end of comments in | |
|
24 | /// the file | |
|
25 | const auto DATA_HEADER_REGEX = QRegularExpression{QStringLiteral("#\\s*DATA\\s*:")}; | |
|
26 | ||
|
27 | /// Format for dates in result files | |
|
28 | const auto DATE_FORMAT = QStringLiteral("yyyy-MM-ddThh:mm:ss.zzz"); | |
|
29 | ||
|
26 | 30 | /// Regex to find unit in a line. Examples of valid lines: |
|
27 |
/// ... |
|
|
28 |
/// ... |
|
|
29 |
/// ... |
|
|
30 |
/// ... |
|
|
31 |
const auto UNIT_REGEX = QRegularExpression{QStringLiteral(" |
|
|
31 | /// ... PARAMETER_UNITS : nT ... | |
|
32 | /// ... PARAMETER_UNITS:nT ... | |
|
33 | /// ... PARAMETER_UNITS: mΒ² ... | |
|
34 | /// ... PARAMETER_UNITS : m/s ... | |
|
35 | const auto UNIT_REGEX = QRegularExpression{QStringLiteral("\\s*PARAMETER_UNITS\\s*:\\s*(.+)")}; | |
|
36 | ||
|
37 | QDateTime dateTimeFromString(const QString &stringDate) noexcept | |
|
38 | { | |
|
39 | #if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0) | |
|
40 | return QDateTime::fromString(stringDate, Qt::ISODateWithMs); | |
|
41 | #else | |
|
42 | return QDateTime::fromString(stringDate, DATE_FORMAT); | |
|
43 | #endif | |
|
44 | } | |
|
32 | 45 | |
|
33 | 46 | /// Converts a string date to a double date |
|
34 | 47 | /// @return a double that represents the date in seconds, NaN if the string date can't be converted |
|
35 | 48 | double doubleDate(const QString &stringDate) noexcept |
|
36 | 49 | { |
|
37 | auto dateTime = QDateTime::fromString(stringDate, DATE_FORMAT); | |
|
50 | // Format: yyyy-MM-ddThh:mm:ss.zzz | |
|
51 | auto dateTime = dateTimeFromString(stringDate); | |
|
38 | 52 | dateTime.setTimeSpec(Qt::UTC); |
|
39 | 53 | return dateTime.isValid() ? DateUtils::secondsSinceEpoch(dateTime) |
|
40 | 54 | : std::numeric_limits<double>::quiet_NaN(); |
@@ -75,8 +89,8 Unit readXAxisUnit(QTextStream &stream) | |||
|
75 | 89 | { |
|
76 | 90 | QString line{}; |
|
77 | 91 | |
|
78 | // Searches unit in the comment lines | |
|
79 |
while (stream.readLineInto(&line) && |
|
|
92 | // Searches unit in the comment lines (as long as the reading has not reached the data header) | |
|
93 | while (stream.readLineInto(&line) && !line.contains(DATA_HEADER_REGEX)) { | |
|
80 | 94 | auto match = UNIT_REGEX.match(line); |
|
81 | 95 | if (match.hasMatch()) { |
|
82 | 96 | return Unit{match.captured(1), true}; |
@@ -97,18 +111,21 Unit readXAxisUnit(QTextStream &stream) | |||
|
97 | 111 | std::pair<std::vector<double>, std::vector<double> > |
|
98 | 112 | readResults(QTextStream &stream, AmdaResultParser::ValueType valueType) |
|
99 | 113 | { |
|
100 | auto expectedNbValues = nbValues(valueType); | |
|
114 | auto expectedNbValues = nbValues(valueType) + 1; | |
|
101 | 115 | |
|
102 | 116 | auto xData = std::vector<double>{}; |
|
103 | 117 | auto valuesData = std::vector<double>{}; |
|
104 | 118 | |
|
105 | 119 | QString line{}; |
|
106 | 120 | |
|
107 | while (stream.readLineInto(&line)) { | |
|
108 | // Ignore comment lines | |
|
109 | if (!isCommentLine(line)) { | |
|
121 | // Skip comment lines | |
|
122 | while (stream.readLineInto(&line) && isCommentLine(line)) { | |
|
123 | } | |
|
124 | ||
|
125 | if (!stream.atEnd()) { | |
|
126 | do { | |
|
110 | 127 | auto lineData = line.split(RESULT_LINE_SEPARATOR, QString::SkipEmptyParts); |
|
111 |
if (lineData.size() == expectedNbValues |
|
|
128 | if (lineData.size() == expectedNbValues) { | |
|
112 | 129 | // X : the data is converted from date to double (in secs) |
|
113 | 130 | auto x = doubleDate(lineData.at(0)); |
|
114 | 131 | |
@@ -117,8 +134,8 readResults(QTextStream &stream, AmdaResultParser::ValueType valueType) | |||
|
117 | 134 | xData.push_back(x); |
|
118 | 135 | |
|
119 | 136 | // Values |
|
120 |
for (auto valueIndex = |
|
|
121 |
auto column = valueIndex |
|
|
137 | for (auto valueIndex = 1; valueIndex < expectedNbValues; ++valueIndex) { | |
|
138 | auto column = valueIndex; | |
|
122 | 139 | |
|
123 | 140 | bool valueOk; |
|
124 | 141 | auto value = lineData.at(column).toDouble(&valueOk); |
@@ -144,7 +161,7 readResults(QTextStream &stream, AmdaResultParser::ValueType valueType) | |||
|
144 | 161 | qCWarning(LOG_AmdaResultParser()) |
|
145 | 162 | << QObject::tr("Can't retrieve results from line %1: invalid line").arg(line); |
|
146 | 163 | } |
|
147 | } | |
|
164 | } while (stream.readLineInto(&line)); | |
|
148 | 165 | } |
|
149 | 166 | |
|
150 | 167 | return std::make_pair(std::move(xData), std::move(valuesData)); |
@@ -186,7 +203,6 std::shared_ptr<IDataSeries> AmdaResultParser::readTxt(const QString &filePath, | |||
|
186 | 203 | auto xAxisUnit = readXAxisUnit(stream); |
|
187 | 204 | |
|
188 | 205 | // Reads results |
|
189 | stream.seek(0); // returns to the beginning of the file | |
|
190 | 206 | auto results = readResults(stream, valueType); |
|
191 | 207 | |
|
192 | 208 | // Creates data series |
General Comments 0
You need to be logged in to leave comments.
Login now