##// END OF EJS Templates
WIP Multicomponent TS...
WIP Multicomponent TS Signed-off-by: Alexis Jeandet <alexis.jeandet@member.fsf.org>

File last commit:

r1423:31110df2feb2
r1431:8eb0c93bfd80
Show More
AmdaResultParser.cpp
149 lines | 4.0 KiB | text/x-c | CppLexer
/ plugins / amda / src / AmdaResultParser.cpp
Alexandre Leroux
Amda provider (3)...
r380 #include "AmdaResultParser.h"
Alexandre Leroux
Parser refactoring (5)...
r948 #include "AmdaResultParserHelper.h"
Alexandre Leroux
Amda provider (3)...
r380
#include <QFile>
New TimeSeries lib integration WIP...
r1416 #include <cmath>
Add the cmath include missing
r400
Alexandre Leroux
Amda provider (3)...
r380 Q_LOGGING_CATEGORY(LOG_AmdaResultParser, "AmdaResultParser")
New TimeSeries lib integration WIP...
r1416 namespace
{
Alexandre Leroux
Amda provider (3)...
r380
Alexandre Leroux
Handles "Not found" error for AMDA result parser
r446 /// Message in result file when the file was not found on server
const auto FILE_NOT_FOUND_MESSAGE = QStringLiteral("Not Found");
Alexandre Leroux
Improves AMDA result parsing...
r492 /// Checks if a line is a comment line
New TimeSeries lib integration WIP...
r1416 bool isCommentLine(const QString& line)
Alexandre Leroux
Improves AMDA result parsing...
r492 {
return line.startsWith("#");
}
Alexandre Leroux
Parser refactoring (5)...
r948 /**
* Creates helper that will be used to read AMDA file, according to the type passed as parameter
* @param valueType the type of values expected in the AMDA file (scalars, vectors, spectrograms...)
* @return the helper created
*/
Alexandre Leroux
Move the AMDA data type to a type accessible from core
r1278 std::unique_ptr<IAmdaResultParserHelper> createHelper(DataSeriesType valueType)
Alexandre Leroux
Updates method for reading results according to the value type (vector or scalar)
r564 {
New TimeSeries lib integration WIP...
r1416 switch (valueType)
{
Alexandre Leroux
Move the AMDA data type to a type accessible from core
r1278 case DataSeriesType::SCALAR:
Alexandre Leroux
Parser refactoring (5)...
r948 return std::make_unique<ScalarParserHelper>();
Alexandre Leroux
Move the AMDA data type to a type accessible from core
r1278 case DataSeriesType::SPECTROGRAM:
Alexandre Leroux
Spectrograms implementation (1)...
r949 return std::make_unique<SpectrogramParserHelper>();
Alexandre Leroux
Move the AMDA data type to a type accessible from core
r1278 case DataSeriesType::VECTOR:
Alexandre Leroux
Parser refactoring (5)...
r948 return std::make_unique<VectorParserHelper>();
New TimeSeries lib integration WIP...
r1416 case DataSeriesType::NONE:
Alexandre Leroux
Updates method for reading results according to the value type (vector or scalar)
r564 // Invalid case
break;
}
// Invalid cases
qCCritical(LOG_AmdaResultParser())
Alexandre Leroux
Parser refactoring (5)...
r948 << QObject::tr("Can't create helper to read result file: unsupported type");
return nullptr;
Alexandre Leroux
Updates method for reading results according to the value type (vector or scalar)
r564 }
Alexandre Leroux
Reads x-axis unit in result file
r393 /**
Alexandre Leroux
Parser refactoring (5)...
r948 * Reads properties of the stream passed as parameter
* @param helper the helper used to read properties line by line
Alexandre Leroux
Reads x-axis unit in result file
r393 * @param stream the stream to read
*/
New TimeSeries lib integration WIP...
r1416 void readProperties(IAmdaResultParserHelper& helper, QTextStream& stream)
Alexandre Leroux
Reads x-axis unit in result file
r393 {
Alexandre Leroux
Parser refactoring (5)...
r948 // Searches properties in the comment lines (as long as the reading has not reached the data)
Alexandre Leroux
Changes way to retrieve unit
r791 // AMDA V2: while (stream.readLineInto(&line) && !line.contains(DATA_HEADER_REGEX)) {
New TimeSeries lib integration WIP...
r1416 QString line {};
while (stream.readLineInto(&line) && isCommentLine(line))
{
Alexandre Leroux
Parser refactoring (5)...
r948 helper.readPropertyLine(line);
Alexandre Leroux
Reads x-axis unit in result file
r393 }
}
Alexandre Leroux
Improves controls when reading results
r394 /**
Alexandre Leroux
Parser refactoring (5)...
r948 * Reads results of the stream passed as parameter
* @param helper the helper used to read results line by line
Alexandre Leroux
Improves controls when reading results
r394 * @param stream the stream to read
*/
New TimeSeries lib integration WIP...
r1416 void readResults(IAmdaResultParserHelper& helper, QTextStream& stream)
Alexandre Leroux
Improves controls when reading results
r394 {
New TimeSeries lib integration WIP...
r1416 QString line {};
Alexandre Leroux
Improves AMDA result parsing...
r492
Alexandre Leroux
- Changes the way to retrieve unit in AMDA result file: The generated header in the result file differs from the first version...
r775 // Skip comment lines
New TimeSeries lib integration WIP...
r1416 while (stream.readLineInto(&line) && isCommentLine(line))
{
Alexandre Leroux
- Changes the way to retrieve unit in AMDA result file: The generated header in the result file differs from the first version...
r775 }
New TimeSeries lib integration WIP...
r1416 if (!stream.atEnd())
{
do
{
Alexandre Leroux
Parser refactoring (5)...
r948 helper.readResultLine(line);
Alexandre Leroux
- Changes the way to retrieve unit in AMDA result file: The generated header in the result file differs from the first version...
r775 } while (stream.readLineInto(&line));
Alexandre Leroux
Improves controls when reading results
r394 }
}
Alexandre Leroux
Amda provider (3)...
r380 } // namespace
New TimeSeries lib integration WIP...
r1416 std::shared_ptr<IDataSeries> AmdaResultParser::readTxt(
const QString& filePath, DataSeriesType type) noexcept
Alexandre Leroux
Amda provider (3)...
r380 {
New TimeSeries lib integration WIP...
r1416 if (type == DataSeriesType::NONE)
{
Alexandre Leroux
Creates enum that represents the value types that can be read in AMDA...
r563 qCCritical(LOG_AmdaResultParser())
<< QObject::tr("Can't retrieve AMDA data: the type of values to be read is unknown");
return nullptr;
}
New TimeSeries lib integration WIP...
r1416 QFile file { filePath };
Alexandre Leroux
Amda provider (3)...
r380
New TimeSeries lib integration WIP...
r1416 if (!file.open(QFile::ReadOnly | QIODevice::Text))
{
Alexandre Leroux
Amda provider (3)...
r380 qCCritical(LOG_AmdaResultParser())
<< QObject::tr("Can't retrieve AMDA data from file %1: %2")
.arg(filePath, file.errorString());
return nullptr;
}
New TimeSeries lib integration WIP...
r1416 return std::shared_ptr<IDataSeries> { AmdaResultParser::readTxt(QTextStream { &file }, type) };
Removed old IDataProvider IF, some small steps toward new VC integration...
r1351 }
New TimeSeries lib integration WIP...
r1416 IDataSeries* AmdaResultParser::readTxt(QTextStream stream, DataSeriesType type) noexcept
Removed old IDataProvider IF, some small steps toward new VC integration...
r1351 {
New TimeSeries lib integration WIP...
r1416 if (type == DataSeriesType::NONE)
Removed old IDataProvider IF, some small steps toward new VC integration...
r1351 {
return nullptr;
}
Alexandre Leroux
Amda provider (3)...
r380
Alexandre Leroux
Handles "Not found" error for AMDA result parser
r446 // Checks if the file was found on the server
auto firstLine = stream.readLine();
Removed old IDataProvider IF, some small steps toward new VC integration...
r1351 if (firstLine.compare(FILE_NOT_FOUND_MESSAGE) == 0)
{
Alexandre Leroux
Handles "Not found" error for AMDA result parser
r446 return nullptr;
}
Alexandre Leroux
Move the AMDA data type to a type accessible from core
r1278 auto helper = createHelper(type);
Alexandre Leroux
Parser refactoring (5)...
r948 Q_ASSERT(helper != nullptr);
Alexandre Leroux
Reads x-axis unit in result file
r393
Alexandre Leroux
Parser refactoring (5)...
r948 // Reads header file to retrieve properties
Alexandre Leroux
Changes way to retrieve unit
r791 stream.seek(0); // returns to the beginning of the file
Alexandre Leroux
Parser refactoring (5)...
r948 readProperties(*helper, stream);
Alexandre Leroux
Updates method for reading results according to the value type (vector or scalar)
r564
Alexandre Leroux
Parser refactoring (5)...
r948 // Checks properties
New TimeSeries lib integration WIP...
r1416 if (helper->checkProperties())
{
Alexandre Leroux
Parser refactoring (5)...
r948 // Reads results
// AMDA V2: remove line
stream.seek(0); // returns to the beginning of the file
readResults(*helper, stream);
Alexandre Leroux
Amda provider (3)...
r380
Alexandre Leroux
Parser refactoring (5)...
r948 // Creates data series
return helper->createSeries();
}
New TimeSeries lib integration WIP...
r1416 else
{
Alexandre Leroux
Parser refactoring (5)...
r948 return nullptr;
}
Alexandre Leroux
Amda provider (3)...
r380 }