##// END OF EJS Templates
Improves reading performances
Alexandre Leroux -
r727:4449c7d1b0d9
parent child
Show More
@@ -17,9 +17,6 namespace {
17 /// Message in result file when the file was not found on server
17 /// Message in result file when the file was not found on server
18 const auto FILE_NOT_FOUND_MESSAGE = QStringLiteral("Not Found");
18 const auto FILE_NOT_FOUND_MESSAGE = QStringLiteral("Not Found");
19
19
20 /// Format for dates in result files
21 const auto DATE_FORMAT = QStringLiteral("yyyy-MM-ddThh:mm:ss.zzz");
22
23 /// Separator between values in a result line
20 /// Separator between values in a result line
24 const auto RESULT_LINE_SEPARATOR = QRegularExpression{QStringLiteral("\\s+")};
21 const auto RESULT_LINE_SEPARATOR = QRegularExpression{QStringLiteral("\\s+")};
25
22
@@ -38,7 +35,8 const auto UNIT_REGEX = QRegularExpression{QStringLiteral("\\s*PARAMETER_UNITS\\
38 /// @return a double that represents the date in seconds, NaN if the string date can't be converted
35 /// @return a double that represents the date in seconds, NaN if the string date can't be converted
39 double doubleDate(const QString &stringDate) noexcept
36 double doubleDate(const QString &stringDate) noexcept
40 {
37 {
41 auto dateTime = QDateTime::fromString(stringDate, DATE_FORMAT);
38 // Format: yyyy-MM-ddThh:mm:ss.zzz
39 auto dateTime = QDateTime::fromString(stringDate, Qt::ISODateWithMs);
42 dateTime.setTimeSpec(Qt::UTC);
40 dateTime.setTimeSpec(Qt::UTC);
43 return dateTime.isValid() ? DateUtils::secondsSinceEpoch(dateTime)
41 return dateTime.isValid() ? DateUtils::secondsSinceEpoch(dateTime)
44 : std::numeric_limits<double>::quiet_NaN();
42 : std::numeric_limits<double>::quiet_NaN();
@@ -101,18 +99,21 Unit readXAxisUnit(QTextStream &stream)
101 std::pair<std::vector<double>, std::vector<double> >
99 std::pair<std::vector<double>, std::vector<double> >
102 readResults(QTextStream &stream, AmdaResultParser::ValueType valueType)
100 readResults(QTextStream &stream, AmdaResultParser::ValueType valueType)
103 {
101 {
104 auto expectedNbValues = nbValues(valueType);
102 auto expectedNbValues = nbValues(valueType) + 1;
105
103
106 auto xData = std::vector<double>{};
104 auto xData = std::vector<double>{};
107 auto valuesData = std::vector<double>{};
105 auto valuesData = std::vector<double>{};
108
106
109 QString line{};
107 QString line{};
110
108
111 while (stream.readLineInto(&line)) {
109 // Skip comment lines
112 // Ignore comment lines
110 while (stream.readLineInto(&line) && isCommentLine(line)) {
113 if (!isCommentLine(line)) {
111 }
112
113 if (!stream.atEnd()) {
114 do {
114 auto lineData = line.split(RESULT_LINE_SEPARATOR, QString::SkipEmptyParts);
115 auto lineData = line.split(RESULT_LINE_SEPARATOR, QString::SkipEmptyParts);
115 if (lineData.size() == expectedNbValues + 1) {
116 if (lineData.size() == expectedNbValues) {
116 // X : the data is converted from date to double (in secs)
117 // X : the data is converted from date to double (in secs)
117 auto x = doubleDate(lineData.at(0));
118 auto x = doubleDate(lineData.at(0));
118
119
@@ -121,8 +122,8 readResults(QTextStream &stream, AmdaResultParser::ValueType valueType)
121 xData.push_back(x);
122 xData.push_back(x);
122
123
123 // Values
124 // Values
124 for (auto valueIndex = 0; valueIndex < expectedNbValues; ++valueIndex) {
125 for (auto valueIndex = 1; valueIndex < expectedNbValues; ++valueIndex) {
125 auto column = valueIndex + 1;
126 auto column = valueIndex;
126
127
127 bool valueOk;
128 bool valueOk;
128 auto value = lineData.at(column).toDouble(&valueOk);
129 auto value = lineData.at(column).toDouble(&valueOk);
@@ -148,7 +149,7 readResults(QTextStream &stream, AmdaResultParser::ValueType valueType)
148 qCWarning(LOG_AmdaResultParser())
149 qCWarning(LOG_AmdaResultParser())
149 << QObject::tr("Can't retrieve results from line %1: invalid line").arg(line);
150 << QObject::tr("Can't retrieve results from line %1: invalid line").arg(line);
150 }
151 }
151 }
152 } while (stream.readLineInto(&line));
152 }
153 }
153
154
154 return std::make_pair(std::move(xData), std::move(valuesData));
155 return std::make_pair(std::move(xData), std::move(valuesData));
General Comments 0
You need to be logged in to leave comments. Login now