@@ -1,111 +1,129 | |||||
1 | #pragma once |
|
1 | #pragma once | |
2 | #include <Data/DataProviderParameters.h> |
|
2 | #include <Data/DataProviderParameters.h> | |
3 | #include <Data/DataSeriesType.h> |
|
3 | #include <Data/DataSeriesType.h> | |
4 | #include <Data/IDataProvider.h> |
|
4 | #include <Data/IDataProvider.h> | |
5 | #include <DataSource/DataSourceController.h> |
|
5 | #include <DataSource/DataSourceController.h> | |
6 | #include <DataSource/DataSourceItem.h> |
|
6 | #include <DataSource/DataSourceItem.h> | |
7 | #include <DataSource/DataSourceItemAction.h> |
|
7 | #include <DataSource/DataSourceItemAction.h> | |
8 | #include <QPair> |
|
8 | #include <QPair> | |
9 | #include <SqpApplication.h> |
|
9 | #include <SqpApplication.h> | |
10 | // must be included last because of Python/Qt definition of slots |
|
10 | // must be included last because of Python/Qt definition of slots | |
11 | #include "numpy_wrappers.h" |
|
11 | #include "numpy_wrappers.h" | |
12 |
|
12 | |||
13 | struct Product |
|
13 | struct Product | |
14 | { |
|
14 | { | |
15 | QString path; |
|
15 | QString path; | |
16 | std::vector<std::string> components; |
|
16 | std::vector<std::string> components; | |
17 | QMap<QString, QString> metadata; |
|
17 | QMap<QString, QString> metadata; | |
18 | Product() = default; |
|
18 | Product() = default; | |
19 | explicit Product(const QString& path, const std::vector<std::string>& components, |
|
19 | explicit Product(const QString& path, const std::vector<std::string>& components, | |
20 | const QMap<QString, QString>& metadata) |
|
20 | const QMap<QString, QString>& metadata) | |
21 | : path { path }, components { components }, metadata { metadata } |
|
21 | : path { path }, components { components }, metadata { metadata } | |
22 | { |
|
22 | { | |
23 | } |
|
23 | } | |
24 | ~Product() = default; |
|
24 | ~Product() = default; | |
25 | }; |
|
25 | }; | |
26 |
|
26 | |||
|
27 | template <typename T> | |||
|
28 | ScalarTimeSerie* make_scalar(T& t, T& y) | |||
|
29 | { | |||
|
30 | return new ScalarTimeSerie { std::move(t.data), std::move(y.data) }; | |||
|
31 | } | |||
|
32 | ||||
|
33 | template <typename T> | |||
|
34 | VectorTimeSerie* make_vector(T& t, T& y) | |||
|
35 | { | |||
|
36 | return new VectorTimeSerie { std::move(t.data), y.to_std_vect_vect() }; | |||
|
37 | } | |||
|
38 | ||||
|
39 | template <typename T> | |||
|
40 | MultiComponentTimeSerie* make_multi_comp(T& t, T& y) | |||
|
41 | { | |||
|
42 | auto y_size = y.flat_size(); | |||
|
43 | auto t_size = t.flat_size(); | |||
|
44 | if (t_size && (y_size % t_size) == 0) | |||
|
45 | { | |||
|
46 | return new MultiComponentTimeSerie { std::move(t.data), std::move(y.data), | |||
|
47 | { t_size, y_size / t_size } }; | |||
|
48 | } | |||
|
49 | return nullptr; | |||
|
50 | } | |||
|
51 | ||||
|
52 | template <typename T> | |||
|
53 | SpectrogramTimeSerie* make_spectro(T& t, T& y) | |||
|
54 | { | |||
|
55 | auto y_size = y.flat_size(); | |||
|
56 | auto t_size = t.flat_size(); | |||
|
57 | if (t_size && (y_size % t_size) == 0) | |||
|
58 | { | |||
|
59 | return new SpectrogramTimeSerie { std::move(t.data), std::move(y.data), | |||
|
60 | { t_size, y_size / t_size } }; | |||
|
61 | } | |||
|
62 | return nullptr; | |||
|
63 | } | |||
|
64 | ||||
|
65 | ||||
27 | class PyDataProvider : public IDataProvider |
|
66 | class PyDataProvider : public IDataProvider | |
28 | { |
|
67 | { | |
29 | public: |
|
68 | public: | |
30 | PyDataProvider() |
|
69 | PyDataProvider() | |
31 | { |
|
70 | { | |
32 | auto& dataSourceController = sqpApp->dataSourceController(); |
|
71 | auto& dataSourceController = sqpApp->dataSourceController(); | |
33 | dataSourceController.registerProvider(this); |
|
72 | dataSourceController.registerProvider(this); | |
34 | } |
|
73 | } | |
35 |
|
74 | |||
36 | virtual ~PyDataProvider() {} |
|
75 | virtual ~PyDataProvider() {} | |
37 |
|
76 | |||
38 |
virtual QPair<QPair<NpArray,NpArray>,DataSeriesType> get_data( |
|
77 | virtual QPair<QPair<NpArray, NpArray>, DataSeriesType> get_data( | |
|
78 | const QMap<QString, QString>& key, double start_time, double stop_time) | |||
39 | { |
|
79 | { | |
40 | (void)key, (void)start_time, (void)stop_time; |
|
80 | (void)key, (void)start_time, (void)stop_time; | |
41 | return {}; |
|
81 | return {}; | |
42 | } |
|
82 | } | |
43 |
|
83 | |||
44 | virtual TimeSeries::ITimeSerie* getData(const DataProviderParameters& parameters) override |
|
84 | virtual TimeSeries::ITimeSerie* getData(const DataProviderParameters& parameters) override | |
45 | { |
|
85 | { | |
|
86 | TimeSeries::ITimeSerie* ts = nullptr; | |||
46 | if (parameters.m_Data.contains("name")) |
|
87 | if (parameters.m_Data.contains("name")) | |
47 | { |
|
88 | { | |
48 | QMap<QString,QString> metadata; |
|
89 | QMap<QString, QString> metadata; | |
49 |
std::for_each(parameters.m_Data.constKeyValueBegin(), |
|
90 | std::for_each(parameters.m_Data.constKeyValueBegin(), | |
50 | metadata[item.first] = item.second.toString(); |
|
91 | parameters.m_Data.constKeyValueEnd(), | |
51 | }); |
|
92 | [&metadata](const auto& item) { metadata[item.first] = item.second.toString(); }); | |
52 |
auto [data, type] |
|
93 | auto [data, type] | |
53 | parameters.m_Range.m_TStart, parameters.m_Range.m_TEnd); |
|
94 | = get_data(metadata, parameters.m_Range.m_TStart, parameters.m_Range.m_TEnd); | |
54 | // TODO add shape/type switch |
|
95 | ||
55 | //if (builder) |
|
|||
56 | { |
|
|||
57 |
|
|
96 | auto& [t, y] = data; | |
58 |
|
|
97 | switch (type) | |
59 |
|
|
98 | { | |
60 |
|
|
99 | case DataSeriesType::SCALAR: | |
61 | return new ScalarTimeSerie { std::move(t.data), |
|
100 | ts = make_scalar(t, y); | |
62 | std::move(y.data) }; |
|
|||
63 |
|
|
101 | break; | |
64 |
|
|
102 | case DataSeriesType::VECTOR: | |
65 | return new VectorTimeSerie { std::move(t.data), |
|
103 | ts = make_vector(t, y); | |
66 | y.to_std_vect_vect() }; |
|
|||
67 |
|
|
104 | break; | |
68 |
|
|
105 | case DataSeriesType::MULTICOMPONENT: | |
69 | { |
|
106 | ts = make_multi_comp(t, y); | |
70 | auto y_size = y.flat_size(); |
|
|||
71 | auto t_size = t.flat_size(); |
|
|||
72 |
|
||||
73 | if(t_size && (y_size%t_size)==0) |
|
|||
74 | { |
|
|||
75 | return new MultiComponentTimeSerie { std::move(t.data), |
|
|||
76 | std::move(y.data),{t_size, y_size/t_size} }; |
|
|||
77 | } |
|
|||
78 |
|
|
107 | break; | |
79 | } |
|
|||
80 |
|
|
108 | case DataSeriesType::SPECTROGRAM: | |
81 |
|
|
109 | ts = make_spectro(t, y); | |
82 | auto y_size = y.flat_size(); |
|
|||
83 | auto t_size = t.flat_size(); |
|
|||
84 |
|
||||
85 | if(t_size && (y_size%t_size)==0) |
|
|||
86 | { |
|
|||
87 | return new SpectrogramTimeSerie { std::move(t.data), |
|
|||
88 | std::move(y.data),{t_size, y_size/t_size} }; |
|
|||
89 | } |
|
|||
90 |
|
|
110 | break; | |
91 | } |
|
|||
92 |
|
|
111 | default: | |
93 |
|
|
112 | break; | |
94 |
|
|
113 | } | |
95 |
|
|
114 | } | |
96 | } |
|
115 | return ts; | |
97 | return nullptr; |
|
|||
98 | } |
|
116 | } | |
99 |
|
117 | |||
100 |
|
118 | |||
101 | inline void register_products(const QVector<Product*>& products) |
|
119 | inline void register_products(const QVector<Product*>& products) | |
102 | { |
|
120 | { | |
103 | auto& dataSourceController = sqpApp->dataSourceController(); |
|
121 | auto& dataSourceController = sqpApp->dataSourceController(); | |
104 | auto id = this->id(); |
|
122 | auto id = this->id(); | |
105 | auto data_source_name = this->name(); |
|
123 | auto data_source_name = this->name(); | |
106 | std::for_each(std::cbegin(products), std::cend(products), |
|
124 | std::for_each(std::cbegin(products), std::cend(products), | |
107 | [&id, &dataSourceController](const Product* product) { |
|
125 | [&id, &dataSourceController](const Product* product) { | |
108 | dataSourceController.setDataSourceItem(id, product->path, product->metadata); |
|
126 | dataSourceController.setDataSourceItem(id, product->path, product->metadata); | |
109 | }); |
|
127 | }); | |
110 | } |
|
128 | } | |
111 | }; |
|
129 | }; |
General Comments 0
You need to be logged in to leave comments.
Login now