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