##// END OF EJS Templates
The cache is now updated only if date requested has been successfully...
perrinel -
r318:fc4b2122dbde
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;
@@ -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 }
@@ -104,8 +104,16 void VariableController::createVariable(const QString &name,
104
104
105 // store the provider
105 // store the provider
106 impl->m_VariableToProviderMap[newVariable] = provider;
106 impl->m_VariableToProviderMap[newVariable] = provider;
107 connect(provider.get(), &IDataProvider::dataProvided, newVariable.get(),
107
108 &Variable::setDataSeries);
108 auto addDateTimeAcquired
109 = [this, newVariable](auto dataSeriesAcquired, auto dateTimeToPutInCache) {
110
111 impl->m_VariableCacheController->addDateTime(newVariable, dateTimeToPutInCache);
112 newVariable->setDataSeries(dataSeriesAcquired);
113
114 };
115
116 connect(provider.get(), &IDataProvider::dataProvided, addDateTimeAcquired);
109
117
110
118
111 // store in cache
119 // store in cache
@@ -144,8 +152,6 void VariableController::onRequestDataLoading(std::shared_ptr<Variable> variable
144 // Ask the provider for each data on the dateTimeListNotInCache
152 // Ask the provider for each data on the dateTimeListNotInCache
145 impl->m_VariableToProviderMap.at(variable)->requestDataLoading(
153 impl->m_VariableToProviderMap.at(variable)->requestDataLoading(
146 std::move(dateTimeListNotInCache));
154 std::move(dateTimeListNotInCache));
147 // store in cache
148 impl->m_VariableCacheController->addDateTime(variable, dateTime);
149 }
155 }
150 else {
156 else {
151 emit variable->updated();
157 emit variable->updated();
@@ -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