-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimeseries.cpp
96 lines (84 loc) · 2.18 KB
/
timeseries.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
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
//
// Hod Amar and Ofek Avergil
//
#include "timeseries.h"
///** constructor
///** initialize map of strings (keys) and vectors.
TimeSeries::TimeSeries(const char* CSVfileName) {
string line, token;
ifstream file;
stringstream ss;
/// open file and check it
file.open(CSVfileName);
if (!file.is_open()) {
throw std::runtime_error("Couldn't open file\n");
}
/// getting features name
if (file.good()) {
getline(file, line);
ss.str(line);
while (getline(ss, line, ',')) {
features.push_back(line);
}
}
/// making map of lines
while (getline(file, line)) {
std::stringstream ss1(line);
/// making the vector and initial keymap
for (auto element : features) {
getline(ss1, token, ',');
data[element].push_back(stof(token));
}
}
vecLen = data[features[0]].size();
//time = makeTimeVec();
file.close();
}
const vector<string> TimeSeries::getFeaturesNames() const {
return features;
}
vector<float> TimeSeries::getData(string s) const{
/// we assome that the string is valid
std::vector<float> v;
v = data.find(s)-> second;
return v;
}
map<string, vector<float>> TimeSeries::getMap() const {
return this->data;
}
int TimeSeries::lineSize(){
if (this->data.empty() && features.empty()){
return 0;
}
else{
return this->data[features[0]].size();;
}
}
///** initialize time vector
//vector<float> TimeSeries::makeTimeVec(){
// vector<float> v;
// smatch m1;
// regex r("[A-Za-z]*[Tt][Ii][Mm][Ee].*");
// int flag = 0;
// /// searching for "TIME" in features vector
// for (std:: string element : features){
// std:: regex_match(element,m1,r);
// if (!m1.empty()){
// flag = 1;
// v = data[element];
// break;
// }
// }
// /// if doesnt exist - making with the same interval.
// if (!flag) {
// for (int i = 0; i < vecLen; ++i) {
// v.push_back(i * 1);
// }
// }
// return v;
//}
//float TimeSeries::returnTime(int i) const {
// if (i <= vecLen){
// return time[i];
// }
//}