-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdataimporter.cpp
43 lines (41 loc) · 1.51 KB
/
dataimporter.cpp
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
#include "dataimporter.h"
TaskData CSVDataImporter::read(std::__cxx11::string filename)
{
TaskData data;
std::stringstream ss;
std::string cell;
std::map<std::string, size_t> holeNamesToIndex;
std::ifstream f(filename, std::ifstream::in);
while(!f.eof())
{
// TODO: escape stringstream overhead
std::string lineStr;
std::getline(f, lineStr);
if(lineStr.size()<4)
continue;
std::stringstream lineStream(lineStr);
LineData lineData{0};
std::getline(lineStream, cell, ',');ss = std::stringstream(cell);
ss>>lineData.time;
std::getline(lineStream, lineData.holeName, ',');
std::getline(lineStream, cell, ',');ss = std::stringstream(cell);
ss>>lineData.workHours;
std::getline(lineStream, cell, ',');ss = std::stringstream(cell);
ss>>lineData.oilTons;
std::getline(lineStream, cell, ',');ss = std::stringstream(cell);
ss>>lineData.waterTons;
if(holeNamesToIndex.find(lineData.holeName) == holeNamesToIndex.end())
{
holeNamesToIndex[lineData.holeName] = data.holes.size();
HoleData holeData;
holeData.name = lineData.holeName;
data.holes.push_back(holeData);
}
size_t holeIndex = holeNamesToIndex[lineData.holeName];
HoleData& workingHole = data.holes[holeIndex];
workingHole.ts.push_back (lineData.workHours);
workingHole.qOils.push_back (lineData.oilTons);
workingHole.qWaters.push_back(lineData.waterTons);
}
return data;
}