@@ -39,6 +39,12 double doubleDate(const QString &stringDate) noexcept | |||||
39 | : std::numeric_limits<double>::quiet_NaN(); |
|
39 | : std::numeric_limits<double>::quiet_NaN(); | |
40 | } |
|
40 | } | |
41 |
|
41 | |||
|
42 | /// Checks if a line is a comment line | |||
|
43 | bool isCommentLine(const QString &line) | |||
|
44 | { | |||
|
45 | return line.startsWith("#"); | |||
|
46 | } | |||
|
47 | ||||
42 | /** |
|
48 | /** | |
43 | * Reads stream to retrieve x-axis unit |
|
49 | * Reads stream to retrieve x-axis unit | |
44 | * @param stream the stream to read |
|
50 | * @param stream the stream to read | |
@@ -49,20 +55,16 Unit readXAxisUnit(QTextStream &stream) | |||||
49 | { |
|
55 | { | |
50 | QString line{}; |
|
56 | QString line{}; | |
51 |
|
57 | |||
52 | if (stream.readLineInto(&line)) { |
|
58 | // Searches unit in the comment lines | |
|
59 | while (stream.readLineInto(&line) && isCommentLine(line)) { | |||
53 | auto match = UNIT_REGEX.match(line); |
|
60 | auto match = UNIT_REGEX.match(line); | |
54 | if (match.hasMatch()) { |
|
61 | if (match.hasMatch()) { | |
55 | return Unit{match.captured(1), true}; |
|
62 | return Unit{match.captured(1), true}; | |
56 | } |
|
63 | } | |
57 | else { |
|
|||
58 | qCWarning(LOG_AmdaResultParser()) |
|
|||
59 | << QObject::tr("Can't read unit: invalid line %1").arg(line); |
|
|||
60 | } |
|
|||
61 | } |
|
|||
62 | else { |
|
|||
63 | qCWarning(LOG_AmdaResultParser()) << QObject::tr("Can't read unit: end of file"); |
|
|||
64 | } |
|
64 | } | |
65 |
|
65 | |||
|
66 | qCWarning(LOG_AmdaResultParser()) << QObject::tr("The unit could not be found in the file"); | |||
|
67 | ||||
66 | // Error cases |
|
68 | // Error cases | |
67 | return Unit{{}, true}; |
|
69 | return Unit{{}, true}; | |
68 | } |
|
70 | } | |
@@ -78,32 +80,36 QPair<QVector<double>, QVector<double> > readResults(QTextStream &stream) | |||||
78 | auto valuesData = QVector<double>{}; |
|
80 | auto valuesData = QVector<double>{}; | |
79 |
|
81 | |||
80 | QString line{}; |
|
82 | QString line{}; | |
|
83 | ||||
81 | while (stream.readLineInto(&line)) { |
|
84 | while (stream.readLineInto(&line)) { | |
82 | auto lineData = line.split(RESULT_LINE_SEPARATOR, QString::SkipEmptyParts); |
|
85 | // Ignore comment lines | |
83 | if (lineData.size() == 2) { |
|
86 | if (!isCommentLine(line)) { | |
84 | // X : the data is converted from date to double (in secs) |
|
87 | auto lineData = line.split(RESULT_LINE_SEPARATOR, QString::SkipEmptyParts); | |
85 | auto x = doubleDate(lineData.at(0)); |
|
88 | if (lineData.size() == 2) { | |
86 |
|
89 | // X : the data is converted from date to double (in secs) | ||
87 | // Value |
|
90 | auto x = doubleDate(lineData.at(0)); | |
88 | bool valueOk; |
|
91 | ||
89 | auto value = lineData.at(1).toDouble(&valueOk); |
|
92 | // Value | |
90 |
|
93 | bool valueOk; | ||
91 | // Adds result only if x and value are valid |
|
94 | auto value = lineData.at(1).toDouble(&valueOk); | |
92 | if (!std::isnan(x) && !std::isnan(value) && valueOk) { |
|
95 | ||
93 | xData.push_back(x); |
|
96 | // Adds result only if x and value are valid | |
94 | valuesData.push_back(value); |
|
97 | if (!std::isnan(x) && !std::isnan(value) && valueOk) { | |
|
98 | xData.push_back(x); | |||
|
99 | valuesData.push_back(value); | |||
|
100 | } | |||
|
101 | else { | |||
|
102 | qCWarning(LOG_AmdaResultParser()) | |||
|
103 | << QObject::tr( | |||
|
104 | "Can't retrieve results from line %1: x and/or value are invalid") | |||
|
105 | .arg(line); | |||
|
106 | } | |||
95 | } |
|
107 | } | |
96 | else { |
|
108 | else { | |
97 | qCWarning(LOG_AmdaResultParser()) |
|
109 | qCWarning(LOG_AmdaResultParser()) | |
98 | << QObject::tr( |
|
110 | << QObject::tr("Can't retrieve results from line %1: invalid line").arg(line); | |
99 | "Can't retrieve results from line %1: x and/or value are invalid") |
|
|||
100 | .arg(line); |
|
|||
101 | } |
|
111 | } | |
102 | } |
|
112 | } | |
103 | else { |
|
|||
104 | qCWarning(LOG_AmdaResultParser()) |
|
|||
105 | << QObject::tr("Can't retrieve results from line %1: invalid line").arg(line); |
|
|||
106 | } |
|
|||
107 | } |
|
113 | } | |
108 |
|
114 | |||
109 | return qMakePair(std::move(xData), std::move(valuesData)); |
|
115 | return qMakePair(std::move(xData), std::move(valuesData)); | |
@@ -133,13 +139,12 std::shared_ptr<IDataSeries> AmdaResultParser::readTxt(const QString &filePath) | |||||
133 | return nullptr; |
|
139 | return nullptr; | |
134 | } |
|
140 | } | |
135 |
|
141 | |||
136 | // Ignore comments lines |
|
|||
137 | stream.readLine(); |
|
|||
138 |
|
||||
139 | // Reads x-axis unit |
|
142 | // Reads x-axis unit | |
|
143 | stream.seek(0); // returns to the beginning of the file | |||
140 | auto xAxisUnit = readXAxisUnit(stream); |
|
144 | auto xAxisUnit = readXAxisUnit(stream); | |
141 |
|
145 | |||
142 | // Reads results |
|
146 | // Reads results | |
|
147 | stream.seek(0); // returns to the beginning of the file | |||
143 | auto results = readResults(stream); |
|
148 | auto results = readResults(stream); | |
144 |
|
149 | |||
145 | return std::make_shared<ScalarSeries>(std::move(results.first), std::move(results.second), |
|
150 | return std::make_shared<ScalarSeries>(std::move(results.first), std::move(results.second), |
General Comments 0
You need to be logged in to leave comments.
Login now