This repository was archived by the owner on Sep 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfileparser.cpp
More file actions
63 lines (54 loc) · 1.72 KB
/
fileparser.cpp
File metadata and controls
63 lines (54 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "fileparser.h"
#include <QString>
#include <QHash>
#include <QFile>
#include <QTextStream>
#include <QDebug>
#include <QStringList>
#include <vector>
#include "sensorvalue.h"
QHash<QString, std::vector<SensorValue>> FileParser::parse() {
QHash<QString, std::vector<SensorValue>> hash;
QFile file(this->fName);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
return hash;
QTextStream in(&file);
QString line = in.readLine();
while(!line.isNull()){
if(line.startsWith(" ;Start Stop;")){
auto values = parseRun(&in);
if(values.size() > 10){ // todo: size to break at ?
hash.insert(values[0].getDate(), values);
}
}
line = in.readLine();
}
return hash;
}
std::vector<SensorValue> FileParser::parseRun(QTextStream *in) {
std::vector<SensorValue> r;
QString line = in->readLine();
while(!line.isNull()){
if(line.startsWith(" ;Start Stop;")){
break;
} else if(!line.startsWith(" ")){
auto value = handleLine(&line);
r.push_back(value);
}
line = in->readLine();
}
return r;
}
SensorValue FileParser::handleLine(QString *line) {
QStringList parts = line->split(";");
QStringList dt = parts.value(0).split(" ");
QStringList date = dt.value(0).split("/");
auto d = date.value(2) + "-" + date.value(1) + "-" + date.value(0)+ " " + dt.value(2);
return SensorValue(d,
parts.value(3).toInt(),
parts.value(4).toInt(),
parts.value(5).toInt(),
parts.value(6).toInt(),
parts.value(7).toInt(),
parts.value(8).toInt());
}