##// END OF EJS Templates
Improves AMDA result parsing...
Alexandre Leroux -
r492:41e897ecff03
parent child
Show More
@@ -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,32 +80,36 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)) {
82 auto lineData = line.split(RESULT_LINE_SEPARATOR, QString::SkipEmptyParts);
83 if (lineData.size() == 2) {
84 // X : the data is converted from date to double (in secs)
85 auto x = doubleDate(lineData.at(0));
86
87 // Value
88 bool valueOk;
89 auto value = lineData.at(1).toDouble(&valueOk);
90
91 // Adds result only if x and value are valid
92 if (!std::isnan(x) && !std::isnan(value) && valueOk) {
93 xData.push_back(x);
94 valuesData.push_back(value);
85 // Ignore comment lines
86 if (!isCommentLine(line)) {
87 auto lineData = line.split(RESULT_LINE_SEPARATOR, QString::SkipEmptyParts);
88 if (lineData.size() == 2) {
89 // X : the data is converted from date to double (in secs)
90 auto x = doubleDate(lineData.at(0));
91
92 // Value
93 bool valueOk;
94 auto value = lineData.at(1).toDouble(&valueOk);
95
96 // Adds result only if x and value are valid
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 108 else {
97 109 qCWarning(LOG_AmdaResultParser())
98 << QObject::tr(
99 "Can't retrieve results from line %1: x and/or value are invalid")
100 .arg(line);
110 << QObject::tr("Can't retrieve results from line %1: invalid line").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 115 return qMakePair(std::move(xData), std::move(valuesData));
@@ -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