##// END OF EJS Templates
Generates vectors (1)...
Alexandre Leroux -
r784:aa1270e6337a
parent child
Show More
@@ -1,124 +1,140
1 1 #include "CosinusProvider.h"
2 2 #include "MockDefs.h"
3 3
4 4 #include <Data/DataProviderParameters.h>
5 5 #include <Data/ScalarSeries.h>
6 6
7 7 #include <cmath>
8 8
9 9 #include <QFuture>
10 10 #include <QThread>
11 11 #include <QtConcurrent/QtConcurrent>
12 12
13 13 Q_LOGGING_CATEGORY(LOG_CosinusProvider, "CosinusProvider")
14 14
15 namespace {
16
17 /// Abstract cosinus type
18 struct ICosinusType {
19 virtual ~ICosinusType() = default;
20 /// @return the number of components generated for the type
21 virtual int componentCount() const = 0;
22 /// @return the data series created for the type
23 virtual std::shared_ptr<IDataSeries> createDataSeries(std::vector<double> xAxisData,
24 std::vector<double> valuesData,
25 Unit xAxisUnit,
26 Unit valuesUnit) const = 0;
27 };
28
29 } // namespace
30
15 31 std::shared_ptr<IDataProvider> CosinusProvider::clone() const
16 32 {
17 33 // No copy is made in clone
18 34 return std::make_shared<CosinusProvider>();
19 35 }
20 36
21 37 std::shared_ptr<IDataSeries> CosinusProvider::retrieveData(QUuid acqIdentifier,
22 38 const SqpRange &dataRangeRequested,
23 39 const QVariantHash &data)
24 40 {
25 41 // TODO: Add Mutex
26 42 auto dataIndex = 0;
27 43
28 44 // Retrieves frequency
29 45 auto freqVariant = data.value(COSINUS_FREQUENCY_KEY, COSINUS_FREQUENCY_DEFAULT_VALUE);
30 46 if (!freqVariant.canConvert<double>()) {
31 47 qCCritical(LOG_CosinusProvider()) << tr("Can't retrieve data: invalid frequency");
32 48 return nullptr;
33 49 }
34 50
35 51 // Gets the timerange from the parameters
36 52 double freq = freqVariant.toDouble();
37 53 double start = std::ceil(dataRangeRequested.m_TStart * freq);
38 54 double end = std::floor(dataRangeRequested.m_TEnd * freq);
39 55
40 56 // We assure that timerange is valid
41 57 if (end < start) {
42 58 std::swap(start, end);
43 59 }
44 60
45 61 // Generates scalar series containing cosinus values (one value per second, end value is
46 62 // included)
47 63 auto dataCount = end - start + 1;
48 64
49 65 auto xAxisData = std::vector<double>{};
50 66 xAxisData.resize(dataCount);
51 67
52 68 auto valuesData = std::vector<double>{};
53 69 valuesData.resize(dataCount);
54 70
55 71 int progress = 0;
56 72 auto progressEnd = dataCount;
57 73 for (auto time = start; time <= end; ++time, ++dataIndex) {
58 74 auto it = m_VariableToEnableProvider.find(acqIdentifier);
59 75 if (it != m_VariableToEnableProvider.end() && it.value()) {
60 76 const auto timeOnFreq = time / freq;
61 77
62 78 xAxisData[dataIndex] = timeOnFreq;
63 79 valuesData[dataIndex] = std::cos(timeOnFreq);
64 80
65 81 // progression
66 82 int currentProgress = (time - start) * 100.0 / progressEnd;
67 83 if (currentProgress != progress) {
68 84 progress = currentProgress;
69 85
70 86 emit dataProvidedProgress(acqIdentifier, progress);
71 87 qCInfo(LOG_CosinusProvider()) << "TORM: CosinusProvider::retrieveData"
72 88 << QThread::currentThread()->objectName() << progress;
73 89 // NOTE: Try to use multithread if possible
74 90 }
75 91 }
76 92 else {
77 93 if (!it.value()) {
78 94 qCDebug(LOG_CosinusProvider())
79 95 << "CosinusProvider::retrieveData: ARRET De l'acquisition detectΓ©"
80 96 << end - time;
81 97 }
82 98 }
83 99 }
84 100 if (progress != 100) {
85 101 // We can close progression beacause all data has been retrieved
86 102 emit dataProvidedProgress(acqIdentifier, 100);
87 103 }
88 104 return std::make_shared<ScalarSeries>(std::move(xAxisData), std::move(valuesData),
89 105 Unit{QStringLiteral("t"), true}, Unit{});
90 106 }
91 107
92 108 void CosinusProvider::requestDataLoading(QUuid acqIdentifier,
93 109 const DataProviderParameters &parameters)
94 110 {
95 111 // TODO: Add Mutex
96 112 m_VariableToEnableProvider[acqIdentifier] = true;
97 113 qCDebug(LOG_CosinusProvider()) << "TORM: CosinusProvider::requestDataLoading"
98 114 << QThread::currentThread()->objectName();
99 115 // NOTE: Try to use multithread if possible
100 116 const auto times = parameters.m_Times;
101 117
102 118 for (const auto &dateTime : qAsConst(times)) {
103 119 if (m_VariableToEnableProvider[acqIdentifier]) {
104 120 auto scalarSeries = this->retrieveData(acqIdentifier, dateTime, parameters.m_Data);
105 121 qCDebug(LOG_CosinusProvider()) << "TORM: CosinusProvider::dataProvided";
106 122 emit dataProvided(acqIdentifier, scalarSeries, dateTime);
107 123 }
108 124 }
109 125 }
110 126
111 127 void CosinusProvider::requestDataAborting(QUuid acqIdentifier)
112 128 {
113 129 // TODO: Add Mutex
114 130 qCDebug(LOG_CosinusProvider()) << "CosinusProvider::requestDataAborting" << acqIdentifier
115 131 << QThread::currentThread()->objectName();
116 132 auto it = m_VariableToEnableProvider.find(acqIdentifier);
117 133 if (it != m_VariableToEnableProvider.end()) {
118 134 it.value() = false;
119 135 }
120 136 else {
121 137 qCWarning(LOG_CosinusProvider())
122 138 << tr("Aborting progression of inexistant identifier detected !!!");
123 139 }
124 140 }
General Comments 0
You need to be logged in to leave comments. Login now