@@ -1,56 +1,82 | |||
|
1 | 1 | #ifndef SCIQLOP_ARRAYDATA_H |
|
2 | 2 | #define SCIQLOP_ARRAYDATA_H |
|
3 | 3 | |
|
4 | 4 | #include <QVector> |
|
5 | 5 | |
|
6 | 6 | /** |
|
7 | 7 | * @brief The ArrayData class represents a dataset for a data series. |
|
8 | 8 | * |
|
9 | 9 | * A dataset can be unidimensional or two-dimensional. This property is determined by the Dim |
|
10 | 10 | * template-parameter. |
|
11 | 11 | * |
|
12 | 12 | * @tparam Dim the dimension of the ArrayData (one or two) |
|
13 | 13 | * @sa IDataSeries |
|
14 | 14 | */ |
|
15 | 15 | template <int Dim> |
|
16 | 16 | class ArrayData { |
|
17 | 17 | public: |
|
18 | 18 | /** |
|
19 | 19 | * Ctor for a unidimensional ArrayData |
|
20 | 20 | * @param nbColumns the number of values the ArrayData will hold |
|
21 | 21 | */ |
|
22 | 22 | template <int D = Dim, typename = std::enable_if_t<D == 1> > |
|
23 | 23 | explicit ArrayData(int nbColumns) : m_Data{1, QVector<double>{}} |
|
24 | 24 | { |
|
25 | 25 | m_Data[0].resize(nbColumns); |
|
26 | 26 | } |
|
27 | 27 | |
|
28 | 28 | /** |
|
29 | 29 | * Sets a data at a specified index. The index has to be valid to be effective |
|
30 | 30 | * @param index the index to which the data will be set |
|
31 | 31 | * @param data the data to set |
|
32 | 32 | * @remarks this method is only available for a unidimensional ArrayData |
|
33 | 33 | */ |
|
34 | 34 | template <int D = Dim, typename = std::enable_if_t<D == 1> > |
|
35 | 35 | void setData(int index, double data) noexcept |
|
36 | 36 | { |
|
37 | 37 | if (index >= 0 && index < m_Data.at(0).size()) { |
|
38 | 38 | m_Data[0].replace(index, data); |
|
39 | 39 | } |
|
40 | 40 | } |
|
41 | 41 | |
|
42 | 42 | /** |
|
43 | 43 | * @return the data as a vector |
|
44 | 44 | * @remarks this method is only available for a unidimensional ArrayData |
|
45 | 45 | */ |
|
46 | 46 | template <int D = Dim, typename = std::enable_if_t<D == 1> > |
|
47 | 47 | QVector<double> data() const noexcept |
|
48 | 48 | { |
|
49 | 49 | return m_Data.at(0); |
|
50 | 50 | } |
|
51 | 51 | |
|
52 | /** | |
|
53 | * @return the data as a vector | |
|
54 | * @remarks this method is only available for a unidimensional ArrayData | |
|
55 | */ | |
|
56 | template <int D = Dim, typename = std::enable_if_t<D == 1> > | |
|
57 | const QVector<double> &data(double tStart, double tEnd) const noexcept | |
|
58 | { | |
|
59 | return m_Data.at(tStart); | |
|
60 | } | |
|
61 | ||
|
62 | // TODO Comment | |
|
63 | template <int D = Dim, typename = std::enable_if_t<D == 1> > | |
|
64 | void merge(ArrayData<1> *arrayData) | |
|
65 | { | |
|
66 | if (!m_Data.empty()) { | |
|
67 | m_Data[0] += arrayData->data(); | |
|
68 | } | |
|
69 | } | |
|
70 | ||
|
71 | template <int D = Dim, typename = std::enable_if_t<D == 1> > | |
|
72 | int size() | |
|
73 | { | |
|
74 | return m_Data[0].size(); | |
|
75 | } | |
|
76 | ||
|
77 | ||
|
52 | 78 | private: |
|
53 | 79 | QVector<QVector<double> > m_Data; |
|
54 | 80 | }; |
|
55 | 81 | |
|
56 | 82 | #endif // SCIQLOP_ARRAYDATA_H |
@@ -1,50 +1,59 | |||
|
1 | 1 | #ifndef SCIQLOP_DATASERIES_H |
|
2 | 2 | #define SCIQLOP_DATASERIES_H |
|
3 | 3 | |
|
4 | 4 | #include <Data/ArrayData.h> |
|
5 | 5 | #include <Data/IDataSeries.h> |
|
6 | 6 | |
|
7 | 7 | #include <memory> |
|
8 | 8 | |
|
9 | 9 | /** |
|
10 | 10 | * @brief The DataSeries class is the base (abstract) implementation of IDataSeries. |
|
11 | 11 | * |
|
12 | 12 | * It proposes to set a dimension for the values ββdata |
|
13 | 13 | * |
|
14 | 14 | * @tparam Dim The dimension of the values data |
|
15 | 15 | * |
|
16 | 16 | */ |
|
17 | 17 | template <int Dim> |
|
18 | 18 | class DataSeries : public IDataSeries { |
|
19 | 19 | public: |
|
20 | 20 | /// @sa IDataSeries::xAxisData() |
|
21 | 21 | std::shared_ptr<ArrayData<1> > xAxisData() override { return m_XAxisData; } |
|
22 | 22 | |
|
23 | 23 | /// @sa IDataSeries::xAxisUnit() |
|
24 | 24 | Unit xAxisUnit() const override { return m_XAxisUnit; } |
|
25 | 25 | |
|
26 | 26 | /// @return the values dataset |
|
27 | 27 | std::shared_ptr<ArrayData<Dim> > valuesData() const { return m_ValuesData; } |
|
28 | 28 | |
|
29 | 29 | /// @sa IDataSeries::valuesUnit() |
|
30 | 30 | Unit valuesUnit() const override { return m_ValuesUnit; } |
|
31 | 31 | |
|
32 | /// @sa IDataSeries::merge() | |
|
33 | void merge(IDataSeries *dataSeries) override | |
|
34 | { | |
|
35 | if (auto dimDataSeries = dynamic_cast<DataSeries<Dim> *>(dataSeries)) { | |
|
36 | m_XAxisData->merge(dimDataSeries->xAxisData().get()); | |
|
37 | m_ValuesData->merge(dimDataSeries->valuesData().get()); | |
|
38 | } | |
|
39 | } | |
|
40 | ||
|
32 | 41 | protected: |
|
33 | 42 | /// Protected ctor (DataSeries is abstract) |
|
34 | 43 | explicit DataSeries(std::shared_ptr<ArrayData<1> > xAxisData, const Unit &xAxisUnit, |
|
35 | 44 | std::shared_ptr<ArrayData<Dim> > valuesData, const Unit &valuesUnit) |
|
36 | 45 | : m_XAxisData{xAxisData}, |
|
37 | 46 | m_XAxisUnit{xAxisUnit}, |
|
38 | 47 | m_ValuesData{valuesData}, |
|
39 | 48 | m_ValuesUnit{valuesUnit} |
|
40 | 49 | { |
|
41 | 50 | } |
|
42 | 51 | |
|
43 | 52 | private: |
|
44 | 53 | std::shared_ptr<ArrayData<1> > m_XAxisData; |
|
45 | 54 | Unit m_XAxisUnit; |
|
46 | 55 | std::shared_ptr<ArrayData<Dim> > m_ValuesData; |
|
47 | 56 | Unit m_ValuesUnit; |
|
48 | 57 | }; |
|
49 | 58 | |
|
50 | 59 | #endif // SCIQLOP_DATASERIES_H |
@@ -1,30 +1,39 | |||
|
1 | 1 | #ifndef SCIQLOP_IDATAPROVIDER_H |
|
2 | 2 | #define SCIQLOP_IDATAPROVIDER_H |
|
3 | 3 | |
|
4 | 4 | #include <memory> |
|
5 | 5 | |
|
6 | 6 | #include <QObject> |
|
7 | 7 | |
|
8 | #include <Data/SqpDateTime.h> | |
|
9 | ||
|
8 | 10 | class DataProviderParameters; |
|
9 | 11 | class IDataSeries; |
|
10 | 12 | |
|
11 | 13 | /** |
|
12 | 14 | * @brief The IDataProvider interface aims to declare a data provider. |
|
13 | 15 | * |
|
14 | 16 | * A data provider is an entity that generates data and returns it according to various parameters |
|
15 | 17 | * (time interval, product to retrieve the data, etc.) |
|
16 | 18 | * |
|
17 | 19 | * @sa IDataSeries |
|
18 | 20 | */ |
|
19 | class IDataProvider { | |
|
21 | class IDataProvider : public QObject { | |
|
22 | ||
|
23 | Q_OBJECT | |
|
20 | 24 | public: |
|
21 | 25 | virtual ~IDataProvider() noexcept = default; |
|
22 | 26 | |
|
23 | 27 | virtual std::unique_ptr<IDataSeries> |
|
24 | 28 | retrieveData(const DataProviderParameters ¶meters) const = 0; |
|
25 | }; | |
|
26 | 29 | |
|
30 | ||
|
31 | virtual void requestDataLoading(const QVector<SqpDateTime> &dateTimeList) = 0; | |
|
32 | ||
|
33 | signals: | |
|
34 | void dataProvided(std::shared_ptr<IDataSeries> dateSerie, SqpDateTime dateTime); | |
|
35 | }; | |
|
27 | 36 | // Required for using shared_ptr in signals/slots |
|
28 | 37 | Q_DECLARE_METATYPE(std::shared_ptr<IDataProvider>) |
|
29 | 38 | |
|
30 | 39 | #endif // SCIQLOP_IDATAPROVIDER_H |
@@ -1,47 +1,54 | |||
|
1 | 1 | #ifndef SCIQLOP_IDATASERIES_H |
|
2 | 2 | #define SCIQLOP_IDATASERIES_H |
|
3 | 3 | |
|
4 | #include <QString> | |
|
5 | 4 | |
|
6 | 5 | #include <memory> |
|
7 | 6 | |
|
7 | #include <QObject> | |
|
8 | #include <QString> | |
|
9 | ||
|
8 | 10 | template <int Dim> |
|
9 | 11 | class ArrayData; |
|
10 | 12 | |
|
11 | 13 | struct Unit { |
|
12 | 14 | explicit Unit(const QString &name = {}, bool timeUnit = false) |
|
13 | 15 | : m_Name{name}, m_TimeUnit{timeUnit} |
|
14 | 16 | { |
|
15 | 17 | } |
|
16 | 18 | |
|
17 | 19 | QString m_Name; ///< Unit name |
|
18 | 20 | bool m_TimeUnit; ///< The unit is a unit of time |
|
19 | 21 | }; |
|
20 | 22 | |
|
21 | 23 | /** |
|
22 | 24 | * @brief The IDataSeries aims to declare a data series. |
|
23 | 25 | * |
|
24 | 26 | * A data series is an entity that contains at least : |
|
25 | 27 | * - one dataset representing the x-axis |
|
26 | 28 | * - one dataset representing the values |
|
27 | 29 | * |
|
28 | 30 | * Each dataset is represented by an ArrayData, and is associated with a unit. |
|
29 | 31 | * |
|
30 | 32 | * An ArrayData can be unidimensional or two-dimensional, depending on the implementation of the |
|
31 | 33 | * IDataSeries. The x-axis dataset is always unidimensional. |
|
32 | 34 | * |
|
33 | 35 | * @sa ArrayData |
|
34 | 36 | */ |
|
35 | 37 | class IDataSeries { |
|
36 | 38 | public: |
|
37 | 39 | virtual ~IDataSeries() noexcept = default; |
|
38 | 40 | |
|
39 | 41 | /// Returns the x-axis dataset |
|
40 | 42 | virtual std::shared_ptr<ArrayData<1> > xAxisData() = 0; |
|
41 | 43 | |
|
42 | 44 | virtual Unit xAxisUnit() const = 0; |
|
43 | 45 | |
|
44 | 46 | virtual Unit valuesUnit() const = 0; |
|
47 | ||
|
48 | virtual void merge(IDataSeries *dataSeries) = 0; | |
|
45 | 49 | }; |
|
46 | 50 | |
|
51 | // Required for using shared_ptr in signals/slots | |
|
52 | Q_DECLARE_METATYPE(std::shared_ptr<IDataSeries>) | |
|
53 | ||
|
47 | 54 | #endif // SCIQLOP_IDATASERIES_H |
General Comments 0
You need to be logged in to leave comments.
Login now