##// END OF EJS Templates
Move the AMDA data type to a type accessible from core
Alexandre Leroux -
r1332:d3daab81283b
parent child
Show More
@@ -0,0 +1,26
1 #ifndef SCIQLOP_DATASERIESTYPE_H
2 #define SCIQLOP_DATASERIESTYPE_H
3
4 #include <QString>
5
6 enum class DataSeriesType { SCALAR, SPECTROGRAM, VECTOR, UNKNOWN };
7
8 struct DataSeriesTypeUtils {
9 static DataSeriesType fromString(const QString &type)
10 {
11 if (type == QStringLiteral("scalar")) {
12 return DataSeriesType::SCALAR;
13 }
14 else if (type == QStringLiteral("spectrogram")) {
15 return DataSeriesType::SPECTROGRAM;
16 }
17 else if (type == QStringLiteral("vector")) {
18 return DataSeriesType::VECTOR;
19 }
20 else {
21 return DataSeriesType::UNKNOWN;
22 }
23 }
24 };
25
26 #endif // SCIQLOP_DATASERIESTYPE_H
@@ -3,6 +3,8
3 3
4 4 #include "AmdaGlobal.h"
5 5
6 #include <Data/DataSeriesType.h>
7
6 8 #include <QLoggingCategory>
7 9
8 10 #include <memory>
@@ -12,10 +14,8 class IDataSeries;
12 14 Q_DECLARE_LOGGING_CATEGORY(LOG_AmdaResultParser)
13 15
14 16 struct SCIQLOP_AMDA_EXPORT AmdaResultParser {
15 enum class ValueType { SCALAR, SPECTROGRAM, VECTOR, UNKNOWN };
16
17 17 static std::shared_ptr<IDataSeries> readTxt(const QString &filePath,
18 ValueType valueType) noexcept;
18 DataSeriesType valueType) noexcept;
19 19 };
20 20
21 21 #endif // SCIQLOP_AMDARESULTPARSER_H
@@ -39,21 +39,6 QString dateFormat(double sqpRange) noexcept
39 39 return dateTime.toString(AMDA_TIME_FORMAT);
40 40 }
41 41
42 AmdaResultParser::ValueType valueType(const QString &valueType)
43 {
44 if (valueType == QStringLiteral("scalar")) {
45 return AmdaResultParser::ValueType::SCALAR;
46 }
47 else if (valueType == QStringLiteral("spectrogram")) {
48 return AmdaResultParser::ValueType::SPECTROGRAM;
49 }
50 else if (valueType == QStringLiteral("vector")) {
51 return AmdaResultParser::ValueType::VECTOR;
52 }
53 else {
54 return AmdaResultParser::ValueType::UNKNOWN;
55 }
56 }
57 42
58 43 } // namespace
59 44
@@ -171,7 +156,8 void AmdaProvider::retrieveData(QUuid token, const SqpRange &dateTime, const QVa
171 156
172 157 // Retrieves the data type that determines whether the expected format for the result file is
173 158 // scalar, vector...
174 auto productValueType = valueType(data.value(AMDA_DATA_TYPE_KEY).toString());
159 auto productValueType
160 = DataSeriesTypeUtils::fromString(data.value(AMDA_DATA_TYPE_KEY).toString());
175 161
176 162 // /////////// //
177 163 // Creates URL //
@@ -24,16 +24,16 bool isCommentLine(const QString &line)
24 24 * @param valueType the type of values expected in the AMDA file (scalars, vectors, spectrograms...)
25 25 * @return the helper created
26 26 */
27 std::unique_ptr<IAmdaResultParserHelper> createHelper(AmdaResultParser::ValueType valueType)
27 std::unique_ptr<IAmdaResultParserHelper> createHelper(DataSeriesType valueType)
28 28 {
29 29 switch (valueType) {
30 case AmdaResultParser::ValueType::SCALAR:
30 case DataSeriesType::SCALAR:
31 31 return std::make_unique<ScalarParserHelper>();
32 case AmdaResultParser::ValueType::SPECTROGRAM:
32 case DataSeriesType::SPECTROGRAM:
33 33 return std::make_unique<SpectrogramParserHelper>();
34 case AmdaResultParser::ValueType::VECTOR:
34 case DataSeriesType::VECTOR:
35 35 return std::make_unique<VectorParserHelper>();
36 case AmdaResultParser::ValueType::UNKNOWN:
36 case DataSeriesType::UNKNOWN:
37 37 // Invalid case
38 38 break;
39 39 }
@@ -82,9 +82,9 void readResults(IAmdaResultParserHelper &helper, QTextStream &stream)
82 82 } // namespace
83 83
84 84 std::shared_ptr<IDataSeries> AmdaResultParser::readTxt(const QString &filePath,
85 ValueType valueType) noexcept
85 DataSeriesType type) noexcept
86 86 {
87 if (valueType == ValueType::UNKNOWN) {
87 if (type == DataSeriesType::UNKNOWN) {
88 88 qCCritical(LOG_AmdaResultParser())
89 89 << QObject::tr("Can't retrieve AMDA data: the type of values to be read is unknown");
90 90 return nullptr;
@@ -110,7 +110,7 std::shared_ptr<IDataSeries> AmdaResultParser::readTxt(const QString &filePath,
110 110 return nullptr;
111 111 }
112 112
113 auto helper = createHelper(valueType);
113 auto helper = createHelper(type);
114 114 Q_ASSERT(helper != nullptr);
115 115
116 116 // Reads header file to retrieve properties
@@ -115,7 +115,7 void TestAmdaAcquisition::testAcquisition()
115 115 // Retrieves data file
116 116 QFETCH(QString, dataFilename);
117 117 auto filePath = QFileInfo{TESTS_RESOURCES_PATH, dataFilename}.absoluteFilePath();
118 auto results = AmdaResultParser::readTxt(filePath, AmdaResultParser::ValueType::SCALAR);
118 auto results = AmdaResultParser::readTxt(filePath, DataSeriesType::SCALAR);
119 119
120 120 /// Lambda used to validate a variable at each step
121 121 auto validateVariable = [results](std::shared_ptr<Variable> variable, const SqpRange &range) {
@@ -187,7 +187,7 private:
187 187 }
188 188
189 189 template <typename T>
190 void testRead(AmdaResultParser::ValueType valueType)
190 void testRead(DataSeriesType valueType)
191 191 {
192 192 QFETCH(QString, inputFileName);
193 193 QFETCH(ExpectedResults<T>, expectedResults);
@@ -319,7 +319,7 void TestAmdaResultParser::testReadScalarTxt_data()
319 319
320 320 void TestAmdaResultParser::testReadScalarTxt()
321 321 {
322 testRead<ScalarSeries>(AmdaResultParser::ValueType::SCALAR);
322 testRead<ScalarSeries>(DataSeriesType::SCALAR);
323 323 }
324 324
325 325 void TestAmdaResultParser::testReadSpectrogramTxt_data()
@@ -533,7 +533,7 void TestAmdaResultParser::testReadSpectrogramTxt_data()
533 533
534 534 void TestAmdaResultParser::testReadSpectrogramTxt()
535 535 {
536 testRead<SpectrogramSeries>(AmdaResultParser::ValueType::SPECTROGRAM);
536 testRead<SpectrogramSeries>(DataSeriesType::SPECTROGRAM);
537 537 }
538 538
539 539 void TestAmdaResultParser::testReadVectorTxt_data()
@@ -572,7 +572,7 void TestAmdaResultParser::testReadVectorTxt_data()
572 572
573 573 void TestAmdaResultParser::testReadVectorTxt()
574 574 {
575 testRead<VectorSeries>(AmdaResultParser::ValueType::VECTOR);
575 testRead<VectorSeries>(DataSeriesType::VECTOR);
576 576 }
577 577
578 578 QTEST_MAIN(TestAmdaResultParser)
General Comments 0
You need to be logged in to leave comments. Login now