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