##// END OF EJS Templates
Mini code clean on PyDataProvider...
jeandet -
r1491:317c38eb0f17
parent child
Show More
@@ -24,6 +24,45 struct Product
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:
@@ -35,7 +74,8 public:
35
74
36 virtual ~PyDataProvider() {}
75 virtual ~PyDataProvider() {}
37
76
38 virtual QPair<QPair<NpArray,NpArray>,DataSeriesType> get_data(const QMap<QString,QString>& key, double start_time, double stop_time)
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 {};
@@ -43,58 +83,36 public:
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(), parameters.m_Data.constKeyValueEnd(), [&metadata](const auto& item) {
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] = get_data(metadata,
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
55 //if (builder)
56 {
57 auto& [t,y]=data;
58 switch (type)
59 {
60 case DataSeriesType::SCALAR:
61 return new ScalarTimeSerie { std::move(t.data),
62 std::move(y.data) };
63 break;
64 case DataSeriesType::VECTOR:
65 return new VectorTimeSerie { std::move(t.data),
66 y.to_std_vect_vect() };
67 break;
68 case DataSeriesType::MULTICOMPONENT:
69 {
70 auto y_size = y.flat_size();
71 auto t_size = t.flat_size();
72
95
73 if(t_size && (y_size%t_size)==0)
96 auto& [t, y] = data;
74 {
97 switch (type)
75 return new MultiComponentTimeSerie { std::move(t.data),
98 {
76 std::move(y.data),{t_size, y_size/t_size} };
99 case DataSeriesType::SCALAR:
77 }
100 ts = make_scalar(t, y);
78 break;
101 break;
79 }
102 case DataSeriesType::VECTOR:
80 case DataSeriesType::SPECTROGRAM:
103 ts = make_vector(t, y);
81 {
104 break;
82 auto y_size = y.flat_size();
105 case DataSeriesType::MULTICOMPONENT:
83 auto t_size = t.flat_size();
106 ts = make_multi_comp(t, y);
84
107 break;
85 if(t_size && (y_size%t_size)==0)
108 case DataSeriesType::SPECTROGRAM:
86 {
109 ts = make_spectro(t, y);
87 return new SpectrogramTimeSerie { std::move(t.data),
110 break;
88 std::move(y.data),{t_size, y_size/t_size} };
111 default:
89 }
112 break;
90 break;
91 }
92 default:
93 break;
94 }
95 }
113 }
96 }
114 }
97 return nullptr;
115 return ts;
98 }
116 }
99
117
100
118
General Comments 0
You need to be logged in to leave comments. Login now