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