-
Notifications
You must be signed in to change notification settings - Fork 0
/
timeseries.h
77 lines (57 loc) · 1.65 KB
/
timeseries.h
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//Orpaz Sondhelm 206492324 Yarin Tzdaka 319091278
#include <fstream>
#include <vector>
//#include <string>
#include <iostream>
#include <fstream>
#include <sstream>
#ifndef TIMESERIES_H_
#define TIMESERIES_H_
using namespace std;
class TimeSeries {
private:
vector<pair<string, vector<float>>> columns;
public:
TimeSeries(const char *CSVfileName) {
string line;
std::ifstream myFile(CSVfileName);
if (myFile.is_open()) {
getline(myFile, line);
std::istringstream ss(line);
std::string token;
while (std::getline(ss, token, ',')) {
vector<float> v1;
columns.push_back(make_pair(token, v1));
}
while (std::getline(myFile, line)) {
int index = 0;
std::istringstream ss(line);
if (line.compare("\n") != 0) {
std::string token;
while (std::getline(ss, token, ',')) {
float num = std::stof(token);
columns[index].second.push_back(num);
index++;
}
} else {
break;
}
}
/*else{
for(int i = 0; i < columns.size(); i++){
v1.push_back();
}
columns[j].second = v1;
}
}*/
}
myFile.close();
}
int getSize(){
return columns[0].second.size();
}
const vector<pair<string, vector<float>>> & getVector() const {
return columns;
};
};
#endif /* TIMESERIES_H_ */