@@ -45,6 +45,25 bool isCommentLine(const QString &line) | |||||
45 | return line.startsWith("#"); |
|
45 | return line.startsWith("#"); | |
46 | } |
|
46 | } | |
47 |
|
47 | |||
|
48 | /// @return the number of lines to be read depending on the type of value passed in parameter | |||
|
49 | int nbValues(AmdaResultParser::ValueType valueType) noexcept | |||
|
50 | { | |||
|
51 | switch (valueType) { | |||
|
52 | case AmdaResultParser::ValueType::SCALAR: | |||
|
53 | return 1; | |||
|
54 | case AmdaResultParser::ValueType::VECTOR: | |||
|
55 | return 3; | |||
|
56 | case AmdaResultParser::ValueType::UNKNOWN: | |||
|
57 | // Invalid case | |||
|
58 | break; | |||
|
59 | } | |||
|
60 | ||||
|
61 | // Invalid cases | |||
|
62 | qCCritical(LOG_AmdaResultParser()) | |||
|
63 | << QObject::tr("Can't get the number of values to read: unsupported type"); | |||
|
64 | return 0; | |||
|
65 | } | |||
|
66 | ||||
48 | /** |
|
67 | /** | |
49 | * Reads stream to retrieve x-axis unit |
|
68 | * Reads stream to retrieve x-axis unit | |
50 | * @param stream the stream to read |
|
69 | * @param stream the stream to read | |
@@ -74,10 +93,13 Unit readXAxisUnit(QTextStream &stream) | |||||
74 | * @param stream the stream to read |
|
93 | * @param stream the stream to read | |
75 | * @return the pair of vectors x-axis data/values data that has been read in the stream |
|
94 | * @return the pair of vectors x-axis data/values data that has been read in the stream | |
76 | */ |
|
95 | */ | |
77 |
QPair<QVector<double>, QVector<double> > |
|
96 | QPair<QVector<double>, QVector<QVector<double> > > | |
|
97 | readResults(QTextStream &stream, AmdaResultParser::ValueType valueType) | |||
78 | { |
|
98 | { | |
|
99 | auto expectedNbValues = nbValues(valueType); | |||
|
100 | ||||
79 | auto xData = QVector<double>{}; |
|
101 | auto xData = QVector<double>{}; | |
80 |
auto valuesData = QVector<double> |
|
102 | auto valuesData = QVector<QVector<double> >(expectedNbValues); | |
81 |
|
103 | |||
82 | QString line{}; |
|
104 | QString line{}; | |
83 |
|
105 | |||
@@ -85,27 +107,31 QPair<QVector<double>, QVector<double> > readResults(QTextStream &stream) | |||||
85 | // Ignore comment lines |
|
107 | // Ignore comment lines | |
86 | if (!isCommentLine(line)) { |
|
108 | if (!isCommentLine(line)) { | |
87 | auto lineData = line.split(RESULT_LINE_SEPARATOR, QString::SkipEmptyParts); |
|
109 | auto lineData = line.split(RESULT_LINE_SEPARATOR, QString::SkipEmptyParts); | |
88 |
if (lineData.size() == |
|
110 | if (lineData.size() == expectedNbValues + 1) { | |
89 | // X : the data is converted from date to double (in secs) |
|
111 | // X : the data is converted from date to double (in secs) | |
90 | auto x = doubleDate(lineData.at(0)); |
|
112 | auto x = doubleDate(lineData.at(0)); | |
91 |
|
113 | |||
92 | // Value |
|
|||
93 | bool valueOk; |
|
|||
94 | auto value = lineData.at(1).toDouble(&valueOk); |
|
|||
95 |
|
||||
96 | // Adds result only if x is valid. Then, if value is invalid, it is set to NaN |
|
114 | // Adds result only if x is valid. Then, if value is invalid, it is set to NaN | |
97 | if (!std::isnan(x)) { |
|
115 | if (!std::isnan(x)) { | |
98 | xData.push_back(x); |
|
116 | xData.push_back(x); | |
99 |
|
117 | |||
|
118 | // Values | |||
|
119 | for (auto valueIndex = 0; valueIndex < expectedNbValues; ++valueIndex) { | |||
|
120 | auto column = valueIndex + 1; | |||
|
121 | ||||
|
122 | bool valueOk; | |||
|
123 | auto value = lineData.at(column).toDouble(&valueOk); | |||
|
124 | ||||
100 | if (!valueOk) { |
|
125 | if (!valueOk) { | |
101 | qCWarning(LOG_AmdaResultParser()) |
|
126 | qCWarning(LOG_AmdaResultParser()) | |
102 | << QObject::tr( |
|
127 | << QObject::tr( | |
103 |
"Value from line %1 is invalid and will be |
|
128 | "Value from (line %1, column %2) is invalid and will be " | |
104 |
|
|
129 | "converted to NaN") | |
|
130 | .arg(line, column); | |||
105 | value = std::numeric_limits<double>::quiet_NaN(); |
|
131 | value = std::numeric_limits<double>::quiet_NaN(); | |
106 | } |
|
132 | } | |
107 |
|
133 | valuesData[valueIndex].append(value); | ||
108 | valuesData.push_back(value); |
|
134 | } | |
109 | } |
|
135 | } | |
110 | else { |
|
136 | else { | |
111 | qCWarning(LOG_AmdaResultParser()) |
|
137 | qCWarning(LOG_AmdaResultParser()) | |
@@ -160,7 +186,8 std::shared_ptr<IDataSeries> AmdaResultParser::readTxt(const QString &filePath, | |||||
160 |
|
186 | |||
161 | // Reads results |
|
187 | // Reads results | |
162 | stream.seek(0); // returns to the beginning of the file |
|
188 | stream.seek(0); // returns to the beginning of the file | |
163 | auto results = readResults(stream); |
|
189 | auto results = readResults(stream, valueType); | |
|
190 | ||||
164 |
|
191 | |||
165 | return std::make_shared<ScalarSeries>(std::move(results.first), std::move(results.second), |
|
192 | return std::make_shared<ScalarSeries>(std::move(results.first), std::move(results.second), | |
166 | xAxisUnit, Unit{}); |
|
193 | xAxisUnit, Unit{}); |
General Comments 0
You need to be logged in to leave comments.
Login now