##// END OF EJS Templates
Amda provider (3)...
Alexandre Leroux -
r380:7ff7615687bf
parent child
Show More
@@ -0,0 +1,19
1 #ifndef SCIQLOP_AMDARESULTPARSER_H
2 #define SCIQLOP_AMDARESULTPARSER_H
3
4 #include "AmdaGlobal.h"
5
6 #include <QLoggingCategory>
7
8 #include <memory>
9
10 class IDataSeries;
11
12 Q_DECLARE_LOGGING_CATEGORY(LOG_AmdaResultParser)
13
14 struct SCIQLOP_AMDA_EXPORT AmdaResultParser {
15
16 static std::shared_ptr<IDataSeries> readTxt(const QString &filePath) noexcept;
17 };
18
19 #endif // SCIQLOP_AMDARESULTPARSER_H
@@ -0,0 +1,70
1 #include "AmdaResultParser.h"
2
3 #include <Data/ScalarSeries.h>
4
5 #include <QDateTime>
6 #include <QFile>
7
8 Q_LOGGING_CATEGORY(LOG_AmdaResultParser, "AmdaResultParser")
9
10 namespace {
11
12 /// Format for dates in result files
13 const auto DATE_FORMAT = QStringLiteral("yyyy-MM-ddThh:mm:ss.zzz");
14
15 /// @todo ALX
16 double doubleDate(const QString &stringDate) noexcept
17 {
18 auto dateTime = QDateTime::fromString(stringDate, DATE_FORMAT);
19 return dateTime.toMSecsSinceEpoch() / 1000.;
20 }
21
22 } // namespace
23
24 std::shared_ptr<IDataSeries> AmdaResultParser::readTxt(const QString &filePath) noexcept
25 {
26 QFile file{filePath};
27
28 if (!file.open(QFile::ReadOnly | QIODevice::Text)) {
29 qCCritical(LOG_AmdaResultParser())
30 << QObject::tr("Can't retrieve AMDA data from file %1: %2")
31 .arg(filePath, file.errorString());
32 return nullptr;
33 }
34
35 auto xData = QVector<double>{};
36 auto valuesData = QVector<double>{};
37
38 QTextStream stream{&file};
39
40 // Ignore comment lines (3 lines)
41 stream.readLine();
42 stream.readLine();
43 stream.readLine();
44
45 QString line{};
46 auto lineRegex = QRegExp{QStringLiteral("\\s+")};
47 while (stream.readLineInto(&line)) {
48 auto lineData = line.split(lineRegex, QString::SkipEmptyParts);
49 if (lineData.size() == 2) {
50 // X : the data is converted from date to double (in secs)
51 xData.push_back(doubleDate(lineData.at(0)));
52
53 // Value
54 valuesData.push_back(lineData.at(1).toDouble());
55 }
56 else {
57 /// @todo ALX : log
58 }
59 }
60
61 /// @todo ALX : handle units
62 auto scalarSeries = std::make_shared<ScalarSeries>(xData.size(), Unit{"nT", true}, Unit{});
63
64 const auto count = xData.size();
65 for (auto i = 0; i < count; ++i) {
66 scalarSeries->setData(i, xData.at(i), valuesData.at(i));
67 }
68
69 return scalarSeries;
70 }
@@ -1,4 +1,6
1 #include "AmdaProvider.h"
1 #include "AmdaProvider.h"
2 #include "AmdaResultParser.h"
3
2 #include <Data/DataProviderParameters.h>
4 #include <Data/DataProviderParameters.h>
3
5
4 #include <QNetworkAccessManager>
6 #include <QNetworkAccessManager>
@@ -107,6 +109,15 void AmdaProvider::httpDownloadFinished() noexcept
107 {
109 {
108 if (impl->m_File) {
110 if (impl->m_File) {
109 impl->m_File->close();
111 impl->m_File->close();
112
113 // Parse results file
114 if (auto dataSeries = AmdaResultParser::readTxt(impl->m_File->fileName())) {
115 emit dataProvided(impl->m_Token, dataSeries, impl->m_Params.m_Time);
116 }
117 else {
118 /// @todo ALX : debug
119 }
120
110 impl->m_File = nullptr;
121 impl->m_File = nullptr;
111 }
122 }
112
123
General Comments 0
You need to be logged in to leave comments. Login now