From 4449c7d1b0d9a4c96d906469684521795c2c0d30 2017-09-27 13:05:43 From: Alexandre Leroux Date: 2017-09-27 13:05:43 Subject: [PATCH] Improves reading performances --- diff --git a/plugins/amda/src/AmdaResultParser.cpp b/plugins/amda/src/AmdaResultParser.cpp index df2fc2c..2532b15 100644 --- a/plugins/amda/src/AmdaResultParser.cpp +++ b/plugins/amda/src/AmdaResultParser.cpp @@ -17,9 +17,6 @@ namespace { /// Message in result file when the file was not found on server const auto FILE_NOT_FOUND_MESSAGE = QStringLiteral("Not Found"); -/// Format for dates in result files -const auto DATE_FORMAT = QStringLiteral("yyyy-MM-ddThh:mm:ss.zzz"); - /// Separator between values in a result line const auto RESULT_LINE_SEPARATOR = QRegularExpression{QStringLiteral("\\s+")}; @@ -38,7 +35,8 @@ const auto UNIT_REGEX = QRegularExpression{QStringLiteral("\\s*PARAMETER_UNITS\\ /// @return a double that represents the date in seconds, NaN if the string date can't be converted double doubleDate(const QString &stringDate) noexcept { - auto dateTime = QDateTime::fromString(stringDate, DATE_FORMAT); + // Format: yyyy-MM-ddThh:mm:ss.zzz + auto dateTime = QDateTime::fromString(stringDate, Qt::ISODateWithMs); dateTime.setTimeSpec(Qt::UTC); return dateTime.isValid() ? DateUtils::secondsSinceEpoch(dateTime) : std::numeric_limits::quiet_NaN(); @@ -101,18 +99,21 @@ Unit readXAxisUnit(QTextStream &stream) std::pair, std::vector > readResults(QTextStream &stream, AmdaResultParser::ValueType valueType) { - auto expectedNbValues = nbValues(valueType); + auto expectedNbValues = nbValues(valueType) + 1; auto xData = std::vector{}; auto valuesData = std::vector{}; QString line{}; - while (stream.readLineInto(&line)) { - // Ignore comment lines - if (!isCommentLine(line)) { + // Skip comment lines + while (stream.readLineInto(&line) && isCommentLine(line)) { + } + + if (!stream.atEnd()) { + do { auto lineData = line.split(RESULT_LINE_SEPARATOR, QString::SkipEmptyParts); - if (lineData.size() == expectedNbValues + 1) { + if (lineData.size() == expectedNbValues) { // X : the data is converted from date to double (in secs) auto x = doubleDate(lineData.at(0)); @@ -121,8 +122,8 @@ readResults(QTextStream &stream, AmdaResultParser::ValueType valueType) xData.push_back(x); // Values - for (auto valueIndex = 0; valueIndex < expectedNbValues; ++valueIndex) { - auto column = valueIndex + 1; + for (auto valueIndex = 1; valueIndex < expectedNbValues; ++valueIndex) { + auto column = valueIndex; bool valueOk; auto value = lineData.at(column).toDouble(&valueOk); @@ -148,7 +149,7 @@ readResults(QTextStream &stream, AmdaResultParser::ValueType valueType) qCWarning(LOG_AmdaResultParser()) << QObject::tr("Can't retrieve results from line %1: invalid line").arg(line); } - } + } while (stream.readLineInto(&line)); } return std::make_pair(std::move(xData), std::move(valuesData));