##// END OF EJS Templates
Removes unit and mission from variable...
Alexandre Leroux -
r405:4fa51b091d97
parent child
Show More
@@ -1,55 +1,52
1 #ifndef SCIQLOP_VARIABLE_H
1 #ifndef SCIQLOP_VARIABLE_H
2 #define SCIQLOP_VARIABLE_H
2 #define SCIQLOP_VARIABLE_H
3
3
4 #include <Data/SqpDateTime.h>
4 #include <Data/SqpDateTime.h>
5
5
6 #include <QLoggingCategory>
6 #include <QLoggingCategory>
7 #include <QObject>
7 #include <QObject>
8
8
9 #include <Common/MetaTypes.h>
9 #include <Common/MetaTypes.h>
10 #include <Common/spimpl.h>
10 #include <Common/spimpl.h>
11
11
12 Q_DECLARE_LOGGING_CATEGORY(LOG_Variable)
12 Q_DECLARE_LOGGING_CATEGORY(LOG_Variable)
13
13
14 class IDataSeries;
14 class IDataSeries;
15 class QString;
15 class QString;
16
16
17 /**
17 /**
18 * @brief The Variable class represents a variable in SciQlop.
18 * @brief The Variable class represents a variable in SciQlop.
19 */
19 */
20 class Variable : public QObject {
20 class Variable : public QObject {
21
21
22 Q_OBJECT
22 Q_OBJECT
23
23
24 public:
24 public:
25 explicit Variable(const QString &name, const QString &unit, const QString &mission,
25 explicit Variable(const QString &name, const SqpDateTime &dateTime);
26 const SqpDateTime &dateTime);
27
26
28 QString name() const noexcept;
27 QString name() const noexcept;
29 QString mission() const noexcept;
30 QString unit() const noexcept;
31 SqpDateTime dateTime() const noexcept;
28 SqpDateTime dateTime() const noexcept;
32 void setDateTime(const SqpDateTime &dateTime) noexcept;
29 void setDateTime(const SqpDateTime &dateTime) noexcept;
33
30
34 /// @return the data of the variable, nullptr if there is no data
31 /// @return the data of the variable, nullptr if there is no data
35 IDataSeries *dataSeries() const noexcept;
32 IDataSeries *dataSeries() const noexcept;
36
33
37 bool contains(const SqpDateTime &dateTime) const noexcept;
34 bool contains(const SqpDateTime &dateTime) const noexcept;
38 bool intersect(const SqpDateTime &dateTime) const noexcept;
35 bool intersect(const SqpDateTime &dateTime) const noexcept;
39 bool isInside(const SqpDateTime &dateTime) const noexcept;
36 bool isInside(const SqpDateTime &dateTime) const noexcept;
40
37
41 public slots:
38 public slots:
42 void setDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept;
39 void setDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept;
43
40
44 signals:
41 signals:
45 void updated();
42 void updated();
46
43
47 private:
44 private:
48 class VariablePrivate;
45 class VariablePrivate;
49 spimpl::unique_impl_ptr<VariablePrivate> impl;
46 spimpl::unique_impl_ptr<VariablePrivate> impl;
50 };
47 };
51
48
52 // Required for using shared_ptr in signals/slots
49 // Required for using shared_ptr in signals/slots
53 SCIQLOP_REGISTER_META_TYPE(VARIABLE_PTR_REGISTRY, std::shared_ptr<Variable>)
50 SCIQLOP_REGISTER_META_TYPE(VARIABLE_PTR_REGISTRY, std::shared_ptr<Variable>)
54
51
55 #endif // SCIQLOP_VARIABLE_H
52 #endif // SCIQLOP_VARIABLE_H
@@ -1,101 +1,83
1 #include "Variable/Variable.h"
1 #include "Variable/Variable.h"
2
2
3 #include <Data/IDataSeries.h>
3 #include <Data/IDataSeries.h>
4 #include <Data/SqpDateTime.h>
4 #include <Data/SqpDateTime.h>
5
5
6 #include <QReadWriteLock>
6 #include <QReadWriteLock>
7 #include <QThread>
7 #include <QThread>
8
8
9 Q_LOGGING_CATEGORY(LOG_Variable, "Variable")
9 Q_LOGGING_CATEGORY(LOG_Variable, "Variable")
10
10
11 struct Variable::VariablePrivate {
11 struct Variable::VariablePrivate {
12 explicit VariablePrivate(const QString &name, const QString &unit, const QString &mission,
12 explicit VariablePrivate(const QString &name, const SqpDateTime &dateTime)
13 const SqpDateTime &dateTime)
13 : m_Name{name}, m_DateTime{dateTime}, m_DataSeries{nullptr}
14 : m_Name{name},
15 m_Unit{unit},
16 m_Mission{mission},
17 m_DateTime{dateTime},
18 m_DataSeries{nullptr}
19 {
14 {
20 }
15 }
21
16
22 QString m_Name;
17 QString m_Name;
23 QString m_Unit;
24 QString m_Mission;
25
18
26 SqpDateTime m_DateTime; // The dateTime available in the view and loaded. not the cache.
19 SqpDateTime m_DateTime; // The dateTime available in the view and loaded. not the cache.
27 std::unique_ptr<IDataSeries> m_DataSeries;
20 std::unique_ptr<IDataSeries> m_DataSeries;
28 };
21 };
29
22
30 Variable::Variable(const QString &name, const QString &unit, const QString &mission,
23 Variable::Variable(const QString &name, const SqpDateTime &dateTime)
31 const SqpDateTime &dateTime)
24 : impl{spimpl::make_unique_impl<VariablePrivate>(name, dateTime)}
32 : impl{spimpl::make_unique_impl<VariablePrivate>(name, unit, mission, dateTime)}
33 {
25 {
34 }
26 }
35
27
36 QString Variable::name() const noexcept
28 QString Variable::name() const noexcept
37 {
29 {
38 return impl->m_Name;
30 return impl->m_Name;
39 }
31 }
40
32
41 QString Variable::mission() const noexcept
42 {
43 return impl->m_Mission;
44 }
45
46 QString Variable::unit() const noexcept
47 {
48 return impl->m_Unit;
49 }
50
51 SqpDateTime Variable::dateTime() const noexcept
33 SqpDateTime Variable::dateTime() const noexcept
52 {
34 {
53 return impl->m_DateTime;
35 return impl->m_DateTime;
54 }
36 }
55
37
56 void Variable::setDateTime(const SqpDateTime &dateTime) noexcept
38 void Variable::setDateTime(const SqpDateTime &dateTime) noexcept
57 {
39 {
58 impl->m_DateTime = dateTime;
40 impl->m_DateTime = dateTime;
59 }
41 }
60
42
61 void Variable::setDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept
43 void Variable::setDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept
62 {
44 {
63 qCDebug(LOG_Variable()) << "Variable::setDataSeries" << QThread::currentThread()->objectName();
45 qCDebug(LOG_Variable()) << "Variable::setDataSeries" << QThread::currentThread()->objectName();
64 if (!dataSeries) {
46 if (!dataSeries) {
65 /// @todo ALX : log
47 /// @todo ALX : log
66 return;
48 return;
67 }
49 }
68
50
69 // Inits the data series of the variable
51 // Inits the data series of the variable
70 if (!impl->m_DataSeries) {
52 if (!impl->m_DataSeries) {
71 impl->m_DataSeries = dataSeries->clone();
53 impl->m_DataSeries = dataSeries->clone();
72 }
54 }
73 else {
55 else {
74 dataSeries->lockWrite();
56 dataSeries->lockWrite();
75 impl->m_DataSeries->lockWrite();
57 impl->m_DataSeries->lockWrite();
76 impl->m_DataSeries->merge(dataSeries.get());
58 impl->m_DataSeries->merge(dataSeries.get());
77 impl->m_DataSeries->unlock();
59 impl->m_DataSeries->unlock();
78 dataSeries->unlock();
60 dataSeries->unlock();
79 emit updated();
61 emit updated();
80 }
62 }
81 }
63 }
82
64
83 IDataSeries *Variable::dataSeries() const noexcept
65 IDataSeries *Variable::dataSeries() const noexcept
84 {
66 {
85 return impl->m_DataSeries.get();
67 return impl->m_DataSeries.get();
86 }
68 }
87
69
88 bool Variable::contains(const SqpDateTime &dateTime) const noexcept
70 bool Variable::contains(const SqpDateTime &dateTime) const noexcept
89 {
71 {
90 return impl->m_DateTime.contains(dateTime);
72 return impl->m_DateTime.contains(dateTime);
91 }
73 }
92
74
93 bool Variable::intersect(const SqpDateTime &dateTime) const noexcept
75 bool Variable::intersect(const SqpDateTime &dateTime) const noexcept
94 {
76 {
95 return impl->m_DateTime.intersect(dateTime);
77 return impl->m_DateTime.intersect(dateTime);
96 }
78 }
97
79
98 bool Variable::isInside(const SqpDateTime &dateTime) const noexcept
80 bool Variable::isInside(const SqpDateTime &dateTime) const noexcept
99 {
81 {
100 return dateTime.contains(SqpDateTime{impl->m_DateTime.m_TStart, impl->m_DateTime.m_TEnd});
82 return dateTime.contains(SqpDateTime{impl->m_DateTime.m_TStart, impl->m_DateTime.m_TEnd});
101 }
83 }
@@ -1,236 +1,234
1 #include <Variable/Variable.h>
1 #include <Variable/Variable.h>
2 #include <Variable/VariableModel.h>
2 #include <Variable/VariableModel.h>
3
3
4 #include <Data/IDataSeries.h>
4 #include <Data/IDataSeries.h>
5
5
6 #include <QDateTime>
6 #include <QDateTime>
7 #include <QSize>
7 #include <QSize>
8 #include <unordered_map>
8 #include <unordered_map>
9
9
10 Q_LOGGING_CATEGORY(LOG_VariableModel, "VariableModel")
10 Q_LOGGING_CATEGORY(LOG_VariableModel, "VariableModel")
11
11
12 namespace {
12 namespace {
13
13
14 // Column indexes
14 // Column indexes
15 const auto NAME_COLUMN = 0;
15 const auto NAME_COLUMN = 0;
16 const auto TSTART_COLUMN = 1;
16 const auto TSTART_COLUMN = 1;
17 const auto TEND_COLUMN = 2;
17 const auto TEND_COLUMN = 2;
18 const auto NB_COLUMNS = 3;
18 const auto NB_COLUMNS = 3;
19
19
20 // Column properties
20 // Column properties
21 const auto DEFAULT_HEIGHT = 25;
21 const auto DEFAULT_HEIGHT = 25;
22 const auto DEFAULT_WIDTH = 100;
22 const auto DEFAULT_WIDTH = 100;
23
23
24 struct ColumnProperties {
24 struct ColumnProperties {
25 ColumnProperties(const QString &name = {}, int width = DEFAULT_WIDTH,
25 ColumnProperties(const QString &name = {}, int width = DEFAULT_WIDTH,
26 int height = DEFAULT_HEIGHT)
26 int height = DEFAULT_HEIGHT)
27 : m_Name{name}, m_Width{width}, m_Height{height}
27 : m_Name{name}, m_Width{width}, m_Height{height}
28 {
28 {
29 }
29 }
30
30
31 QString m_Name;
31 QString m_Name;
32 int m_Width;
32 int m_Width;
33 int m_Height;
33 int m_Height;
34 };
34 };
35
35
36 const auto COLUMN_PROPERTIES
36 const auto COLUMN_PROPERTIES
37 = QHash<int, ColumnProperties>{{NAME_COLUMN, {QObject::tr("Name")}},
37 = QHash<int, ColumnProperties>{{NAME_COLUMN, {QObject::tr("Name")}},
38 {TSTART_COLUMN, {QObject::tr("tStart"), 180}},
38 {TSTART_COLUMN, {QObject::tr("tStart"), 180}},
39 {TEND_COLUMN, {QObject::tr("tEnd"), 180}}};
39 {TEND_COLUMN, {QObject::tr("tEnd"), 180}}};
40
40
41 /// Format for datetimes
41 /// Format for datetimes
42 const auto DATETIME_FORMAT = QStringLiteral("dd/MM/yyyy \nhh:mm:ss:zzz");
42 const auto DATETIME_FORMAT = QStringLiteral("dd/MM/yyyy \nhh:mm:ss:zzz");
43
43
44
44
45 } // namespace
45 } // namespace
46
46
47 struct VariableModel::VariableModelPrivate {
47 struct VariableModel::VariableModelPrivate {
48 /// Variables created in SciQlop
48 /// Variables created in SciQlop
49 std::vector<std::shared_ptr<Variable> > m_Variables;
49 std::vector<std::shared_ptr<Variable> > m_Variables;
50 std::unordered_map<std::shared_ptr<Variable>, double> m_VariableToProgress;
50 std::unordered_map<std::shared_ptr<Variable>, double> m_VariableToProgress;
51
51
52
52
53 /// Return the row index of the variable. -1 if it's not found
53 /// Return the row index of the variable. -1 if it's not found
54 int indexOfVariable(Variable *variable) const noexcept;
54 int indexOfVariable(Variable *variable) const noexcept;
55 };
55 };
56
56
57 VariableModel::VariableModel(QObject *parent)
57 VariableModel::VariableModel(QObject *parent)
58 : QAbstractTableModel{parent}, impl{spimpl::make_unique_impl<VariableModelPrivate>()}
58 : QAbstractTableModel{parent}, impl{spimpl::make_unique_impl<VariableModelPrivate>()}
59 {
59 {
60 }
60 }
61
61
62 std::shared_ptr<Variable> VariableModel::createVariable(const QString &name,
62 std::shared_ptr<Variable> VariableModel::createVariable(const QString &name,
63 const SqpDateTime &dateTime) noexcept
63 const SqpDateTime &dateTime) noexcept
64 {
64 {
65 auto insertIndex = rowCount();
65 auto insertIndex = rowCount();
66 beginInsertRows({}, insertIndex, insertIndex);
66 beginInsertRows({}, insertIndex, insertIndex);
67
67
68 /// @todo For the moment, the other data of the variable is initialized with default values
68 auto variable = std::make_shared<Variable>(name, dateTime);
69 auto variable = std::make_shared<Variable>(name, QStringLiteral("unit"),
70 QStringLiteral("mission"), dateTime);
71
69
72 impl->m_Variables.push_back(variable);
70 impl->m_Variables.push_back(variable);
73 connect(variable.get(), &Variable::updated, this, &VariableModel::onVariableUpdated);
71 connect(variable.get(), &Variable::updated, this, &VariableModel::onVariableUpdated);
74
72
75 endInsertRows();
73 endInsertRows();
76
74
77 return variable;
75 return variable;
78 }
76 }
79
77
80 void VariableModel::deleteVariable(std::shared_ptr<Variable> variable) noexcept
78 void VariableModel::deleteVariable(std::shared_ptr<Variable> variable) noexcept
81 {
79 {
82 if (!variable) {
80 if (!variable) {
83 qCCritical(LOG_Variable()) << "Can't delete a null variable from the model";
81 qCCritical(LOG_Variable()) << "Can't delete a null variable from the model";
84 return;
82 return;
85 }
83 }
86
84
87 // Finds variable in the model
85 // Finds variable in the model
88 auto begin = impl->m_Variables.cbegin();
86 auto begin = impl->m_Variables.cbegin();
89 auto end = impl->m_Variables.cend();
87 auto end = impl->m_Variables.cend();
90 auto it = std::find(begin, end, variable);
88 auto it = std::find(begin, end, variable);
91 if (it != end) {
89 if (it != end) {
92 auto removeIndex = std::distance(begin, it);
90 auto removeIndex = std::distance(begin, it);
93
91
94 // Deletes variable
92 // Deletes variable
95 beginRemoveRows({}, removeIndex, removeIndex);
93 beginRemoveRows({}, removeIndex, removeIndex);
96 impl->m_Variables.erase(it);
94 impl->m_Variables.erase(it);
97 endRemoveRows();
95 endRemoveRows();
98 }
96 }
99 else {
97 else {
100 qCritical(LOG_VariableModel())
98 qCritical(LOG_VariableModel())
101 << tr("Can't delete variable %1 from the model: the variable is not in the model")
99 << tr("Can't delete variable %1 from the model: the variable is not in the model")
102 .arg(variable->name());
100 .arg(variable->name());
103 }
101 }
104 }
102 }
105
103
106
104
107 std::shared_ptr<Variable> VariableModel::variable(int index) const
105 std::shared_ptr<Variable> VariableModel::variable(int index) const
108 {
106 {
109 return (index >= 0 && index < impl->m_Variables.size()) ? impl->m_Variables[index] : nullptr;
107 return (index >= 0 && index < impl->m_Variables.size()) ? impl->m_Variables[index] : nullptr;
110 }
108 }
111
109
112 void VariableModel::setDataProgress(std::shared_ptr<Variable> variable, double progress)
110 void VariableModel::setDataProgress(std::shared_ptr<Variable> variable, double progress)
113 {
111 {
114
112
115 impl->m_VariableToProgress[variable] = progress;
113 impl->m_VariableToProgress[variable] = progress;
116 auto modelIndex = createIndex(impl->indexOfVariable(variable.get()), NAME_COLUMN);
114 auto modelIndex = createIndex(impl->indexOfVariable(variable.get()), NAME_COLUMN);
117
115
118 emit dataChanged(modelIndex, modelIndex);
116 emit dataChanged(modelIndex, modelIndex);
119 }
117 }
120
118
121 int VariableModel::columnCount(const QModelIndex &parent) const
119 int VariableModel::columnCount(const QModelIndex &parent) const
122 {
120 {
123 Q_UNUSED(parent);
121 Q_UNUSED(parent);
124
122
125 return NB_COLUMNS;
123 return NB_COLUMNS;
126 }
124 }
127
125
128 int VariableModel::rowCount(const QModelIndex &parent) const
126 int VariableModel::rowCount(const QModelIndex &parent) const
129 {
127 {
130 Q_UNUSED(parent);
128 Q_UNUSED(parent);
131
129
132 return impl->m_Variables.size();
130 return impl->m_Variables.size();
133 }
131 }
134
132
135 QVariant VariableModel::data(const QModelIndex &index, int role) const
133 QVariant VariableModel::data(const QModelIndex &index, int role) const
136 {
134 {
137 if (!index.isValid()) {
135 if (!index.isValid()) {
138 return QVariant{};
136 return QVariant{};
139 }
137 }
140
138
141 if (index.row() < 0 || index.row() >= rowCount()) {
139 if (index.row() < 0 || index.row() >= rowCount()) {
142 return QVariant{};
140 return QVariant{};
143 }
141 }
144
142
145 if (role == Qt::DisplayRole) {
143 if (role == Qt::DisplayRole) {
146 if (auto variable = impl->m_Variables.at(index.row()).get()) {
144 if (auto variable = impl->m_Variables.at(index.row()).get()) {
147 /// Lambda function that builds the variant to return for a time value
145 /// Lambda function that builds the variant to return for a time value
148 auto dateTimeVariant = [](double time) {
146 auto dateTimeVariant = [](double time) {
149 auto dateTime = QDateTime::fromMSecsSinceEpoch(time * 1000.);
147 auto dateTime = QDateTime::fromMSecsSinceEpoch(time * 1000.);
150 return dateTime.toString(DATETIME_FORMAT);
148 return dateTime.toString(DATETIME_FORMAT);
151 };
149 };
152
150
153 switch (index.column()) {
151 switch (index.column()) {
154 case NAME_COLUMN:
152 case NAME_COLUMN:
155 return variable->name();
153 return variable->name();
156 case TSTART_COLUMN:
154 case TSTART_COLUMN:
157 return dateTimeVariant(variable->dateTime().m_TStart);
155 return dateTimeVariant(variable->dateTime().m_TStart);
158 case TEND_COLUMN:
156 case TEND_COLUMN:
159 return dateTimeVariant(variable->dateTime().m_TEnd);
157 return dateTimeVariant(variable->dateTime().m_TEnd);
160 default:
158 default:
161 // No action
159 // No action
162 break;
160 break;
163 }
161 }
164
162
165 qWarning(LOG_VariableModel())
163 qWarning(LOG_VariableModel())
166 << tr("Can't get data (unknown column %1)").arg(index.column());
164 << tr("Can't get data (unknown column %1)").arg(index.column());
167 }
165 }
168 else {
166 else {
169 qWarning(LOG_VariableModel()) << tr("Can't get data (no variable)");
167 qWarning(LOG_VariableModel()) << tr("Can't get data (no variable)");
170 }
168 }
171 }
169 }
172 else if (role == VariableRoles::ProgressRole) {
170 else if (role == VariableRoles::ProgressRole) {
173 if (auto variable = impl->m_Variables.at(index.row())) {
171 if (auto variable = impl->m_Variables.at(index.row())) {
174
172
175 auto it = impl->m_VariableToProgress.find(variable);
173 auto it = impl->m_VariableToProgress.find(variable);
176 if (it != impl->m_VariableToProgress.cend()) {
174 if (it != impl->m_VariableToProgress.cend()) {
177 return it->second;
175 return it->second;
178 }
176 }
179 }
177 }
180 }
178 }
181
179
182 return QVariant{};
180 return QVariant{};
183 }
181 }
184
182
185 QVariant VariableModel::headerData(int section, Qt::Orientation orientation, int role) const
183 QVariant VariableModel::headerData(int section, Qt::Orientation orientation, int role) const
186 {
184 {
187 if (role != Qt::DisplayRole && role != Qt::SizeHintRole) {
185 if (role != Qt::DisplayRole && role != Qt::SizeHintRole) {
188 return QVariant{};
186 return QVariant{};
189 }
187 }
190
188
191 if (orientation == Qt::Horizontal) {
189 if (orientation == Qt::Horizontal) {
192 auto propertiesIt = COLUMN_PROPERTIES.find(section);
190 auto propertiesIt = COLUMN_PROPERTIES.find(section);
193 if (propertiesIt != COLUMN_PROPERTIES.cend()) {
191 if (propertiesIt != COLUMN_PROPERTIES.cend()) {
194 // Role is either DisplayRole or SizeHintRole
192 // Role is either DisplayRole or SizeHintRole
195 return (role == Qt::DisplayRole)
193 return (role == Qt::DisplayRole)
196 ? QVariant{propertiesIt->m_Name}
194 ? QVariant{propertiesIt->m_Name}
197 : QVariant{QSize{propertiesIt->m_Width, propertiesIt->m_Height}};
195 : QVariant{QSize{propertiesIt->m_Width, propertiesIt->m_Height}};
198 }
196 }
199 else {
197 else {
200 qWarning(LOG_VariableModel())
198 qWarning(LOG_VariableModel())
201 << tr("Can't get header data (unknown column %1)").arg(section);
199 << tr("Can't get header data (unknown column %1)").arg(section);
202 }
200 }
203 }
201 }
204
202
205 return QVariant{};
203 return QVariant{};
206 }
204 }
207
205
208 void VariableModel::onVariableUpdated() noexcept
206 void VariableModel::onVariableUpdated() noexcept
209 {
207 {
210 // Finds variable that has been updated in the model
208 // Finds variable that has been updated in the model
211 if (auto updatedVariable = dynamic_cast<Variable *>(sender())) {
209 if (auto updatedVariable = dynamic_cast<Variable *>(sender())) {
212 auto updatedVariableIndex = impl->indexOfVariable(updatedVariable);
210 auto updatedVariableIndex = impl->indexOfVariable(updatedVariable);
213
211
214 if (updatedVariableIndex > -1) {
212 if (updatedVariableIndex > -1) {
215 emit dataChanged(createIndex(updatedVariableIndex, 0),
213 emit dataChanged(createIndex(updatedVariableIndex, 0),
216 createIndex(updatedVariableIndex, columnCount() - 1));
214 createIndex(updatedVariableIndex, columnCount() - 1));
217 }
215 }
218 }
216 }
219 }
217 }
220
218
221 int VariableModel::VariableModelPrivate::indexOfVariable(Variable *variable) const noexcept
219 int VariableModel::VariableModelPrivate::indexOfVariable(Variable *variable) const noexcept
222 {
220 {
223 auto begin = std::cbegin(m_Variables);
221 auto begin = std::cbegin(m_Variables);
224 auto end = std::cend(m_Variables);
222 auto end = std::cend(m_Variables);
225 auto it
223 auto it
226 = std::find_if(begin, end, [variable](const auto &var) { return var.get() == variable; });
224 = std::find_if(begin, end, [variable](const auto &var) { return var.get() == variable; });
227
225
228 if (it != end) {
226 if (it != end) {
229 // Gets the index of the variable in the model: we assume here that views have the same
227 // Gets the index of the variable in the model: we assume here that views have the same
230 // order as the model
228 // order as the model
231 return std::distance(begin, it);
229 return std::distance(begin, it);
232 }
230 }
233 else {
231 else {
234 return -1;
232 return -1;
235 }
233 }
236 }
234 }
@@ -1,353 +1,353
1 #include <Variable/Variable.h>
1 #include <Variable/Variable.h>
2 #include <Variable/VariableCacheController.h>
2 #include <Variable/VariableCacheController.h>
3
3
4 #include <QObject>
4 #include <QObject>
5 #include <QtTest>
5 #include <QtTest>
6
6
7 #include <memory>
7 #include <memory>
8
8
9 class TestVariableCacheController : public QObject {
9 class TestVariableCacheController : public QObject {
10 Q_OBJECT
10 Q_OBJECT
11
11
12 private slots:
12 private slots:
13 void testProvideNotInCacheDateTimeList();
13 void testProvideNotInCacheDateTimeList();
14
14
15 void testAddDateTime();
15 void testAddDateTime();
16 };
16 };
17
17
18
18
19 void TestVariableCacheController::testProvideNotInCacheDateTimeList()
19 void TestVariableCacheController::testProvideNotInCacheDateTimeList()
20 {
20 {
21 VariableCacheController variableCacheController{};
21 VariableCacheController variableCacheController{};
22
22
23 auto ts0 = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 0, 0}};
23 auto ts0 = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 0, 0}};
24 auto te0 = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 0, 0}};
24 auto te0 = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 0, 0}};
25 auto sqp0 = SqpDateTime{static_cast<double>(ts0.toMSecsSinceEpoch()),
25 auto sqp0 = SqpDateTime{static_cast<double>(ts0.toMSecsSinceEpoch()),
26 static_cast<double>(te0.toMSecsSinceEpoch())};
26 static_cast<double>(te0.toMSecsSinceEpoch())};
27
27
28 auto ts1 = QDateTime{QDate{2017, 01, 01}, QTime{2, 6, 0, 0}};
28 auto ts1 = QDateTime{QDate{2017, 01, 01}, QTime{2, 6, 0, 0}};
29 auto te1 = QDateTime{QDate{2017, 01, 01}, QTime{2, 8, 0, 0}};
29 auto te1 = QDateTime{QDate{2017, 01, 01}, QTime{2, 8, 0, 0}};
30 auto sqp1 = SqpDateTime{static_cast<double>(ts1.toMSecsSinceEpoch()),
30 auto sqp1 = SqpDateTime{static_cast<double>(ts1.toMSecsSinceEpoch()),
31 static_cast<double>(te1.toMSecsSinceEpoch())};
31 static_cast<double>(te1.toMSecsSinceEpoch())};
32
32
33 auto ts2 = QDateTime{QDate{2017, 01, 01}, QTime{2, 18, 0, 0}};
33 auto ts2 = QDateTime{QDate{2017, 01, 01}, QTime{2, 18, 0, 0}};
34 auto te2 = QDateTime{QDate{2017, 01, 01}, QTime{2, 20, 0, 0}};
34 auto te2 = QDateTime{QDate{2017, 01, 01}, QTime{2, 20, 0, 0}};
35 auto sqp2 = SqpDateTime{static_cast<double>(ts2.toMSecsSinceEpoch()),
35 auto sqp2 = SqpDateTime{static_cast<double>(ts2.toMSecsSinceEpoch()),
36 static_cast<double>(te2.toMSecsSinceEpoch())};
36 static_cast<double>(te2.toMSecsSinceEpoch())};
37
37
38 auto var0 = std::make_shared<Variable>("", "", "", sqp0);
38 auto var0 = std::make_shared<Variable>("", sqp0);
39
39
40 variableCacheController.addDateTime(var0, sqp0);
40 variableCacheController.addDateTime(var0, sqp0);
41 variableCacheController.addDateTime(var0, sqp1);
41 variableCacheController.addDateTime(var0, sqp1);
42 variableCacheController.addDateTime(var0, sqp2);
42 variableCacheController.addDateTime(var0, sqp2);
43
43
44 // first case [ts,te] < ts0
44 // first case [ts,te] < ts0
45 auto ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}};
45 auto ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}};
46 auto te = QDateTime{QDate{2017, 01, 01}, QTime{2, 1, 0, 0}};
46 auto te = QDateTime{QDate{2017, 01, 01}, QTime{2, 1, 0, 0}};
47 auto sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()),
47 auto sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()),
48 static_cast<double>(te.toMSecsSinceEpoch())};
48 static_cast<double>(te.toMSecsSinceEpoch())};
49
49
50
50
51 auto notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp);
51 auto notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp);
52
52
53 QCOMPARE(notInCach.size(), 1);
53 QCOMPARE(notInCach.size(), 1);
54 auto notInCacheSqp = notInCach.first();
54 auto notInCacheSqp = notInCach.first();
55 QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch()));
55 QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch()));
56 QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch()));
56 QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch()));
57
57
58
58
59 // second case ts < ts0 && ts0 < te <= te0
59 // second case ts < ts0 && ts0 < te <= te0
60 ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}};
60 ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}};
61 te = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 30, 0}};
61 te = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 30, 0}};
62 sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()),
62 sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()),
63 static_cast<double>(te.toMSecsSinceEpoch())};
63 static_cast<double>(te.toMSecsSinceEpoch())};
64
64
65
65
66 notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp);
66 notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp);
67
67
68 QCOMPARE(notInCach.size(), 1);
68 QCOMPARE(notInCach.size(), 1);
69 notInCacheSqp = notInCach.first();
69 notInCacheSqp = notInCach.first();
70 QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch()));
70 QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch()));
71 QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(ts0.toMSecsSinceEpoch()));
71 QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(ts0.toMSecsSinceEpoch()));
72
72
73 // 3th case ts < ts0 && te0 < te <= ts1
73 // 3th case ts < ts0 && te0 < te <= ts1
74 ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}};
74 ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}};
75 te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}};
75 te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}};
76 sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()),
76 sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()),
77 static_cast<double>(te.toMSecsSinceEpoch())};
77 static_cast<double>(te.toMSecsSinceEpoch())};
78
78
79
79
80 notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp);
80 notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp);
81
81
82 QCOMPARE(notInCach.size(), 2);
82 QCOMPARE(notInCach.size(), 2);
83 notInCacheSqp = notInCach.first();
83 notInCacheSqp = notInCach.first();
84 QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch()));
84 QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch()));
85 QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(ts0.toMSecsSinceEpoch()));
85 QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(ts0.toMSecsSinceEpoch()));
86
86
87 notInCacheSqp = notInCach.at(1);
87 notInCacheSqp = notInCach.at(1);
88 QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(te0.toMSecsSinceEpoch()));
88 QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(te0.toMSecsSinceEpoch()));
89 QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch()));
89 QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch()));
90
90
91 // 4th case ts < ts0 && ts1 < te <= te1
91 // 4th case ts < ts0 && ts1 < te <= te1
92 ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}};
92 ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}};
93 te = QDateTime{QDate{2017, 01, 01}, QTime{2, 7, 0, 0}};
93 te = QDateTime{QDate{2017, 01, 01}, QTime{2, 7, 0, 0}};
94 sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()),
94 sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()),
95 static_cast<double>(te.toMSecsSinceEpoch())};
95 static_cast<double>(te.toMSecsSinceEpoch())};
96
96
97
97
98 notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp);
98 notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp);
99
99
100 QCOMPARE(notInCach.size(), 2);
100 QCOMPARE(notInCach.size(), 2);
101 notInCacheSqp = notInCach.first();
101 notInCacheSqp = notInCach.first();
102 QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch()));
102 QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch()));
103 QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(ts0.toMSecsSinceEpoch()));
103 QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(ts0.toMSecsSinceEpoch()));
104
104
105 notInCacheSqp = notInCach.at(1);
105 notInCacheSqp = notInCach.at(1);
106 QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(te0.toMSecsSinceEpoch()));
106 QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(te0.toMSecsSinceEpoch()));
107 QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(ts1.toMSecsSinceEpoch()));
107 QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(ts1.toMSecsSinceEpoch()));
108
108
109 // 5th case ts < ts0 && te3 < te
109 // 5th case ts < ts0 && te3 < te
110 ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}};
110 ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}};
111 te = QDateTime{QDate{2017, 01, 01}, QTime{2, 22, 0, 0}};
111 te = QDateTime{QDate{2017, 01, 01}, QTime{2, 22, 0, 0}};
112 sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()),
112 sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()),
113 static_cast<double>(te.toMSecsSinceEpoch())};
113 static_cast<double>(te.toMSecsSinceEpoch())};
114
114
115
115
116 notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp);
116 notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp);
117
117
118 QCOMPARE(notInCach.size(), 4);
118 QCOMPARE(notInCach.size(), 4);
119 notInCacheSqp = notInCach.first();
119 notInCacheSqp = notInCach.first();
120 QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch()));
120 QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch()));
121 QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(ts0.toMSecsSinceEpoch()));
121 QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(ts0.toMSecsSinceEpoch()));
122
122
123 notInCacheSqp = notInCach.at(1);
123 notInCacheSqp = notInCach.at(1);
124 QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(te0.toMSecsSinceEpoch()));
124 QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(te0.toMSecsSinceEpoch()));
125 QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(ts1.toMSecsSinceEpoch()));
125 QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(ts1.toMSecsSinceEpoch()));
126
126
127 notInCacheSqp = notInCach.at(2);
127 notInCacheSqp = notInCach.at(2);
128 QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(te1.toMSecsSinceEpoch()));
128 QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(te1.toMSecsSinceEpoch()));
129 QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(ts2.toMSecsSinceEpoch()));
129 QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(ts2.toMSecsSinceEpoch()));
130
130
131 notInCacheSqp = notInCach.at(3);
131 notInCacheSqp = notInCach.at(3);
132 QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(te2.toMSecsSinceEpoch()));
132 QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(te2.toMSecsSinceEpoch()));
133 QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch()));
133 QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch()));
134
134
135
135
136 // 6th case ts2 < ts
136 // 6th case ts2 < ts
137 ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 45, 0, 0}};
137 ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 45, 0, 0}};
138 te = QDateTime{QDate{2017, 01, 01}, QTime{2, 47, 0, 0}};
138 te = QDateTime{QDate{2017, 01, 01}, QTime{2, 47, 0, 0}};
139 sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()),
139 sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()),
140 static_cast<double>(te.toMSecsSinceEpoch())};
140 static_cast<double>(te.toMSecsSinceEpoch())};
141
141
142
142
143 notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp);
143 notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp);
144
144
145 QCOMPARE(notInCach.size(), 1);
145 QCOMPARE(notInCach.size(), 1);
146 notInCacheSqp = notInCach.first();
146 notInCacheSqp = notInCach.first();
147 QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch()));
147 QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch()));
148 QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch()));
148 QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch()));
149
149
150 // 7th case ts = te0 && te < ts1
150 // 7th case ts = te0 && te < ts1
151 ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 0, 0}};
151 ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 0, 0}};
152 te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}};
152 te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}};
153 sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()),
153 sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()),
154 static_cast<double>(te.toMSecsSinceEpoch())};
154 static_cast<double>(te.toMSecsSinceEpoch())};
155
155
156
156
157 notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp);
157 notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp);
158
158
159 QCOMPARE(notInCach.size(), 1);
159 QCOMPARE(notInCach.size(), 1);
160 notInCacheSqp = notInCach.first();
160 notInCacheSqp = notInCach.first();
161 QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(te0.toMSecsSinceEpoch()));
161 QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(te0.toMSecsSinceEpoch()));
162 QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch()));
162 QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch()));
163
163
164 // 8th case ts0 < ts < te0 && te < ts1
164 // 8th case ts0 < ts < te0 && te < ts1
165 ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 30, 0}};
165 ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 30, 0}};
166 te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}};
166 te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}};
167 sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()),
167 sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()),
168 static_cast<double>(te.toMSecsSinceEpoch())};
168 static_cast<double>(te.toMSecsSinceEpoch())};
169
169
170
170
171 notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp);
171 notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp);
172
172
173 QCOMPARE(notInCach.size(), 1);
173 QCOMPARE(notInCach.size(), 1);
174 notInCacheSqp = notInCach.first();
174 notInCacheSqp = notInCach.first();
175 QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(te0.toMSecsSinceEpoch()));
175 QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(te0.toMSecsSinceEpoch()));
176 QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch()));
176 QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch()));
177
177
178 // 9th case ts0 < ts < te0 && ts1 < te < te1
178 // 9th case ts0 < ts < te0 && ts1 < te < te1
179 ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 30, 0}};
179 ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 30, 0}};
180 te = QDateTime{QDate{2017, 01, 01}, QTime{2, 7, 0, 0}};
180 te = QDateTime{QDate{2017, 01, 01}, QTime{2, 7, 0, 0}};
181 sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()),
181 sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()),
182 static_cast<double>(te.toMSecsSinceEpoch())};
182 static_cast<double>(te.toMSecsSinceEpoch())};
183
183
184
184
185 notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp);
185 notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp);
186
186
187 QCOMPARE(notInCach.size(), 1);
187 QCOMPARE(notInCach.size(), 1);
188 notInCacheSqp = notInCach.first();
188 notInCacheSqp = notInCach.first();
189 QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(te0.toMSecsSinceEpoch()));
189 QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(te0.toMSecsSinceEpoch()));
190 QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(ts1.toMSecsSinceEpoch()));
190 QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(ts1.toMSecsSinceEpoch()));
191
191
192 // 10th case te1 < ts < te < ts2
192 // 10th case te1 < ts < te < ts2
193 ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 9, 0, 0}};
193 ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 9, 0, 0}};
194 te = QDateTime{QDate{2017, 01, 01}, QTime{2, 10, 0, 0}};
194 te = QDateTime{QDate{2017, 01, 01}, QTime{2, 10, 0, 0}};
195 sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()),
195 sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()),
196 static_cast<double>(te.toMSecsSinceEpoch())};
196 static_cast<double>(te.toMSecsSinceEpoch())};
197
197
198
198
199 notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp);
199 notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp);
200
200
201 QCOMPARE(notInCach.size(), 1);
201 QCOMPARE(notInCach.size(), 1);
202 notInCacheSqp = notInCach.first();
202 notInCacheSqp = notInCach.first();
203 QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch()));
203 QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch()));
204 QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch()));
204 QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch()));
205
205
206 // 11th case te0 < ts < ts1 && te3 < te
206 // 11th case te0 < ts < ts1 && te3 < te
207 ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}};
207 ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}};
208 te = QDateTime{QDate{2017, 01, 01}, QTime{2, 47, 0, 0}};
208 te = QDateTime{QDate{2017, 01, 01}, QTime{2, 47, 0, 0}};
209 sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()),
209 sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()),
210 static_cast<double>(te.toMSecsSinceEpoch())};
210 static_cast<double>(te.toMSecsSinceEpoch())};
211
211
212
212
213 notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp);
213 notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp);
214
214
215 QCOMPARE(notInCach.size(), 3);
215 QCOMPARE(notInCach.size(), 3);
216 notInCacheSqp = notInCach.first();
216 notInCacheSqp = notInCach.first();
217 QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch()));
217 QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch()));
218 QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(ts1.toMSecsSinceEpoch()));
218 QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(ts1.toMSecsSinceEpoch()));
219
219
220 notInCacheSqp = notInCach.at(1);
220 notInCacheSqp = notInCach.at(1);
221 QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(te1.toMSecsSinceEpoch()));
221 QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(te1.toMSecsSinceEpoch()));
222 QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(ts2.toMSecsSinceEpoch()));
222 QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(ts2.toMSecsSinceEpoch()));
223
223
224 notInCacheSqp = notInCach.at(2);
224 notInCacheSqp = notInCach.at(2);
225 QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(te2.toMSecsSinceEpoch()));
225 QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(te2.toMSecsSinceEpoch()));
226 QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch()));
226 QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch()));
227
227
228 // 12th case te0 < ts < ts1 && te3 < te
228 // 12th case te0 < ts < ts1 && te3 < te
229 ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}};
229 ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}};
230 te = QDateTime{QDate{2017, 01, 01}, QTime{2, 10, 0, 0}};
230 te = QDateTime{QDate{2017, 01, 01}, QTime{2, 10, 0, 0}};
231 sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()),
231 sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()),
232 static_cast<double>(te.toMSecsSinceEpoch())};
232 static_cast<double>(te.toMSecsSinceEpoch())};
233
233
234 notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp);
234 notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp);
235
235
236 QCOMPARE(notInCach.size(), 2);
236 QCOMPARE(notInCach.size(), 2);
237 notInCacheSqp = notInCach.first();
237 notInCacheSqp = notInCach.first();
238 QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch()));
238 QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch()));
239 QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(ts1.toMSecsSinceEpoch()));
239 QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(ts1.toMSecsSinceEpoch()));
240
240
241 notInCacheSqp = notInCach.at(1);
241 notInCacheSqp = notInCach.at(1);
242 QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(te1.toMSecsSinceEpoch()));
242 QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(te1.toMSecsSinceEpoch()));
243 QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch()));
243 QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch()));
244
244
245
245
246 // 12th case ts0 < ts < te0
246 // 12th case ts0 < ts < te0
247 ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 10, 0}};
247 ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 10, 0}};
248 te = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 50, 0}};
248 te = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 50, 0}};
249 sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()),
249 sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()),
250 static_cast<double>(te.toMSecsSinceEpoch())};
250 static_cast<double>(te.toMSecsSinceEpoch())};
251
251
252 notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp);
252 notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp);
253 QCOMPARE(notInCach.size(), 0);
253 QCOMPARE(notInCach.size(), 0);
254 }
254 }
255
255
256
256
257 void TestVariableCacheController::testAddDateTime()
257 void TestVariableCacheController::testAddDateTime()
258 {
258 {
259 VariableCacheController variableCacheController{};
259 VariableCacheController variableCacheController{};
260
260
261 auto ts0 = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 0, 0}};
261 auto ts0 = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 0, 0}};
262 auto te0 = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 0, 0}};
262 auto te0 = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 0, 0}};
263 auto sqp0 = SqpDateTime{static_cast<double>(ts0.toMSecsSinceEpoch()),
263 auto sqp0 = SqpDateTime{static_cast<double>(ts0.toMSecsSinceEpoch()),
264 static_cast<double>(te0.toMSecsSinceEpoch())};
264 static_cast<double>(te0.toMSecsSinceEpoch())};
265
265
266 auto ts1 = QDateTime{QDate{2017, 01, 01}, QTime{2, 6, 0, 0}};
266 auto ts1 = QDateTime{QDate{2017, 01, 01}, QTime{2, 6, 0, 0}};
267 auto te1 = QDateTime{QDate{2017, 01, 01}, QTime{2, 8, 0, 0}};
267 auto te1 = QDateTime{QDate{2017, 01, 01}, QTime{2, 8, 0, 0}};
268 auto sqp1 = SqpDateTime{static_cast<double>(ts1.toMSecsSinceEpoch()),
268 auto sqp1 = SqpDateTime{static_cast<double>(ts1.toMSecsSinceEpoch()),
269 static_cast<double>(te1.toMSecsSinceEpoch())};
269 static_cast<double>(te1.toMSecsSinceEpoch())};
270
270
271 auto ts2 = QDateTime{QDate{2017, 01, 01}, QTime{2, 18, 0, 0}};
271 auto ts2 = QDateTime{QDate{2017, 01, 01}, QTime{2, 18, 0, 0}};
272 auto te2 = QDateTime{QDate{2017, 01, 01}, QTime{2, 20, 0, 0}};
272 auto te2 = QDateTime{QDate{2017, 01, 01}, QTime{2, 20, 0, 0}};
273 auto sqp2 = SqpDateTime{static_cast<double>(ts2.toMSecsSinceEpoch()),
273 auto sqp2 = SqpDateTime{static_cast<double>(ts2.toMSecsSinceEpoch()),
274 static_cast<double>(te2.toMSecsSinceEpoch())};
274 static_cast<double>(te2.toMSecsSinceEpoch())};
275
275
276 auto ts01 = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 0, 0}};
276 auto ts01 = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 0, 0}};
277 auto te01 = QDateTime{QDate{2017, 01, 01}, QTime{2, 6, 0, 0}};
277 auto te01 = QDateTime{QDate{2017, 01, 01}, QTime{2, 6, 0, 0}};
278 auto sqp01 = SqpDateTime{static_cast<double>(ts01.toMSecsSinceEpoch()),
278 auto sqp01 = SqpDateTime{static_cast<double>(ts01.toMSecsSinceEpoch()),
279 static_cast<double>(te01.toMSecsSinceEpoch())};
279 static_cast<double>(te01.toMSecsSinceEpoch())};
280
280
281 auto ts3 = QDateTime{QDate{2017, 01, 01}, QTime{2, 14, 0, 0}};
281 auto ts3 = QDateTime{QDate{2017, 01, 01}, QTime{2, 14, 0, 0}};
282 auto te3 = QDateTime{QDate{2017, 01, 01}, QTime{2, 16, 0, 0}};
282 auto te3 = QDateTime{QDate{2017, 01, 01}, QTime{2, 16, 0, 0}};
283 auto sqp3 = SqpDateTime{static_cast<double>(ts3.toMSecsSinceEpoch()),
283 auto sqp3 = SqpDateTime{static_cast<double>(ts3.toMSecsSinceEpoch()),
284 static_cast<double>(te3.toMSecsSinceEpoch())};
284 static_cast<double>(te3.toMSecsSinceEpoch())};
285
285
286 auto ts03 = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 0, 0}};
286 auto ts03 = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 0, 0}};
287 auto te03 = QDateTime{QDate{2017, 01, 01}, QTime{2, 22, 0, 0}};
287 auto te03 = QDateTime{QDate{2017, 01, 01}, QTime{2, 22, 0, 0}};
288 auto sqp03 = SqpDateTime{static_cast<double>(ts03.toMSecsSinceEpoch()),
288 auto sqp03 = SqpDateTime{static_cast<double>(ts03.toMSecsSinceEpoch()),
289 static_cast<double>(te03.toMSecsSinceEpoch())};
289 static_cast<double>(te03.toMSecsSinceEpoch())};
290
290
291
291
292 auto var0 = std::make_shared<Variable>("", "", "", sqp0);
292 auto var0 = std::make_shared<Variable>("", sqp0);
293
293
294
294
295 // First case: add the first interval to the variable :sqp0
295 // First case: add the first interval to the variable :sqp0
296 variableCacheController.addDateTime(var0, sqp0);
296 variableCacheController.addDateTime(var0, sqp0);
297 auto dateCacheList = variableCacheController.dateCacheList(var0);
297 auto dateCacheList = variableCacheController.dateCacheList(var0);
298 QCOMPARE(dateCacheList.count(), 1);
298 QCOMPARE(dateCacheList.count(), 1);
299 auto dateCache = dateCacheList.at(0);
299 auto dateCache = dateCacheList.at(0);
300 QCOMPARE(dateCache.m_TStart, static_cast<double>(ts0.toMSecsSinceEpoch()));
300 QCOMPARE(dateCache.m_TStart, static_cast<double>(ts0.toMSecsSinceEpoch()));
301 QCOMPARE(dateCache.m_TEnd, static_cast<double>(te0.toMSecsSinceEpoch()));
301 QCOMPARE(dateCache.m_TEnd, static_cast<double>(te0.toMSecsSinceEpoch()));
302
302
303 // 2nd case: add a second interval : sqp1 > sqp0
303 // 2nd case: add a second interval : sqp1 > sqp0
304 variableCacheController.addDateTime(var0, sqp1);
304 variableCacheController.addDateTime(var0, sqp1);
305 dateCacheList = variableCacheController.dateCacheList(var0);
305 dateCacheList = variableCacheController.dateCacheList(var0);
306 QCOMPARE(dateCacheList.count(), 2);
306 QCOMPARE(dateCacheList.count(), 2);
307 dateCache = dateCacheList.at(0);
307 dateCache = dateCacheList.at(0);
308 QCOMPARE(dateCache.m_TStart, static_cast<double>(ts0.toMSecsSinceEpoch()));
308 QCOMPARE(dateCache.m_TStart, static_cast<double>(ts0.toMSecsSinceEpoch()));
309 QCOMPARE(dateCache.m_TEnd, static_cast<double>(te0.toMSecsSinceEpoch()));
309 QCOMPARE(dateCache.m_TEnd, static_cast<double>(te0.toMSecsSinceEpoch()));
310
310
311 dateCache = dateCacheList.at(1);
311 dateCache = dateCacheList.at(1);
312 QCOMPARE(dateCache.m_TStart, static_cast<double>(ts1.toMSecsSinceEpoch()));
312 QCOMPARE(dateCache.m_TStart, static_cast<double>(ts1.toMSecsSinceEpoch()));
313 QCOMPARE(dateCache.m_TEnd, static_cast<double>(te1.toMSecsSinceEpoch()));
313 QCOMPARE(dateCache.m_TEnd, static_cast<double>(te1.toMSecsSinceEpoch()));
314
314
315 // 3th case: merge sqp0 & sqp1 with sqp01
315 // 3th case: merge sqp0 & sqp1 with sqp01
316 variableCacheController.addDateTime(var0, sqp01);
316 variableCacheController.addDateTime(var0, sqp01);
317 dateCacheList = variableCacheController.dateCacheList(var0);
317 dateCacheList = variableCacheController.dateCacheList(var0);
318 QCOMPARE(dateCacheList.count(), 1);
318 QCOMPARE(dateCacheList.count(), 1);
319 dateCache = dateCacheList.at(0);
319 dateCache = dateCacheList.at(0);
320 QCOMPARE(dateCache.m_TStart, static_cast<double>(ts0.toMSecsSinceEpoch()));
320 QCOMPARE(dateCache.m_TStart, static_cast<double>(ts0.toMSecsSinceEpoch()));
321 QCOMPARE(dateCache.m_TEnd, static_cast<double>(te1.toMSecsSinceEpoch()));
321 QCOMPARE(dateCache.m_TEnd, static_cast<double>(te1.toMSecsSinceEpoch()));
322
322
323
323
324 // 4th case: add a second interval : sqp1 > sqp0
324 // 4th case: add a second interval : sqp1 > sqp0
325 variableCacheController.addDateTime(var0, sqp2);
325 variableCacheController.addDateTime(var0, sqp2);
326 variableCacheController.addDateTime(var0, sqp3);
326 variableCacheController.addDateTime(var0, sqp3);
327 dateCacheList = variableCacheController.dateCacheList(var0);
327 dateCacheList = variableCacheController.dateCacheList(var0);
328 QCOMPARE(dateCacheList.count(), 3);
328 QCOMPARE(dateCacheList.count(), 3);
329 dateCache = dateCacheList.at(0);
329 dateCache = dateCacheList.at(0);
330 QCOMPARE(dateCache.m_TStart, static_cast<double>(ts0.toMSecsSinceEpoch()));
330 QCOMPARE(dateCache.m_TStart, static_cast<double>(ts0.toMSecsSinceEpoch()));
331 QCOMPARE(dateCache.m_TEnd, static_cast<double>(te1.toMSecsSinceEpoch()));
331 QCOMPARE(dateCache.m_TEnd, static_cast<double>(te1.toMSecsSinceEpoch()));
332
332
333 dateCache = dateCacheList.at(1);
333 dateCache = dateCacheList.at(1);
334 QCOMPARE(dateCache.m_TStart, static_cast<double>(ts3.toMSecsSinceEpoch()));
334 QCOMPARE(dateCache.m_TStart, static_cast<double>(ts3.toMSecsSinceEpoch()));
335 QCOMPARE(dateCache.m_TEnd, static_cast<double>(te3.toMSecsSinceEpoch()));
335 QCOMPARE(dateCache.m_TEnd, static_cast<double>(te3.toMSecsSinceEpoch()));
336
336
337 dateCache = dateCacheList.at(2);
337 dateCache = dateCacheList.at(2);
338 QCOMPARE(dateCache.m_TStart, static_cast<double>(ts2.toMSecsSinceEpoch()));
338 QCOMPARE(dateCache.m_TStart, static_cast<double>(ts2.toMSecsSinceEpoch()));
339 QCOMPARE(dateCache.m_TEnd, static_cast<double>(te2.toMSecsSinceEpoch()));
339 QCOMPARE(dateCache.m_TEnd, static_cast<double>(te2.toMSecsSinceEpoch()));
340
340
341
341
342 // 5th case: merge all interval
342 // 5th case: merge all interval
343 variableCacheController.addDateTime(var0, sqp03);
343 variableCacheController.addDateTime(var0, sqp03);
344 dateCacheList = variableCacheController.dateCacheList(var0);
344 dateCacheList = variableCacheController.dateCacheList(var0);
345 QCOMPARE(dateCacheList.count(), 1);
345 QCOMPARE(dateCacheList.count(), 1);
346 dateCache = dateCacheList.at(0);
346 dateCache = dateCacheList.at(0);
347 QCOMPARE(dateCache.m_TStart, static_cast<double>(ts0.toMSecsSinceEpoch()));
347 QCOMPARE(dateCache.m_TStart, static_cast<double>(ts0.toMSecsSinceEpoch()));
348 QCOMPARE(dateCache.m_TEnd, static_cast<double>(te03.toMSecsSinceEpoch()));
348 QCOMPARE(dateCache.m_TEnd, static_cast<double>(te03.toMSecsSinceEpoch()));
349 }
349 }
350
350
351
351
352 QTEST_MAIN(TestVariableCacheController)
352 QTEST_MAIN(TestVariableCacheController)
353 #include "TestVariableCacheController.moc"
353 #include "TestVariableCacheController.moc"
General Comments 0
You need to be logged in to leave comments. Login now