@@ -0,0 +1,23 | |||||
|
1 | #ifndef SCIQLOP_MOCKDEFS_H | |||
|
2 | #define SCIQLOP_MOCKDEFS_H | |||
|
3 | ||||
|
4 | #include "MockPluginGlobal.h" | |||
|
5 | ||||
|
6 | #include <QString> | |||
|
7 | #include <QVariant> | |||
|
8 | ||||
|
9 | // ////////////// // | |||
|
10 | // Mock constants // | |||
|
11 | // ////////////// // | |||
|
12 | ||||
|
13 | // Metadata for cosinus provider // | |||
|
14 | ||||
|
15 | /// Cosinus frequency (Hz) | |||
|
16 | extern SCIQLOP_MOCKPLUGIN_EXPORT const QString COSINUS_FREQUENCY_KEY; | |||
|
17 | extern SCIQLOP_MOCKPLUGIN_EXPORT const QVariant COSINUS_FREQUENCY_DEFAULT_VALUE; | |||
|
18 | ||||
|
19 | /// Cosinus type ("scalar" or "vector") | |||
|
20 | extern SCIQLOP_MOCKPLUGIN_EXPORT const QString COSINUS_TYPE_KEY; | |||
|
21 | extern SCIQLOP_MOCKPLUGIN_EXPORT const QVariant COSINUS_TYPE_DEFAULT_VALUE; | |||
|
22 | ||||
|
23 | #endif // SCIQLOP_MOCKDEFS_H |
@@ -0,0 +1,7 | |||||
|
1 | #include "MockDefs.h" | |||
|
2 | ||||
|
3 | const QString COSINUS_FREQUENCY_KEY = QStringLiteral("cosinusFrequency"); | |||
|
4 | const QVariant COSINUS_FREQUENCY_DEFAULT_VALUE = 60.; | |||
|
5 | ||||
|
6 | const QString COSINUS_TYPE_KEY = QStringLiteral("cosinusType"); | |||
|
7 | const QVariant COSINUS_TYPE_DEFAULT_VALUE = QStringLiteral("scalar"); |
@@ -1,116 +1,124 | |||||
1 | #include "CosinusProvider.h" |
|
1 | #include "CosinusProvider.h" | |
|
2 | #include "MockDefs.h" | |||
2 |
|
3 | |||
3 | #include <Data/DataProviderParameters.h> |
|
4 | #include <Data/DataProviderParameters.h> | |
4 | #include <Data/ScalarSeries.h> |
|
5 | #include <Data/ScalarSeries.h> | |
5 |
|
6 | |||
6 | #include <cmath> |
|
7 | #include <cmath> | |
7 |
|
8 | |||
8 | #include <QFuture> |
|
9 | #include <QFuture> | |
9 | #include <QThread> |
|
10 | #include <QThread> | |
10 | #include <QtConcurrent/QtConcurrent> |
|
11 | #include <QtConcurrent/QtConcurrent> | |
11 |
|
12 | |||
12 | Q_LOGGING_CATEGORY(LOG_CosinusProvider, "CosinusProvider") |
|
13 | Q_LOGGING_CATEGORY(LOG_CosinusProvider, "CosinusProvider") | |
13 |
|
14 | |||
14 | std::shared_ptr<IDataProvider> CosinusProvider::clone() const |
|
15 | std::shared_ptr<IDataProvider> CosinusProvider::clone() const | |
15 | { |
|
16 | { | |
16 | // No copy is made in clone |
|
17 | // No copy is made in clone | |
17 | return std::make_shared<CosinusProvider>(); |
|
18 | return std::make_shared<CosinusProvider>(); | |
18 | } |
|
19 | } | |
19 |
|
20 | |||
20 | std::shared_ptr<IDataSeries> CosinusProvider::retrieveData(QUuid acqIdentifier, |
|
21 | std::shared_ptr<IDataSeries> CosinusProvider::retrieveData(QUuid acqIdentifier, | |
21 | const SqpRange &dataRangeRequested, |
|
22 | const SqpRange &dataRangeRequested, | |
22 | const QVariantHash &data) |
|
23 | const QVariantHash &data) | |
23 | { |
|
24 | { | |
24 | // TODO: Add Mutex |
|
25 | // TODO: Add Mutex | |
25 | auto dataIndex = 0; |
|
26 | auto dataIndex = 0; | |
26 |
|
27 | |||
|
28 | // Retrieves frequency | |||
|
29 | auto freqVariant = data.value(COSINUS_FREQUENCY_KEY, COSINUS_FREQUENCY_DEFAULT_VALUE); | |||
|
30 | if (!freqVariant.canConvert<double>()) { | |||
|
31 | qCCritical(LOG_CosinusProvider()) << tr("Can't retrieve data: invalid frequency"); | |||
|
32 | return nullptr; | |||
|
33 | } | |||
|
34 | ||||
27 | // Gets the timerange from the parameters |
|
35 | // Gets the timerange from the parameters | |
28 |
double freq = |
|
36 | double freq = freqVariant.toDouble(); | |
29 |
double start = std::ceil(dataRangeRequested.m_TStart * freq); |
|
37 | double start = std::ceil(dataRangeRequested.m_TStart * freq); | |
30 |
double end = std::floor(dataRangeRequested.m_TEnd * freq); |
|
38 | double end = std::floor(dataRangeRequested.m_TEnd * freq); | |
31 |
|
39 | |||
32 | // We assure that timerange is valid |
|
40 | // We assure that timerange is valid | |
33 | if (end < start) { |
|
41 | if (end < start) { | |
34 | std::swap(start, end); |
|
42 | std::swap(start, end); | |
35 | } |
|
43 | } | |
36 |
|
44 | |||
37 | // Generates scalar series containing cosinus values (one value per second, end value is |
|
45 | // Generates scalar series containing cosinus values (one value per second, end value is | |
38 | // included) |
|
46 | // included) | |
39 | auto dataCount = end - start + 1; |
|
47 | auto dataCount = end - start + 1; | |
40 |
|
48 | |||
41 | auto xAxisData = std::vector<double>{}; |
|
49 | auto xAxisData = std::vector<double>{}; | |
42 | xAxisData.resize(dataCount); |
|
50 | xAxisData.resize(dataCount); | |
43 |
|
51 | |||
44 | auto valuesData = std::vector<double>{}; |
|
52 | auto valuesData = std::vector<double>{}; | |
45 | valuesData.resize(dataCount); |
|
53 | valuesData.resize(dataCount); | |
46 |
|
54 | |||
47 | int progress = 0; |
|
55 | int progress = 0; | |
48 | auto progressEnd = dataCount; |
|
56 | auto progressEnd = dataCount; | |
49 | for (auto time = start; time <= end; ++time, ++dataIndex) { |
|
57 | for (auto time = start; time <= end; ++time, ++dataIndex) { | |
50 | auto it = m_VariableToEnableProvider.find(acqIdentifier); |
|
58 | auto it = m_VariableToEnableProvider.find(acqIdentifier); | |
51 | if (it != m_VariableToEnableProvider.end() && it.value()) { |
|
59 | if (it != m_VariableToEnableProvider.end() && it.value()) { | |
52 | const auto timeOnFreq = time / freq; |
|
60 | const auto timeOnFreq = time / freq; | |
53 |
|
61 | |||
54 | xAxisData[dataIndex] = timeOnFreq; |
|
62 | xAxisData[dataIndex] = timeOnFreq; | |
55 | valuesData[dataIndex] = std::cos(timeOnFreq); |
|
63 | valuesData[dataIndex] = std::cos(timeOnFreq); | |
56 |
|
64 | |||
57 | // progression |
|
65 | // progression | |
58 | int currentProgress = (time - start) * 100.0 / progressEnd; |
|
66 | int currentProgress = (time - start) * 100.0 / progressEnd; | |
59 | if (currentProgress != progress) { |
|
67 | if (currentProgress != progress) { | |
60 | progress = currentProgress; |
|
68 | progress = currentProgress; | |
61 |
|
69 | |||
62 | emit dataProvidedProgress(acqIdentifier, progress); |
|
70 | emit dataProvidedProgress(acqIdentifier, progress); | |
63 | qCInfo(LOG_CosinusProvider()) << "TORM: CosinusProvider::retrieveData" |
|
71 | qCInfo(LOG_CosinusProvider()) << "TORM: CosinusProvider::retrieveData" | |
64 | << QThread::currentThread()->objectName() << progress; |
|
72 | << QThread::currentThread()->objectName() << progress; | |
65 | // NOTE: Try to use multithread if possible |
|
73 | // NOTE: Try to use multithread if possible | |
66 | } |
|
74 | } | |
67 | } |
|
75 | } | |
68 | else { |
|
76 | else { | |
69 | if (!it.value()) { |
|
77 | if (!it.value()) { | |
70 | qCDebug(LOG_CosinusProvider()) |
|
78 | qCDebug(LOG_CosinusProvider()) | |
71 | << "CosinusProvider::retrieveData: ARRET De l'acquisition detectΓ©" |
|
79 | << "CosinusProvider::retrieveData: ARRET De l'acquisition detectΓ©" | |
72 | << end - time; |
|
80 | << end - time; | |
73 | } |
|
81 | } | |
74 | } |
|
82 | } | |
75 | } |
|
83 | } | |
76 | if (progress != 100) { |
|
84 | if (progress != 100) { | |
77 | // We can close progression beacause all data has been retrieved |
|
85 | // We can close progression beacause all data has been retrieved | |
78 | emit dataProvidedProgress(acqIdentifier, 100); |
|
86 | emit dataProvidedProgress(acqIdentifier, 100); | |
79 | } |
|
87 | } | |
80 | return std::make_shared<ScalarSeries>(std::move(xAxisData), std::move(valuesData), |
|
88 | return std::make_shared<ScalarSeries>(std::move(xAxisData), std::move(valuesData), | |
81 | Unit{QStringLiteral("t"), true}, Unit{}); |
|
89 | Unit{QStringLiteral("t"), true}, Unit{}); | |
82 | } |
|
90 | } | |
83 |
|
91 | |||
84 | void CosinusProvider::requestDataLoading(QUuid acqIdentifier, |
|
92 | void CosinusProvider::requestDataLoading(QUuid acqIdentifier, | |
85 | const DataProviderParameters ¶meters) |
|
93 | const DataProviderParameters ¶meters) | |
86 | { |
|
94 | { | |
87 | // TODO: Add Mutex |
|
95 | // TODO: Add Mutex | |
88 | m_VariableToEnableProvider[acqIdentifier] = true; |
|
96 | m_VariableToEnableProvider[acqIdentifier] = true; | |
89 | qCDebug(LOG_CosinusProvider()) << "TORM: CosinusProvider::requestDataLoading" |
|
97 | qCDebug(LOG_CosinusProvider()) << "TORM: CosinusProvider::requestDataLoading" | |
90 | << QThread::currentThread()->objectName(); |
|
98 | << QThread::currentThread()->objectName(); | |
91 | // NOTE: Try to use multithread if possible |
|
99 | // NOTE: Try to use multithread if possible | |
92 | const auto times = parameters.m_Times; |
|
100 | const auto times = parameters.m_Times; | |
93 |
|
101 | |||
94 | for (const auto &dateTime : qAsConst(times)) { |
|
102 | for (const auto &dateTime : qAsConst(times)) { | |
95 | if (m_VariableToEnableProvider[acqIdentifier]) { |
|
103 | if (m_VariableToEnableProvider[acqIdentifier]) { | |
96 | auto scalarSeries = this->retrieveData(acqIdentifier, dateTime, parameters.m_Data); |
|
104 | auto scalarSeries = this->retrieveData(acqIdentifier, dateTime, parameters.m_Data); | |
97 | qCDebug(LOG_CosinusProvider()) << "TORM: CosinusProvider::dataProvided"; |
|
105 | qCDebug(LOG_CosinusProvider()) << "TORM: CosinusProvider::dataProvided"; | |
98 | emit dataProvided(acqIdentifier, scalarSeries, dateTime); |
|
106 | emit dataProvided(acqIdentifier, scalarSeries, dateTime); | |
99 | } |
|
107 | } | |
100 | } |
|
108 | } | |
101 | } |
|
109 | } | |
102 |
|
110 | |||
103 | void CosinusProvider::requestDataAborting(QUuid acqIdentifier) |
|
111 | void CosinusProvider::requestDataAborting(QUuid acqIdentifier) | |
104 | { |
|
112 | { | |
105 | // TODO: Add Mutex |
|
113 | // TODO: Add Mutex | |
106 | qCDebug(LOG_CosinusProvider()) << "CosinusProvider::requestDataAborting" << acqIdentifier |
|
114 | qCDebug(LOG_CosinusProvider()) << "CosinusProvider::requestDataAborting" << acqIdentifier | |
107 | << QThread::currentThread()->objectName(); |
|
115 | << QThread::currentThread()->objectName(); | |
108 | auto it = m_VariableToEnableProvider.find(acqIdentifier); |
|
116 | auto it = m_VariableToEnableProvider.find(acqIdentifier); | |
109 | if (it != m_VariableToEnableProvider.end()) { |
|
117 | if (it != m_VariableToEnableProvider.end()) { | |
110 | it.value() = false; |
|
118 | it.value() = false; | |
111 | } |
|
119 | } | |
112 | else { |
|
120 | else { | |
113 | qCWarning(LOG_CosinusProvider()) |
|
121 | qCWarning(LOG_CosinusProvider()) | |
114 | << tr("Aborting progression of inexistant identifier detected !!!"); |
|
122 | << tr("Aborting progression of inexistant identifier detected !!!"); | |
115 | } |
|
123 | } | |
116 | } |
|
124 | } |
@@ -1,79 +1,81 | |||||
1 | #include "MockPlugin.h" |
|
1 | #include "MockPlugin.h" | |
2 | #include "CosinusProvider.h" |
|
2 | #include "CosinusProvider.h" | |
|
3 | #include "MockDefs.h" | |||
3 |
|
4 | |||
4 | #include <DataSource/DataSourceController.h> |
|
5 | #include <DataSource/DataSourceController.h> | |
5 | #include <DataSource/DataSourceItem.h> |
|
6 | #include <DataSource/DataSourceItem.h> | |
6 | #include <DataSource/DataSourceItemAction.h> |
|
7 | #include <DataSource/DataSourceItemAction.h> | |
7 |
|
8 | |||
8 | #include <SqpApplication.h> |
|
9 | #include <SqpApplication.h> | |
9 |
|
10 | |||
10 | Q_LOGGING_CATEGORY(LOG_MockPlugin, "MockPlugin") |
|
11 | Q_LOGGING_CATEGORY(LOG_MockPlugin, "MockPlugin") | |
11 |
|
12 | |||
12 | namespace { |
|
13 | namespace { | |
13 |
|
14 | |||
14 | /// Name of the data source |
|
15 | /// Name of the data source | |
15 | const auto DATA_SOURCE_NAME = QStringLiteral("MMS"); |
|
16 | const auto DATA_SOURCE_NAME = QStringLiteral("MMS"); | |
16 |
|
17 | |||
17 | /// Creates the data provider relative to the plugin |
|
18 | /// Creates the data provider relative to the plugin | |
18 | std::unique_ptr<IDataProvider> createDataProvider() noexcept |
|
19 | std::unique_ptr<IDataProvider> createDataProvider() noexcept | |
19 | { |
|
20 | { | |
20 | return std::make_unique<CosinusProvider>(); |
|
21 | return std::make_unique<CosinusProvider>(); | |
21 | } |
|
22 | } | |
22 |
|
23 | |||
23 |
std::unique_ptr<DataSourceItem> createProductItem(const Q |
|
24 | std::unique_ptr<DataSourceItem> createProductItem(const QVariantHash &data, | |
24 | const QUuid &dataSourceUid) |
|
25 | const QUuid &dataSourceUid) | |
25 | { |
|
26 | { | |
26 |
auto result = std::make_unique<DataSourceItem>(DataSourceItemType::PRODUCT, |
|
27 | auto result = std::make_unique<DataSourceItem>(DataSourceItemType::PRODUCT, data); | |
|
28 | auto productName = data.value(DataSourceItem::NAME_DATA_KEY).toString(); | |||
27 |
|
29 | |||
28 | // Add action to load product from DataSourceController |
|
30 | // Add action to load product from DataSourceController | |
29 | result->addAction(std::make_unique<DataSourceItemAction>( |
|
31 | result->addAction(std::make_unique<DataSourceItemAction>( | |
30 | QObject::tr("Load %1 product").arg(productName), |
|
32 | QObject::tr("Load %1 product").arg(productName), | |
31 | [productName, dataSourceUid](DataSourceItem &item) { |
|
33 | [productName, dataSourceUid](DataSourceItem &item) { | |
32 | if (auto app = sqpApp) { |
|
34 | if (auto app = sqpApp) { | |
33 | app->dataSourceController().loadProductItem(dataSourceUid, item); |
|
35 | app->dataSourceController().loadProductItem(dataSourceUid, item); | |
34 | } |
|
36 | } | |
35 | })); |
|
37 | })); | |
36 |
|
38 | |||
37 | return result; |
|
39 | return result; | |
38 | } |
|
40 | } | |
39 |
|
41 | |||
40 | /// Creates the data source item relative to the plugin |
|
42 | /// Creates the data source item relative to the plugin | |
41 | std::unique_ptr<DataSourceItem> createDataSourceItem(const QUuid &dataSourceUid) noexcept |
|
43 | std::unique_ptr<DataSourceItem> createDataSourceItem(const QUuid &dataSourceUid) noexcept | |
42 | { |
|
44 | { | |
43 | // Magnetic field products |
|
45 | // Magnetic field products | |
44 | auto magneticFieldFolder = std::make_unique<DataSourceItem>(DataSourceItemType::NODE, |
|
46 | auto magneticFieldFolder = std::make_unique<DataSourceItem>(DataSourceItemType::NODE, | |
45 | QStringLiteral("Magnetic field")); |
|
47 | QStringLiteral("Magnetic field")); | |
46 | magneticFieldFolder->appendChild(createProductItem(QStringLiteral("FGM"), dataSourceUid)); |
|
48 | magneticFieldFolder->appendChild(createProductItem(QStringLiteral("FGM"), dataSourceUid)); | |
47 | magneticFieldFolder->appendChild(createProductItem(QStringLiteral("SC"), dataSourceUid)); |
|
49 | magneticFieldFolder->appendChild(createProductItem(QStringLiteral("SC"), dataSourceUid)); | |
48 |
|
50 | |||
49 | // Electric field products |
|
51 | // Electric field products | |
50 | auto electricFieldFolder = std::make_unique<DataSourceItem>(DataSourceItemType::NODE, |
|
52 | auto electricFieldFolder = std::make_unique<DataSourceItem>(DataSourceItemType::NODE, | |
51 | QStringLiteral("Electric field")); |
|
53 | QStringLiteral("Electric field")); | |
52 |
|
54 | |||
53 | // Root |
|
55 | // Root | |
54 | auto root = std::make_unique<DataSourceItem>(DataSourceItemType::NODE, DATA_SOURCE_NAME); |
|
56 | auto root = std::make_unique<DataSourceItem>(DataSourceItemType::NODE, DATA_SOURCE_NAME); | |
55 | root->appendChild(std::move(magneticFieldFolder)); |
|
57 | root->appendChild(std::move(magneticFieldFolder)); | |
56 | root->appendChild(std::move(electricFieldFolder)); |
|
58 | root->appendChild(std::move(electricFieldFolder)); | |
57 |
|
59 | |||
58 | return root; |
|
60 | return root; | |
59 | } |
|
61 | } | |
60 |
|
62 | |||
61 | } // namespace |
|
63 | } // namespace | |
62 |
|
64 | |||
63 | void MockPlugin::initialize() |
|
65 | void MockPlugin::initialize() | |
64 | { |
|
66 | { | |
65 | if (auto app = sqpApp) { |
|
67 | if (auto app = sqpApp) { | |
66 | // Registers to the data source controller |
|
68 | // Registers to the data source controller | |
67 | auto &dataSourceController = app->dataSourceController(); |
|
69 | auto &dataSourceController = app->dataSourceController(); | |
68 | auto dataSourceUid = dataSourceController.registerDataSource(DATA_SOURCE_NAME); |
|
70 | auto dataSourceUid = dataSourceController.registerDataSource(DATA_SOURCE_NAME); | |
69 |
|
71 | |||
70 | // Sets data source tree |
|
72 | // Sets data source tree | |
71 | dataSourceController.setDataSourceItem(dataSourceUid, createDataSourceItem(dataSourceUid)); |
|
73 | dataSourceController.setDataSourceItem(dataSourceUid, createDataSourceItem(dataSourceUid)); | |
72 |
|
74 | |||
73 | // Sets data provider |
|
75 | // Sets data provider | |
74 | dataSourceController.setDataProvider(dataSourceUid, createDataProvider()); |
|
76 | dataSourceController.setDataProvider(dataSourceUid, createDataProvider()); | |
75 | } |
|
77 | } | |
76 | else { |
|
78 | else { | |
77 | qCWarning(LOG_MockPlugin()) << tr("Can't access to SciQlop application"); |
|
79 | qCWarning(LOG_MockPlugin()) << tr("Can't access to SciQlop application"); | |
78 | } |
|
80 | } | |
79 | } |
|
81 | } |
General Comments 0
You need to be logged in to leave comments.
Login now