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