@@ -0,0 +1,26 | |||||
|
1 | include_directories(include) | |||
|
2 | FILE (GLOB_RECURSE python_providers | |||
|
3 | include/*.h | |||
|
4 | src/*.cpp | |||
|
5 | resources/*.qrc | |||
|
6 | ) | |||
|
7 | ||||
|
8 | add_definitions(-DQT_PLUGIN) | |||
|
9 | add_definitions(-DSCIQLOP_PLUGIN_JSON_FILE_PATH="${CMAKE_CURRENT_SOURCE_DIR}/resources/python_providers.json") | |||
|
10 | if(NOT BUILD_SHARED_LIBS) | |||
|
11 | add_definitions(-DQT_STATICPLUGIN) | |||
|
12 | endif() | |||
|
13 | ||||
|
14 | add_library(python_providers ${python_providers}) | |||
|
15 | SET_TARGET_PROPERTIES(python_providers PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS TRUE) | |||
|
16 | ||||
|
17 | target_link_libraries(python_providers PUBLIC sciqlopgui) | |||
|
18 | target_link_libraries(python_providers PRIVATE pybind11::embed) | |||
|
19 | ADD_DEFINITIONS(-DQT_NO_KEYWORDS) | |||
|
20 | install(TARGETS python_providers | |||
|
21 | ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}/SciQlop | |||
|
22 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/SciQlop | |||
|
23 | RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) | |||
|
24 | ||||
|
25 | include(sciqlop_tests) | |||
|
26 |
@@ -0,0 +1,25 | |||||
|
1 | #ifndef PYTHON_PROVIDERS_H | |||
|
2 | #define PYTHON_PROVIDERS_H | |||
|
3 | ||||
|
4 | #include <Plugin/IPlugin.h> | |||
|
5 | ||||
|
6 | ||||
|
7 | #include <memory> | |||
|
8 | ||||
|
9 | #ifndef SCIQLOP_PLUGIN_JSON_FILE_PATH | |||
|
10 | #define SCIQLOP_PLUGIN_JSON_FILE_PATH "python_providers.json" | |||
|
11 | #endif | |||
|
12 | ||||
|
13 | class DataSourceItem; | |||
|
14 | ||||
|
15 | class PythonProviders : public QObject, public IPlugin | |||
|
16 | { | |||
|
17 | Q_OBJECT | |||
|
18 | Q_INTERFACES(IPlugin) | |||
|
19 | Q_PLUGIN_METADATA(IID "sciqlop.plugin.IPlugin" FILE SCIQLOP_PLUGIN_JSON_FILE_PATH) | |||
|
20 | public: | |||
|
21 | /// @sa IPlugin::initialize() | |||
|
22 | void initialize() override; | |||
|
23 | }; | |||
|
24 | ||||
|
25 | #endif // PYTHON_PROVIDERS_H |
@@ -0,0 +1,9 | |||||
|
1 | #include "python_providers.h" | |||
|
2 | #include <pybind11/embed.h> | |||
|
3 | namespace py = pybind11; | |||
|
4 | ||||
|
5 | void PythonProviders::initialize() | |||
|
6 | { | |||
|
7 | py::scoped_interpreter guard {}; | |||
|
8 | py::print("Hello, World!"); | |||
|
9 | } |
@@ -15,7 +15,8 if(NOT BUILD_SHARED_LIBS) | |||||
15 | add_definitions(-DQT_STATICPLUGIN) |
|
15 | add_definitions(-DQT_STATICPLUGIN) | |
16 | if(BUILD_PLUGINS) |
|
16 | if(BUILD_PLUGINS) | |
17 | target_link_libraries(sciqlopapp mockplugin) |
|
17 | target_link_libraries(sciqlopapp mockplugin) | |
18 | target_link_libraries(sciqlopapp amdaplugin) |
|
18 | #target_link_libraries(sciqlopapp amdaplugin) | |
|
19 | target_link_libraries(sciqlopapp python_providers) | |||
19 | endif() |
|
20 | endif() | |
20 | endif() |
|
21 | endif() | |
21 |
|
22 |
@@ -46,8 +46,9 int main(int argc, char* argv[]) | |||||
46 | #ifdef QT_STATICPLUGIN |
|
46 | #ifdef QT_STATICPLUGIN | |
47 | #ifndef SQP_NO_PLUGINS |
|
47 | #ifndef SQP_NO_PLUGINS | |
48 | Q_IMPORT_PLUGIN(MockPlugin) |
|
48 | Q_IMPORT_PLUGIN(MockPlugin) | |
49 |
Q_IMPORT_PLUGIN( |
|
49 | Q_IMPORT_PLUGIN(PythonProviders) | |
50 | Q_INIT_RESOURCE(amdaresources); |
|
50 | // Q_IMPORT_PLUGIN(AmdaPlugin) | |
|
51 | // Q_INIT_RESOURCE(amdaresources); | |||
51 | #endif |
|
52 | #endif | |
52 | #endif |
|
53 | #endif | |
53 | Q_INIT_RESOURCE(sqpguiresources); |
|
54 | Q_INIT_RESOURCE(sqpguiresources); |
@@ -304,12 +304,12 MainWindow::MainWindow(QWidget* parent) | |||||
304 |
|
304 | |||
305 | // Visualization |
|
305 | // Visualization | |
306 | connect(&sqpApp->visualizationController(), |
|
306 | connect(&sqpApp->visualizationController(), | |
307 | SIGNAL(variableAboutToBeDeleted(std::shared_ptr<Variable>)), m_Ui->view, |
|
307 | SIGNAL(variableAboutToBeDeleted(std::shared_ptr<Variable2>)), m_Ui->view, | |
308 | SLOT(onVariableAboutToBeDeleted(std::shared_ptr<Variable>))); |
|
308 | SLOT(onVariableAboutToBeDeleted(std::shared_ptr<Variable2>))); | |
309 |
|
309 | |||
310 | connect(&sqpApp->visualizationController(), |
|
310 | connect(&sqpApp->visualizationController(), | |
311 | SIGNAL(rangeChanged(std::shared_ptr<Variable>, const DateTimeRange&)), m_Ui->view, |
|
311 | SIGNAL(rangeChanged(std::shared_ptr<Variable2>, const DateTimeRange&)), m_Ui->view, | |
312 | SLOT(onRangeChanged(std::shared_ptr<Variable>, const DateTimeRange&))); |
|
312 | SLOT(onRangeChanged(std::shared_ptr<Variable2>, const DateTimeRange&))); | |
313 |
|
313 | |||
314 | // Widgets / widgets connections |
|
314 | // Widgets / widgets connections | |
315 |
|
315 |
@@ -1,1 +1,1 | |||||
1 | Subproject commit cc26524fb5d10feca3820e6921c9cd3cfb1a3591 |
|
1 | Subproject commit 00ce7df31d3e11df8a418988c601247f6dc64d13 |
@@ -11,7 +11,7 | |||||
11 |
|
11 | |||
12 | Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationTabWidget) |
|
12 | Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationTabWidget) | |
13 |
|
13 | |||
14 | class Variable; |
|
14 | class Variable2; | |
15 | class VisualizationZoneWidget; |
|
15 | class VisualizationZoneWidget; | |
16 |
|
16 | |||
17 | namespace Ui |
|
17 | namespace Ui |
@@ -120,8 +120,11 struct PlottablesUpdater<T, typename std::enable_if_t<std::is_base_of<ScalarTime | |||||
120 | auto minValue = 0., maxValue = 0.; |
|
120 | auto minValue = 0., maxValue = 0.; | |
121 | if (auto serie = dynamic_cast<ScalarTimeSerie*>(&dataSeries)) |
|
121 | if (auto serie = dynamic_cast<ScalarTimeSerie*>(&dataSeries)) | |
122 | { |
|
122 | { | |
123 | maxValue = (*std::max_element(std::begin(*serie), std::end(*serie))).v(); |
|
123 | if (serie->size()) | |
124 | minValue = (*std::min_element(std::begin(*serie), std::end(*serie))).v(); |
|
124 | { | |
|
125 | maxValue = (*std::max_element(std::begin(*serie), std::end(*serie))).v(); | |||
|
126 | minValue = (*std::min_element(std::begin(*serie), std::end(*serie))).v(); | |||
|
127 | } | |||
125 | } |
|
128 | } | |
126 | plot.yAxis->setRange(QCPRange { minValue, maxValue }); |
|
129 | plot.yAxis->setRange(QCPRange { minValue, maxValue }); | |
127 | } |
|
130 | } |
@@ -1,3 +1,4 | |||||
1 | add_subdirectory(mockplugin) |
|
1 | add_subdirectory(mockplugin) | |
2 |
add_subdirectory( |
|
2 | add_subdirectory(python_providers) | |
3 |
add_subdirectory( |
|
3 | #add_subdirectory(amda) | |
|
4 | #add_subdirectory(generic_ws) |
@@ -17,14 +17,14 class QNetworkRequest; | |||||
17 | /** |
|
17 | /** | |
18 | * @brief The AmdaProvider class is an example of how a data provider can generate data |
|
18 | * @brief The AmdaProvider class is an example of how a data provider can generate data | |
19 | */ |
|
19 | */ | |
20 |
class SCIQLOP_AMDA_EXPORT AmdaProvider : public IDataProvider |
|
20 | class SCIQLOP_AMDA_EXPORT AmdaProvider : public IDataProvider | |
|
21 | { | |||
21 | Q_OBJECT |
|
22 | Q_OBJECT | |
22 | public: |
|
23 | public: | |
23 | explicit AmdaProvider(); |
|
24 | explicit AmdaProvider(); | |
24 | std::shared_ptr<IDataProvider> clone() const override; |
|
25 | std::shared_ptr<IDataProvider> clone() const override; | |
25 |
|
26 | |||
26 |
virtual |
|
27 | virtual TimeSeries::ITimeSerie* getData(const DataProviderParameters& parameters) override; | |
27 |
|
||||
28 | }; |
|
28 | }; | |
29 |
|
29 | |||
30 | #endif // SCIQLOP_AMDAPROVIDER_H |
|
30 | #endif // SCIQLOP_AMDAPROVIDER_H |
@@ -7,18 +7,18 | |||||
7 | #include <Data/DataProviderParameters.h> |
|
7 | #include <Data/DataProviderParameters.h> | |
8 | #include <Network/NetworkController.h> |
|
8 | #include <Network/NetworkController.h> | |
9 | #include <SqpApplication.h> |
|
9 | #include <SqpApplication.h> | |
10 | #include <Variable/Variable.h> |
|
|||
11 |
|
10 | |||
|
11 | #include <Network/Downloader.h> | |||
|
12 | #include <QJsonDocument> | |||
12 | #include <QNetworkAccessManager> |
|
13 | #include <QNetworkAccessManager> | |
13 | #include <QNetworkReply> |
|
14 | #include <QNetworkReply> | |
14 | #include <QTemporaryFile> |
|
15 | #include <QTemporaryFile> | |
15 | #include <QThread> |
|
16 | #include <QThread> | |
16 | #include <QJsonDocument> |
|
|||
17 | #include <Network/Downloader.h> |
|
|||
18 |
|
17 | |||
19 | Q_LOGGING_CATEGORY(LOG_AmdaProvider, "AmdaProvider") |
|
18 | Q_LOGGING_CATEGORY(LOG_AmdaProvider, "AmdaProvider") | |
20 |
|
19 | |||
21 |
namespace |
|
20 | namespace | |
|
21 | { | |||
22 |
|
22 | |||
23 | /// URL format for a request on AMDA server. The parameters are as follows: |
|
23 | /// URL format for a request on AMDA server. The parameters are as follows: | |
24 | /// - %1: server URL |
|
24 | /// - %1: server URL | |
@@ -54,10 +54,7 QString dateFormat(double sqpRange) noexcept | |||||
54 |
|
54 | |||
55 | } // namespace |
|
55 | } // namespace | |
56 |
|
56 | |||
57 | AmdaProvider::AmdaProvider() |
|
57 | AmdaProvider::AmdaProvider() {} | |
58 | { |
|
|||
59 |
|
||||
60 | } |
|
|||
61 |
|
58 | |||
62 | std::shared_ptr<IDataProvider> AmdaProvider::clone() const |
|
59 | std::shared_ptr<IDataProvider> AmdaProvider::clone() const | |
63 | { |
|
60 | { | |
@@ -65,7 +62,7 std::shared_ptr<IDataProvider> AmdaProvider::clone() const | |||||
65 | return std::make_shared<AmdaProvider>(); |
|
62 | return std::make_shared<AmdaProvider>(); | |
66 | } |
|
63 | } | |
67 |
|
64 | |||
68 |
|
|
65 | TimeSeries::ITimeSerie* AmdaProvider::getData(const DataProviderParameters& parameters) | |
69 | { |
|
66 | { | |
70 | auto range = parameters.m_Range; |
|
67 | auto range = parameters.m_Range; | |
71 | auto metaData = parameters.m_Data; |
|
68 | auto metaData = parameters.m_Data; | |
@@ -74,15 +71,15 IDataSeries* AmdaProvider::getData(const DataProviderParameters ¶meters) | |||||
74 | = DataSeriesTypeUtils::fromString(metaData.value(AMDA_DATA_TYPE_KEY).toString()); |
|
71 | = DataSeriesTypeUtils::fromString(metaData.value(AMDA_DATA_TYPE_KEY).toString()); | |
75 | auto startDate = dateFormat(range.m_TStart); |
|
72 | auto startDate = dateFormat(range.m_TStart); | |
76 | auto endDate = dateFormat(range.m_TEnd); |
|
73 | auto endDate = dateFormat(range.m_TEnd); | |
77 | QVariantHash urlProperties{{AMDA_SERVER_KEY, metaData.value(AMDA_SERVER_KEY)}}; |
|
74 | QVariantHash urlProperties { { AMDA_SERVER_KEY, metaData.value(AMDA_SERVER_KEY) } }; | |
78 | auto token_url = QString{AMDA_TOKEN_URL_FORMAT}.arg(AmdaServer::instance().url(urlProperties)); |
|
75 | auto token_url | |
|
76 | = QString { AMDA_TOKEN_URL_FORMAT }.arg(AmdaServer::instance().url(urlProperties)); | |||
79 | auto response = Downloader::get(token_url); |
|
77 | auto response = Downloader::get(token_url); | |
80 | auto url = QString{AMDA_URL_FORMAT_WITH_TOKEN}.arg(AmdaServer::instance().url(urlProperties), |
|
78 | auto url = QString { AMDA_URL_FORMAT_WITH_TOKEN }.arg(AmdaServer::instance().url(urlProperties), | |
81 |
|
|
79 | startDate, endDate, productId, QString(response.data())); | |
82 | response = Downloader::get(url); |
|
80 | response = Downloader::get(url); | |
83 | auto test = QJsonDocument::fromJson(response.data()); |
|
81 | auto test = QJsonDocument::fromJson(response.data()); | |
84 | url = test["dataFileURLs"].toString(); |
|
82 | url = test["dataFileURLs"].toString(); | |
85 | response = Downloader::get(url); |
|
83 | response = Downloader::get(url); | |
86 |
return |
|
84 | return nullptr; // AmdaResultParser::readTxt(QTextStream { response.data() }, productValueType); | |
87 | } |
|
85 | } | |
88 |
|
@@ -4,7 +4,6 | |||||
4 |
|
4 | |||
5 | #include <QFile> |
|
5 | #include <QFile> | |
6 |
|
6 | |||
7 | #include <Data/IDataSeries.h> |
|
|||
8 | #include <cmath> |
|
7 | #include <cmath> | |
9 |
|
8 | |||
10 | Q_LOGGING_CATEGORY(LOG_AmdaResultParser, "AmdaResultParser") |
|
9 | Q_LOGGING_CATEGORY(LOG_AmdaResultParser, "AmdaResultParser") |
@@ -67,9 +67,10 extern const QString VALIDATION_FREQUENCY_BOUNDS_PROPERTY; | |||||
67 | // /////// // |
|
67 | // /////// // | |
68 |
|
68 | |||
69 | class Variable; |
|
69 | class Variable; | |
70 |
struct VariableState |
|
70 | struct VariableState | |
71 | std::shared_ptr<Variable> m_Variable{nullptr}; |
|
71 | { | |
72 | DateTimeRange m_Range{INVALID_RANGE}; |
|
72 | std::shared_ptr<Variable> m_Variable { nullptr }; | |
|
73 | DateTimeRange m_Range { INVALID_RANGE }; | |||
73 | }; |
|
74 | }; | |
74 |
|
75 | |||
75 | using VariableId = int; |
|
76 | using VariableId = int; | |
@@ -80,9 +81,10 using VariablesPool = std::map<VariableId, VariableState>; | |||||
80 | * with each other, and the current range of the group (i.e. range of the last synchronized variable |
|
81 | * with each other, and the current range of the group (i.e. range of the last synchronized variable | |
81 | * that has been moved) |
|
82 | * that has been moved) | |
82 | */ |
|
83 | */ | |
83 |
struct SyncGroup |
|
84 | struct SyncGroup | |
84 | std::set<VariableId> m_Variables{}; |
|
85 | { | |
85 | DateTimeRange m_Range{INVALID_RANGE}; |
|
86 | std::set<VariableId> m_Variables {}; | |
|
87 | DateTimeRange m_Range { INVALID_RANGE }; | |||
86 | }; |
|
88 | }; | |
87 |
|
89 | |||
88 | using SyncGroupId = QUuid; |
|
90 | using SyncGroupId = QUuid; | |
@@ -92,12 +94,13 using SyncGroupsPool = std::map<SyncGroupId, SyncGroup>; | |||||
92 | * Defines a current state during a fuzzing state. It contains all the variables manipulated during |
|
94 | * Defines a current state during a fuzzing state. It contains all the variables manipulated during | |
93 | * the test, as well as the synchronization status of these variables. |
|
95 | * the test, as well as the synchronization status of these variables. | |
94 | */ |
|
96 | */ | |
95 |
struct FuzzingState |
|
97 | struct FuzzingState | |
96 | const SyncGroup &syncGroup(SyncGroupId id) const; |
|
98 | { | |
97 |
SyncGroup |
|
99 | const SyncGroup& syncGroup(SyncGroupId id) const; | |
|
100 | SyncGroup& syncGroup(SyncGroupId id); | |||
98 |
|
101 | |||
99 |
const VariableState |
|
102 | const VariableState& variableState(VariableId id) const; | |
100 |
VariableState |
|
103 | VariableState& variableState(VariableId id); | |
101 |
|
104 | |||
102 | /// @return the identifier of the synchronization group in which the variable passed in |
|
105 | /// @return the identifier of the synchronization group in which the variable passed in | |
103 | /// parameter is located. If the variable is not in any group, returns an invalid identifier |
|
106 | /// parameter is located. If the variable is not in any group, returns an invalid identifier | |
@@ -119,7 +122,7 struct FuzzingState { | |||||
119 | /// Updates the range of a variable and all variables to which it is synchronized |
|
122 | /// Updates the range of a variable and all variables to which it is synchronized | |
120 | /// @param the variable for which to affect the range |
|
123 | /// @param the variable for which to affect the range | |
121 | /// @param the range to affect |
|
124 | /// @param the range to affect | |
122 |
void updateRanges(VariableId variableId, const DateTimeRange |
|
125 | void updateRanges(VariableId variableId, const DateTimeRange& newRange); | |
123 |
|
126 | |||
124 | VariablesPool m_VariablesPool; |
|
127 | VariablesPool m_VariablesPool; | |
125 | SyncGroupsPool m_SyncGroupsPool; |
|
128 | SyncGroupsPool m_SyncGroupsPool; |
@@ -13,17 +13,18 | |||||
13 | /** |
|
13 | /** | |
14 | * @brief The CosinusProvider class is an example of how a data provider can generate data |
|
14 | * @brief The CosinusProvider class is an example of how a data provider can generate data | |
15 | */ |
|
15 | */ | |
16 |
class SCIQLOP_MOCKPLUGIN_EXPORT CosinusProvider : public IDataProvider |
|
16 | class SCIQLOP_MOCKPLUGIN_EXPORT CosinusProvider : public IDataProvider | |
|
17 | { | |||
17 | public: |
|
18 | public: | |
18 | std::shared_ptr<IDataProvider> clone() const override; |
|
19 | std::shared_ptr<IDataProvider> clone() const override; | |
19 |
|
20 | |||
20 |
virtual |
|
21 | virtual TimeSeries::ITimeSerie* getData(const DataProviderParameters& parameters) override; | |
21 |
|
22 | |||
22 | private: |
|
23 | private: | |
23 | std::shared_ptr<IDataSeries> |
|
24 | std::shared_ptr<IDataSeries> retrieveData( | |
24 |
|
|
25 | QUuid acqIdentifier, const DateTimeRange& dataRangeRequested, const QVariantHash& data); | |
25 |
|
26 | |||
26 |
|
|
27 | TimeSeries::ITimeSerie* _generate(const DateTimeRange& range, const QVariantHash& metaData); | |
27 |
|
28 | |||
28 | QHash<QUuid, bool> m_VariableToEnableProvider; |
|
29 | QHash<QUuid, bool> m_VariableToEnableProvider; | |
29 | }; |
|
30 | }; |
@@ -2,9 +2,9 | |||||
2 | #include "MockDefs.h" |
|
2 | #include "MockDefs.h" | |
3 |
|
3 | |||
4 | #include <Data/DataProviderParameters.h> |
|
4 | #include <Data/DataProviderParameters.h> | |
5 |
#include <Data/ScalarSerie |
|
5 | #include <Data/ScalarTimeSerie.h> | |
6 |
#include <Data/SpectrogramSerie |
|
6 | #include <Data/SpectrogramTimeSerie.h> | |
7 |
#include <Data/VectorSerie |
|
7 | #include <Data/VectorTimeSerie.h> | |
8 |
|
8 | |||
9 | #include <cmath> |
|
9 | #include <cmath> | |
10 | #include <set> |
|
10 | #include <set> | |
@@ -14,145 +14,18 | |||||
14 | #include <QtConcurrent/QtConcurrent> |
|
14 | #include <QtConcurrent/QtConcurrent> | |
15 |
|
15 | |||
16 |
|
16 | |||
17 |
namespace |
|
17 | namespace | |
|
18 | { | |||
18 |
|
19 | |||
19 | /// Number of bands generated for a spectrogram |
|
20 | /// Number of bands generated for a spectrogram | |
20 | const auto SPECTROGRAM_NUMBER_BANDS = 30; |
|
21 | const auto SPECTROGRAM_NUMBER_BANDS = 30; | |
21 |
|
22 | |||
22 | /// Bands for which to generate NaN values for a spectrogram |
|
23 | /// Bands for which to generate NaN values for a spectrogram | |
23 | const auto SPECTROGRAM_NAN_BANDS = std::set<int>{1, 3, 10, 20}; |
|
24 | const auto SPECTROGRAM_NAN_BANDS = std::set<int> { 1, 3, 10, 20 }; | |
24 |
|
25 | |||
25 | /// Bands for which to generate zeros for a spectrogram |
|
26 | /// Bands for which to generate zeros for a spectrogram | |
26 | const auto SPECTROGRAM_ZERO_BANDS = std::set<int>{2, 15, 19, 29}; |
|
27 | const auto SPECTROGRAM_ZERO_BANDS = std::set<int> { 2, 15, 19, 29 }; | |
27 |
|
||||
28 | /// Abstract cosinus type |
|
|||
29 | struct ICosinusType { |
|
|||
30 | virtual ~ICosinusType() = default; |
|
|||
31 | /// @return the number of components generated for the type |
|
|||
32 | virtual std::size_t componentCount() const = 0; |
|
|||
33 | /// @return the data series created for the type |
|
|||
34 | virtual IDataSeries* createDataSeries(std::vector<double> xAxisData, |
|
|||
35 | std::vector<double> valuesData) const = 0; |
|
|||
36 | /// Generates values (one value per component) |
|
|||
37 | /// @param x the x-axis data used to generate values |
|
|||
38 | /// @param values the vector in which to insert the generated values |
|
|||
39 | /// @param dataIndex the index of insertion of the generated values |
|
|||
40 | /// |
|
|||
41 | virtual void generateValues(double x, std::vector<double> &values, int dataIndex) const = 0; |
|
|||
42 | }; |
|
|||
43 |
|
||||
44 | struct ScalarCosinus : public ICosinusType { |
|
|||
45 | std::size_t componentCount() const override { return 1; } |
|
|||
46 |
|
||||
47 | IDataSeries* createDataSeries(std::vector<double> xAxisData, |
|
|||
48 | std::vector<double> valuesData) const override |
|
|||
49 | { |
|
|||
50 | return new ScalarSeries(std::move(xAxisData), std::move(valuesData), |
|
|||
51 | Unit{QStringLiteral("t"), true}, Unit{}); |
|
|||
52 | } |
|
|||
53 |
|
||||
54 | void generateValues(double x, std::vector<double> &values, int dataIndex) const override |
|
|||
55 | { |
|
|||
56 | values[dataIndex] = std::cos(x); |
|
|||
57 | } |
|
|||
58 | }; |
|
|||
59 |
|
||||
60 | struct SpectrogramCosinus : public ICosinusType { |
|
|||
61 | /// Ctor with y-axis |
|
|||
62 | explicit SpectrogramCosinus(std::vector<double> yAxisData, Unit yAxisUnit, Unit valuesUnit) |
|
|||
63 | : m_YAxisData{std::move(yAxisData)}, |
|
|||
64 | m_YAxisUnit{std::move(yAxisUnit)}, |
|
|||
65 | m_ValuesUnit{std::move(valuesUnit)} |
|
|||
66 | { |
|
|||
67 | } |
|
|||
68 |
|
||||
69 | std::size_t componentCount() const override { return m_YAxisData.size(); } |
|
|||
70 |
|
||||
71 | IDataSeries* createDataSeries(std::vector<double> xAxisData, |
|
|||
72 | std::vector<double> valuesData) const override |
|
|||
73 | { |
|
|||
74 | return new SpectrogramSeries( |
|
|||
75 | std::move(xAxisData), m_YAxisData, std::move(valuesData), |
|
|||
76 | Unit{QStringLiteral("t"), true}, m_YAxisUnit, m_ValuesUnit); |
|
|||
77 | } |
|
|||
78 |
|
||||
79 | void generateValues(double x, std::vector<double> &values, int dataIndex) const override |
|
|||
80 | { |
|
|||
81 | auto componentCount = this->componentCount(); |
|
|||
82 | for (int i = 0; i < componentCount; ++i) { |
|
|||
83 | auto y = m_YAxisData[i]; |
|
|||
84 |
|
||||
85 | double value; |
|
|||
86 |
|
||||
87 | // if (SPECTROGRAM_ZERO_BANDS.find(y) != SPECTROGRAM_ZERO_BANDS.end()) { |
|
|||
88 | // value = 0.; |
|
|||
89 | // } |
|
|||
90 | // else if (SPECTROGRAM_NAN_BANDS.find(y) != SPECTROGRAM_NAN_BANDS.end()) { |
|
|||
91 | // value = std::numeric_limits<double>::quiet_NaN(); |
|
|||
92 | // } |
|
|||
93 | // else |
|
|||
94 | { |
|
|||
95 | // Generates value for non NaN/zero bands |
|
|||
96 | //auto r = 3 * std::sqrt(x * x + y * y) + 1e-2; |
|
|||
97 | //value = 2 * x * (std::cos(r + 2) / r - std::sin(r + 2) / r); |
|
|||
98 | value = x + 10*y; |
|
|||
99 | } |
|
|||
100 |
|
||||
101 | values[componentCount * dataIndex + i] = value; |
|
|||
102 | } |
|
|||
103 | } |
|
|||
104 |
|
||||
105 | std::vector<double> m_YAxisData; |
|
|||
106 | Unit m_YAxisUnit; |
|
|||
107 | Unit m_ValuesUnit; |
|
|||
108 | }; |
|
|||
109 |
|
||||
110 | struct VectorCosinus : public ICosinusType { |
|
|||
111 | std::size_t componentCount() const override { return 3; } |
|
|||
112 |
|
28 | |||
113 | IDataSeries* createDataSeries(std::vector<double> xAxisData, |
|
|||
114 | std::vector<double> valuesData) const override |
|
|||
115 | { |
|
|||
116 | return new VectorSeries(std::move(xAxisData), std::move(valuesData), |
|
|||
117 | Unit{QStringLiteral("t"), true}, Unit{}); |
|
|||
118 | } |
|
|||
119 |
|
||||
120 | void generateValues(double x, std::vector<double> &values, int dataIndex) const override |
|
|||
121 | { |
|
|||
122 | // Generates value for each component: cos(x), cos(x)/2, cos(x)/3 |
|
|||
123 | auto xValue = std::cos(x); |
|
|||
124 | auto componentCount = this->componentCount(); |
|
|||
125 | for (auto i = 0; i < componentCount; ++i) { |
|
|||
126 | values[componentCount * dataIndex + i] = xValue / (i + 1); |
|
|||
127 | } |
|
|||
128 | } |
|
|||
129 | }; |
|
|||
130 |
|
||||
131 | /// Converts string to cosinus type |
|
|||
132 | /// @return the cosinus type if the string could be converted, nullptr otherwise |
|
|||
133 | std::unique_ptr<ICosinusType> cosinusType(const QString &type) noexcept |
|
|||
134 | { |
|
|||
135 | if (type.compare(QStringLiteral("scalar"), Qt::CaseInsensitive) == 0) { |
|
|||
136 | return std::make_unique<ScalarCosinus>(); |
|
|||
137 | } |
|
|||
138 | else if (type.compare(QStringLiteral("spectrogram"), Qt::CaseInsensitive) == 0) { |
|
|||
139 | // Generates default y-axis data for spectrogram [0., 1., 2., ...] |
|
|||
140 | std::vector<double> yAxisData(SPECTROGRAM_NUMBER_BANDS); |
|
|||
141 | std::iota(yAxisData.begin(), yAxisData.end(), 1.); |
|
|||
142 | for (auto & v:yAxisData) |
|
|||
143 | { |
|
|||
144 | v = std::pow(2,v); |
|
|||
145 | } |
|
|||
146 | return std::make_unique<SpectrogramCosinus>(std::move(yAxisData), Unit{"eV"}, |
|
|||
147 | Unit{"eV/(cm^2-s-sr-eV)"}); |
|
|||
148 | } |
|
|||
149 | else if (type.compare(QStringLiteral("vector"), Qt::CaseInsensitive) == 0) { |
|
|||
150 | return std::make_unique<VectorCosinus>(); |
|
|||
151 | } |
|
|||
152 | else { |
|
|||
153 | return nullptr; |
|
|||
154 | } |
|
|||
155 | } |
|
|||
156 |
|
29 | |||
157 | } // namespace |
|
30 | } // namespace | |
158 |
|
31 | |||
@@ -162,43 +35,53 std::shared_ptr<IDataProvider> CosinusProvider::clone() const | |||||
162 | return std::make_shared<CosinusProvider>(); |
|
35 | return std::make_shared<CosinusProvider>(); | |
163 | } |
|
36 | } | |
164 |
|
37 | |||
165 | IDataSeries *CosinusProvider::_generate(const DateTimeRange &range, const QVariantHash &metaData) |
|
38 | TimeSeries::ITimeSerie* CosinusProvider::_generate( | |
|
39 | const DateTimeRange& range, const QVariantHash& metaData) | |||
166 | { |
|
40 | { | |
167 | auto dataIndex = 0; |
|
|||
168 |
|
||||
169 | // Retrieves cosinus type |
|
41 | // Retrieves cosinus type | |
170 | auto typeVariant = metaData.value(COSINUS_TYPE_KEY, COSINUS_TYPE_DEFAULT_VALUE); |
|
42 | auto typeVariant = metaData.value(COSINUS_TYPE_KEY, COSINUS_TYPE_DEFAULT_VALUE); | |
171 | auto type = cosinusType(typeVariant.toString()); |
|
|||
172 | auto freqVariant = metaData.value(COSINUS_FREQUENCY_KEY, COSINUS_FREQUENCY_DEFAULT_VALUE); |
|
43 | auto freqVariant = metaData.value(COSINUS_FREQUENCY_KEY, COSINUS_FREQUENCY_DEFAULT_VALUE); | |
|
44 | const auto fs = 200.; | |||
173 | double freq = freqVariant.toDouble(); |
|
45 | double freq = freqVariant.toDouble(); | |
174 | double start = std::ceil(range.m_TStart * freq); |
|
46 | double start = std::ceil(range.m_TStart * freq); | |
175 | double end = std::floor(range.m_TEnd * freq); |
|
47 | double end = std::floor(range.m_TEnd * freq); | |
176 |
if (end < start) |
|
48 | if (end < start) | |
|
49 | { | |||
177 | std::swap(start, end); |
|
50 | std::swap(start, end); | |
178 | } |
|
51 | } | |
179 | std::size_t dataCount = static_cast<std::size_t>(end - start + 1); |
|
52 | std::size_t dataCount = static_cast<std::size_t>(end - start + 1); | |
180 | std::size_t componentCount = type->componentCount(); |
|
53 | if (typeVariant.toString() == QStringLiteral("scalar")) | |
181 |
|
||||
182 | auto xAxisData = std::vector<double>{}; |
|
|||
183 | xAxisData.resize(dataCount); |
|
|||
184 |
|
||||
185 | auto valuesData = std::vector<double>{}; |
|
|||
186 | valuesData.resize(dataCount * componentCount); |
|
|||
187 |
|
||||
188 | int progress = 0; |
|
|||
189 | auto progressEnd = dataCount; |
|
|||
190 | for (auto time = start; time <= end; ++time, ++dataIndex) |
|
|||
191 | { |
|
54 | { | |
192 | const auto x = time / freq; |
|
55 | auto ts = new ScalarTimeSerie(dataCount); | |
193 | xAxisData[dataIndex] = x; |
|
56 | std::generate( | |
194 | // Generates values (depending on the type) |
|
57 | std::begin(*ts), std::end(*ts), [range, freq, fs, dt = 1. / freq, i = 0.]() mutable { | |
195 | type->generateValues(x, valuesData, dataIndex); |
|
58 | auto t = range.m_TStart + i * dt; | |
|
59 | i++; | |||
|
60 | return std::pair<double, double> { t, std::cos(2 * 3.14 * freq / fs * t) }; | |||
|
61 | }); | |||
|
62 | return ts; | |||
196 | } |
|
63 | } | |
197 | return type->createDataSeries(std::move(xAxisData), std::move(valuesData)); |
|
64 | if (typeVariant.toString() == QStringLiteral("vector")) | |
|
65 | { | |||
|
66 | auto ts = new VectorTimeSerie(dataCount); | |||
|
67 | std::generate( | |||
|
68 | std::begin(*ts), std::end(*ts), [range, freq, fs, dt = 1. / freq, i = 0.]() mutable { | |||
|
69 | auto t = range.m_TStart + i * dt; | |||
|
70 | i++; | |||
|
71 | return std::pair<double, VectorTimeSerie::raw_value_type> { t, | |||
|
72 | { std::cos(2 * 3.14 * freq / fs * t), std::sin(2 * 3.14 * freq / fs * t), | |||
|
73 | std::cos(2 * 3.14 * freq / fs * t) * std::sin(2 * 3.14 * freq / fs * t) } }; | |||
|
74 | }); | |||
|
75 | return ts; | |||
|
76 | } | |||
|
77 | if (typeVariant.toString() == QStringLiteral("spectrogram")) | |||
|
78 | { | |||
|
79 | return nullptr; | |||
|
80 | } | |||
|
81 | return nullptr; | |||
198 | } |
|
82 | } | |
199 |
|
83 | |||
200 |
|
|
84 | TimeSeries::ITimeSerie* CosinusProvider::getData(const DataProviderParameters& parameters) | |
201 | { |
|
85 | { | |
202 | return _generate(parameters.m_Range, parameters.m_Data); |
|
86 | return _generate(parameters.m_Range, parameters.m_Data); | |
203 | } |
|
87 | } | |
204 |
|
@@ -19,45 +19,41 | |||||
19 | /*-- Author : Alexis Jeandet |
|
19 | /*-- Author : Alexis Jeandet | |
20 | -- Mail : alexis.jeandet@member.fsf.org |
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |
21 | ----------------------------------------------------------------------------*/ |
|
21 | ----------------------------------------------------------------------------*/ | |
22 | #include <string> |
|
|||
23 | #include <sstream> |
|
|||
24 | #include <memory> |
|
22 | #include <memory> | |
|
23 | #include <sstream> | |||
|
24 | #include <string> | |||
25 |
|
25 | |||
26 |
#include <pybind11/ |
|
26 | #include <pybind11/chrono.h> | |
27 | #include <pybind11/operators.h> |
|
|||
28 | #include <pybind11/embed.h> |
|
27 | #include <pybind11/embed.h> | |
29 | #include <pybind11/numpy.h> |
|
28 | #include <pybind11/numpy.h> | |
30 |
#include <pybind11/ |
|
29 | #include <pybind11/operators.h> | |
|
30 | #include <pybind11/pybind11.h> | |||
31 |
|
31 | |||
|
32 | #include <Common/DateUtils.h> | |||
|
33 | #include <Data/DataSeriesType.h> | |||
|
34 | #include <Data/DateTimeRange.h> | |||
32 | #include <SqpApplication.h> |
|
35 | #include <SqpApplication.h> | |
33 | #include <Variable/VariableController2.h> |
|
|||
34 | #include <Time/TimeController.h> |
|
36 | #include <Time/TimeController.h> | |
35 | #include <Data/DateTimeRange.h> |
|
37 | #include <Variable/VariableController2.h> | |
36 | #include <Data/DataSeriesType.h> |
|
|||
37 | #include <Common/DateUtils.h> |
|
|||
38 | #include <Variable/Variable.h> |
|
|||
39 | #include <Data/ScalarSeries.h> |
|
|||
40 | #include <Data/VectorSeries.h> |
|
|||
41 |
|
38 | |||
42 | #include <MockPlugin.h> |
|
|||
43 | #include <CosinusProvider.h> |
|
39 | #include <CosinusProvider.h> | |
|
40 | #include <MockPlugin.h> | |||
44 |
|
41 | |||
45 | #include <QFile> |
|
42 | #include <QFile> | |
46 |
|
43 | |||
47 | #include <pywrappers_common.h> |
|
|||
48 | #include <CoreWrappers.h> |
|
44 | #include <CoreWrappers.h> | |
49 |
|
45 | #include <pywrappers_common.h> | ||
50 |
|
46 | |||
51 |
|
47 | |||
52 | using namespace std::chrono; |
|
48 | using namespace std::chrono; | |
53 | namespace py = pybind11; |
|
49 | namespace py = pybind11; | |
54 |
|
50 | |||
55 |
|
51 | |||
56 |
|
52 | PYBIND11_MODULE(pytestmockplugin, m) | ||
57 | PYBIND11_MODULE(pytestmockplugin, m){ |
|
53 | { | |
58 |
|
54 | |||
59 | int argc = 0; |
|
55 | int argc = 0; | |
60 |
char |
|
56 | char** argv = nullptr; | |
61 | SqpApplication::setOrganizationName("LPP"); |
|
57 | SqpApplication::setOrganizationName("LPP"); | |
62 | SqpApplication::setOrganizationDomain("lpp.fr"); |
|
58 | SqpApplication::setOrganizationDomain("lpp.fr"); | |
63 | SqpApplication::setApplicationName("SciQLop"); |
|
59 | SqpApplication::setApplicationName("SciQLop"); | |
@@ -68,18 +64,23 PYBIND11_MODULE(pytestmockplugin, m){ | |||||
68 |
|
64 | |||
69 | m.doc() = ""; |
|
65 | m.doc() = ""; | |
70 |
|
66 | |||
71 |
py::class_<VariableController2>(m, "VariableController2") |
|
67 | py::class_<VariableController2>(m, "VariableController2") | |
72 | std::shared_ptr<IDataProvider> provider, const DateTimeRange& range){ |
|
68 | .def_static("createVariable", | |
73 | return sqpApp->variableController().createVariable(name, {{"cosinusType", "spectrogram"}, {"cosinusFrequency", "0.1"}}, provider, range); |
|
69 | [](const QString& name, std::shared_ptr<IDataProvider> provider, | |
|
70 | const DateTimeRange& range) { | |||
|
71 | return sqpApp->variableController().createVariable(name, | |||
|
72 | { { "cosinusType", "spectrogram" }, { "cosinusFrequency", "0.1" } }, provider, | |||
|
73 | range); | |||
|
74 | }); | |||
|
75 | ||||
|
76 | py::class_<TimeController>(m, "TimeController").def_static("setTime", [](DateTimeRange range) { | |||
|
77 | sqpApp->timeController().setDateTimeRange(range); | |||
74 | }); |
|
78 | }); | |
75 |
|
79 | |||
76 | py::class_<TimeController>(m,"TimeController") |
|
|||
77 | .def_static("setTime", [](DateTimeRange range){sqpApp->timeController().setDateTimeRange(range);}); |
|
|||
78 |
|
||||
79 | auto mock_provider = std::make_shared<CosinusProvider>(); |
|
80 | auto mock_provider = std::make_shared<CosinusProvider>(); | |
80 |
m.def("mock_provider",[mock_provider](){return mock_provider;}, |
|
81 | m.def("mock_provider", [mock_provider]() { return mock_provider; }, | |
81 |
|
82 | py::return_value_policy::copy); | ||
82 | py::class_<CosinusProvider, std::shared_ptr<CosinusProvider>, IDataProvider>(m, "CosinusProvider"); |
|
|||
83 |
|
83 | |||
|
84 | py::class_<CosinusProvider, std::shared_ptr<CosinusProvider>, IDataProvider>( | |||
|
85 | m, "CosinusProvider"); | |||
84 | } |
|
86 | } | |
85 |
|
General Comments 0
You need to be logged in to leave comments.
Login now