-
Notifications
You must be signed in to change notification settings - Fork 0
/
request.cpp
165 lines (154 loc) · 5.6 KB
/
request.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#include "request.h"
/**
* @file request.cpp
* @brief This file contains the declaration of the moveBankRequests class
*/
/**
* @brief Constructor for moveBankRequests.
*
* Make the call to the database, retrieve the data and store them
*
* @param adresse This is the https adress to where the request is made
* @param outputFilePath This is the path to where the data from the request are stored
*/
moveBankRequests::moveBankRequests(const string &adresse, const string &outputFilePath){
curl = curl_easy_init();
CURLcode res;
curl_easy_setopt(curl, CURLOPT_URL, adresse.c_str());
curl_easy_setopt(curl, CURLOPT_USERPWD, "valpaz:valpaz21");
FILE* outputFile;
outputFile = fopen(outputFilePath.c_str(), "wb");
curl_easy_setopt(curl, CURLOPT_WRITEDATA, outputFile);
res = curl_easy_perform(curl);
if (res != CURLE_OK) {
cerr << "Request error " << endl;
}else {
cout << "Successful request " << endl;
}
fclose(outputFile);
}
/**
* @brief cleaner for moveBankAuth as the destructor bring core dump error with curl cleanup
*
*/
void moveBankRequests::cleanUp() {
if (curl) {
curl_easy_cleanup(curl);
}
}
/**
* @brief Destructor for moveBankRequests.
*
*/
// moveBankRequests::~moveBankRequests() {
// if (curl) {
// curl_easy_cleanup(curl);
// }
// }
/**
* @brief Parsing for moveBank individual data.
*
* Parse the raw data containing ids, informations, etc and create a new file containing only the tag Id (skipping useless data)
*
* @param homeDir The path representing your home directory
* @param outputInd This is the path to where the raw data from the request are stored
*/
void moveBankRequests::idParsing(const string &homeDir,const string &outputInd){
string line;
ifstream fileOutput(outputInd.c_str());
ofstream fileIndiv(string(homeDir) + "/moveBankProjet/data/individu.txt", std::ios::out | std::ios::trunc);
while (getline(fileOutput, line)) {
stringstream ss(line);
int cpt = 0;
while (ss.good()) {
std::string substr;
getline(ss, substr, ',');
if (cpt == 2){
if (isdigit(substr[0])){
fileIndiv << substr << std::endl;
}
}
cpt++;
}
}
fileIndiv.close();
fileOutput.close();
}
/**
* @brief Parsing for moveBank initial event data.
*
* Parse the raw event data (containing mixed data of all individual) and create new files for each tag_id.
* Each of this new files are filled with their corresponding event which contain their location and time of this location.
* Thus are the initial data to populate the future graph. You can choose how much day of data you want to initialy retrieve by changing the number of day in myFunctions.cpp
*
* @param homeDir The path representing your home directory
* @param outputEvent This is the path to where the raw data from the request are stored
*/
void moveBankRequests::eventInitialParsing(const string &homeDir,const string &outputEvent){
ifstream fileInds(string(homeDir) + "/moveBankProjet/data/individu.txt");
string ligne;
string ligneEvent;
string currentId;
int cptt;
while (getline(fileInds, ligne)) {
currentId = ligne;
// Creating a file for each individual
ofstream fileInd((string(homeDir) + "/moveBankProjet/indFiles/"+currentId + ".csv").c_str());
ifstream fileEvent(outputEvent.c_str());
getline(fileEvent, ligneEvent);
while (getline(fileEvent, ligneEvent)) {
stringstream ss(ligneEvent);
string valeur;
cptt = 0;
while (getline(ss, valeur, ',')) {
if (cptt==4){
valeur.erase(valeur.find_last_not_of("\n\r") + 1);
if (valeur==currentId){
fileInd << ligneEvent << endl;
}
}
cptt++;
}
}
fileInd.close();
fileEvent.close();
}
fileInds.close();
}
/**
* @brief Parsing for moveBank update event data.
*
* Parse the raw event data (containing mixed data of all individual) and update already existing files for each tag_id.
* Each of this files are filled with their new corresponding event which contain their location and time of this location.
*
* @param homeDir The path representing your home directory
* @param outputUpdateEvent This is the path to where the raw data from the request are stored
*/
void moveBankRequests::eventUpdateparsing(const string &homeDir,const string &outputUpdateEvent){
ifstream fileIndis(string(homeDir) + "/moveBankProjet/data/individu.txt");
string line;
string ligneEvent;
string currentId;
int cptt;
while (getline(fileIndis, line)) {
currentId = line;
ofstream fileUpdateInd((string(homeDir) + "/moveBankProjet/indFiles/"+currentId + ".csv").c_str(),std::ios::app);
ifstream fileUpdateEvent(outputUpdateEvent.c_str());
while (getline(fileUpdateEvent, ligneEvent)) {
stringstream ss(ligneEvent);
string valeur;
cptt = 0;
while (getline(ss, valeur, ',')) {
if (cptt==4){
valeur.erase(valeur.find_last_not_of("\n\r") + 1);
if (valeur==currentId){
fileUpdateInd << ligneEvent << endl;
}
}
cptt++;
}
}
fileUpdateInd.close();
fileUpdateEvent.close();
}
}