@@ -1,28 +1,33 | |||||
1 | #ifndef SCIQLOP_COSINUSPROVIDER_H |
|
1 | #ifndef SCIQLOP_COSINUSPROVIDER_H | |
2 | #define SCIQLOP_COSINUSPROVIDER_H |
|
2 | #define SCIQLOP_COSINUSPROVIDER_H | |
3 |
|
3 | |||
4 | #include "MockPluginGlobal.h" |
|
4 | #include "MockPluginGlobal.h" | |
5 |
|
5 | |||
6 | #include <Data/IDataProvider.h> |
|
6 | #include <Data/IDataProvider.h> | |
7 |
|
7 | |||
8 | #include <QLoggingCategory> |
|
8 | #include <QLoggingCategory> | |
|
9 | #include <QUuid> | |||
9 |
|
10 | |||
|
11 | #include <QHash> | |||
10 | Q_DECLARE_LOGGING_CATEGORY(LOG_CosinusProvider) |
|
12 | Q_DECLARE_LOGGING_CATEGORY(LOG_CosinusProvider) | |
11 |
|
13 | |||
12 | /** |
|
14 | /** | |
13 | * @brief The CosinusProvider class is an example of how a data provider can generate data |
|
15 | * @brief The CosinusProvider class is an example of how a data provider can generate data | |
14 | */ |
|
16 | */ | |
15 | class SCIQLOP_MOCKPLUGIN_EXPORT CosinusProvider : public IDataProvider { |
|
17 | class SCIQLOP_MOCKPLUGIN_EXPORT CosinusProvider : public IDataProvider { | |
16 | public: |
|
18 | public: | |
|
19 | /// @sa IDataProvider::requestDataLoading(). The current impl isn't thread safe. | |||
17 | void requestDataLoading(QUuid token, const DataProviderParameters ¶meters) override; |
|
20 | void requestDataLoading(QUuid token, const DataProviderParameters ¶meters) override; | |
18 |
|
21 | |||
19 |
|
22 | |||
|
23 | /// @sa IDataProvider::requestDataAborting(). The current impl isn't thread safe. | |||
20 | void requestDataAborting(QUuid identifier) override; |
|
24 | void requestDataAborting(QUuid identifier) override; | |
21 |
|
25 | |||
22 |
|
26 | |||
23 | private: |
|
27 | private: | |
24 | /// @sa IDataProvider::retrieveData() |
|
28 | std::shared_ptr<IDataSeries> retrieveData(QUuid token, const SqpDateTime &dateTime); | |
25 | std::shared_ptr<IDataSeries> retrieveData(const SqpDateTime &dateTime) const; |
|
29 | ||
|
30 | QHash<QUuid, bool> m_VariableToEnableProvider; | |||
26 | }; |
|
31 | }; | |
27 |
|
32 | |||
28 | #endif // SCIQLOP_COSINUSPROVIDER_H |
|
33 | #endif // SCIQLOP_COSINUSPROVIDER_H |
@@ -1,53 +1,95 | |||||
1 | #include "CosinusProvider.h" |
|
1 | #include "CosinusProvider.h" | |
2 |
|
2 | |||
3 | #include <Data/DataProviderParameters.h> |
|
3 | #include <Data/DataProviderParameters.h> | |
4 | #include <Data/ScalarSeries.h> |
|
4 | #include <Data/ScalarSeries.h> | |
5 |
|
5 | |||
6 | #include <cmath> |
|
6 | #include <cmath> | |
7 |
|
7 | |||
8 | #include <QDateTime> |
|
8 | #include <QDateTime> | |
|
9 | #include <QFuture> | |||
9 | #include <QThread> |
|
10 | #include <QThread> | |
|
11 | #include <QtConcurrent/QtConcurrent> | |||
10 |
|
12 | |||
11 | Q_LOGGING_CATEGORY(LOG_CosinusProvider, "CosinusProvider") |
|
13 | Q_LOGGING_CATEGORY(LOG_CosinusProvider, "CosinusProvider") | |
12 |
|
14 | |||
13 |
std::shared_ptr<IDataSeries> CosinusProvider::retrieveData(const SqpDateTime &dateTime) |
|
15 | std::shared_ptr<IDataSeries> CosinusProvider::retrieveData(QUuid token, const SqpDateTime &dateTime) | |
14 | { |
|
16 | { | |
|
17 | // TODO: Add Mutex | |||
15 | auto dataIndex = 0; |
|
18 | auto dataIndex = 0; | |
16 |
|
19 | |||
17 | // Gets the timerange from the parameters |
|
20 | // Gets the timerange from the parameters | |
18 | double freq = 100.0; |
|
21 | double freq = 100.0; | |
19 | double start = dateTime.m_TStart * freq; // 100 htz |
|
22 | double start = dateTime.m_TStart * freq; // 100 htz | |
20 | double end = dateTime.m_TEnd * freq; // 100 htz |
|
23 | double end = dateTime.m_TEnd * freq; // 100 htz | |
21 |
|
24 | |||
22 | // We assure that timerange is valid |
|
25 | // We assure that timerange is valid | |
23 | if (end < start) { |
|
26 | if (end < start) { | |
24 | std::swap(start, end); |
|
27 | std::swap(start, end); | |
25 | } |
|
28 | } | |
26 |
|
29 | |||
27 | // Generates scalar series containing cosinus values (one value per second) |
|
30 | // Generates scalar series containing cosinus values (one value per second) | |
28 | auto scalarSeries |
|
31 | auto scalarSeries | |
29 | = std::make_shared<ScalarSeries>(end - start, Unit{QStringLiteral("t"), true}, Unit{}); |
|
32 | = std::make_shared<ScalarSeries>(end - start, Unit{QStringLiteral("t"), true}, Unit{}); | |
30 |
|
33 | |||
|
34 | ||||
|
35 | int progress = 0; | |||
|
36 | auto progressEnd = end - start; | |||
31 | for (auto time = start; time < end; ++time, ++dataIndex) { |
|
37 | for (auto time = start; time < end; ++time, ++dataIndex) { | |
32 | const auto timeOnFreq = time / freq; |
|
38 | auto it = m_VariableToEnableProvider.find(token); | |
33 | scalarSeries->setData(dataIndex, timeOnFreq, std::cos(timeOnFreq)); |
|
39 | if (it != m_VariableToEnableProvider.end() && it.value()) { | |
|
40 | const auto timeOnFreq = time / freq; | |||
|
41 | scalarSeries->setData(dataIndex, timeOnFreq, std::cos(timeOnFreq)); | |||
|
42 | ||||
|
43 | // progression | |||
|
44 | int currentProgress = (time - start) * 100.0 / progressEnd; | |||
|
45 | if (currentProgress != progress) { | |||
|
46 | progress = currentProgress; | |||
|
47 | ||||
|
48 | emit dataProvidedProgress(token, progress); | |||
|
49 | } | |||
|
50 | } | |||
|
51 | else { | |||
|
52 | if (!it.value()) { | |||
|
53 | qCDebug(LOG_CosinusProvider()) | |||
|
54 | << "CosinusProvider::retrieveData: ARRET De l'acquisition detectΓ©" | |||
|
55 | << end - time; | |||
|
56 | } | |||
|
57 | } | |||
34 | } |
|
58 | } | |
|
59 | emit dataProvidedProgress(token, 0.0); | |||
|
60 | ||||
|
61 | ||||
35 | return scalarSeries; |
|
62 | return scalarSeries; | |
36 | } |
|
63 | } | |
37 |
|
64 | |||
38 | void CosinusProvider::requestDataLoading(QUuid token, const DataProviderParameters ¶meters) |
|
65 | void CosinusProvider::requestDataLoading(QUuid token, const DataProviderParameters ¶meters) | |
39 | { |
|
66 | { | |
|
67 | // TODO: Add Mutex | |||
|
68 | m_VariableToEnableProvider[token] = true; | |||
40 | qCDebug(LOG_CosinusProvider()) << "CosinusProvider::requestDataLoading" |
|
69 | qCDebug(LOG_CosinusProvider()) << "CosinusProvider::requestDataLoading" | |
41 | << QThread::currentThread()->objectName(); |
|
70 | << QThread::currentThread()->objectName(); | |
42 | // NOTE: Try to use multithread if possible |
|
71 | // NOTE: Try to use multithread if possible | |
43 | const auto times = parameters.m_Times; |
|
72 | const auto times = parameters.m_Times; | |
|
73 | ||||
44 | for (const auto &dateTime : qAsConst(times)) { |
|
74 | for (const auto &dateTime : qAsConst(times)) { | |
45 | auto scalarSeries = this->retrieveData(dateTime); |
|
75 | if (m_VariableToEnableProvider[token]) { | |
46 | emit dataProvided(token, scalarSeries, dateTime); |
|
76 | auto scalarSeries = this->retrieveData(token, dateTime); | |
|
77 | emit dataProvided(token, scalarSeries, dateTime); | |||
|
78 | } | |||
47 | } |
|
79 | } | |
48 | } |
|
80 | } | |
49 |
|
81 | |||
50 | void CosinusProvider::requestDataAborting(QUuid identifier) |
|
82 | void CosinusProvider::requestDataAborting(QUuid identifier) | |
51 | { |
|
83 | { | |
52 | // TODO |
|
84 | // TODO: Add Mutex | |
|
85 | qCDebug(LOG_CosinusProvider()) << "CosinusProvider::requestDataAborting" << identifier | |||
|
86 | << QThread::currentThread()->objectName(); | |||
|
87 | auto it = m_VariableToEnableProvider.find(identifier); | |||
|
88 | if (it != m_VariableToEnableProvider.end()) { | |||
|
89 | it.value() = false; | |||
|
90 | } | |||
|
91 | else { | |||
|
92 | qCWarning(LOG_CosinusProvider()) | |||
|
93 | << tr("Aborting progression of inexistant identifier detected !!!"); | |||
|
94 | } | |||
53 | } |
|
95 | } |
General Comments 0
You need to be logged in to leave comments.
Login now