@@ -1,39 +1,23 | |||
|
1 | 1 | #ifndef SCIQLOP_SCALARSERIES_H |
|
2 | 2 | #define SCIQLOP_SCALARSERIES_H |
|
3 | 3 | |
|
4 | 4 | #include <Data/DataSeries.h> |
|
5 | 5 | |
|
6 | 6 | /** |
|
7 | 7 | * @brief The ScalarSeries class is the implementation for a data series representing a scalar. |
|
8 | 8 | */ |
|
9 | 9 | class ScalarSeries : public DataSeries<1> { |
|
10 | 10 | public: |
|
11 | 11 | /** |
|
12 | * Ctor | |
|
13 | * @param size the number of data the series will hold | |
|
14 | * @param xAxisUnit x-axis unit | |
|
15 | * @param valuesUnit values unit | |
|
16 | */ | |
|
17 | explicit ScalarSeries(int size, const Unit &xAxisUnit, const Unit &valuesUnit); | |
|
18 | ||
|
19 | /** | |
|
20 | 12 | * Ctor with two vectors. The vectors must have the same size, otherwise a ScalarSeries with no |
|
21 | 13 | * values will be created. |
|
22 | 14 | * @param xAxisData x-axis data |
|
23 | 15 | * @param valuesData values data |
|
24 | 16 | */ |
|
25 | 17 | explicit ScalarSeries(QVector<double> xAxisData, QVector<double> valuesData, |
|
26 | 18 | const Unit &xAxisUnit, const Unit &valuesUnit); |
|
27 | 19 | |
|
28 | /** | |
|
29 | * Sets data for a specific index. The index has to be valid to be effective | |
|
30 | * @param index the index to which the data will be set | |
|
31 | * @param x the x-axis data | |
|
32 | * @param value the value data | |
|
33 | */ | |
|
34 | void setData(int index, double x, double value) noexcept; | |
|
35 | ||
|
36 | 20 | std::unique_ptr<IDataSeries> clone() const; |
|
37 | 21 | }; |
|
38 | 22 | |
|
39 | 23 | #endif // SCIQLOP_SCALARSERIES_H |
@@ -1,25 +1,13 | |||
|
1 | 1 | #include <Data/ScalarSeries.h> |
|
2 | 2 | |
|
3 | ScalarSeries::ScalarSeries(int size, const Unit &xAxisUnit, const Unit &valuesUnit) | |
|
4 | : DataSeries{std::make_shared<ArrayData<1> >(size), xAxisUnit, | |
|
5 | std::make_shared<ArrayData<1> >(size), valuesUnit} | |
|
6 | { | |
|
7 | } | |
|
8 | ||
|
9 | 3 | ScalarSeries::ScalarSeries(QVector<double> xAxisData, QVector<double> valuesData, |
|
10 | 4 | const Unit &xAxisUnit, const Unit &valuesUnit) |
|
11 | 5 | : DataSeries{std::make_shared<ArrayData<1> >(std::move(xAxisData)), xAxisUnit, |
|
12 | 6 | std::make_shared<ArrayData<1> >(std::move(valuesData)), valuesUnit} |
|
13 | 7 | { |
|
14 | 8 | } |
|
15 | 9 | |
|
16 | void ScalarSeries::setData(int index, double x, double value) noexcept | |
|
17 | { | |
|
18 | xAxisData()->setData(index, x); | |
|
19 | valuesData()->setData(index, value); | |
|
20 | } | |
|
21 | ||
|
22 | 10 | std::unique_ptr<IDataSeries> ScalarSeries::clone() const |
|
23 | 11 | { |
|
24 | 12 | return std::make_unique<ScalarSeries>(*this); |
|
25 | 13 | } |
@@ -1,95 +1,101 | |||
|
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 | 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 | 15 | std::shared_ptr<IDataSeries> CosinusProvider::retrieveData(QUuid token, const SqpDateTime &dateTime) |
|
16 | 16 | { |
|
17 | 17 | // TODO: Add Mutex |
|
18 | 18 | auto dataIndex = 0; |
|
19 | 19 | |
|
20 | 20 | // Gets the timerange from the parameters |
|
21 | 21 | double freq = 100.0; |
|
22 | double start = dateTime.m_TStart * freq; // 100 htz | |
|
23 |
double end = dateTime.m_TEnd * freq; |
|
|
22 | double start = std::ceil(dateTime.m_TStart * freq); // 100 htz | |
|
23 | double end = std::floor(dateTime.m_TEnd * freq); // 100 htz | |
|
24 | 24 | |
|
25 | 25 | // We assure that timerange is valid |
|
26 | 26 | if (end < start) { |
|
27 | 27 | std::swap(start, end); |
|
28 | 28 | } |
|
29 | 29 | |
|
30 | 30 | // Generates scalar series containing cosinus values (one value per second) |
|
31 | auto scalarSeries | |
|
32 | = std::make_shared<ScalarSeries>(end - start, Unit{QStringLiteral("t"), true}, Unit{}); | |
|
31 | auto dataCount = end - start; | |
|
33 | 32 | |
|
33 | auto xAxisData = QVector<double>{}; | |
|
34 | xAxisData.resize(dataCount); | |
|
35 | ||
|
36 | auto valuesData = QVector<double>{}; | |
|
37 | valuesData.resize(dataCount); | |
|
34 | 38 | |
|
35 | 39 | int progress = 0; |
|
36 |
auto progressEnd = |
|
|
40 | auto progressEnd = dataCount; | |
|
37 | 41 | for (auto time = start; time < end; ++time, ++dataIndex) { |
|
38 | 42 | auto it = m_VariableToEnableProvider.find(token); |
|
39 | 43 | if (it != m_VariableToEnableProvider.end() && it.value()) { |
|
40 | 44 | const auto timeOnFreq = time / freq; |
|
41 | scalarSeries->setData(dataIndex, timeOnFreq, std::cos(timeOnFreq)); | |
|
45 | ||
|
46 | xAxisData.replace(dataIndex, timeOnFreq); | |
|
47 | valuesData.replace(dataIndex, std::cos(timeOnFreq)); | |
|
42 | 48 | |
|
43 | 49 | // progression |
|
44 | 50 | int currentProgress = (time - start) * 100.0 / progressEnd; |
|
45 | 51 | if (currentProgress != progress) { |
|
46 | 52 | progress = currentProgress; |
|
47 | 53 | |
|
48 | 54 | emit dataProvidedProgress(token, progress); |
|
49 | 55 | } |
|
50 | 56 | } |
|
51 | 57 | else { |
|
52 | 58 | if (!it.value()) { |
|
53 | 59 | qCDebug(LOG_CosinusProvider()) |
|
54 | 60 | << "CosinusProvider::retrieveData: ARRET De l'acquisition detectΓ©" |
|
55 | 61 | << end - time; |
|
56 | 62 | } |
|
57 | 63 | } |
|
58 | 64 | } |
|
59 | 65 | emit dataProvidedProgress(token, 0.0); |
|
60 | 66 | |
|
61 | ||
|
62 | return scalarSeries; | |
|
67 | return std::make_shared<ScalarSeries>(std::move(xAxisData), std::move(valuesData), | |
|
68 | Unit{QStringLiteral("t"), true}, Unit{}); | |
|
63 | 69 | } |
|
64 | 70 | |
|
65 | 71 | void CosinusProvider::requestDataLoading(QUuid token, const DataProviderParameters ¶meters) |
|
66 | 72 | { |
|
67 | 73 | // TODO: Add Mutex |
|
68 | 74 | m_VariableToEnableProvider[token] = true; |
|
69 | 75 | qCDebug(LOG_CosinusProvider()) << "CosinusProvider::requestDataLoading" |
|
70 | 76 | << QThread::currentThread()->objectName(); |
|
71 | 77 | // NOTE: Try to use multithread if possible |
|
72 | 78 | const auto times = parameters.m_Times; |
|
73 | 79 | |
|
74 | 80 | for (const auto &dateTime : qAsConst(times)) { |
|
75 | 81 | if (m_VariableToEnableProvider[token]) { |
|
76 | 82 | auto scalarSeries = this->retrieveData(token, dateTime); |
|
77 | 83 | emit dataProvided(token, scalarSeries, dateTime); |
|
78 | 84 | } |
|
79 | 85 | } |
|
80 | 86 | } |
|
81 | 87 | |
|
82 | 88 | void CosinusProvider::requestDataAborting(QUuid identifier) |
|
83 | 89 | { |
|
84 | 90 | // TODO: Add Mutex |
|
85 | 91 | qCDebug(LOG_CosinusProvider()) << "CosinusProvider::requestDataAborting" << identifier |
|
86 | 92 | << QThread::currentThread()->objectName(); |
|
87 | 93 | auto it = m_VariableToEnableProvider.find(identifier); |
|
88 | 94 | if (it != m_VariableToEnableProvider.end()) { |
|
89 | 95 | it.value() = false; |
|
90 | 96 | } |
|
91 | 97 | else { |
|
92 | 98 | qCWarning(LOG_CosinusProvider()) |
|
93 | 99 | << tr("Aborting progression of inexistant identifier detected !!!"); |
|
94 | 100 | } |
|
95 | 101 | } |
General Comments 0
You need to be logged in to leave comments.
Login now