##// END OF EJS Templates
Merge branch 'feature/addTimeToCache' into develop
perrinel -
r320:a634d49196c6 merge
parent child
Show More
@@ -17,12 +17,12 struct SqpDateTime {
17 /// End time
17 /// End time
18 double m_TEnd;
18 double m_TEnd;
19
19
20 bool contains(const SqpDateTime &dateTime)
20 bool contains(const SqpDateTime &dateTime) const noexcept
21 {
21 {
22 return (m_TStart <= dateTime.m_TStart && m_TEnd >= dateTime.m_TEnd);
22 return (m_TStart <= dateTime.m_TStart && m_TEnd >= dateTime.m_TEnd);
23 }
23 }
24
24
25 bool intersect(const SqpDateTime &dateTime)
25 bool intersect(const SqpDateTime &dateTime) const noexcept
26 {
26 {
27 return (m_TEnd >= dateTime.m_TStart && m_TStart <= dateTime.m_TEnd);
27 return (m_TEnd >= dateTime.m_TStart && m_TStart <= dateTime.m_TEnd);
28 }
28 }
@@ -34,8 +34,9 public:
34 /// @return the data of the variable, nullptr if there is no data
34 /// @return the data of the variable, nullptr if there is no data
35 IDataSeries *dataSeries() const noexcept;
35 IDataSeries *dataSeries() const noexcept;
36
36
37 bool contains(const SqpDateTime &dateTime);
37 bool contains(const SqpDateTime &dateTime) const noexcept;
38 bool intersect(const SqpDateTime &dateTime);
38 bool intersect(const SqpDateTime &dateTime) const noexcept;
39 bool isInside(const SqpDateTime &dateTime) const noexcept;
39
40
40 public slots:
41 public slots:
41 void setDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept;
42 void setDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept;
@@ -25,12 +25,10 public:
25 * Creates a new variable in the model
25 * Creates a new variable in the model
26 * @param name the name of the new variable
26 * @param name the name of the new variable
27 * @param dateTime the dateTime of the new variable
27 * @param dateTime the dateTime of the new variable
28 * @param defaultDataSeries the default data of the new variable
29 * @return the pointer to the new variable
28 * @return the pointer to the new variable
30 */
29 */
31 std::shared_ptr<Variable>
30 std::shared_ptr<Variable> createVariable(const QString &name,
32 createVariable(const QString &name, const SqpDateTime &dateTime,
31 const SqpDateTime &dateTime) noexcept;
33 std::shared_ptr<IDataSeries> defaultDataSeries) noexcept;
34
32
35 std::shared_ptr<Variable> variable(int index) const;
33 std::shared_ptr<Variable> variable(int index) const;
36
34
@@ -78,12 +78,17 IDataSeries *Variable::dataSeries() const noexcept
78 return impl->m_DataSeries.get();
78 return impl->m_DataSeries.get();
79 }
79 }
80
80
81 bool Variable::contains(const SqpDateTime &dateTime)
81 bool Variable::contains(const SqpDateTime &dateTime) const noexcept
82 {
82 {
83 return impl->m_DateTime.contains(dateTime);
83 return impl->m_DateTime.contains(dateTime);
84 }
84 }
85
85
86 bool Variable::intersect(const SqpDateTime &dateTime)
86 bool Variable::intersect(const SqpDateTime &dateTime) const noexcept
87 {
87 {
88 return impl->m_DateTime.intersect(dateTime);
88 return impl->m_DateTime.intersect(dateTime);
89 }
89 }
90
91 bool Variable::isInside(const SqpDateTime &dateTime) const noexcept
92 {
93 return dateTime.contains(SqpDateTime{impl->m_DateTime.m_TStart, impl->m_DateTime.m_TEnd});
94 }
@@ -55,7 +55,7 void VariableCacheController::addDateTime(std::shared_ptr<Variable> variable,
55 impl->m_VariableToSqpDateTimeListMap.at(variable), 0);
55 impl->m_VariableToSqpDateTimeListMap.at(variable), 0);
56 }
56 }
57 catch (const std::out_of_range &e) {
57 catch (const std::out_of_range &e) {
58 qCWarning(LOG_VariableCacheController()) << e.what();
58 qCWarning(LOG_VariableCacheController()) << "addDateTime" << e.what();
59 }
59 }
60 }
60 }
61 }
61 }
@@ -71,13 +71,12 VariableCacheController::provideNotInCacheDateTimeList(std::shared_ptr<Variable>
71 // list of date time request associated to the variable
71 // list of date time request associated to the variable
72 // We assume that the list is ordered in a way that l(0) < l(1). We assume also a < b
72 // We assume that the list is ordered in a way that l(0) < l(1). We assume also a < b
73 // (with a & b of type SqpDateTime) means ts(b) > te(a)
73 // (with a & b of type SqpDateTime) means ts(b) > te(a)
74
74 auto it = impl->m_VariableToSqpDateTimeListMap.find(variable);
75 try {
75 if (it != impl->m_VariableToSqpDateTimeListMap.end()) {
76 impl->addInCacheDataByStart(dateTime, impl->m_VariableToSqpDateTimeListMap.at(variable),
76 impl->addInCacheDataByStart(dateTime, it->second, notInCache, 0, dateTime.m_TStart);
77 notInCache, 0, dateTime.m_TStart);
78 }
77 }
79 catch (const std::out_of_range &e) {
78 else {
80 qCWarning(LOG_VariableCacheController()) << e.what();
79 notInCache << dateTime;
81 }
80 }
82
81
83 return notInCache;
82 return notInCache;
@@ -99,17 +99,21 void VariableController::createVariable(const QString &name,
99 /// - default data are generated for the variable, without taking into account the timerange set
99 /// - default data are generated for the variable, without taking into account the timerange set
100 /// in sciqlop
100 /// in sciqlop
101 auto dateTime = impl->m_TimeController->dateTime();
101 auto dateTime = impl->m_TimeController->dateTime();
102 if (auto newVariable = impl->m_VariableModel->createVariable(
102 if (auto newVariable = impl->m_VariableModel->createVariable(name, dateTime)) {
103 name, dateTime, generateDefaultDataSeries(*provider, dateTime))) {
104
103
105 // store the provider
104 // store the provider
106 impl->m_VariableToProviderMap[newVariable] = provider;
105 impl->m_VariableToProviderMap[newVariable] = provider;
107 connect(provider.get(), &IDataProvider::dataProvided, newVariable.get(),
108 &Variable::setDataSeries);
109
106
107 auto addDateTimeAcquired
108 = [this, newVariable](auto dataSeriesAcquired, auto dateTimeToPutInCache) {
110
109
111 // store in cache
110 impl->m_VariableCacheController->addDateTime(newVariable, dateTimeToPutInCache);
112 impl->m_VariableCacheController->addDateTime(newVariable, dateTime);
111 newVariable->setDataSeries(dataSeriesAcquired);
112
113 };
114
115 connect(provider.get(), &IDataProvider::dataProvided, addDateTimeAcquired);
116 this->onRequestDataLoading(newVariable, dateTime);
113
117
114 // notify the creation
118 // notify the creation
115 emit variableCreated(newVariable);
119 emit variableCreated(newVariable);
@@ -144,8 +148,6 void VariableController::onRequestDataLoading(std::shared_ptr<Variable> variable
144 // Ask the provider for each data on the dateTimeListNotInCache
148 // Ask the provider for each data on the dateTimeListNotInCache
145 impl->m_VariableToProviderMap.at(variable)->requestDataLoading(
149 impl->m_VariableToProviderMap.at(variable)->requestDataLoading(
146 std::move(dateTimeListNotInCache));
150 std::move(dateTimeListNotInCache));
147 // store in cache
148 impl->m_VariableCacheController->addDateTime(variable, dateTime);
149 }
151 }
150 else {
152 else {
151 emit variable->updated();
153 emit variable->updated();
@@ -52,9 +52,8 VariableModel::VariableModel(QObject *parent)
52 {
52 {
53 }
53 }
54
54
55 std::shared_ptr<Variable>
55 std::shared_ptr<Variable> VariableModel::createVariable(const QString &name,
56 VariableModel::createVariable(const QString &name, const SqpDateTime &dateTime,
56 const SqpDateTime &dateTime) noexcept
57 std::shared_ptr<IDataSeries> defaultDataSeries) noexcept
58 {
57 {
59 auto insertIndex = rowCount();
58 auto insertIndex = rowCount();
60 beginInsertRows({}, insertIndex, insertIndex);
59 beginInsertRows({}, insertIndex, insertIndex);
@@ -62,7 +61,6 VariableModel::createVariable(const QString &name, const SqpDateTime &dateTime,
62 /// @todo For the moment, the other data of the variable is initialized with default values
61 /// @todo For the moment, the other data of the variable is initialized with default values
63 auto variable = std::make_shared<Variable>(name, QStringLiteral("unit"),
62 auto variable = std::make_shared<Variable>(name, QStringLiteral("unit"),
64 QStringLiteral("mission"), dateTime);
63 QStringLiteral("mission"), dateTime);
65 variable->setDataSeries(std::move(defaultDataSeries));
66
64
67 impl->m_Variables.push_back(variable);
65 impl->m_Variables.push_back(variable);
68
66
@@ -42,7 +42,6 void updateScalarData(QCPAbstractPlottable *component, ScalarSeries &scalarSerie
42 const auto &valuesData = scalarSeries.valuesData()->data();
42 const auto &valuesData = scalarSeries.valuesData()->data();
43 const auto count = xData.count();
43 const auto count = xData.count();
44 qCInfo(LOG_VisualizationGraphHelper()) << "TORM: Current points in cache" << xData.count();
44 qCInfo(LOG_VisualizationGraphHelper()) << "TORM: Current points in cache" << xData.count();
45
46 auto xValue = QVector<double>(count);
45 auto xValue = QVector<double>(count);
47 auto vValue = QVector<double>(count);
46 auto vValue = QVector<double>(count);
48
47
@@ -65,7 +64,6 void updateScalarData(QCPAbstractPlottable *component, ScalarSeries &scalarSerie
65 qcpGraph->setData(xValue, vValue);
64 qcpGraph->setData(xValue, vValue);
66
65
67 // Display all data
66 // Display all data
68 // component->parentPlot()->xAxis->setRange(dateTime.m_TStart, dateTime.m_TEnd);
69 component->rescaleAxes();
67 component->rescaleAxes();
70 component->parentPlot()->replot();
68 component->parentPlot()->replot();
71 }
69 }
@@ -177,9 +177,10 void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1)
177 if (!variable->contains(dateTime)) {
177 if (!variable->contains(dateTime)) {
178
178
179 auto variableDateTimeWithTolerance = dateTime;
179 auto variableDateTimeWithTolerance = dateTime;
180 if (variable->intersect(dateTime)) {
180 if (!variable->isInside(dateTime)) {
181 auto variableDateTime = variable->dateTime();
181 auto variableDateTime = variable->dateTime();
182 if (variableDateTime.m_TStart < dateTime.m_TStart) {
182 if (variableDateTime.m_TStart < dateTime.m_TStart) {
183 qCDebug(LOG_VisualizationGraphWidget()) << tr("TDetection pan to right:");
183
184
184 auto diffEndToKeepDelta = dateTime.m_TEnd - variableDateTime.m_TEnd;
185 auto diffEndToKeepDelta = dateTime.m_TEnd - variableDateTime.m_TEnd;
185 dateTime.m_TStart = variableDateTime.m_TStart + diffEndToKeepDelta;
186 dateTime.m_TStart = variableDateTime.m_TStart + diffEndToKeepDelta;
@@ -188,7 +189,8 void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1)
188 auto tolerance = 0.1 * (dateTime.m_TEnd - dateTime.m_TStart);
189 auto tolerance = 0.1 * (dateTime.m_TEnd - dateTime.m_TStart);
189 variableDateTimeWithTolerance.m_TEnd += tolerance;
190 variableDateTimeWithTolerance.m_TEnd += tolerance;
190 }
191 }
191 if (variableDateTime.m_TEnd > dateTime.m_TEnd) {
192 else if (variableDateTime.m_TEnd > dateTime.m_TEnd) {
193 qCDebug(LOG_VisualizationGraphWidget()) << tr("Detection pan to left: ");
192 auto diffStartToKeepDelta = variableDateTime.m_TStart - dateTime.m_TStart;
194 auto diffStartToKeepDelta = variableDateTime.m_TStart - dateTime.m_TStart;
193 dateTime.m_TEnd = variableDateTime.m_TEnd - diffStartToKeepDelta;
195 dateTime.m_TEnd = variableDateTime.m_TEnd - diffStartToKeepDelta;
194 // Tolerance have to be added to the left
196 // Tolerance have to be added to the left
@@ -196,8 +198,13 void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1)
196 auto tolerance = 0.1 * (dateTime.m_TEnd - dateTime.m_TStart);
198 auto tolerance = 0.1 * (dateTime.m_TEnd - dateTime.m_TStart);
197 variableDateTimeWithTolerance.m_TStart -= tolerance;
199 variableDateTimeWithTolerance.m_TStart -= tolerance;
198 }
200 }
201 else {
202 qCWarning(LOG_VisualizationGraphWidget())
203 << tr("Detection anormal zoom detection: ");
204 }
199 }
205 }
200 else {
206 else {
207 qCDebug(LOG_VisualizationGraphWidget()) << tr("Detection zoom out: ");
201 // add 10% tolerance for each side
208 // add 10% tolerance for each side
202 auto tolerance = 0.1 * (dateTime.m_TEnd - dateTime.m_TStart);
209 auto tolerance = 0.1 * (dateTime.m_TEnd - dateTime.m_TStart);
203 variableDateTimeWithTolerance.m_TStart -= tolerance;
210 variableDateTimeWithTolerance.m_TStart -= tolerance;
@@ -208,6 +215,9 void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1)
208 // CHangement detected, we need to ask controller to request data loading
215 // CHangement detected, we need to ask controller to request data loading
209 emit requestDataLoading(variable, variableDateTimeWithTolerance);
216 emit requestDataLoading(variable, variableDateTimeWithTolerance);
210 }
217 }
218 else {
219 qCDebug(LOG_VisualizationGraphWidget()) << tr("Detection zoom in: ");
220 }
211 }
221 }
212 }
222 }
213
223
General Comments 0
You need to be logged in to leave comments. Login now