@@ -45,6 +45,25 bool isCommentLine(const QString &line) | |||
|
45 | 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 | 68 | * Reads stream to retrieve x-axis unit |
|
50 | 69 | * @param stream the stream to read |
@@ -74,10 +93,13 Unit readXAxisUnit(QTextStream &stream) | |||
|
74 | 93 | * @param stream the stream to read |
|
75 | 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 | 101 | auto xData = QVector<double>{}; |
|
80 |
auto valuesData = QVector<double> |
|
|
102 | auto valuesData = QVector<QVector<double> >(expectedNbValues); | |
|
81 | 103 | |
|
82 | 104 | QString line{}; |
|
83 | 105 | |
@@ -85,27 +107,31 QPair<QVector<double>, QVector<double> > readResults(QTextStream &stream) | |||
|
85 | 107 | // Ignore comment lines |
|
86 | 108 | if (!isCommentLine(line)) { |
|
87 | 109 | auto lineData = line.split(RESULT_LINE_SEPARATOR, QString::SkipEmptyParts); |
|
88 |
if (lineData.size() == |
|
|
110 | if (lineData.size() == expectedNbValues + 1) { | |
|
89 | 111 | // X : the data is converted from date to double (in secs) |
|
90 | 112 | auto x = doubleDate(lineData.at(0)); |
|
91 | 113 | |
|
92 | // Value | |
|
93 | bool valueOk; | |
|
94 | auto value = lineData.at(1).toDouble(&valueOk); | |
|
95 | ||
|
96 | 114 | // Adds result only if x is valid. Then, if value is invalid, it is set to NaN |
|
97 | 115 | if (!std::isnan(x)) { |
|
98 | 116 | xData.push_back(x); |
|
99 | 117 | |
|
100 |
|
|
|
101 | qCWarning(LOG_AmdaResultParser()) | |
|
102 |
|
|
|
103 | "Value from line %1 is invalid and will be converted to NaN") | |
|
104 |
|
|
|
105 |
value = |
|
|
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 | ||
|
125 | if (!valueOk) { | |
|
126 | qCWarning(LOG_AmdaResultParser()) | |
|
127 | << QObject::tr( | |
|
128 | "Value from (line %1, column %2) is invalid and will be " | |
|
129 | "converted to NaN") | |
|
130 | .arg(line, column); | |
|
131 | value = std::numeric_limits<double>::quiet_NaN(); | |
|
132 | } | |
|
133 | valuesData[valueIndex].append(value); | |
|
106 | 134 | } |
|
107 | ||
|
108 | valuesData.push_back(value); | |
|
109 | 135 | } |
|
110 | 136 | else { |
|
111 | 137 | qCWarning(LOG_AmdaResultParser()) |
@@ -160,7 +186,8 std::shared_ptr<IDataSeries> AmdaResultParser::readTxt(const QString &filePath, | |||
|
160 | 186 | |
|
161 | 187 | // Reads results |
|
162 | 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 | 192 | return std::make_shared<ScalarSeries>(std::move(results.first), std::move(results.second), |
|
166 | 193 | xAxisUnit, Unit{}); |
General Comments 0
You need to be logged in to leave comments.
Login now