##// END OF EJS Templates
Updates cosinus provider to handle metadata
Alexandre Leroux -
r781:f40c95a9e362
parent child
Show More
@@ -1,36 +1,36
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 #include <QUuid>
10
10
11 #include <QHash>
11 #include <QHash>
12 Q_DECLARE_LOGGING_CATEGORY(LOG_CosinusProvider)
12 Q_DECLARE_LOGGING_CATEGORY(LOG_CosinusProvider)
13
13
14 /**
14 /**
15 * @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
16 */
16 */
17 class SCIQLOP_MOCKPLUGIN_EXPORT CosinusProvider : public IDataProvider {
17 class SCIQLOP_MOCKPLUGIN_EXPORT CosinusProvider : public IDataProvider {
18 public:
18 public:
19 std::shared_ptr<IDataProvider> clone() const override;
19 std::shared_ptr<IDataProvider> clone() const override;
20
20
21 /// @sa IDataProvider::requestDataLoading(). The current impl isn't thread safe.
21 /// @sa IDataProvider::requestDataLoading(). The current impl isn't thread safe.
22 void requestDataLoading(QUuid acqIdentifier, const DataProviderParameters &parameters) override;
22 void requestDataLoading(QUuid acqIdentifier, const DataProviderParameters &parameters) override;
23
23
24
24
25 /// @sa IDataProvider::requestDataAborting(). The current impl isn't thread safe.
25 /// @sa IDataProvider::requestDataAborting(). The current impl isn't thread safe.
26 void requestDataAborting(QUuid acqIdentifier) override;
26 void requestDataAborting(QUuid acqIdentifier) override;
27
27
28
28
29 private:
29 private:
30 std::shared_ptr<IDataSeries> retrieveData(QUuid acqIdentifier,
30 std::shared_ptr<IDataSeries>
31 const SqpRange &dataRangeRequested);
31 retrieveData(QUuid acqIdentifier, const SqpRange &dataRangeRequested, const QVariantHash &data);
32
32
33 QHash<QUuid, bool> m_VariableToEnableProvider;
33 QHash<QUuid, bool> m_VariableToEnableProvider;
34 };
34 };
35
35
36 #endif // SCIQLOP_COSINUSPROVIDER_H
36 #endif // SCIQLOP_COSINUSPROVIDER_H
@@ -1,115 +1,116
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 <QFuture>
8 #include <QFuture>
9 #include <QThread>
9 #include <QThread>
10 #include <QtConcurrent/QtConcurrent>
10 #include <QtConcurrent/QtConcurrent>
11
11
12 Q_LOGGING_CATEGORY(LOG_CosinusProvider, "CosinusProvider")
12 Q_LOGGING_CATEGORY(LOG_CosinusProvider, "CosinusProvider")
13
13
14 std::shared_ptr<IDataProvider> CosinusProvider::clone() const
14 std::shared_ptr<IDataProvider> CosinusProvider::clone() const
15 {
15 {
16 // No copy is made in clone
16 // No copy is made in clone
17 return std::make_shared<CosinusProvider>();
17 return std::make_shared<CosinusProvider>();
18 }
18 }
19
19
20 std::shared_ptr<IDataSeries> CosinusProvider::retrieveData(QUuid acqIdentifier,
20 std::shared_ptr<IDataSeries> CosinusProvider::retrieveData(QUuid acqIdentifier,
21 const SqpRange &dataRangeRequested)
21 const SqpRange &dataRangeRequested,
22 const QVariantHash &data)
22 {
23 {
23 // TODO: Add Mutex
24 // TODO: Add Mutex
24 auto dataIndex = 0;
25 auto dataIndex = 0;
25
26
26 // Gets the timerange from the parameters
27 // Gets the timerange from the parameters
27 double freq = 100.0;
28 double freq = 100.0;
28 double start = std::ceil(dataRangeRequested.m_TStart * freq); // 100 htz
29 double start = std::ceil(dataRangeRequested.m_TStart * freq); // 100 htz
29 double end = std::floor(dataRangeRequested.m_TEnd * freq); // 100 htz
30 double end = std::floor(dataRangeRequested.m_TEnd * freq); // 100 htz
30
31
31 // We assure that timerange is valid
32 // We assure that timerange is valid
32 if (end < start) {
33 if (end < start) {
33 std::swap(start, end);
34 std::swap(start, end);
34 }
35 }
35
36
36 // Generates scalar series containing cosinus values (one value per second, end value is
37 // Generates scalar series containing cosinus values (one value per second, end value is
37 // included)
38 // included)
38 auto dataCount = end - start + 1;
39 auto dataCount = end - start + 1;
39
40
40 auto xAxisData = std::vector<double>{};
41 auto xAxisData = std::vector<double>{};
41 xAxisData.resize(dataCount);
42 xAxisData.resize(dataCount);
42
43
43 auto valuesData = std::vector<double>{};
44 auto valuesData = std::vector<double>{};
44 valuesData.resize(dataCount);
45 valuesData.resize(dataCount);
45
46
46 int progress = 0;
47 int progress = 0;
47 auto progressEnd = dataCount;
48 auto progressEnd = dataCount;
48 for (auto time = start; time <= end; ++time, ++dataIndex) {
49 for (auto time = start; time <= end; ++time, ++dataIndex) {
49 auto it = m_VariableToEnableProvider.find(acqIdentifier);
50 auto it = m_VariableToEnableProvider.find(acqIdentifier);
50 if (it != m_VariableToEnableProvider.end() && it.value()) {
51 if (it != m_VariableToEnableProvider.end() && it.value()) {
51 const auto timeOnFreq = time / freq;
52 const auto timeOnFreq = time / freq;
52
53
53 xAxisData[dataIndex] = timeOnFreq;
54 xAxisData[dataIndex] = timeOnFreq;
54 valuesData[dataIndex] = std::cos(timeOnFreq);
55 valuesData[dataIndex] = std::cos(timeOnFreq);
55
56
56 // progression
57 // progression
57 int currentProgress = (time - start) * 100.0 / progressEnd;
58 int currentProgress = (time - start) * 100.0 / progressEnd;
58 if (currentProgress != progress) {
59 if (currentProgress != progress) {
59 progress = currentProgress;
60 progress = currentProgress;
60
61
61 emit dataProvidedProgress(acqIdentifier, progress);
62 emit dataProvidedProgress(acqIdentifier, progress);
62 qCInfo(LOG_CosinusProvider()) << "TORM: CosinusProvider::retrieveData"
63 qCInfo(LOG_CosinusProvider()) << "TORM: CosinusProvider::retrieveData"
63 << QThread::currentThread()->objectName() << progress;
64 << QThread::currentThread()->objectName() << progress;
64 // NOTE: Try to use multithread if possible
65 // NOTE: Try to use multithread if possible
65 }
66 }
66 }
67 }
67 else {
68 else {
68 if (!it.value()) {
69 if (!it.value()) {
69 qCDebug(LOG_CosinusProvider())
70 qCDebug(LOG_CosinusProvider())
70 << "CosinusProvider::retrieveData: ARRET De l'acquisition detectΓ©"
71 << "CosinusProvider::retrieveData: ARRET De l'acquisition detectΓ©"
71 << end - time;
72 << end - time;
72 }
73 }
73 }
74 }
74 }
75 }
75 if (progress != 100) {
76 if (progress != 100) {
76 // We can close progression beacause all data has been retrieved
77 // We can close progression beacause all data has been retrieved
77 emit dataProvidedProgress(acqIdentifier, 100);
78 emit dataProvidedProgress(acqIdentifier, 100);
78 }
79 }
79 return std::make_shared<ScalarSeries>(std::move(xAxisData), std::move(valuesData),
80 return std::make_shared<ScalarSeries>(std::move(xAxisData), std::move(valuesData),
80 Unit{QStringLiteral("t"), true}, Unit{});
81 Unit{QStringLiteral("t"), true}, Unit{});
81 }
82 }
82
83
83 void CosinusProvider::requestDataLoading(QUuid acqIdentifier,
84 void CosinusProvider::requestDataLoading(QUuid acqIdentifier,
84 const DataProviderParameters &parameters)
85 const DataProviderParameters &parameters)
85 {
86 {
86 // TODO: Add Mutex
87 // TODO: Add Mutex
87 m_VariableToEnableProvider[acqIdentifier] = true;
88 m_VariableToEnableProvider[acqIdentifier] = true;
88 qCDebug(LOG_CosinusProvider()) << "TORM: CosinusProvider::requestDataLoading"
89 qCDebug(LOG_CosinusProvider()) << "TORM: CosinusProvider::requestDataLoading"
89 << QThread::currentThread()->objectName();
90 << QThread::currentThread()->objectName();
90 // NOTE: Try to use multithread if possible
91 // NOTE: Try to use multithread if possible
91 const auto times = parameters.m_Times;
92 const auto times = parameters.m_Times;
92
93
93 for (const auto &dateTime : qAsConst(times)) {
94 for (const auto &dateTime : qAsConst(times)) {
94 if (m_VariableToEnableProvider[acqIdentifier]) {
95 if (m_VariableToEnableProvider[acqIdentifier]) {
95 auto scalarSeries = this->retrieveData(acqIdentifier, dateTime);
96 auto scalarSeries = this->retrieveData(acqIdentifier, dateTime, parameters.m_Data);
96 qCDebug(LOG_CosinusProvider()) << "TORM: CosinusProvider::dataProvided";
97 qCDebug(LOG_CosinusProvider()) << "TORM: CosinusProvider::dataProvided";
97 emit dataProvided(acqIdentifier, scalarSeries, dateTime);
98 emit dataProvided(acqIdentifier, scalarSeries, dateTime);
98 }
99 }
99 }
100 }
100 }
101 }
101
102
102 void CosinusProvider::requestDataAborting(QUuid acqIdentifier)
103 void CosinusProvider::requestDataAborting(QUuid acqIdentifier)
103 {
104 {
104 // TODO: Add Mutex
105 // TODO: Add Mutex
105 qCDebug(LOG_CosinusProvider()) << "CosinusProvider::requestDataAborting" << acqIdentifier
106 qCDebug(LOG_CosinusProvider()) << "CosinusProvider::requestDataAborting" << acqIdentifier
106 << QThread::currentThread()->objectName();
107 << QThread::currentThread()->objectName();
107 auto it = m_VariableToEnableProvider.find(acqIdentifier);
108 auto it = m_VariableToEnableProvider.find(acqIdentifier);
108 if (it != m_VariableToEnableProvider.end()) {
109 if (it != m_VariableToEnableProvider.end()) {
109 it.value() = false;
110 it.value() = false;
110 }
111 }
111 else {
112 else {
112 qCWarning(LOG_CosinusProvider())
113 qCWarning(LOG_CosinusProvider())
113 << tr("Aborting progression of inexistant identifier detected !!!");
114 << tr("Aborting progression of inexistant identifier detected !!!");
114 }
115 }
115 }
116 }
General Comments 0
You need to be logged in to leave comments. Login now