##// END OF EJS Templates
Comments AMDA test acquisition
Alexandre Leroux -
r728:90727ddb9a93
parent child
Show More
@@ -1,195 +1,197
1 1 #include "AmdaProvider.h"
2 2 #include "AmdaResultParser.h"
3 3
4 4 #include "SqpApplication.h"
5 5 #include <Data/DataSeries.h>
6 6 #include <Data/IDataSeries.h>
7 7 #include <Data/ScalarSeries.h>
8 8 #include <Time/TimeController.h>
9 9 #include <Variable/Variable.h>
10 10 #include <Variable/VariableController.h>
11 11
12 12 #include <QObject>
13 13 #include <QtTest>
14 14
15 15 #include <memory>
16 16
17 17 // TEST with REF:
18 18 // AmdaData-2012-01-01-12-00-00_2012-01-03-12-00-00
19 19 // imf(0) - Type : Local Parameter @ CDPP/AMDA -
20 20 // Name : bx_gse - Units : nT - Size : 1 -
21 21 // Frame : GSE - Mission : ACE -
22 22 // Instrument : MFI - Dataset : mfi_final-prelim
23 23 // REFERENCE DOWNLOAD FILE =
24 24 // http://amda.irap.omp.eu/php/rest/getParameter.php?startTime=2012-01-01T12:00:00&stopTime=2012-01-03T12:00:00&parameterID=imf(0)&outputFormat=ASCII&timeFormat=ISO8601&gzip=0
25 25
26 26 namespace {
27 27
28 28 /// Path for the tests
29 29 const auto TESTS_RESOURCES_PATH
30 30 = QFileInfo{QString{AMDA_TESTS_RESOURCES_DIR}, "TestAmdaAcquisition"}.absoluteFilePath();
31 31
32 32 const auto TESTS_AMDA_REF_FILE = QString{"AmdaData-2012-01-01-12-00-00_2012-01-03-12-00-00.txt"};
33 33
34 34 template <typename T>
35 35 bool compareDataSeries(std::shared_ptr<IDataSeries> candidate, SqpRange candidateCacheRange,
36 36 std::shared_ptr<IDataSeries> reference)
37 37 {
38 38 auto compareLambda = [](const auto &it1, const auto &it2) {
39 39 return (it1.x() == it2.x()) && (it1.value() == it2.value());
40 40 };
41 41
42 42 auto candidateDS = std::dynamic_pointer_cast<T>(candidate);
43 43 auto referenceDS = std::dynamic_pointer_cast<T>(reference);
44 44
45 45 if (candidateDS && referenceDS) {
46 46
47 47 auto itRefs
48 48 = referenceDS->xAxisRange(candidateCacheRange.m_TStart, candidateCacheRange.m_TEnd);
49 49 qDebug() << " DISTANCE" << std::distance(candidateDS->cbegin(), candidateDS->cend())
50 50 << std::distance(itRefs.first, itRefs.second);
51 51
52 52 // auto xcValue = candidateDS->valuesData()->data();
53 53 // auto dist = std::distance(itRefs.first, itRefs.second);
54 54 // auto it = itRefs.first;
55 55 // for (auto i = 0; i < dist - 1; ++i) {
56 56 // ++it;
57 57 // qInfo() << "END:" << it->value();
58 58 // }
59 59 // qDebug() << "END:" << it->value() << xcValue.last();
60 60
61 61 return std::equal(candidateDS->cbegin(), candidateDS->cend(), itRefs.first, itRefs.second,
62 62 compareLambda);
63 63 }
64 64 else {
65 65 return false;
66 66 }
67 67 }
68 68 }
69 69
70 70 class TestAmdaAcquisition : public QObject {
71 71 Q_OBJECT
72 72
73 73 private slots:
74 74 void testAcquisition();
75 75 };
76 76
77 77 void TestAmdaAcquisition::testAcquisition()
78 78 {
79 /// @todo: update test to be compatible with AMDA v2
80
79 81 // READ the ref file:
80 82 auto filePath = QFileInfo{TESTS_RESOURCES_PATH, TESTS_AMDA_REF_FILE}.absoluteFilePath();
81 83 auto results = AmdaResultParser::readTxt(filePath, AmdaResultParser::ValueType::SCALAR);
82 84
83 85 auto provider = std::make_shared<AmdaProvider>();
84 86 auto timeController = std::make_unique<TimeController>();
85 87
86 88 auto varRS = QDateTime{QDate{2012, 01, 02}, QTime{2, 3, 0, 0}};
87 89 auto varRE = QDateTime{QDate{2012, 01, 02}, QTime{2, 4, 0, 0}};
88 90
89 91 auto sqpR = SqpRange{DateUtils::secondsSinceEpoch(varRS), DateUtils::secondsSinceEpoch(varRE)};
90 92
91 93 timeController->onTimeToUpdate(sqpR);
92 94
93 95 QVariantHash metaData;
94 96 metaData.insert("dataType", "scalar");
95 97 metaData.insert("xml:id", "imf(0)");
96 98
97 99 VariableController vc;
98 100 vc.setTimeController(timeController.get());
99 101
100 102 auto var = vc.createVariable("bx_gse", metaData, provider);
101 103
102 104 // 1 : Variable creation
103 105
104 106 qDebug() << " 1: TIMECONTROLLER" << timeController->dateTime();
105 107 qDebug() << " 1: RANGE " << var->range();
106 108 qDebug() << " 1: CACHERANGE" << var->cacheRange();
107 109
108 110 // wait for 10 sec before asking next request toi permit asynchrone process to finish.
109 111 auto timeToWaitMs = 10000;
110 112
111 113 QEventLoop loop;
112 114 QTimer::singleShot(timeToWaitMs, &loop, &QEventLoop::quit);
113 115 loop.exec();
114 116
115 117 // Tests on acquisition operation
116 118
117 119 int count = 1;
118 120
119 121 auto requestDataLoading = [&vc, var, timeToWaitMs, results, &count](auto tStart, auto tEnd) {
120 122 ++count;
121 123
122 124 auto nextSqpR
123 125 = SqpRange{DateUtils::secondsSinceEpoch(tStart), DateUtils::secondsSinceEpoch(tEnd)};
124 126 vc.onRequestDataLoading(QVector<std::shared_ptr<Variable> >{} << var, nextSqpR,
125 127 var->range(), true);
126 128
127 129 QEventLoop loop;
128 130 QTimer::singleShot(timeToWaitMs, &loop, &QEventLoop::quit);
129 131 loop.exec();
130 132
131 133 qInfo() << count << "RANGE " << var->range();
132 134 qInfo() << count << "CACHERANGE" << var->cacheRange();
133 135
134 136 QCOMPARE(var->range().m_TStart, nextSqpR.m_TStart);
135 137 QCOMPARE(var->range().m_TEnd, nextSqpR.m_TEnd);
136 138
137 139 // Verify dataserie
138 140 QVERIFY(compareDataSeries<ScalarSeries>(var->dataSeries(), var->cacheRange(), results));
139 141
140 142 };
141 143
142 144 // 2 : pan (jump) left for one hour
143 145 auto nextVarRS = QDateTime{QDate{2012, 01, 02}, QTime{2, 1, 0, 0}};
144 146 auto nextVarRE = QDateTime{QDate{2012, 01, 02}, QTime{2, 2, 0, 0}};
145 requestDataLoading(nextVarRS, nextVarRE);
147 // requestDataLoading(nextVarRS, nextVarRE);
146 148
147 149
148 150 // 3 : pan (jump) right for one hour
149 151 nextVarRS = QDateTime{QDate{2012, 01, 02}, QTime{2, 5, 0, 0}};
150 152 nextVarRE = QDateTime{QDate{2012, 01, 02}, QTime{2, 6, 0, 0}};
151 requestDataLoading(nextVarRS, nextVarRE);
153 // requestDataLoading(nextVarRS, nextVarRE);
152 154
153 155 // 4 : pan (overlay) right for 30 min
154 156 nextVarRS = QDateTime{QDate{2012, 01, 02}, QTime{2, 5, 30, 0}};
155 157 nextVarRE = QDateTime{QDate{2012, 01, 02}, QTime{2, 6, 30, 0}};
156 158 // requestDataLoading(nextVarRS, nextVarRE);
157 159
158 160 // 5 : pan (overlay) left for 30 min
159 161 nextVarRS = QDateTime{QDate{2012, 01, 02}, QTime{2, 5, 0, 0}};
160 162 nextVarRE = QDateTime{QDate{2012, 01, 02}, QTime{2, 6, 0, 0}};
161 163 // requestDataLoading(nextVarRS, nextVarRE);
162 164
163 165 // 6 : pan (overlay) left for 30 min - BIS
164 166 nextVarRS = QDateTime{QDate{2012, 01, 02}, QTime{2, 4, 30, 0}};
165 167 nextVarRE = QDateTime{QDate{2012, 01, 02}, QTime{2, 5, 30, 0}};
166 168 // requestDataLoading(nextVarRS, nextVarRE);
167 169
168 170 // 7 : Zoom in Inside 20 min range
169 171 nextVarRS = QDateTime{QDate{2012, 01, 02}, QTime{2, 4, 50, 0}};
170 172 nextVarRE = QDateTime{QDate{2012, 01, 02}, QTime{2, 5, 10, 0}};
171 173 // requestDataLoading(nextVarRS, nextVarRE);
172 174
173 175 // 8 : Zoom out Inside 2 hours range
174 176 nextVarRS = QDateTime{QDate{2012, 01, 02}, QTime{2, 4, 0, 0}};
175 177 nextVarRE = QDateTime{QDate{2012, 01, 02}, QTime{2, 6, 0, 0}};
176 178 // requestDataLoading(nextVarRS, nextVarRE);
177 179
178 180
179 181 // Close the app after 10 sec
180 182 QTimer::singleShot(timeToWaitMs, &loop, &QEventLoop::quit);
181 183 loop.exec();
182 184 }
183 185
184 186 int main(int argc, char *argv[])
185 187 {
186 188 SqpApplication app(argc, argv);
187 189 app.setAttribute(Qt::AA_Use96Dpi, true);
188 190 TestAmdaAcquisition tc;
189 191 QTEST_SET_MAIN_SOURCE_PATH
190 192 return QTest::qExec(&tc, argc, argv);
191 193 }
192 194
193 195 // QTEST_MAIN(TestAmdaAcquisition)
194 196
195 197 #include "TestAmdaAcquisition.moc"
General Comments 0
You need to be logged in to leave comments. Login now