-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimeseries.cpp
52 lines (38 loc) · 1.25 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
#include "timeseries.h"
/* TimeSeries constructor - opening csv file entering the data to a map
* first row is the features name after that is the data. */
TimeSeries::TimeSeries(const char *CSVfileName) {
//fields for time series
fstream csvFile;
string featuresName, data;
map<string, vector<float>>::iterator mapIt;
csvFileName = CSVfileName;
//open csv file
csvFile.open(csvFileName);
//getting column names - first line - headers
getline(csvFile, featuresName);
stringstream featureString(featuresName);
//getting features name and inserting to list and map
while (getline(featureString, data, ',')) {
featuresNameList.push_back(data);
dataMap.insert(pair<string, vector<float>>(data, {}));
}
//getting data to map
while (getline(csvFile, data)) {
mapIt = dataMap.begin();
stringstream s(data);
while (getline(s, data, ',') && mapIt != dataMap.end()) {
mapIt->second.push_back(stof(data));
mapIt++;
}
}
//closing csv file
csvFile.close();
}
/* Getter for map data */
map<string, vector<float>> TimeSeries::getMap() const {
return dataMap;
}
int TimeSeries::getMapSize() {
return dataMap.begin()->second.size();
}