From 317c38eb0f178966a096ccc8dd2b6af76380e10b 2019-10-15 14:35:54 From: Alexis Jeandet Date: 2019-10-15 14:35:54 Subject: [PATCH] Mini code clean on PyDataProvider Signed-off-by: Alexis Jeandet --- diff --git a/app/PySide2-bindings/PyDataProvider.h b/app/PySide2-bindings/PyDataProvider.h index 31e8993..37db653 100644 --- a/app/PySide2-bindings/PyDataProvider.h +++ b/app/PySide2-bindings/PyDataProvider.h @@ -24,6 +24,45 @@ struct Product ~Product() = default; }; +template +ScalarTimeSerie* make_scalar(T& t, T& y) +{ + return new ScalarTimeSerie { std::move(t.data), std::move(y.data) }; +} + +template +VectorTimeSerie* make_vector(T& t, T& y) +{ + return new VectorTimeSerie { std::move(t.data), y.to_std_vect_vect() }; +} + +template +MultiComponentTimeSerie* make_multi_comp(T& t, T& y) +{ + auto y_size = y.flat_size(); + auto t_size = t.flat_size(); + if (t_size && (y_size % t_size) == 0) + { + return new MultiComponentTimeSerie { std::move(t.data), std::move(y.data), + { t_size, y_size / t_size } }; + } + return nullptr; +} + +template +SpectrogramTimeSerie* make_spectro(T& t, T& y) +{ + auto y_size = y.flat_size(); + auto t_size = t.flat_size(); + if (t_size && (y_size % t_size) == 0) + { + return new SpectrogramTimeSerie { std::move(t.data), std::move(y.data), + { t_size, y_size / t_size } }; + } + return nullptr; +} + + class PyDataProvider : public IDataProvider { public: @@ -35,7 +74,8 @@ public: virtual ~PyDataProvider() {} - virtual QPair,DataSeriesType> get_data(const QMap& key, double start_time, double stop_time) + virtual QPair, DataSeriesType> get_data( + const QMap& key, double start_time, double stop_time) { (void)key, (void)start_time, (void)stop_time; return {}; @@ -43,58 +83,36 @@ public: virtual TimeSeries::ITimeSerie* getData(const DataProviderParameters& parameters) override { + TimeSeries::ITimeSerie* ts = nullptr; if (parameters.m_Data.contains("name")) { - QMap metadata; - std::for_each(parameters.m_Data.constKeyValueBegin(), parameters.m_Data.constKeyValueEnd(), [&metadata](const auto& item) { - metadata[item.first] = item.second.toString(); - }); - auto [data, type] = get_data(metadata, - parameters.m_Range.m_TStart, parameters.m_Range.m_TEnd); - // TODO add shape/type switch - //if (builder) - { - auto& [t,y]=data; - switch (type) - { - case DataSeriesType::SCALAR: - return new ScalarTimeSerie { std::move(t.data), - std::move(y.data) }; - break; - case DataSeriesType::VECTOR: - return new VectorTimeSerie { std::move(t.data), - y.to_std_vect_vect() }; - break; - case DataSeriesType::MULTICOMPONENT: - { - auto y_size = y.flat_size(); - auto t_size = t.flat_size(); + QMap metadata; + std::for_each(parameters.m_Data.constKeyValueBegin(), + parameters.m_Data.constKeyValueEnd(), + [&metadata](const auto& item) { metadata[item.first] = item.second.toString(); }); + auto [data, type] + = get_data(metadata, parameters.m_Range.m_TStart, parameters.m_Range.m_TEnd); - if(t_size && (y_size%t_size)==0) - { - return new MultiComponentTimeSerie { std::move(t.data), - std::move(y.data),{t_size, y_size/t_size} }; - } - break; - } - case DataSeriesType::SPECTROGRAM: - { - auto y_size = y.flat_size(); - auto t_size = t.flat_size(); - - if(t_size && (y_size%t_size)==0) - { - return new SpectrogramTimeSerie { std::move(t.data), - std::move(y.data),{t_size, y_size/t_size} }; - } - break; - } - default: - break; - } + auto& [t, y] = data; + switch (type) + { + case DataSeriesType::SCALAR: + ts = make_scalar(t, y); + break; + case DataSeriesType::VECTOR: + ts = make_vector(t, y); + break; + case DataSeriesType::MULTICOMPONENT: + ts = make_multi_comp(t, y); + break; + case DataSeriesType::SPECTROGRAM: + ts = make_spectro(t, y); + break; + default: + break; } } - return nullptr; + return ts; }