##// END OF EJS Templates
Merge branch 'feature/CompilFlagServer' into develop
Alexandre Leroux -
r1155:2e3c32b33d04 merge
parent child
Show More
@@ -0,0 +1,35
1 #ifndef SCIQLOP_AMDASERVER_H
2 #define SCIQLOP_AMDASERVER_H
3
4 #include <QLoggingCategory>
5
6 #include <memory>
7
8 Q_DECLARE_LOGGING_CATEGORY(LOG_AmdaServer)
9
10 // Directive used to determine the active AMDA server
11 #ifndef SCIQLOP_AMDA_SERVER
12 #define SCIQLOP_AMDA_SERVER "default"
13 #endif
14
15 /**
16 * @brief The AmdaServer class represents the server used to retrieve AMDA data (singleton).
17 *
18 * The server instance is initialized at compile time, as defined by the AMDA_SERVER value.
19 */
20 class AmdaServer {
21 public:
22 /// @return the unique instance of the AMDA server
23 static AmdaServer &instance();
24
25 virtual ~AmdaServer() noexcept = default;
26
27 /// @return the name of the server
28 virtual QString name() const = 0;
29
30 /// @param properties used to generate url
31 /// @return the url of the server (used to retrieve data)
32 virtual QString url(const QVariantHash &properties = {}) const = 0;
33 };
34
35 #endif // SCIQLOP_AMDASERVER_H
@@ -0,0 +1,99
1 #include "AmdaServer.h"
2
3 #include "AmdaDefs.h"
4
5 Q_LOGGING_CATEGORY(LOG_AmdaServer, "AmdaServer")
6
7 namespace {
8
9 /// URL of the default AMDA server
10 const auto AMDA_DEFAULT_SERVER_URL = QStringLiteral("amda.irap.omp.eu");
11
12 /// URL of the AMDA test server
13 const auto AMDA_TEST_SERVER_URL = QStringLiteral("amdatest.irap.omp.eu");
14
15 /// Port used for local server
16 const auto AMDA_LOCAL_SERVER_PORT = 6543;
17
18 /// URL of the local server
19 const auto AMDA_LOCAL_SERVER_URL
20 = QString{"localhost:%1"}.arg(QString::number(AMDA_LOCAL_SERVER_PORT));
21
22 /// Default AMDA server
23 struct AmdaDefaultServer : public AmdaServer {
24 public:
25 QString name() const override { return QStringLiteral("AMDA (default)"); }
26 QString url(const QVariantHash &properties) const override
27 {
28 Q_UNUSED(properties);
29 return AMDA_DEFAULT_SERVER_URL;
30 }
31 };
32
33 /// Alternative AMDA server (tests)
34 struct AmdaTestServer : public AmdaServer {
35 public:
36 QString name() const override { return QStringLiteral("AMDA (test)"); }
37 QString url(const QVariantHash &properties) const override
38 {
39 Q_UNUSED(properties);
40 return AMDA_TEST_SERVER_URL;
41 }
42 };
43
44 /// Hybrid AMDA server: use both of default and test server.
45 /// The server used is relative to each product for which to retrieve url, according to its "server"
46 /// property
47 struct AmdaHybridServer : public AmdaServer {
48 public:
49 QString name() const override { return QStringLiteral("AMDA (hybrid)"); }
50 QString url(const QVariantHash &properties) const override
51 {
52 // Reads "server" property to determine which server url to use
53 auto server = properties.value(AMDA_SERVER_KEY).toString();
54 return server == QString{"amdatest"} ? AMDA_TEST_SERVER_URL : AMDA_DEFAULT_SERVER_URL;
55 }
56 };
57
58 /// Local AMDA server: use local python server to simulate AMDA requests
59 struct AmdaLocalServer : public AmdaServer {
60 public:
61 QString name() const override { return AMDA_LOCAL_SERVER_URL; }
62 QString url(const QVariantHash &properties) const override
63 {
64 Q_UNUSED(properties);
65 return AMDA_LOCAL_SERVER_URL;
66 }
67 };
68
69 /// @return an AMDA server instance created from the name of the server passed in parameter. If the
70 /// name does not match any known server, a default server instance is created
71 std::unique_ptr<AmdaServer> createInstance(const QString &server)
72 {
73 if (server == QString{"amdatest"}) {
74 return std::make_unique<AmdaTestServer>();
75 }
76 else if (server == QString{"hybrid"}) {
77 return std::make_unique<AmdaHybridServer>();
78 }
79 else if (server == QString{"localhost"}) {
80 return std::make_unique<AmdaLocalServer>();
81 }
82 else {
83 if (server != QString{"default"}) {
84 qCWarning(LOG_AmdaServer())
85 << QObject::tr("Unknown server '%1': default AMDA server will be used").arg(server);
86 }
87
88 return std::make_unique<AmdaDefaultServer>();
89 }
90 }
91
92 } // namespace
93
94 AmdaServer &AmdaServer::instance()
95 {
96 // Creates instance depending on the SCIQLOP_AMDA_SERVER value at compile time
97 static auto instance = createInstance(SCIQLOP_AMDA_SERVER);
98 return *instance;
99 }
@@ -0,0 +1,5
1 AmdaResultParser\.h:\d+:.*IPSIS_S01.*
2 AmdaResultParserHelper\.h:\d+:.*IPSIS_S01.*
3
4 AmdaProvider\.cpp:\d+:.*IPSIS_S04_VARIABLE.*found: QStringLiteral
5 AmdaResultParserHelper\.cpp:\d+:.*IPSIS_S04_VARIABLE.*found: QT_VERSION_CHECK No newline at end of file
@@ -27,6 +27,15 IF(BUILD_PLUGINS)
27 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${sciqlop-mockplugin_DIR}")
27 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${sciqlop-mockplugin_DIR}")
28 ADD_SUBDIRECTORY("${CMAKE_SOURCE_DIR}/plugins/mockplugin")
28 ADD_SUBDIRECTORY("${CMAKE_SOURCE_DIR}/plugins/mockplugin")
29
29
30 # Sets AMDA server that will be used during execution.
31 # Available values are:
32 # - "default": default AMDA server
33 # - "amdatest": AMDA test server
34 # - "hybrid": use both the default server and the test server (the server used is relative to each product, according to its "server" property in the JSON file)
35 # - "localhost": use local AMDA server
36 # Any other value will lead to the use of the default server
37 ADD_DEFINITIONS(-DSCIQLOP_AMDA_SERVER="hybrid")
38
30 set(sciqlop-amda_DIR "${CMAKE_SOURCE_DIR}/plugins/amda/cmake")
39 set(sciqlop-amda_DIR "${CMAKE_SOURCE_DIR}/plugins/amda/cmake")
31 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${sciqlop-amda_DIR}")
40 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${sciqlop-amda_DIR}")
32 ADD_SUBDIRECTORY("${CMAKE_SOURCE_DIR}/plugins/amda")
41 ADD_SUBDIRECTORY("${CMAKE_SOURCE_DIR}/plugins/amda")
@@ -22,6 +22,15 elif host_machine.system()=='windows'
22 meson.add_install_script('build_cfg/windows/install_script.sh')
22 meson.add_install_script('build_cfg/windows/install_script.sh')
23 endif
23 endif
24
24
25 # Sets AMDA server that will be used during execution.
26 # Available values are:
27 # - "default": default AMDA server
28 # - "amdatest": AMDA test server
29 # - "hybrid": use both the default server and the test server (the server used is relative to each product, according to its "server" property in the JSON file)
30 # - "localhost": use local AMDA server
31 # Any other value will lead to the use of the default server
32 add_project_arguments('-DSCIQLOP_AMDA_SERVER="hybrid"', language : 'cpp')
33
25 subdir('core')
34 subdir('core')
26 subdir('gui')
35 subdir('gui')
27 subdir('app')
36 subdir('app')
@@ -92,7 +92,7 SCIQLOP_COPY_TO_TARGET(LIBRARY ${SQPAMDA_LIBRARY_NAME} ${EXTERN_SHARED_LIBRARIES
92 LIST(APPEND CHECKSTYLE_INPUT_FILES ${MODULE_SOURCES})
92 LIST(APPEND CHECKSTYLE_INPUT_FILES ${MODULE_SOURCES})
93 SCIQLOP_SET_TO_PARENT_SCOPE(CHECKSTYLE_INPUT_FILES)
93 SCIQLOP_SET_TO_PARENT_SCOPE(CHECKSTYLE_INPUT_FILES)
94 # Vera++ exclusion files
94 # Vera++ exclusion files
95 #LIST(APPEND CHECKSTYLE_EXCLUSION_FILES ${CMAKE_CURRENT_SOURCE_DIR}/vera-exclusions/exclusions.txt)
95 LIST(APPEND CHECKSTYLE_EXCLUSION_FILES ${CMAKE_CURRENT_SOURCE_DIR}/vera-exclusions/exclusions.txt)
96 SCIQLOP_SET_TO_PARENT_SCOPE(CHECKSTYLE_EXCLUSION_FILES)
96 SCIQLOP_SET_TO_PARENT_SCOPE(CHECKSTYLE_EXCLUSION_FILES)
97
97
98 #
98 #
@@ -11,8 +11,8
11
11
12 Q_DECLARE_LOGGING_CATEGORY(LOG_AmdaPlugin)
12 Q_DECLARE_LOGGING_CATEGORY(LOG_AmdaPlugin)
13
13
14 #ifndef PLUGIN_JSON_FILE_PATH
14 #ifndef SCIQLOP_PLUGIN_JSON_FILE_PATH
15 #define PLUGIN_JSON_FILE_PATH "amda.json"
15 #define SCIQLOP_PLUGIN_JSON_FILE_PATH "amda.json"
16 #endif
16 #endif
17
17
18 class DataSourceItem;
18 class DataSourceItem;
@@ -20,7 +20,7 class DataSourceItem;
20 class SCIQLOP_AMDA_EXPORT AmdaPlugin : public QObject, public IPlugin {
20 class SCIQLOP_AMDA_EXPORT AmdaPlugin : public QObject, public IPlugin {
21 Q_OBJECT
21 Q_OBJECT
22 Q_INTERFACES(IPlugin)
22 Q_INTERFACES(IPlugin)
23 Q_PLUGIN_METADATA(IID "sciqlop.plugin.IPlugin" FILE PLUGIN_JSON_FILE_PATH)
23 Q_PLUGIN_METADATA(IID "sciqlop.plugin.IPlugin" FILE SCIQLOP_PLUGIN_JSON_FILE_PATH)
24 public:
24 public:
25 /// @sa IPlugin::initialize()
25 /// @sa IPlugin::initialize()
26 void initialize() override;
26 void initialize() override;
@@ -27,10 +27,6 public:
27
27
28 void requestDataAborting(QUuid acqIdentifier) override;
28 void requestDataAborting(QUuid acqIdentifier) override;
29
29
30 private slots:
31 void onReplyDownloadProgress(QUuid acqIdentifier,
32 std::shared_ptr<QNetworkRequest> networkRequest, double progress);
33
34 private:
30 private:
35 void retrieveData(QUuid token, const SqpRange &dateTime, const QVariantHash &data);
31 void retrieveData(QUuid token, const SqpRange &dateTime, const QVariantHash &data);
36
32
@@ -39,6 +35,10 private:
39
35
40 std::map<QUuid, std::map<std::shared_ptr<QNetworkRequest>, double> >
36 std::map<QUuid, std::map<std::shared_ptr<QNetworkRequest>, double> >
41 m_AcqIdToRequestProgressMap;
37 m_AcqIdToRequestProgressMap;
38
39 private slots:
40 void onReplyDownloadProgress(QUuid acqIdentifier,
41 std::shared_ptr<QNetworkRequest> networkRequest, double progress);
42 };
42 };
43
43
44 #endif // SCIQLOP_AMDAPROVIDER_H
44 #endif // SCIQLOP_AMDAPROVIDER_H
@@ -46,6 +46,9 extern const QString VALUES_UNIT_PROPERTY;
46 /// ... - Units : m/s - ...
46 /// ... - Units : m/s - ...
47 extern const QRegularExpression DEFAULT_X_AXIS_UNIT_REGEX;
47 extern const QRegularExpression DEFAULT_X_AXIS_UNIT_REGEX;
48
48
49 /// Alternative regex to find x-axis unit in a line
50 extern const QRegularExpression ALTERNATIVE_X_AXIS_UNIT_REGEX;
51
49 /// Regex to find end time of data in a line for a spectrogram
52 /// Regex to find end time of data in a line for a spectrogram
50 extern const QRegularExpression SPECTROGRAM_END_TIME_REGEX;
53 extern const QRegularExpression SPECTROGRAM_END_TIME_REGEX;
51
54
@@ -11,7 +11,8 amdaplugin_sources = [
11 'src/AmdaProvider.cpp',
11 'src/AmdaProvider.cpp',
12 'src/AmdaResultParser.cpp',
12 'src/AmdaResultParser.cpp',
13 'src/AmdaResultParserDefs.cpp',
13 'src/AmdaResultParserDefs.cpp',
14 'src/AmdaResultParserHelper.cpp'
14 'src/AmdaResultParserHelper.cpp',
15 'src/AmdaServer.cpp'
15 ]
16 ]
16
17
17 amdaplugin_ui_files = []
18 amdaplugin_ui_files = []
@@ -24,7 +25,7 amdaplugin_inc = include_directories(['include', '../../plugin/include'])
24 moc_gen = generator(moc,
25 moc_gen = generator(moc,
25 output : 'moc_@BASENAME@.cpp',
26 output : 'moc_@BASENAME@.cpp',
26 arguments : ['@INPUT@',
27 arguments : ['@INPUT@',
27 '-DPLUGIN_JSON_FILE_PATH="'+meson.source_root()+'/plugins/amda/resources/amda.json"',
28 '-DSCIQLOP_PLUGIN_JSON_FILE_PATH="'+meson.source_root()+'/plugins/amda/resources/amda.json"',
28 '-I', meson.current_source_dir()+'/include',
29 '-I', meson.current_source_dir()+'/include',
29 '-I', meson.current_source_dir()+'/../../plugin/include',
30 '-I', meson.current_source_dir()+'/../../plugin/include',
30 '-o', '@OUTPUT@'])
31 '-o', '@OUTPUT@'])
@@ -2,6 +2,7
2 #include "AmdaDefs.h"
2 #include "AmdaDefs.h"
3 #include "AmdaParser.h"
3 #include "AmdaParser.h"
4 #include "AmdaProvider.h"
4 #include "AmdaProvider.h"
5 #include "AmdaServer.h"
5
6
6 #include <DataSource/DataSourceController.h>
7 #include <DataSource/DataSourceController.h>
7 #include <DataSource/DataSourceItem.h>
8 #include <DataSource/DataSourceItem.h>
@@ -13,9 +14,6 Q_LOGGING_CATEGORY(LOG_AmdaPlugin, "AmdaPlugin")
13
14
14 namespace {
15 namespace {
15
16
16 /// Name of the data source
17 const auto DATA_SOURCE_NAME = QStringLiteral("AMDA");
18
19 /// Path of the file used to generate the data source item for AMDA
17 /// Path of the file used to generate the data source item for AMDA
20 const auto JSON_FILE_PATH = QStringLiteral(":/samples/AmdaSampleV3.json");
18 const auto JSON_FILE_PATH = QStringLiteral(":/samples/AmdaSampleV3.json");
21
19
@@ -33,7 +31,7 void associateActions(DataSourceItem &item, const QUuid &dataSourceUid)
33 const auto itemType = item.type();
31 const auto itemType = item.type();
34 if (itemType == DataSourceItemType::PRODUCT || itemType == DataSourceItemType::COMPONENT) {
32 if (itemType == DataSourceItemType::PRODUCT || itemType == DataSourceItemType::COMPONENT) {
35 // Adds plugin name to item metadata
33 // Adds plugin name to item metadata
36 item.setData(DataSourceItem::PLUGIN_DATA_KEY, DATA_SOURCE_NAME);
34 item.setData(DataSourceItem::PLUGIN_DATA_KEY, AmdaServer::instance().name());
37
35
38 // Adds load action
36 // Adds load action
39 auto actionLabel = QObject::tr(
37 auto actionLabel = QObject::tr(
@@ -54,14 +52,17 void associateActions(DataSourceItem &item, const QUuid &dataSourceUid)
54 void AmdaPlugin::initialize()
52 void AmdaPlugin::initialize()
55 {
53 {
56 if (auto app = sqpApp) {
54 if (auto app = sqpApp) {
55 auto dataSourceName = AmdaServer::instance().name();
56
57 // Registers to the data source controller
57 // Registers to the data source controller
58 auto &dataSourceController = app->dataSourceController();
58 auto &dataSourceController = app->dataSourceController();
59 auto dataSourceUid = dataSourceController.registerDataSource(DATA_SOURCE_NAME);
59 auto dataSourceUid = dataSourceController.registerDataSource(dataSourceName);
60
60
61 // Sets data source tree
61 // Sets data source tree
62 if (auto dataSourceItem = AmdaParser::readJson(JSON_FILE_PATH)) {
62 if (auto dataSourceItem = AmdaParser::readJson(JSON_FILE_PATH)) {
63 associateActions(*dataSourceItem, dataSourceUid);
63 dataSourceItem->setData(DataSourceItem::NAME_DATA_KEY, dataSourceName);
64
64
65 associateActions(*dataSourceItem, dataSourceUid);
65 dataSourceController.setDataSourceItem(dataSourceUid, std::move(dataSourceItem));
66 dataSourceController.setDataSourceItem(dataSourceUid, std::move(dataSourceItem));
66 }
67 }
67 else {
68 else {
@@ -1,6 +1,7
1 #include "AmdaProvider.h"
1 #include "AmdaProvider.h"
2 #include "AmdaDefs.h"
2 #include "AmdaDefs.h"
3 #include "AmdaResultParser.h"
3 #include "AmdaResultParser.h"
4 #include "AmdaServer.h"
4
5
5 #include <Common/DateUtils.h>
6 #include <Common/DateUtils.h>
6 #include <Data/DataProviderParameters.h>
7 #include <Data/DataProviderParameters.h>
@@ -17,12 +18,6 Q_LOGGING_CATEGORY(LOG_AmdaProvider, "AmdaProvider")
17
18
18 namespace {
19 namespace {
19
20
20 /// URL of the default AMDA server
21 const auto AMDA_SERVER_URL = QStringLiteral("amda.irap.omp.eu");
22
23 /// URL of the AMDA test server
24 const auto AMDA_TEST_SERVER_URL = QStringLiteral("amdatest.irap.omp.eu");
25
26 /// URL format for a request on AMDA server. The parameters are as follows:
21 /// URL format for a request on AMDA server. The parameters are as follows:
27 /// - %1: server URL
22 /// - %1: server URL
28 /// - %2: start date
23 /// - %2: start date
@@ -44,18 +39,6 QString dateFormat(double sqpRange) noexcept
44 return dateTime.toString(AMDA_TIME_FORMAT);
39 return dateTime.toString(AMDA_TIME_FORMAT);
45 }
40 }
46
41
47 /// Returns the URL of the AMDA server queried for requests, depending on the type of server passed
48 /// as a parameter
49 QString serverURL(const QString &server)
50 {
51 if (server == QString{"amdatest"}) {
52 return AMDA_TEST_SERVER_URL;
53 }
54 else {
55 return AMDA_SERVER_URL;
56 }
57 }
58
59 AmdaResultParser::ValueType valueType(const QString &valueType)
42 AmdaResultParser::ValueType valueType(const QString &valueType)
60 {
43 {
61 if (valueType == QStringLiteral("scalar")) {
44 if (valueType == QStringLiteral("scalar")) {
@@ -190,9 +173,6 void AmdaProvider::retrieveData(QUuid token, const SqpRange &dateTime, const QVa
190 // scalar, vector...
173 // scalar, vector...
191 auto productValueType = valueType(data.value(AMDA_DATA_TYPE_KEY).toString());
174 auto productValueType = valueType(data.value(AMDA_DATA_TYPE_KEY).toString());
192
175
193 // Gets the server being queried to retrieve the product. It's then used to set the server URL
194 auto productServer = data.value(AMDA_SERVER_KEY).toString();
195
196 // /////////// //
176 // /////////// //
197 // Creates URL //
177 // Creates URL //
198 // /////////// //
178 // /////////// //
@@ -200,8 +180,9 void AmdaProvider::retrieveData(QUuid token, const SqpRange &dateTime, const QVa
200 auto startDate = dateFormat(dateTime.m_TStart);
180 auto startDate = dateFormat(dateTime.m_TStart);
201 auto endDate = dateFormat(dateTime.m_TEnd);
181 auto endDate = dateFormat(dateTime.m_TEnd);
202
182
203 auto url = QUrl{
183 QVariantHash urlProperties{{AMDA_SERVER_KEY, data.value(AMDA_SERVER_KEY)}};
204 QString{AMDA_URL_FORMAT}.arg(serverURL(productServer), startDate, endDate, productId)};
184 auto url = QUrl{QString{AMDA_URL_FORMAT}.arg(AmdaServer::instance().url(urlProperties),
185 startDate, endDate, productId)};
205 qCInfo(LOG_AmdaProvider()) << tr("TORM AmdaProvider::retrieveData url:") << url;
186 qCInfo(LOG_AmdaProvider()) << tr("TORM AmdaProvider::retrieveData url:") << url;
206 auto tempFile = std::make_shared<QTemporaryFile>();
187 auto tempFile = std::make_shared<QTemporaryFile>();
207
188
@@ -11,9 +11,17 const QString X_AXIS_UNIT_PROPERTY = QStringLiteral("xAxisUnit");
11 const QString Y_AXIS_UNIT_PROPERTY = QStringLiteral("yAxisUnit");
11 const QString Y_AXIS_UNIT_PROPERTY = QStringLiteral("yAxisUnit");
12 const QString VALUES_UNIT_PROPERTY = QStringLiteral("valuesUnit");
12 const QString VALUES_UNIT_PROPERTY = QStringLiteral("valuesUnit");
13
13
14 namespace {
15
16 const auto PARAMETER_UNITS_REGEX
17 = QRegularExpression{QStringLiteral("\\s*PARAMETER_UNITS\\s*:\\s*(.*)")};
18 }
19
14 const QRegularExpression DEFAULT_X_AXIS_UNIT_REGEX
20 const QRegularExpression DEFAULT_X_AXIS_UNIT_REGEX
15 = QRegularExpression{QStringLiteral("-\\s*Units\\s*:\\s*(.+?)\\s*-")};
21 = QRegularExpression{QStringLiteral("-\\s*Units\\s*:\\s*(.+?)\\s*-")};
16
22
23 const QRegularExpression ALTERNATIVE_X_AXIS_UNIT_REGEX = PARAMETER_UNITS_REGEX;
24
17 const QRegularExpression SPECTROGRAM_END_TIME_REGEX
25 const QRegularExpression SPECTROGRAM_END_TIME_REGEX
18 = QRegularExpression{QStringLiteral("\\s*INTERVAL_STOP\\s*:\\s*(.*)")};
26 = QRegularExpression{QStringLiteral("\\s*INTERVAL_STOP\\s*:\\s*(.*)")};
19
27
@@ -38,5 +46,4 const QRegularExpression SPECTROGRAM_START_TIME_REGEX
38 const QRegularExpression SPECTROGRAM_Y_AXIS_UNIT_REGEX
46 const QRegularExpression SPECTROGRAM_Y_AXIS_UNIT_REGEX
39 = QRegularExpression{QStringLiteral("\\s*PARAMETER_TABLE_UNITS\\[0\\]\\s*:\\s*(.*)")};
47 = QRegularExpression{QStringLiteral("\\s*PARAMETER_TABLE_UNITS\\[0\\]\\s*:\\s*(.*)")};
40
48
41 const QRegularExpression SPECTROGRAM_VALUES_UNIT_REGEX
49 const QRegularExpression SPECTROGRAM_VALUES_UNIT_REGEX = PARAMETER_UNITS_REGEX;
42 = QRegularExpression{QStringLiteral("\\s*PARAMETER_UNITS\\s*:\\s*(.*)")};
@@ -136,7 +136,7 void tryReadResult(std::vector<double> &xAxisData, std::vector<double> &valuesDa
136 * @param properties the properties map in which to put the property extracted from the line
136 * @param properties the properties map in which to put the property extracted from the line
137 * @param key the key to which the property is added in the properties map
137 * @param key the key to which the property is added in the properties map
138 * @param line the line to read to extract the property
138 * @param line the line to read to extract the property
139 * @param regex the expected regex to extract the property. If the line matches this regex, the
139 * @param regexes the expected regexes to extract the property. If the line matches one regex, the
140 * property is generated
140 * property is generated
141 * @param fun the function used to generate the property
141 * @param fun the function used to generate the property
142 * @return true if the property could be generated, false if the line does not match the regex, or
142 * @return true if the property could be generated, false if the line does not match the regex, or
@@ -144,18 +144,24 void tryReadResult(std::vector<double> &xAxisData, std::vector<double> &valuesDa
144 */
144 */
145 template <typename GeneratePropertyFun>
145 template <typename GeneratePropertyFun>
146 bool tryReadProperty(Properties &properties, const QString &key, const QString &line,
146 bool tryReadProperty(Properties &properties, const QString &key, const QString &line,
147 const QRegularExpression &regex, GeneratePropertyFun fun)
147 const std::vector<QRegularExpression> &regexes, GeneratePropertyFun fun)
148 {
148 {
149 if (properties.contains(key)) {
149 if (properties.contains(key)) {
150 return false;
150 return false;
151 }
151 }
152
152
153 auto match = regex.match(line);
153 // Searches for a match among all possible regexes
154 if (match.hasMatch()) {
154 auto hasMatch = false;
155 for (auto regexIt = regexes.cbegin(), end = regexes.cend(); regexIt != end && !hasMatch;
156 ++regexIt) {
157 auto match = regexIt->match(line);
158 auto hasMatch = match.hasMatch();
159 if (hasMatch) {
155 properties.insert(key, fun(match));
160 properties.insert(key, fun(match));
156 }
161 }
162 }
157
163
158 return match.hasMatch();
164 return hasMatch;
159 }
165 }
160
166
161 /**
167 /**
@@ -163,9 +169,9 bool tryReadProperty(Properties &properties, const QString &key, const QString &
163 * @sa tryReadProperty()
169 * @sa tryReadProperty()
164 */
170 */
165 bool tryReadDate(Properties &properties, const QString &key, const QString &line,
171 bool tryReadDate(Properties &properties, const QString &key, const QString &line,
166 const QRegularExpression &regex, bool timeUnit = false)
172 const std::vector<QRegularExpression> &regexes, bool timeUnit = false)
167 {
173 {
168 return tryReadProperty(properties, key, line, regex, [timeUnit](const auto &match) {
174 return tryReadProperty(properties, key, line, regexes, [timeUnit](const auto &match) {
169 return QVariant::fromValue(doubleDate(match.captured(1)));
175 return QVariant::fromValue(doubleDate(match.captured(1)));
170 });
176 });
171 }
177 }
@@ -175,9 +181,9 bool tryReadDate(Properties &properties, const QString &key, const QString &line
175 * @sa tryReadProperty()
181 * @sa tryReadProperty()
176 */
182 */
177 bool tryReadDouble(Properties &properties, const QString &key, const QString &line,
183 bool tryReadDouble(Properties &properties, const QString &key, const QString &line,
178 const QRegularExpression &regex)
184 const std::vector<QRegularExpression> &regexes)
179 {
185 {
180 return tryReadProperty(properties, key, line, regex, [](const auto &match) {
186 return tryReadProperty(properties, key, line, regexes, [](const auto &match) {
181 bool ok;
187 bool ok;
182
188
183 // If the value can't be converted to double, it is set to NaN
189 // If the value can't be converted to double, it is set to NaN
@@ -196,9 +202,10 bool tryReadDouble(Properties &properties, const QString &key, const QString &li
196 * @sa tryReadProperty()
202 * @sa tryReadProperty()
197 */
203 */
198 bool tryReadDoubles(Properties &properties, const QString &key, const QString &line,
204 bool tryReadDoubles(Properties &properties, const QString &key, const QString &line,
199 const QRegularExpression &regex, const QString &sep = QStringLiteral(","))
205 const std::vector<QRegularExpression> &regexes,
206 const QString &sep = QStringLiteral(","))
200 {
207 {
201 return tryReadProperty(properties, key, line, regex, [sep](const auto &match) {
208 return tryReadProperty(properties, key, line, regexes, [sep](const auto &match) {
202 std::vector<double> doubleValues{};
209 std::vector<double> doubleValues{};
203
210
204 // If the value can't be converted to double, it is set to NaN
211 // If the value can't be converted to double, it is set to NaN
@@ -223,9 +230,9 bool tryReadDoubles(Properties &properties, const QString &key, const QString &l
223 * @sa tryReadProperty()
230 * @sa tryReadProperty()
224 */
231 */
225 bool tryReadUnit(Properties &properties, const QString &key, const QString &line,
232 bool tryReadUnit(Properties &properties, const QString &key, const QString &line,
226 const QRegularExpression &regex, bool timeUnit = false)
233 const std::vector<QRegularExpression> &regexes, bool timeUnit = false)
227 {
234 {
228 return tryReadProperty(properties, key, line, regex, [timeUnit](const auto &match) {
235 return tryReadProperty(properties, key, line, regexes, [timeUnit](const auto &match) {
229 return QVariant::fromValue(Unit{match.captured(1), timeUnit});
236 return QVariant::fromValue(Unit{match.captured(1), timeUnit});
230 });
237 });
231 }
238 }
@@ -251,7 +258,8 std::shared_ptr<IDataSeries> ScalarParserHelper::createSeries()
251
258
252 void ScalarParserHelper::readPropertyLine(const QString &line)
259 void ScalarParserHelper::readPropertyLine(const QString &line)
253 {
260 {
254 tryReadUnit(m_Properties, X_AXIS_UNIT_PROPERTY, line, DEFAULT_X_AXIS_UNIT_REGEX, true);
261 tryReadUnit(m_Properties, X_AXIS_UNIT_PROPERTY, line,
262 {DEFAULT_X_AXIS_UNIT_REGEX, ALTERNATIVE_X_AXIS_UNIT_REGEX}, true);
255 }
263 }
256
264
257 void ScalarParserHelper::readResultLine(const QString &line)
265 void ScalarParserHelper::readResultLine(const QString &line)
@@ -321,46 +329,46 void SpectrogramParserHelper::readPropertyLine(const QString &line)
321 // values unit
329 // values unit
322 [&] {
330 [&] {
323 return tryReadUnit(m_Properties, VALUES_UNIT_PROPERTY, line,
331 return tryReadUnit(m_Properties, VALUES_UNIT_PROPERTY, line,
324 SPECTROGRAM_VALUES_UNIT_REGEX);
332 {SPECTROGRAM_VALUES_UNIT_REGEX});
325 },
333 },
326 // y-axis unit
334 // y-axis unit
327 [&] {
335 [&] {
328 return tryReadUnit(m_Properties, Y_AXIS_UNIT_PROPERTY, line,
336 return tryReadUnit(m_Properties, Y_AXIS_UNIT_PROPERTY, line,
329 SPECTROGRAM_Y_AXIS_UNIT_REGEX);
337 {SPECTROGRAM_Y_AXIS_UNIT_REGEX});
330 },
338 },
331 // min sampling
339 // min sampling
332 [&] {
340 [&] {
333 return tryReadDouble(m_Properties, MIN_SAMPLING_PROPERTY, line,
341 return tryReadDouble(m_Properties, MIN_SAMPLING_PROPERTY, line,
334 SPECTROGRAM_MIN_SAMPLING_REGEX);
342 {SPECTROGRAM_MIN_SAMPLING_REGEX});
335 },
343 },
336 // max sampling
344 // max sampling
337 [&] {
345 [&] {
338 return tryReadDouble(m_Properties, MAX_SAMPLING_PROPERTY, line,
346 return tryReadDouble(m_Properties, MAX_SAMPLING_PROPERTY, line,
339 SPECTROGRAM_MAX_SAMPLING_REGEX);
347 {SPECTROGRAM_MAX_SAMPLING_REGEX});
340 },
348 },
341 // fill value
349 // fill value
342 [&] {
350 [&] {
343 return tryReadDouble(m_Properties, FILL_VALUE_PROPERTY, line,
351 return tryReadDouble(m_Properties, FILL_VALUE_PROPERTY, line,
344 SPECTROGRAM_FILL_VALUE_REGEX);
352 {SPECTROGRAM_FILL_VALUE_REGEX});
345 },
353 },
346 // min bounds of each band
354 // min bounds of each band
347 [&] {
355 [&] {
348 return tryReadDoubles(m_Properties, MIN_BANDS_PROPERTY, line,
356 return tryReadDoubles(m_Properties, MIN_BANDS_PROPERTY, line,
349 SPECTROGRAM_MIN_BANDS_REGEX);
357 {SPECTROGRAM_MIN_BANDS_REGEX});
350 },
358 },
351 // max bounds of each band
359 // max bounds of each band
352 [&] {
360 [&] {
353 return tryReadDoubles(m_Properties, MAX_BANDS_PROPERTY, line,
361 return tryReadDoubles(m_Properties, MAX_BANDS_PROPERTY, line,
354 SPECTROGRAM_MAX_BANDS_REGEX);
362 {SPECTROGRAM_MAX_BANDS_REGEX});
355 },
363 },
356 // start time of data
364 // start time of data
357 [&] {
365 [&] {
358 return tryReadDate(m_Properties, START_TIME_PROPERTY, line,
366 return tryReadDate(m_Properties, START_TIME_PROPERTY, line,
359 SPECTROGRAM_START_TIME_REGEX);
367 {SPECTROGRAM_START_TIME_REGEX});
360 },
368 },
361 // end time of data
369 // end time of data
362 [&] {
370 [&] {
363 return tryReadDate(m_Properties, END_TIME_PROPERTY, line, SPECTROGRAM_END_TIME_REGEX);
371 return tryReadDate(m_Properties, END_TIME_PROPERTY, line, {SPECTROGRAM_END_TIME_REGEX});
364 }};
372 }};
365
373
366 for (auto function : functions) {
374 for (auto function : functions) {
@@ -407,7 +415,8 std::shared_ptr<IDataSeries> VectorParserHelper::createSeries()
407
415
408 void VectorParserHelper::readPropertyLine(const QString &line)
416 void VectorParserHelper::readPropertyLine(const QString &line)
409 {
417 {
410 tryReadUnit(m_Properties, X_AXIS_UNIT_PROPERTY, line, DEFAULT_X_AXIS_UNIT_REGEX, true);
418 tryReadUnit(m_Properties, X_AXIS_UNIT_PROPERTY, line,
419 {DEFAULT_X_AXIS_UNIT_REGEX, ALTERNATIVE_X_AXIS_UNIT_REGEX}, true);
411 }
420 }
412
421
413 void VectorParserHelper::readResultLine(const QString &line)
422 void VectorParserHelper::readResultLine(const QString &line)
General Comments 0
You need to be logged in to leave comments. Login now