@@ -39,6 +39,12 double doubleDate(const QString &stringDate) noexcept | |||
|
39 | 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 | 49 | * Reads stream to retrieve x-axis unit |
|
44 | 50 | * @param stream the stream to read |
@@ -49,20 +55,16 Unit readXAxisUnit(QTextStream &stream) | |||
|
49 | 55 | { |
|
50 | 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 | 60 | auto match = UNIT_REGEX.match(line); |
|
54 | 61 | if (match.hasMatch()) { |
|
55 | 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 | 68 | // Error cases |
|
67 | 69 | return Unit{{}, true}; |
|
68 | 70 | } |
@@ -78,7 +80,10 QPair<QVector<double>, QVector<double> > readResults(QTextStream &stream) | |||
|
78 | 80 | auto valuesData = QVector<double>{}; |
|
79 | 81 | |
|
80 | 82 | QString line{}; |
|
83 | ||
|
81 | 84 | while (stream.readLineInto(&line)) { |
|
85 | // Ignore comment lines | |
|
86 | if (!isCommentLine(line)) { | |
|
82 | 87 | auto lineData = line.split(RESULT_LINE_SEPARATOR, QString::SkipEmptyParts); |
|
83 | 88 | if (lineData.size() == 2) { |
|
84 | 89 | // X : the data is converted from date to double (in secs) |
@@ -105,6 +110,7 QPair<QVector<double>, QVector<double> > readResults(QTextStream &stream) | |||
|
105 | 110 | << QObject::tr("Can't retrieve results from line %1: invalid line").arg(line); |
|
106 | 111 | } |
|
107 | 112 | } |
|
113 | } | |
|
108 | 114 | |
|
109 | 115 | return qMakePair(std::move(xData), std::move(valuesData)); |
|
110 | 116 | } |
@@ -133,13 +139,12 std::shared_ptr<IDataSeries> AmdaResultParser::readTxt(const QString &filePath) | |||
|
133 | 139 | return nullptr; |
|
134 | 140 | } |
|
135 | 141 | |
|
136 | // Ignore comments lines | |
|
137 | stream.readLine(); | |
|
138 | ||
|
139 | 142 | // Reads x-axis unit |
|
143 | stream.seek(0); // returns to the beginning of the file | |
|
140 | 144 | auto xAxisUnit = readXAxisUnit(stream); |
|
141 | 145 | |
|
142 | 146 | // Reads results |
|
147 | stream.seek(0); // returns to the beginning of the file | |
|
143 | 148 | auto results = readResults(stream); |
|
144 | 149 | |
|
145 | 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