@@ -1,1 +1,1 | |||||
1 | Subproject commit 27b582a32334943a9c8fe7d0b96423c3825cdc70 |
|
1 | Subproject commit 7315812f38391ae65688cfd4309ded15ec96d7e6 |
@@ -4,18 +4,19 | |||||
4 |
|
4 | |||
5 | #include <QFile> |
|
5 | #include <QFile> | |
6 |
|
6 | |||
7 | #include <cmath> |
|
|||
8 | #include <Data/IDataSeries.h> |
|
7 | #include <Data/IDataSeries.h> | |
|
8 | #include <cmath> | |||
9 |
|
9 | |||
10 | Q_LOGGING_CATEGORY(LOG_AmdaResultParser, "AmdaResultParser") |
|
10 | Q_LOGGING_CATEGORY(LOG_AmdaResultParser, "AmdaResultParser") | |
11 |
|
11 | |||
12 |
namespace |
|
12 | namespace | |
|
13 | { | |||
13 |
|
14 | |||
14 | /// Message in result file when the file was not found on server |
|
15 | /// Message in result file when the file was not found on server | |
15 | const auto FILE_NOT_FOUND_MESSAGE = QStringLiteral("Not Found"); |
|
16 | const auto FILE_NOT_FOUND_MESSAGE = QStringLiteral("Not Found"); | |
16 |
|
17 | |||
17 | /// Checks if a line is a comment line |
|
18 | /// Checks if a line is a comment line | |
18 |
bool isCommentLine(const QString |
|
19 | bool isCommentLine(const QString& line) | |
19 | { |
|
20 | { | |
20 | return line.startsWith("#"); |
|
21 | return line.startsWith("#"); | |
21 | } |
|
22 | } | |
@@ -27,14 +28,15 bool isCommentLine(const QString &line) | |||||
27 | */ |
|
28 | */ | |
28 | std::unique_ptr<IAmdaResultParserHelper> createHelper(DataSeriesType valueType) |
|
29 | std::unique_ptr<IAmdaResultParserHelper> createHelper(DataSeriesType valueType) | |
29 | { |
|
30 | { | |
30 |
switch (valueType) |
|
31 | switch (valueType) | |
|
32 | { | |||
31 | case DataSeriesType::SCALAR: |
|
33 | case DataSeriesType::SCALAR: | |
32 | return std::make_unique<ScalarParserHelper>(); |
|
34 | return std::make_unique<ScalarParserHelper>(); | |
33 | case DataSeriesType::SPECTROGRAM: |
|
35 | case DataSeriesType::SPECTROGRAM: | |
34 | return std::make_unique<SpectrogramParserHelper>(); |
|
36 | return std::make_unique<SpectrogramParserHelper>(); | |
35 | case DataSeriesType::VECTOR: |
|
37 | case DataSeriesType::VECTOR: | |
36 | return std::make_unique<VectorParserHelper>(); |
|
38 | return std::make_unique<VectorParserHelper>(); | |
37 |
case DataSeriesType:: |
|
39 | case DataSeriesType::NONE: | |
38 | // Invalid case |
|
40 | // Invalid case | |
39 | break; |
|
41 | break; | |
40 | } |
|
42 | } | |
@@ -50,12 +52,13 std::unique_ptr<IAmdaResultParserHelper> createHelper(DataSeriesType valueType) | |||||
50 | * @param helper the helper used to read properties line by line |
|
52 | * @param helper the helper used to read properties line by line | |
51 | * @param stream the stream to read |
|
53 | * @param stream the stream to read | |
52 | */ |
|
54 | */ | |
53 |
void readProperties(IAmdaResultParserHelper |
|
55 | void readProperties(IAmdaResultParserHelper& helper, QTextStream& stream) | |
54 | { |
|
56 | { | |
55 | // Searches properties in the comment lines (as long as the reading has not reached the data) |
|
57 | // Searches properties in the comment lines (as long as the reading has not reached the data) | |
56 | // AMDA V2: while (stream.readLineInto(&line) && !line.contains(DATA_HEADER_REGEX)) { |
|
58 | // AMDA V2: while (stream.readLineInto(&line) && !line.contains(DATA_HEADER_REGEX)) { | |
57 | QString line{}; |
|
59 | QString line {}; | |
58 |
while (stream.readLineInto(&line) && isCommentLine(line)) |
|
60 | while (stream.readLineInto(&line) && isCommentLine(line)) | |
|
61 | { | |||
59 | helper.readPropertyLine(line); |
|
62 | helper.readPropertyLine(line); | |
60 | } |
|
63 | } | |
61 | } |
|
64 | } | |
@@ -65,16 +68,19 void readProperties(IAmdaResultParserHelper &helper, QTextStream &stream) | |||||
65 | * @param helper the helper used to read results line by line |
|
68 | * @param helper the helper used to read results line by line | |
66 | * @param stream the stream to read |
|
69 | * @param stream the stream to read | |
67 | */ |
|
70 | */ | |
68 |
void readResults(IAmdaResultParserHelper |
|
71 | void readResults(IAmdaResultParserHelper& helper, QTextStream& stream) | |
69 | { |
|
72 | { | |
70 | QString line{}; |
|
73 | QString line {}; | |
71 |
|
74 | |||
72 | // Skip comment lines |
|
75 | // Skip comment lines | |
73 |
while (stream.readLineInto(&line) && isCommentLine(line)) |
|
76 | while (stream.readLineInto(&line) && isCommentLine(line)) | |
|
77 | { | |||
74 | } |
|
78 | } | |
75 |
|
79 | |||
76 |
if (!stream.atEnd()) |
|
80 | if (!stream.atEnd()) | |
77 | do { |
|
81 | { | |
|
82 | do | |||
|
83 | { | |||
78 | helper.readResultLine(line); |
|
84 | helper.readResultLine(line); | |
79 | } while (stream.readLineInto(&line)); |
|
85 | } while (stream.readLineInto(&line)); | |
80 | } |
|
86 | } | |
@@ -82,31 +88,32 void readResults(IAmdaResultParserHelper &helper, QTextStream &stream) | |||||
82 |
|
88 | |||
83 | } // namespace |
|
89 | } // namespace | |
84 |
|
90 | |||
85 |
std::shared_ptr<IDataSeries> AmdaResultParser::readTxt( |
|
91 | std::shared_ptr<IDataSeries> AmdaResultParser::readTxt( | |
86 | DataSeriesType type) noexcept |
|
92 | const QString& filePath, DataSeriesType type) noexcept | |
87 | { |
|
93 | { | |
88 |
if (type == DataSeriesType:: |
|
94 | if (type == DataSeriesType::NONE) | |
|
95 | { | |||
89 | qCCritical(LOG_AmdaResultParser()) |
|
96 | qCCritical(LOG_AmdaResultParser()) | |
90 | << QObject::tr("Can't retrieve AMDA data: the type of values to be read is unknown"); |
|
97 | << QObject::tr("Can't retrieve AMDA data: the type of values to be read is unknown"); | |
91 | return nullptr; |
|
98 | return nullptr; | |
92 | } |
|
99 | } | |
93 |
|
100 | |||
94 | QFile file{filePath}; |
|
101 | QFile file { filePath }; | |
95 |
|
102 | |||
96 |
if (!file.open(QFile::ReadOnly | QIODevice::Text)) |
|
103 | if (!file.open(QFile::ReadOnly | QIODevice::Text)) | |
|
104 | { | |||
97 | qCCritical(LOG_AmdaResultParser()) |
|
105 | qCCritical(LOG_AmdaResultParser()) | |
98 | << QObject::tr("Can't retrieve AMDA data from file %1: %2") |
|
106 | << QObject::tr("Can't retrieve AMDA data from file %1: %2") | |
99 | .arg(filePath, file.errorString()); |
|
107 | .arg(filePath, file.errorString()); | |
100 | return nullptr; |
|
108 | return nullptr; | |
101 | } |
|
109 | } | |
102 |
|
110 | |||
103 | return std::shared_ptr<IDataSeries>{AmdaResultParser::readTxt(QTextStream{&file},type)}; |
|
111 | return std::shared_ptr<IDataSeries> { AmdaResultParser::readTxt(QTextStream { &file }, type) }; | |
104 | } |
|
112 | } | |
105 |
|
113 | |||
106 |
IDataSeries |
|
114 | IDataSeries* AmdaResultParser::readTxt(QTextStream stream, DataSeriesType type) noexcept | |
107 | DataSeriesType type) noexcept |
|
|||
108 | { |
|
115 | { | |
109 |
if (type == DataSeriesType:: |
|
116 | if (type == DataSeriesType::NONE) | |
110 | { |
|
117 | { | |
111 | return nullptr; |
|
118 | return nullptr; | |
112 | } |
|
119 | } | |
@@ -126,7 +133,8 IDataSeries *AmdaResultParser::readTxt(QTextStream stream, | |||||
126 | readProperties(*helper, stream); |
|
133 | readProperties(*helper, stream); | |
127 |
|
134 | |||
128 | // Checks properties |
|
135 | // Checks properties | |
129 |
if (helper->checkProperties()) |
|
136 | if (helper->checkProperties()) | |
|
137 | { | |||
130 | // Reads results |
|
138 | // Reads results | |
131 | // AMDA V2: remove line |
|
139 | // AMDA V2: remove line | |
132 | stream.seek(0); // returns to the beginning of the file |
|
140 | stream.seek(0); // returns to the beginning of the file | |
@@ -135,7 +143,8 IDataSeries *AmdaResultParser::readTxt(QTextStream stream, | |||||
135 | // Creates data series |
|
143 | // Creates data series | |
136 | return helper->createSeries(); |
|
144 | return helper->createSeries(); | |
137 | } |
|
145 | } | |
138 |
else |
|
146 | else | |
|
147 | { | |||
139 | return nullptr; |
|
148 | return nullptr; | |
140 | } |
|
149 | } | |
141 | } |
|
150 | } |
General Comments 0
You need to be logged in to leave comments.
Login now