@@ -1,28 +1,33 | |||
|
1 | 1 | #ifndef SCIQLOP_COSINUSPROVIDER_H |
|
2 | 2 | #define SCIQLOP_COSINUSPROVIDER_H |
|
3 | 3 | |
|
4 | 4 | #include "MockPluginGlobal.h" |
|
5 | 5 | |
|
6 | 6 | #include <Data/IDataProvider.h> |
|
7 | 7 | |
|
8 | 8 | #include <QLoggingCategory> |
|
9 | #include <QUuid> | |
|
9 | 10 | |
|
11 | #include <QHash> | |
|
10 | 12 | Q_DECLARE_LOGGING_CATEGORY(LOG_CosinusProvider) |
|
11 | 13 | |
|
12 | 14 | /** |
|
13 | 15 | * @brief The CosinusProvider class is an example of how a data provider can generate data |
|
14 | 16 | */ |
|
15 | 17 | class SCIQLOP_MOCKPLUGIN_EXPORT CosinusProvider : public IDataProvider { |
|
16 | 18 | public: |
|
19 | /// @sa IDataProvider::requestDataLoading(). The current impl isn't thread safe. | |
|
17 | 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 | 24 | void requestDataAborting(QUuid identifier) override; |
|
21 | 25 | |
|
22 | 26 | |
|
23 | 27 | private: |
|
24 | /// @sa IDataProvider::retrieveData() | |
|
25 | std::shared_ptr<IDataSeries> retrieveData(const SqpDateTime &dateTime) const; | |
|
28 | std::shared_ptr<IDataSeries> retrieveData(QUuid token, const SqpDateTime &dateTime); | |
|
29 | ||
|
30 | QHash<QUuid, bool> m_VariableToEnableProvider; | |
|
26 | 31 | }; |
|
27 | 32 | |
|
28 | 33 | #endif // SCIQLOP_COSINUSPROVIDER_H |
@@ -1,53 +1,95 | |||
|
1 | 1 | #include "CosinusProvider.h" |
|
2 | 2 | |
|
3 | 3 | #include <Data/DataProviderParameters.h> |
|
4 | 4 | #include <Data/ScalarSeries.h> |
|
5 | 5 | |
|
6 | 6 | #include <cmath> |
|
7 | 7 | |
|
8 | 8 | #include <QDateTime> |
|
9 | #include <QFuture> | |
|
9 | 10 | #include <QThread> |
|
11 | #include <QtConcurrent/QtConcurrent> | |
|
10 | 12 | |
|
11 | 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 | 18 | auto dataIndex = 0; |
|
16 | 19 | |
|
17 | 20 | // Gets the timerange from the parameters |
|
18 | 21 | double freq = 100.0; |
|
19 | 22 | double start = dateTime.m_TStart * freq; // 100 htz |
|
20 | 23 | double end = dateTime.m_TEnd * freq; // 100 htz |
|
21 | 24 | |
|
22 | 25 | // We assure that timerange is valid |
|
23 | 26 | if (end < start) { |
|
24 | 27 | std::swap(start, end); |
|
25 | 28 | } |
|
26 | 29 | |
|
27 | 30 | // Generates scalar series containing cosinus values (one value per second) |
|
28 | 31 | auto scalarSeries |
|
29 | 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 | 37 | for (auto time = start; time < end; ++time, ++dataIndex) { |
|
38 | auto it = m_VariableToEnableProvider.find(token); | |
|
39 | if (it != m_VariableToEnableProvider.end() && it.value()) { | |
|
32 | 40 | const auto timeOnFreq = time / freq; |
|
33 | 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 | 62 | return scalarSeries; |
|
36 | 63 | } |
|
37 | 64 | |
|
38 | 65 | void CosinusProvider::requestDataLoading(QUuid token, const DataProviderParameters ¶meters) |
|
39 | 66 | { |
|
67 | // TODO: Add Mutex | |
|
68 | m_VariableToEnableProvider[token] = true; | |
|
40 | 69 | qCDebug(LOG_CosinusProvider()) << "CosinusProvider::requestDataLoading" |
|
41 | 70 | << QThread::currentThread()->objectName(); |
|
42 | 71 | // NOTE: Try to use multithread if possible |
|
43 | 72 | const auto times = parameters.m_Times; |
|
73 | ||
|
44 | 74 | for (const auto &dateTime : qAsConst(times)) { |
|
45 | auto scalarSeries = this->retrieveData(dateTime); | |
|
75 | if (m_VariableToEnableProvider[token]) { | |
|
76 | auto scalarSeries = this->retrieveData(token, dateTime); | |
|
46 | 77 | emit dataProvided(token, scalarSeries, dateTime); |
|
47 | 78 | } |
|
48 | 79 | } |
|
80 | } | |
|
49 | 81 | |
|
50 | 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