@@ -0,0 +1,22 | |||||
|
1 | #ifndef SCIQLOP_SINGLETHRESHOLDCACHESTRATEGY_H | |||
|
2 | #define SCIQLOP_SINGLETHRESHOLDCACHESTRATEGY_H | |||
|
3 | ||||
|
4 | #include "Settings/SqpSettingsDefs.h" | |||
|
5 | #include "VariableCacheStrategy.h" | |||
|
6 | ||||
|
7 | class SCIQLOP_CORE_EXPORT SingleThresholdCacheStrategy : public VariableCacheStrategy { | |||
|
8 | public: | |||
|
9 | SingleThresholdCacheStrategy() = default; | |||
|
10 | ||||
|
11 | DateTimeRange computeRange(const DateTimeRange ¤tCacheRange, | |||
|
12 | const DateTimeRange &rangeRequested) override | |||
|
13 | { | |||
|
14 | Q_UNUSED(currentCacheRange); | |||
|
15 | if(currentCacheRange.contains (rangeRequested*1.1)) | |||
|
16 | return currentCacheRange; | |||
|
17 | return rangeRequested*2.; | |||
|
18 | } | |||
|
19 | }; | |||
|
20 | ||||
|
21 | ||||
|
22 | #endif // SCIQLOP_SINGLETHRESHOLDCACHESTRATEGY_H |
@@ -1,190 +1,191 | |||||
1 | cmake_minimum_required(VERSION 3.6) |
|
1 | cmake_minimum_required(VERSION 3.6) | |
2 | project(SciQLOPCore CXX) |
|
2 | project(SciQLOPCore CXX) | |
3 |
|
3 | |||
4 | OPTION (CPPCHECK "Analyzes the source code with cppcheck" OFF) |
|
4 | OPTION (CPPCHECK "Analyzes the source code with cppcheck" OFF) | |
5 | OPTION (CLANG_TIDY "Analyzes the source code with Clang Tidy" OFF) |
|
5 | OPTION (CLANG_TIDY "Analyzes the source code with Clang Tidy" OFF) | |
6 | OPTION (IWYU "Analyzes the source code with Include What You Use" OFF) |
|
6 | OPTION (IWYU "Analyzes the source code with Include What You Use" OFF) | |
7 |
|
7 | |||
8 | OPTION (Catalog "builds catalog API" OFF) |
|
8 | OPTION (Catalog "builds catalog API" OFF) | |
9 |
|
9 | |||
10 | set(CMAKE_CXX_STANDARD 17) |
|
10 | set(CMAKE_CXX_STANDARD 17) | |
11 |
|
11 | |||
12 | set(CMAKE_AUTOMOC ON) |
|
12 | set(CMAKE_AUTOMOC ON) | |
13 | #https://gitlab.kitware.com/cmake/cmake/issues/15227 |
|
13 | #https://gitlab.kitware.com/cmake/cmake/issues/15227 | |
14 | #set(CMAKE_AUTOUIC ON) |
|
14 | #set(CMAKE_AUTOUIC ON) | |
15 | if(POLICY CMP0071) |
|
15 | if(POLICY CMP0071) | |
16 | cmake_policy(SET CMP0071 OLD) |
|
16 | cmake_policy(SET CMP0071 OLD) | |
17 | endif() |
|
17 | endif() | |
18 | set(CMAKE_AUTORCC ON) |
|
18 | set(CMAKE_AUTORCC ON) | |
19 | set(CMAKE_INCLUDE_CURRENT_DIR ON) |
|
19 | set(CMAKE_INCLUDE_CURRENT_DIR ON) | |
20 |
|
20 | |||
21 | find_package(Qt5 COMPONENTS Core Widgets Network PrintSupport Svg Test REQUIRED) |
|
21 | find_package(Qt5 COMPONENTS Core Widgets Network PrintSupport Svg Test REQUIRED) | |
22 |
|
22 | |||
23 | find_package(pybind11 CONFIG QUIET) |
|
23 | find_package(pybind11 CONFIG QUIET) | |
24 | if (NOT pybind11_FOUND) |
|
24 | if (NOT pybind11_FOUND) | |
25 | execute_process(COMMAND git submodule init external/pybind11 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) |
|
25 | execute_process(COMMAND git submodule init external/pybind11 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) | |
26 | execute_process(COMMAND git submodule update external/pybind11 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) |
|
26 | execute_process(COMMAND git submodule update external/pybind11 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) | |
27 | add_subdirectory(external/pybind11) |
|
27 | add_subdirectory(external/pybind11) | |
28 | endif() |
|
28 | endif() | |
29 |
|
29 | |||
30 | macro(declare_test testname testexe sources libraries) |
|
30 | macro(declare_test testname testexe sources libraries) | |
31 | add_executable(${testexe} ${sources}) |
|
31 | add_executable(${testexe} ${sources}) | |
32 | target_link_libraries(${testexe} ${libraries}) |
|
32 | target_link_libraries(${testexe} ${libraries}) | |
33 | add_test(NAME ${testname} COMMAND ${testexe}) |
|
33 | add_test(NAME ${testname} COMMAND ${testexe}) | |
34 | endmacro(declare_test) |
|
34 | endmacro(declare_test) | |
35 |
|
35 | |||
36 | enable_testing() |
|
36 | enable_testing() | |
37 |
|
37 | |||
38 | FILE (GLOB_RECURSE core_SRCS |
|
38 | FILE (GLOB_RECURSE core_SRCS | |
39 | ./include/DataSource/DataSourceItemMergeHelper.h |
|
39 | ./include/DataSource/DataSourceItemMergeHelper.h | |
40 | ./include/DataSource/DataSourceItemAction.h |
|
40 | ./include/DataSource/DataSourceItemAction.h | |
41 | ./include/DataSource/DataSourceItem.h |
|
41 | ./include/DataSource/DataSourceItem.h | |
42 | ./include/DataSource/DataSourceController.h |
|
42 | ./include/DataSource/DataSourceController.h | |
43 | ./include/Common/SortUtils.h |
|
43 | ./include/Common/SortUtils.h | |
44 | ./include/Common/spimpl.h |
|
44 | ./include/Common/spimpl.h | |
45 | ./include/Common/MimeTypesDef.h |
|
45 | ./include/Common/MimeTypesDef.h | |
46 | ./include/Common/MetaTypes.h |
|
46 | ./include/Common/MetaTypes.h | |
47 | ./include/Common/StringUtils.h |
|
47 | ./include/Common/StringUtils.h | |
48 | ./include/Common/SignalWaiter.h |
|
48 | ./include/Common/SignalWaiter.h | |
49 | ./include/Common/DateUtils.h |
|
49 | ./include/Common/DateUtils.h | |
50 | ./include/Common/Numeric.h |
|
50 | ./include/Common/Numeric.h | |
51 | ./include/Common/deprecate.h |
|
51 | ./include/Common/deprecate.h | |
52 | ./include/Common/containers.h |
|
52 | ./include/Common/containers.h | |
53 | ./include/Common/debug.h |
|
53 | ./include/Common/debug.h | |
54 | ./include/Plugin/IPlugin.h |
|
54 | ./include/Plugin/IPlugin.h | |
55 | ./include/Data/ArrayDataIterator.h |
|
55 | ./include/Data/ArrayDataIterator.h | |
56 | ./include/Data/VariableRequest.h |
|
56 | ./include/Data/VariableRequest.h | |
57 | ./include/Data/VectorSeries.h |
|
57 | ./include/Data/VectorSeries.h | |
58 | ./include/Data/DateTimeRange.h |
|
58 | ./include/Data/DateTimeRange.h | |
59 | ./include/Data/DateTimeRangeHelper.h |
|
59 | ./include/Data/DateTimeRangeHelper.h | |
60 | ./include/Data/ScalarSeries.h |
|
60 | ./include/Data/ScalarSeries.h | |
61 | ./include/Data/DataSeriesMergeHelper.h |
|
61 | ./include/Data/DataSeriesMergeHelper.h | |
62 | ./include/Data/DataSeries.h |
|
62 | ./include/Data/DataSeries.h | |
63 | ./include/Data/AcquisitionDataPacket.h |
|
63 | ./include/Data/AcquisitionDataPacket.h | |
64 | ./include/Data/DataSeriesType.h |
|
64 | ./include/Data/DataSeriesType.h | |
65 | ./include/Data/AcquisitionRequest.h |
|
65 | ./include/Data/AcquisitionRequest.h | |
66 | ./include/Data/SqpIterator.h |
|
66 | ./include/Data/SqpIterator.h | |
67 | ./include/Data/ArrayData.h |
|
67 | ./include/Data/ArrayData.h | |
68 | ./include/Data/DataSeriesIterator.h |
|
68 | ./include/Data/DataSeriesIterator.h | |
69 | ./include/Data/DataSeriesUtils.h |
|
69 | ./include/Data/DataSeriesUtils.h | |
70 | ./include/Data/SpectrogramSeries.h |
|
70 | ./include/Data/SpectrogramSeries.h | |
71 | ./include/Data/Unit.h |
|
71 | ./include/Data/Unit.h | |
72 | ./include/Data/DataProviderParameters.h |
|
72 | ./include/Data/DataProviderParameters.h | |
73 | ./include/Data/OptionalAxis.h |
|
73 | ./include/Data/OptionalAxis.h | |
74 | ./include/Data/IDataProvider.h |
|
74 | ./include/Data/IDataProvider.h | |
75 | ./include/Data/IDataSeries.h |
|
75 | ./include/Data/IDataSeries.h | |
76 | ./include/Network/NetworkController.h |
|
76 | ./include/Network/NetworkController.h | |
77 | ./include/Network/Downloader.h |
|
77 | ./include/Network/Downloader.h | |
78 | ./include/Version.h |
|
78 | ./include/Version.h | |
79 | ./include/CoreGlobal.h |
|
79 | ./include/CoreGlobal.h | |
80 | ./include/Visualization/VisualizationController.h |
|
80 | ./include/Visualization/VisualizationController.h | |
81 | ./include/PluginManager/PluginManager.h |
|
81 | ./include/PluginManager/PluginManager.h | |
82 | ./include/Variable/VariableModel.h |
|
82 | ./include/Variable/VariableModel.h | |
83 | ./include/Variable/VariableAcquisitionWorker.h |
|
83 | ./include/Variable/VariableAcquisitionWorker.h | |
84 | ./include/Variable/VariableCacheStrategy.h |
|
84 | ./include/Variable/VariableCacheStrategy.h | |
85 | ./include/Variable/VariableSynchronizationGroup.h |
|
85 | ./include/Variable/VariableSynchronizationGroup.h | |
86 | ./include/Variable/VariableSynchronizationGroup2.h |
|
86 | ./include/Variable/VariableSynchronizationGroup2.h | |
87 | ./include/Variable/ProportionalCacheStrategy.h |
|
87 | ./include/Variable/ProportionalCacheStrategy.h | |
|
88 | ./include/Variable/SingleThresholdCacheStrategy.h | |||
88 | ./include/Variable/VariableCacheStrategyFactory.h |
|
89 | ./include/Variable/VariableCacheStrategyFactory.h | |
89 | ./include/Variable/Variable.h |
|
90 | ./include/Variable/Variable.h | |
90 | ./include/Variable/VariableCacheController.h |
|
91 | ./include/Variable/VariableCacheController.h | |
91 | ./include/Variable/VariableController.h |
|
92 | ./include/Variable/VariableController.h | |
92 | ./include/Variable/VariableController2.h |
|
93 | ./include/Variable/VariableController2.h | |
93 | ./include/Time/TimeController.h |
|
94 | ./include/Time/TimeController.h | |
94 | ./include/Settings/ISqpSettingsBindable.h |
|
95 | ./include/Settings/ISqpSettingsBindable.h | |
95 | ./include/Settings/SqpSettingsDefs.h |
|
96 | ./include/Settings/SqpSettingsDefs.h | |
96 |
|
97 | |||
97 | ./src/DataSource/DataSourceItem.cpp |
|
98 | ./src/DataSource/DataSourceItem.cpp | |
98 | ./src/DataSource/DataSourceItemAction.cpp |
|
99 | ./src/DataSource/DataSourceItemAction.cpp | |
99 | ./src/DataSource/DataSourceItemMergeHelper.cpp |
|
100 | ./src/DataSource/DataSourceItemMergeHelper.cpp | |
100 | ./src/DataSource/DataSourceController.cpp |
|
101 | ./src/DataSource/DataSourceController.cpp | |
101 | ./src/Common/DateUtils.cpp |
|
102 | ./src/Common/DateUtils.cpp | |
102 | ./src/Common/MimeTypesDef.cpp |
|
103 | ./src/Common/MimeTypesDef.cpp | |
103 | ./src/Common/StringUtils.cpp |
|
104 | ./src/Common/StringUtils.cpp | |
104 | ./src/Common/SignalWaiter.cpp |
|
105 | ./src/Common/SignalWaiter.cpp | |
105 | ./src/Data/ScalarSeries.cpp |
|
106 | ./src/Data/ScalarSeries.cpp | |
106 | ./src/Data/DataSeriesIterator.cpp |
|
107 | ./src/Data/DataSeriesIterator.cpp | |
107 | ./src/Data/OptionalAxis.cpp |
|
108 | ./src/Data/OptionalAxis.cpp | |
108 | ./src/Data/ArrayDataIterator.cpp |
|
109 | ./src/Data/ArrayDataIterator.cpp | |
109 | ./src/Data/SpectrogramSeries.cpp |
|
110 | ./src/Data/SpectrogramSeries.cpp | |
110 | ./src/Data/DataSeriesUtils.cpp |
|
111 | ./src/Data/DataSeriesUtils.cpp | |
111 | ./src/Data/VectorSeries.cpp |
|
112 | ./src/Data/VectorSeries.cpp | |
112 | ./src/Network/NetworkController.cpp |
|
113 | ./src/Network/NetworkController.cpp | |
113 | ./src/Network/Downloader.cpp |
|
114 | ./src/Network/Downloader.cpp | |
114 | ./src/Visualization/VisualizationController.cpp |
|
115 | ./src/Visualization/VisualizationController.cpp | |
115 | ./src/PluginManager/PluginManager.cpp |
|
116 | ./src/PluginManager/PluginManager.cpp | |
116 | ./src/Variable/VariableController.cpp |
|
117 | ./src/Variable/VariableController.cpp | |
117 | ./src/Variable/VariableController2.cpp |
|
118 | ./src/Variable/VariableController2.cpp | |
118 | ./src/Variable/VariableModel.cpp |
|
119 | ./src/Variable/VariableModel.cpp | |
119 | ./src/Variable/VariableCacheController.cpp |
|
120 | ./src/Variable/VariableCacheController.cpp | |
120 | ./src/Variable/VariableSynchronizationGroup.cpp |
|
121 | ./src/Variable/VariableSynchronizationGroup.cpp | |
121 | ./src/Variable/VariableSynchronizationGroup2.cpp |
|
122 | ./src/Variable/VariableSynchronizationGroup2.cpp | |
122 | ./src/Variable/Variable.cpp |
|
123 | ./src/Variable/Variable.cpp | |
123 | ./src/Variable/VariableAcquisitionWorker.cpp |
|
124 | ./src/Variable/VariableAcquisitionWorker.cpp | |
124 | ./src/Version.cpp |
|
125 | ./src/Version.cpp | |
125 | ./src/Time/TimeController.cpp |
|
126 | ./src/Time/TimeController.cpp | |
126 | ./src/Settings/SqpSettingsDefs.cpp |
|
127 | ./src/Settings/SqpSettingsDefs.cpp | |
127 |
|
128 | |||
128 | ) |
|
129 | ) | |
129 |
|
130 | |||
130 |
|
131 | |||
131 | IF(Catalog) |
|
132 | IF(Catalog) | |
132 | FILE (GLOB_RECURSE core_catalog_SRCS |
|
133 | FILE (GLOB_RECURSE core_catalog_SRCS | |
133 | ./src/Catalogue/CatalogueController.cpp |
|
134 | ./src/Catalogue/CatalogueController.cpp | |
134 | ./include/Catalogue/CatalogueController.h |
|
135 | ./include/Catalogue/CatalogueController.h | |
135 | ) |
|
136 | ) | |
136 | ELSE() |
|
137 | ELSE() | |
137 | FILE (GLOB_RECURSE core_catalog_SRCS |
|
138 | FILE (GLOB_RECURSE core_catalog_SRCS | |
138 | ) |
|
139 | ) | |
139 | ENDIF(Catalog) |
|
140 | ENDIF(Catalog) | |
140 |
|
141 | |||
141 | add_definitions(-DCORE_STATIC) |
|
142 | add_definitions(-DCORE_STATIC) | |
142 | #add_definitions(-DHIDE_DEPRECATED) |
|
143 | #add_definitions(-DHIDE_DEPRECATED) | |
143 | add_definitions(-DSCIQLOP_CRASH_ON_ERROR) |
|
144 | add_definitions(-DSCIQLOP_CRASH_ON_ERROR) | |
144 |
|
145 | |||
145 | add_library(sciqlopcore ${core_SRCS} ${core_catalog_SRCS}) |
|
146 | add_library(sciqlopcore ${core_SRCS} ${core_catalog_SRCS}) | |
146 | SET_TARGET_PROPERTIES(sciqlopcore PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS TRUE) |
|
147 | SET_TARGET_PROPERTIES(sciqlopcore PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS TRUE) | |
147 |
|
148 | |||
148 | target_include_directories(sciqlopcore PUBLIC |
|
149 | target_include_directories(sciqlopcore PUBLIC | |
149 | $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> |
|
150 | $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> | |
150 | $<INSTALL_INTERFACE:include/SciQLOP> |
|
151 | $<INSTALL_INTERFACE:include/SciQLOP> | |
151 | ) |
|
152 | ) | |
152 |
|
153 | |||
153 | target_link_libraries(sciqlopcore PUBLIC |
|
154 | target_link_libraries(sciqlopcore PUBLIC | |
154 | Qt5::Core |
|
155 | Qt5::Core | |
155 | Qt5::Network |
|
156 | Qt5::Network | |
156 | ) |
|
157 | ) | |
157 |
|
158 | |||
158 | if(Catalog) |
|
159 | if(Catalog) | |
159 | target_link_libraries(sciqlopcore PUBLIC |
|
160 | target_link_libraries(sciqlopcore PUBLIC | |
160 | catalogs |
|
161 | catalogs | |
161 | ) |
|
162 | ) | |
162 | endif() |
|
163 | endif() | |
163 |
|
164 | |||
164 |
|
165 | |||
165 | pybind11_add_module(sciqlopqt src/pybind11_wrappers/QtWrappers.cpp) |
|
166 | pybind11_add_module(sciqlopqt src/pybind11_wrappers/QtWrappers.cpp) | |
166 | target_link_libraries(sciqlopqt PUBLIC Qt5::Core) |
|
167 | target_link_libraries(sciqlopqt PUBLIC Qt5::Core) | |
167 |
|
168 | |||
168 | pybind11_add_module(pysciqlopcore src/pybind11_wrappers/CoreWrappers.cpp) |
|
169 | pybind11_add_module(pysciqlopcore src/pybind11_wrappers/CoreWrappers.cpp) | |
169 | target_link_libraries(pysciqlopcore PUBLIC sciqlopcore) |
|
170 | target_link_libraries(pysciqlopcore PUBLIC sciqlopcore) | |
170 |
|
171 | |||
171 | add_library(pysciqlop src/pybind11_wrappers/pywrappers_common.h) |
|
172 | add_library(pysciqlop src/pybind11_wrappers/pywrappers_common.h) | |
172 | target_link_libraries(pysciqlop PUBLIC Qt5::Core) |
|
173 | target_link_libraries(pysciqlop PUBLIC Qt5::Core) | |
173 | target_include_directories(pysciqlop PUBLIC |
|
174 | target_include_directories(pysciqlop PUBLIC | |
174 | $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/pybind11_wrappers/> |
|
175 | $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/pybind11_wrappers/> | |
175 | $<INSTALL_INTERFACE:include/SciQLOP/py_wrappers> |
|
176 | $<INSTALL_INTERFACE:include/SciQLOP/py_wrappers> | |
176 | ) |
|
177 | ) | |
177 |
|
178 | |||
178 | SET_PROPERTY(GLOBAL PROPERTY CORE_PYTHON_PATH ${CMAKE_CURRENT_BINARY_DIR}) |
|
179 | SET_PROPERTY(GLOBAL PROPERTY CORE_PYTHON_PATH ${CMAKE_CURRENT_BINARY_DIR}) | |
179 |
|
180 | |||
180 |
|
181 | |||
181 | install(TARGETS sciqlopcore EXPORT SciQLOPCoreConfig |
|
182 | install(TARGETS sciqlopcore EXPORT SciQLOPCoreConfig | |
182 | ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} |
|
183 | ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} | |
183 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} |
|
184 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} | |
184 | RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) |
|
185 | RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) | |
185 |
|
186 | |||
186 | install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/SciQLOP) |
|
187 | install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/SciQLOP) | |
187 | install(EXPORT SciQLOPCoreConfig DESTINATION share/SciQLOPCore/cmake) |
|
188 | install(EXPORT SciQLOPCoreConfig DESTINATION share/SciQLOPCore/cmake) | |
188 | export(TARGETS sciqlopcore FILE SciQLOPCoreConfig.cmake) |
|
189 | export(TARGETS sciqlopcore FILE SciQLOPCoreConfig.cmake) | |
189 |
|
190 | |||
190 | add_subdirectory(tests) |
|
191 | add_subdirectory(tests) |
@@ -1,61 +1,62 | |||||
1 | #ifndef SCIQLOP_DATETIMERANGEHELPER_H |
|
1 | #ifndef SCIQLOP_DATETIMERANGEHELPER_H | |
2 | #define SCIQLOP_DATETIMERANGEHELPER_H |
|
2 | #define SCIQLOP_DATETIMERANGEHELPER_H | |
3 |
|
3 | |||
4 | #include <cmath> |
|
4 | #include <cmath> | |
|
5 | #include <variant> | |||
5 | #include <QObject> |
|
6 | #include <QObject> | |
6 |
|
7 | |||
7 | #include <QDebug> |
|
8 | #include <QDebug> | |
8 |
|
9 | |||
9 | #include <opaque/numeric_typedef.hpp> |
|
10 | #include <opaque/numeric_typedef.hpp> | |
10 | #include <Common/DateUtils.h> |
|
11 | #include <Common/DateUtils.h> | |
11 | #include <Common/MetaTypes.h> |
|
12 | #include <Common/MetaTypes.h> | |
12 | #include <Common/Numeric.h> |
|
13 | #include <Common/Numeric.h> | |
13 | #include <Data/DateTimeRange.h> |
|
14 | #include <Data/DateTimeRange.h> | |
14 |
|
15 | |||
15 | namespace DateTimeRangeHelper { |
|
16 | namespace DateTimeRangeHelper { | |
16 |
|
17 | |||
17 |
|
18 | |||
18 | bool isnan(const DateTimeRange& range) |
|
19 | bool isnan(const DateTimeRange& range) | |
19 | { |
|
20 | { | |
20 | return std::isnan(range.m_TStart) && std::isnan(range.m_TEnd); |
|
21 | return std::isnan(range.m_TStart) && std::isnan(range.m_TEnd); | |
21 | } |
|
22 | } | |
22 |
|
23 | |||
23 | bool hasnan(const DateTimeRange& range) |
|
24 | bool hasnan(const DateTimeRange& range) | |
24 | { |
|
25 | { | |
25 | return std::isnan(range.m_TStart) || std::isnan(range.m_TEnd); |
|
26 | return std::isnan(range.m_TStart) || std::isnan(range.m_TEnd); | |
26 | } |
|
27 | } | |
27 |
|
28 | |||
28 | bool isPureShift(const DateTimeRange& range1, const DateTimeRange& range2) |
|
29 | bool isPureShift(const DateTimeRange& range1, const DateTimeRange& range2) | |
29 | { |
|
30 | { | |
30 | return SciQLop::numeric::almost_equal<double>(range1.delta(), range2.delta(), 1) |
|
31 | return SciQLop::numeric::almost_equal<double>(range1.delta(), range2.delta(), 1) | |
31 | && !SciQLop::numeric::almost_equal(range1.m_TStart, range2.m_TStart, 1); |
|
32 | && !SciQLop::numeric::almost_equal(range1.m_TStart, range2.m_TStart, 1); | |
32 | } |
|
33 | } | |
33 |
|
34 | |||
34 | bool isPureZoom(const DateTimeRange& range1, const DateTimeRange& range2) |
|
35 | bool isPureZoom(const DateTimeRange& range1, const DateTimeRange& range2) | |
35 | { |
|
36 | { | |
36 | return !SciQLop::numeric::almost_equal<double>(range1.delta(),range2.delta(),1)&& |
|
37 | return !SciQLop::numeric::almost_equal<double>(range1.delta(),range2.delta(),1)&& | |
37 | SciQLop::numeric::almost_equal<double>(range1.center(), range2.center(),1); |
|
38 | SciQLop::numeric::almost_equal<double>(range1.center(), range2.center(),1); | |
38 | } |
|
39 | } | |
39 |
|
40 | |||
40 | /** |
|
41 | /** | |
41 | * @brief computeTransformation such as range2 = zoom*range1 + shift |
|
42 | * @brief computeTransformation such as range2 = zoom*range1 + shift | |
42 | * @param range1 |
|
43 | * @param range1 | |
43 | * @param range2 |
|
44 | * @param range2 | |
44 | * @return trnaformation applied to range1 to get range2 or an object of type |
|
45 | * @return trnaformation applied to range1 to get range2 or an object of type | |
45 | * InvalidDateTimeRangeTransformation if the transformation has NaN or forbiden values |
|
46 | * InvalidDateTimeRangeTransformation if the transformation has NaN or forbiden values | |
46 | */ |
|
47 | */ | |
47 | std::variant<DateTimeRangeTransformation, InvalidDateTimeRangeTransformation> |
|
48 | std::variant<DateTimeRangeTransformation, InvalidDateTimeRangeTransformation> | |
48 | computeTransformation(const DateTimeRange& range1, const DateTimeRange& range2) |
|
49 | computeTransformation(const DateTimeRange& range1, const DateTimeRange& range2) | |
49 | { |
|
50 | { | |
50 | double zoom = range2.delta()/range1.delta(); |
|
51 | double zoom = range2.delta()/range1.delta(); | |
51 | Seconds<double> shift = range2.center() - (range1*zoom).center(); |
|
52 | Seconds<double> shift = range2.center() - (range1*zoom).center(); | |
52 | bool zoomValid = zoom!=0. && !std::isnan(zoom) && !std::isinf(zoom); |
|
53 | bool zoomValid = zoom!=0. && !std::isnan(zoom) && !std::isinf(zoom); | |
53 | bool shiftValid = !std::isnan(shift.value) && !std::isinf(shift.value); |
|
54 | bool shiftValid = !std::isnan(shift.value) && !std::isinf(shift.value); | |
54 | if(zoomValid && shiftValid) |
|
55 | if(zoomValid && shiftValid) | |
55 | return DateTimeRangeTransformation{zoom, shift}; |
|
56 | return DateTimeRangeTransformation{zoom, shift}; | |
56 | return InvalidDateTimeRangeTransformation{}; |
|
57 | return InvalidDateTimeRangeTransformation{}; | |
57 | } |
|
58 | } | |
58 |
|
59 | |||
59 | } |
|
60 | } | |
60 |
|
61 | |||
61 | #endif // SCIQLOP_DATETIMERANGEHELPER_H |
|
62 | #endif // SCIQLOP_DATETIMERANGEHELPER_H |
@@ -1,24 +1,24 | |||||
1 |
#ifndef SCIQLOP_ |
|
1 | #ifndef SCIQLOP_PROPORTIONALCACHESTRATEGY_H | |
2 |
#define SCIQLOP_ |
|
2 | #define SCIQLOP_PROPORTIONALCACHESTRATEGY_H | |
3 |
|
3 | |||
4 | #include "Settings/SqpSettingsDefs.h" |
|
4 | #include "Settings/SqpSettingsDefs.h" | |
5 | #include "VariableCacheStrategy.h" |
|
5 | #include "VariableCacheStrategy.h" | |
6 |
|
6 | |||
7 |
|
7 | |||
8 | /// This class aims to hande the cache strategy. |
|
8 | /// This class aims to hande the cache strategy. | |
9 | class SCIQLOP_CORE_EXPORT ProportionalCacheStrategy : public VariableCacheStrategy { |
|
9 | class SCIQLOP_CORE_EXPORT ProportionalCacheStrategy : public VariableCacheStrategy { | |
10 | public: |
|
10 | public: | |
11 | ProportionalCacheStrategy() = default; |
|
11 | ProportionalCacheStrategy() = default; | |
12 |
|
12 | |||
13 | DateTimeRange computeRange(const DateTimeRange ¤tCacheRange, |
|
13 | DateTimeRange computeRange(const DateTimeRange ¤tCacheRange, | |
14 | const DateTimeRange &rangeRequested) override |
|
14 | const DateTimeRange &rangeRequested) override | |
15 | { |
|
15 | { | |
16 | Q_UNUSED(currentCacheRange); |
|
16 | Q_UNUSED(currentCacheRange); | |
17 | auto toleranceFactor = SqpSettings::toleranceValue( |
|
17 | auto toleranceFactor = SqpSettings::toleranceValue( | |
18 | GENERAL_TOLERANCE_AT_UPDATE_KEY, GENERAL_TOLERANCE_AT_UPDATE_DEFAULT_VALUE); |
|
18 | GENERAL_TOLERANCE_AT_UPDATE_KEY, GENERAL_TOLERANCE_AT_UPDATE_DEFAULT_VALUE); | |
19 | return rangeRequested*(1.+toleranceFactor); |
|
19 | return rangeRequested*(1.+toleranceFactor); | |
20 | } |
|
20 | } | |
21 | }; |
|
21 | }; | |
22 |
|
22 | |||
23 |
|
23 | |||
24 |
#endif // SCIQLOP_ |
|
24 | #endif // SCIQLOP_PROPORTIONALCACHESTRATEGY_H |
@@ -1,47 +1,48 | |||||
1 | #ifndef SCIQLOP_VARIABLECACHESTRATEGYFACTORY_H |
|
1 | #ifndef SCIQLOP_VARIABLECACHESTRATEGYFACTORY_H | |
2 | #define SCIQLOP_VARIABLECACHESTRATEGYFACTORY_H |
|
2 | #define SCIQLOP_VARIABLECACHESTRATEGYFACTORY_H | |
3 |
|
3 | |||
4 |
|
4 | |||
5 | #include <memory> |
|
5 | #include <memory> | |
6 | #include <stdexcept> |
|
6 | #include <stdexcept> | |
7 |
|
7 | |||
8 | #include "VariableCacheStrategy.h" |
|
8 | #include "VariableCacheStrategy.h" | |
9 | #include "ProportionalCacheStrategy.h" |
|
9 | #include "ProportionalCacheStrategy.h" | |
|
10 | #include "SingleThresholdCacheStrategy.h" | |||
10 |
|
11 | |||
11 | #include <Common/debug.h> |
|
12 | #include <Common/debug.h> | |
12 | #include <QString> |
|
13 | #include <QString> | |
13 |
|
14 | |||
14 |
|
15 | |||
15 | enum class CacheStrategy { Proportional, SingleThreshold, TwoThreshold }; |
|
16 | enum class CacheStrategy { Proportional, SingleThreshold, TwoThreshold }; | |
16 |
|
17 | |||
17 | class VariableCacheStrategyFactory { |
|
18 | class VariableCacheStrategyFactory { | |
18 |
|
19 | |||
19 | using cacheStratPtr = std::unique_ptr<VariableCacheStrategy>; |
|
20 | using cacheStratPtr = std::unique_ptr<VariableCacheStrategy>; | |
20 |
|
21 | |||
21 | public: |
|
22 | public: | |
22 | static cacheStratPtr createCacheStrategy(CacheStrategy specificStrategy) |
|
23 | static cacheStratPtr createCacheStrategy(CacheStrategy specificStrategy) | |
23 | { |
|
24 | { | |
24 | switch (specificStrategy) { |
|
25 | switch (specificStrategy) { | |
25 | case CacheStrategy::Proportional: { |
|
26 | case CacheStrategy::Proportional: { | |
26 | return std::unique_ptr<VariableCacheStrategy>{ |
|
27 | return std::unique_ptr<VariableCacheStrategy>{ | |
27 | new ProportionalCacheStrategy{}}; |
|
28 | new ProportionalCacheStrategy{}}; | |
28 | } |
|
29 | } | |
29 | case CacheStrategy::SingleThreshold: { |
|
30 | case CacheStrategy::SingleThreshold: { | |
30 | SCIQLOP_ERROR(VariableCacheStrategyFactory, "CacheStrategy::SingleThreshold not implemented yet"); |
|
31 | return std::unique_ptr<VariableCacheStrategy>{ | |
31 | break; |
|
32 | new SingleThresholdCacheStrategy{}}; | |
32 | } |
|
33 | } | |
33 | case CacheStrategy::TwoThreshold: { |
|
34 | case CacheStrategy::TwoThreshold: { | |
34 | SCIQLOP_ERROR(VariableCacheStrategyFactory, "CacheStrategy::TwoThreshold not implemented yet"); |
|
35 | SCIQLOP_ERROR(VariableCacheStrategyFactory, "CacheStrategy::TwoThreshold not implemented yet"); | |
35 | break; |
|
36 | break; | |
36 | } |
|
37 | } | |
37 | default: |
|
38 | default: | |
38 | SCIQLOP_ERROR(VariableCacheStrategyFactory, "Unknown cache strategy"); |
|
39 | SCIQLOP_ERROR(VariableCacheStrategyFactory, "Unknown cache strategy"); | |
39 | break; |
|
40 | break; | |
40 | } |
|
41 | } | |
41 |
|
42 | |||
42 | return nullptr; |
|
43 | return nullptr; | |
43 | } |
|
44 | } | |
44 | }; |
|
45 | }; | |
45 |
|
46 | |||
46 |
|
47 | |||
47 | #endif // VARIABLECACHESTRATEGYFACTORY_H |
|
48 | #endif // VARIABLECACHESTRATEGYFACTORY_H |
@@ -1,71 +1,71 | |||||
1 | #ifndef SCIQLOP_VARIABLESYNCHRONIZATIONGROUP2_H |
|
1 | #ifndef SCIQLOP_VARIABLESYNCHRONIZATIONGROUP2_H | |
2 | #define SCIQLOP_VARIABLESYNCHRONIZATIONGROUP2_H |
|
2 | #define SCIQLOP_VARIABLESYNCHRONIZATIONGROUP2_H | |
3 |
|
3 | |||
4 | #include <QUuid> |
|
4 | #include <QUuid> | |
5 | #include <set> |
|
5 | #include <set> | |
6 |
|
6 | |||
7 | #include "CoreGlobal.h" |
|
7 | #include "CoreGlobal.h" | |
8 | #include <Common/spimpl.h> |
|
8 | #include <Common/spimpl.h> | |
9 | #include <Common/containers.h> |
|
9 | #include <Common/containers.h> | |
10 |
|
10 | |||
11 | /** |
|
11 | /** | |
12 | * @brief The VariableSynchronizationGroup2 class holds a list of Variables uuid which are synchronized |
|
12 | * @brief The VariableSynchronizationGroup2 class holds a list of Variables uuid which are synchronized | |
13 | * @note This class is part of SciQLop internals, as a normal user you shouldn't have to care about it |
|
13 | * @note This class is part of SciQLop internals, as a normal user you shouldn't have to care about it | |
14 | */ |
|
14 | */ | |
15 | class SCIQLOP_CORE_EXPORT VariableSynchronizationGroup2 |
|
15 | class SCIQLOP_CORE_EXPORT VariableSynchronizationGroup2 | |
16 | { |
|
16 | { | |
17 |
|
17 | |||
18 | public: |
|
18 | public: | |
19 | explicit VariableSynchronizationGroup2()=default; |
|
19 | explicit VariableSynchronizationGroup2()=default; | |
20 | /** |
|
20 | /** | |
21 | * @brief VariableSynchronizationGroup2 is a convenience ctor to build a group with a default variable |
|
21 | * @brief VariableSynchronizationGroup2 is a convenience ctor to build a group with a default variable | |
22 | * @param variable |
|
22 | * @param variable | |
23 | */ |
|
23 | */ | |
24 | explicit VariableSynchronizationGroup2(QUuid variable) |
|
24 | explicit VariableSynchronizationGroup2(QUuid variable) | |
25 | :_variables{{variable}} |
|
25 | :_variables{{variable}} | |
26 | {} |
|
26 | {} | |
27 |
|
27 | |||
28 | /** |
|
28 | /** | |
29 | * @brief addVariable adds the given variable to the group, does nothing if the varaible is alredy in the group |
|
29 | * @brief addVariable adds the given variable to the group, does nothing if the varaible is alredy in the group | |
30 | * @param variable |
|
30 | * @param variable | |
31 | * @sa removeVariable |
|
31 | * @sa removeVariable | |
32 | */ |
|
32 | */ | |
33 | void addVariable(QUuid variable) noexcept |
|
33 | void addVariable(QUuid variable) noexcept | |
34 | { |
|
34 | { | |
35 | this->_variables.insert(variable); |
|
35 | this->_variables.insert(variable); | |
36 | } |
|
36 | } | |
37 |
|
37 | |||
38 | /** |
|
38 | /** | |
39 | * @brief removeVariable removes the given variable from the group, does nothing if the varaible is not in the group |
|
39 | * @brief removeVariable removes the given variable from the group, does nothing if the varaible is not in the group | |
40 | * @param variable |
|
40 | * @param variable | |
41 | * @sa addVariable |
|
41 | * @sa addVariable | |
42 | */ |
|
42 | */ | |
43 | void removeVariable(QUuid variable) noexcept |
|
43 | void removeVariable(QUuid variable) noexcept | |
44 | { |
|
44 | { | |
45 |
this->_variables.e |
|
45 | this->_variables.erase(variable); | |
46 | } |
|
46 | } | |
47 |
|
47 | |||
48 | /** |
|
48 | /** | |
49 | * @brief contains checks if the given variable is in the group |
|
49 | * @brief contains checks if the given variable is in the group | |
50 | * @param variable |
|
50 | * @param variable | |
51 | * @return true if the variable is in the group |
|
51 | * @return true if the variable is in the group | |
52 | */ |
|
52 | */ | |
53 | bool contains(QUuid variable) const noexcept |
|
53 | bool contains(QUuid variable) const noexcept | |
54 | { |
|
54 | { | |
55 | return SciQLop::containers::contains(this->_variables,variable); |
|
55 | return SciQLop::containers::contains(this->_variables,variable); | |
56 | } |
|
56 | } | |
57 |
|
57 | |||
58 | /** |
|
58 | /** | |
59 | * @brief variables |
|
59 | * @brief variables | |
60 | * @return the list of synchronized variables in this group as a std::set |
|
60 | * @return the list of synchronized variables in this group as a std::set | |
61 | */ |
|
61 | */ | |
62 | const std::set<QUuid> &variables() const noexcept |
|
62 | const std::set<QUuid> &variables() const noexcept | |
63 | { |
|
63 | { | |
64 | return this->_variables; |
|
64 | return this->_variables; | |
65 | } |
|
65 | } | |
66 |
|
66 | |||
67 | private: |
|
67 | private: | |
68 | std::set<QUuid> _variables; |
|
68 | std::set<QUuid> _variables; | |
69 | }; |
|
69 | }; | |
70 |
|
70 | |||
71 | #endif // SCIQLOP_VARIABLESYNCHRONIZATIONGROUP2_H |
|
71 | #endif // SCIQLOP_VARIABLESYNCHRONIZATIONGROUP2_H |
@@ -1,190 +1,190 | |||||
1 | #include "Variable/VariableController2.h" |
|
1 | #include "Variable/VariableController2.h" | |
2 | #include "Variable/VariableSynchronizationGroup2.h" |
|
2 | #include "Variable/VariableSynchronizationGroup2.h" | |
3 | #include <Common/containers.h> |
|
3 | #include <Common/containers.h> | |
4 | #include <Common/debug.h> |
|
4 | #include <Common/debug.h> | |
5 | #include <Data/DataProviderParameters.h> |
|
5 | #include <Data/DataProviderParameters.h> | |
6 | #include <Data/DateTimeRangeHelper.h> |
|
6 | #include <Data/DateTimeRangeHelper.h> | |
7 | #include <Variable/VariableCacheStrategyFactory.h> |
|
7 | #include <Variable/VariableCacheStrategyFactory.h> | |
8 |
|
8 | |||
9 | class VariableController2::VariableController2Private |
|
9 | class VariableController2::VariableController2Private | |
10 | { |
|
10 | { | |
11 | QMap<QUuid,std::shared_ptr<Variable>> _variables; |
|
11 | QMap<QUuid,std::shared_ptr<Variable>> _variables; | |
12 | QMap<QUuid,std::shared_ptr<IDataProvider>> _providers; |
|
12 | QMap<QUuid,std::shared_ptr<IDataProvider>> _providers; | |
13 | QMap<QUuid,std::shared_ptr<VariableSynchronizationGroup2>> _synchronizationGroups; |
|
13 | QMap<QUuid,std::shared_ptr<VariableSynchronizationGroup2>> _synchronizationGroups; | |
14 | std::unique_ptr<VariableCacheStrategy> _cacheStrategy; |
|
14 | std::unique_ptr<VariableCacheStrategy> _cacheStrategy; | |
15 | bool p_contains(std::shared_ptr<Variable> variable) |
|
15 | bool p_contains(std::shared_ptr<Variable> variable) | |
16 | { |
|
16 | { | |
17 | return _providers.contains(variable->ID()); |
|
17 | return _providers.contains(variable->ID()); | |
18 | } |
|
18 | } | |
19 | bool v_contains(std::shared_ptr<Variable> variable) |
|
19 | bool v_contains(std::shared_ptr<Variable> variable) | |
20 | { |
|
20 | { | |
21 | return SciQLop::containers::contains(this->_variables, variable); |
|
21 | return SciQLop::containers::contains(this->_variables, variable); | |
22 | } |
|
22 | } | |
23 | bool sg_contains(std::shared_ptr<Variable> variable) |
|
23 | bool sg_contains(std::shared_ptr<Variable> variable) | |
24 | { |
|
24 | { | |
25 | return _synchronizationGroups.contains(variable->ID()); |
|
25 | return _synchronizationGroups.contains(variable->ID()); | |
26 | } |
|
26 | } | |
27 |
|
27 | |||
28 | void _changeRange(std::shared_ptr<Variable> var, DateTimeRange r) |
|
28 | void _changeRange(std::shared_ptr<Variable> var, DateTimeRange r) | |
29 | { |
|
29 | { | |
30 | auto provider = _providers[var->ID()]; |
|
30 | auto provider = _providers[var->ID()]; | |
31 | DateTimeRange newCacheRange; |
|
31 | DateTimeRange newCacheRange; | |
32 | std::vector<DateTimeRange> missingRanges; |
|
32 | std::vector<DateTimeRange> missingRanges; | |
33 | if(DateTimeRangeHelper::hasnan(var->cacheRange())) |
|
33 | if(DateTimeRangeHelper::hasnan(var->cacheRange())) | |
34 | { |
|
34 | { | |
35 | newCacheRange = _cacheStrategy->computeRange(r,r); |
|
35 | newCacheRange = _cacheStrategy->computeRange(r,r); | |
36 | missingRanges = {newCacheRange}; |
|
36 | missingRanges = {newCacheRange}; | |
37 | } |
|
37 | } | |
38 | else |
|
38 | else | |
39 | { |
|
39 | { | |
40 | newCacheRange = _cacheStrategy->computeRange(var->cacheRange(),r); |
|
40 | newCacheRange = _cacheStrategy->computeRange(var->cacheRange(),r); | |
41 | missingRanges = newCacheRange - var->cacheRange(); |
|
41 | missingRanges = newCacheRange - var->cacheRange(); | |
42 | } |
|
42 | } | |
43 | for(auto range:missingRanges) |
|
43 | for(auto range:missingRanges) | |
44 | { |
|
44 | { | |
45 | auto data = provider->getData(DataProviderParameters{{range},var->metadata()}); |
|
45 | auto data = provider->getData(DataProviderParameters{{range},var->metadata()}); | |
46 | var->mergeDataSeries(data); |
|
46 | var->mergeDataSeries(data); | |
47 | } |
|
47 | } | |
48 |
var->setCacheRange( |
|
48 | var->setCacheRange(newCacheRange); | |
49 | var->setRange(r); |
|
49 | var->setRange(r); | |
50 | } |
|
50 | } | |
51 | public: |
|
51 | public: | |
52 | VariableController2Private(QObject* parent=Q_NULLPTR) |
|
52 | VariableController2Private(QObject* parent=Q_NULLPTR) | |
53 |
:_cacheStrategy(VariableCacheStrategyFactory::createCacheStrategy(CacheStrategy:: |
|
53 | :_cacheStrategy(VariableCacheStrategyFactory::createCacheStrategy(CacheStrategy::SingleThreshold)) | |
54 | { |
|
54 | { | |
55 | Q_UNUSED(parent); |
|
55 | Q_UNUSED(parent); | |
56 | } |
|
56 | } | |
57 |
|
57 | |||
58 | ~VariableController2Private() = default; |
|
58 | ~VariableController2Private() = default; | |
59 |
|
59 | |||
60 | std::shared_ptr<Variable> createVariable(const QString &name, const QVariantHash &metadata, std::shared_ptr<IDataProvider> provider) |
|
60 | std::shared_ptr<Variable> createVariable(const QString &name, const QVariantHash &metadata, std::shared_ptr<IDataProvider> provider) | |
61 | { |
|
61 | { | |
62 | auto newVar = std::make_shared<Variable>(name,metadata); |
|
62 | auto newVar = std::make_shared<Variable>(name,metadata); | |
63 | this->_variables[newVar->ID()] = newVar; |
|
63 | this->_variables[newVar->ID()] = newVar; | |
64 | this->_providers[newVar->ID()] = provider; |
|
64 | this->_providers[newVar->ID()] = provider; | |
65 | this->_synchronizationGroups[newVar->ID()] = std::make_shared<VariableSynchronizationGroup2>(newVar->ID()); |
|
65 | this->_synchronizationGroups[newVar->ID()] = std::make_shared<VariableSynchronizationGroup2>(newVar->ID()); | |
66 | return newVar; |
|
66 | return newVar; | |
67 | } |
|
67 | } | |
68 |
|
68 | |||
69 | void deleteVariable(std::shared_ptr<Variable> variable) |
|
69 | void deleteVariable(std::shared_ptr<Variable> variable) | |
70 | { |
|
70 | { | |
71 | /* |
|
71 | /* | |
72 | * Removing twice a var is ok but a var without provider has to be a hard error |
|
72 | * Removing twice a var is ok but a var without provider has to be a hard error | |
73 | * this means we got the var controller in an inconsistent state |
|
73 | * this means we got the var controller in an inconsistent state | |
74 | */ |
|
74 | */ | |
75 | if(v_contains(variable)) |
|
75 | if(v_contains(variable)) | |
76 | this->_variables.remove(variable->ID()); |
|
76 | this->_variables.remove(variable->ID()); | |
77 | if(p_contains(variable)) |
|
77 | if(p_contains(variable)) | |
78 | this->_providers.remove(variable->ID()); |
|
78 | this->_providers.remove(variable->ID()); | |
79 | else |
|
79 | else | |
80 | SCIQLOP_ERROR(VariableController2Private, "No provider found for given variable"); |
|
80 | SCIQLOP_ERROR(VariableController2Private, "No provider found for given variable"); | |
81 | } |
|
81 | } | |
82 |
|
82 | |||
83 | void changeRange(std::shared_ptr<Variable> variable, DateTimeRange r) |
|
83 | void changeRange(std::shared_ptr<Variable> variable, DateTimeRange r) | |
84 | { |
|
84 | { | |
85 | if(p_contains(variable)) |
|
85 | if(p_contains(variable)) | |
86 | { |
|
86 | { | |
87 | if(!DateTimeRangeHelper::hasnan(r)) |
|
87 | if(!DateTimeRangeHelper::hasnan(r)) | |
88 | { |
|
88 | { | |
89 | auto transformation = DateTimeRangeHelper::computeTransformation(variable->range(),r); |
|
89 | auto transformation = DateTimeRangeHelper::computeTransformation(variable->range(),r); | |
90 | auto group = _synchronizationGroups[variable->ID()]; |
|
90 | auto group = _synchronizationGroups[variable->ID()]; | |
91 | if(std::holds_alternative<DateTimeRangeTransformation>(transformation)) |
|
91 | if(std::holds_alternative<DateTimeRangeTransformation>(transformation)) | |
92 | { |
|
92 | { | |
93 | for(auto varId:group->variables()) |
|
93 | for(auto varId:group->variables()) | |
94 | { |
|
94 | { | |
95 | auto var = _variables[varId]; |
|
95 | auto var = _variables[varId]; | |
96 | auto newRange = var->range().transform(std::get<DateTimeRangeTransformation>(transformation)); |
|
96 | auto newRange = var->range().transform(std::get<DateTimeRangeTransformation>(transformation)); | |
97 | _changeRange(var,newRange); |
|
97 | _changeRange(var,newRange); | |
98 | } |
|
98 | } | |
99 | } |
|
99 | } | |
100 | else // force new range to all variables -> may be weird if more than one var in the group |
|
100 | else // force new range to all variables -> may be weird if more than one var in the group | |
101 | // @TODO ensure that there is no side effects |
|
101 | // @TODO ensure that there is no side effects | |
102 | { |
|
102 | { | |
103 | for(auto varId:group->variables()) |
|
103 | for(auto varId:group->variables()) | |
104 | { |
|
104 | { | |
105 | auto var = _variables[varId]; |
|
105 | auto var = _variables[varId]; | |
106 | _changeRange(var,r); |
|
106 | _changeRange(var,r); | |
107 | } |
|
107 | } | |
108 | } |
|
108 | } | |
109 | } |
|
109 | } | |
110 | else |
|
110 | else | |
111 | { |
|
111 | { | |
112 | SCIQLOP_ERROR(VariableController2Private, "Invalid range containing NaN"); |
|
112 | SCIQLOP_ERROR(VariableController2Private, "Invalid range containing NaN"); | |
113 | } |
|
113 | } | |
114 | } |
|
114 | } | |
115 | else |
|
115 | else | |
116 | { |
|
116 | { | |
117 | SCIQLOP_ERROR(VariableController2Private, "No provider found for given variable"); |
|
117 | SCIQLOP_ERROR(VariableController2Private, "No provider found for given variable"); | |
118 | } |
|
118 | } | |
119 | } |
|
119 | } | |
120 |
|
120 | |||
121 | void synchronize(std::shared_ptr<Variable> var, std::shared_ptr<Variable> with) |
|
121 | void synchronize(std::shared_ptr<Variable> var, std::shared_ptr<Variable> with) | |
122 | { |
|
122 | { | |
123 | if(v_contains(var) && v_contains(with)) |
|
123 | if(v_contains(var) && v_contains(with)) | |
124 | { |
|
124 | { | |
125 | if(sg_contains(var) && sg_contains(with)) |
|
125 | if(sg_contains(var) && sg_contains(with)) | |
126 | { |
|
126 | { | |
127 |
|
127 | |||
128 | auto dest_group = this->_synchronizationGroups[with->ID()]; |
|
128 | auto dest_group = this->_synchronizationGroups[with->ID()]; | |
129 | this->_synchronizationGroups[var->ID()] = dest_group; |
|
129 | this->_synchronizationGroups[var->ID()] = dest_group; | |
130 | dest_group->addVariable(var->ID()); |
|
130 | dest_group->addVariable(var->ID()); | |
131 | } |
|
131 | } | |
132 | else |
|
132 | else | |
133 | { |
|
133 | { | |
134 | SCIQLOP_ERROR(VariableController2Private, "At least one of the given variables isn't in a sync group"); |
|
134 | SCIQLOP_ERROR(VariableController2Private, "At least one of the given variables isn't in a sync group"); | |
135 | } |
|
135 | } | |
136 | } |
|
136 | } | |
137 | else |
|
137 | else | |
138 | { |
|
138 | { | |
139 | SCIQLOP_ERROR(VariableController2Private, "At least one of the given variables is not found"); |
|
139 | SCIQLOP_ERROR(VariableController2Private, "At least one of the given variables is not found"); | |
140 | } |
|
140 | } | |
141 | } |
|
141 | } | |
142 |
|
142 | |||
143 | const std::set<std::shared_ptr<Variable>> variables() |
|
143 | const std::set<std::shared_ptr<Variable>> variables() | |
144 | { |
|
144 | { | |
145 | std::set<std::shared_ptr<Variable>> vars; |
|
145 | std::set<std::shared_ptr<Variable>> vars; | |
146 | for(auto var:_variables.values()) |
|
146 | for(auto var:_variables.values()) | |
147 | { |
|
147 | { | |
148 | vars.insert(var); |
|
148 | vars.insert(var); | |
149 | } |
|
149 | } | |
150 | return vars; |
|
150 | return vars; | |
151 | } |
|
151 | } | |
152 |
|
152 | |||
153 | }; |
|
153 | }; | |
154 |
|
154 | |||
155 | VariableController2::VariableController2() |
|
155 | VariableController2::VariableController2() | |
156 | :impl{spimpl::make_unique_impl<VariableController2Private>()} |
|
156 | :impl{spimpl::make_unique_impl<VariableController2Private>()} | |
157 | {} |
|
157 | {} | |
158 |
|
158 | |||
159 | std::shared_ptr<Variable> VariableController2::createVariable(const QString &name, const QVariantHash &metadata, std::shared_ptr<IDataProvider> provider, const DateTimeRange &range) |
|
159 | std::shared_ptr<Variable> VariableController2::createVariable(const QString &name, const QVariantHash &metadata, std::shared_ptr<IDataProvider> provider, const DateTimeRange &range) | |
160 | { |
|
160 | { | |
161 | auto var = impl->createVariable(name, metadata, provider); |
|
161 | auto var = impl->createVariable(name, metadata, provider); | |
162 | emit variableAdded(var); |
|
162 | emit variableAdded(var); | |
163 | if(!DateTimeRangeHelper::hasnan(range)) |
|
163 | if(!DateTimeRangeHelper::hasnan(range)) | |
164 | impl->changeRange(var,range); |
|
164 | impl->changeRange(var,range); | |
165 | else |
|
165 | else | |
166 | SCIQLOP_ERROR(VariableController2, "Creating a variable with default constructed DateTimeRange is an error"); |
|
166 | SCIQLOP_ERROR(VariableController2, "Creating a variable with default constructed DateTimeRange is an error"); | |
167 | return var; |
|
167 | return var; | |
168 | } |
|
168 | } | |
169 |
|
169 | |||
170 | void VariableController2::deleteVariable(std::shared_ptr<Variable> variable) |
|
170 | void VariableController2::deleteVariable(std::shared_ptr<Variable> variable) | |
171 | { |
|
171 | { | |
172 | impl->deleteVariable(variable); |
|
172 | impl->deleteVariable(variable); | |
173 | emit variableDeleted(variable); |
|
173 | emit variableDeleted(variable); | |
174 | } |
|
174 | } | |
175 |
|
175 | |||
176 | void VariableController2::changeRange(std::shared_ptr<Variable> variable, DateTimeRange r) |
|
176 | void VariableController2::changeRange(std::shared_ptr<Variable> variable, DateTimeRange r) | |
177 | { |
|
177 | { | |
178 | impl->changeRange(variable, r); |
|
178 | impl->changeRange(variable, r); | |
179 | } |
|
179 | } | |
180 |
|
180 | |||
181 | const std::set<std::shared_ptr<Variable> > VariableController2::variables() |
|
181 | const std::set<std::shared_ptr<Variable> > VariableController2::variables() | |
182 | { |
|
182 | { | |
183 | return impl->variables(); |
|
183 | return impl->variables(); | |
184 | } |
|
184 | } | |
185 |
|
185 | |||
186 | void VariableController2::synchronize(std::shared_ptr<Variable> var, std::shared_ptr<Variable> with) |
|
186 | void VariableController2::synchronize(std::shared_ptr<Variable> var, std::shared_ptr<Variable> with) | |
187 | { |
|
187 | { | |
188 | impl->synchronize(var, with); |
|
188 | impl->synchronize(var, with); | |
189 | } |
|
189 | } | |
190 |
|
190 |
General Comments 0
You need to be logged in to leave comments.
Login now