-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathread.cpp
132 lines (125 loc) · 4.37 KB
/
read.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
#include "read.h"
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
#include <cstdlib>
using namespace std;
vector<vector<string>> Read::readRoute(const string & filename) {
// initialize the variables
vector<vector<string>> allRoute;
ifstream dataSheet (filename);
string airline;
string airlineId;
string sourceAirport;
string sourceAirportId;
string destinationAirport;
string destinationAirportId;
string useless;
if (dataSheet.is_open()) {
while (dataSheet.good()) {
vector<string> route;
// given value
getline(dataSheet, airline, ',');
getline(dataSheet, airlineId, ',');
getline(dataSheet, sourceAirport, ',');
getline(dataSheet, sourceAirportId, ',');
getline(dataSheet, destinationAirport, ',');
getline(dataSheet, destinationAirportId, ',');
getline(dataSheet, useless, '\n');
// store value in single route
route.push_back(airline);
route.push_back(airlineId);
route.push_back(sourceAirport);
route.push_back(sourceAirportId);
route.push_back(destinationAirport);
route.push_back(destinationAirportId);
// route.push_back(useless);
// store the route into the total route
allRoute.push_back(route);
}
}
// open out of the function, close in the function
dataSheet.close();
return allRoute;
}
map<string, vector<string>> Read::readAirportPosition(const string & filename) {
// initialize the variables
map<string, vector<string>> airport;
ifstream dataSheet (filename);
string airportId;
string name;
string city;
string country;
string iata;
string icao;
string latitude;
string longitude;
string useless;
if (dataSheet.is_open()) {
while (dataSheet.good()) {
// given value
getline(dataSheet, airportId, ',');
getline(dataSheet, name, ',');
getline(dataSheet, city, ',');
getline(dataSheet, country, ',');
getline(dataSheet, iata, ',');
getline(dataSheet, icao, ',');
getline(dataSheet, latitude, ',');
getline(dataSheet, longitude, ',');
getline(dataSheet, useless, '\n');
if (airport.find(airportId) == airport.end()) {
airport[airportId].push_back(latitude);
airport[airportId].push_back(longitude);
}
}
}
// open out of the function, close in the function
dataSheet.close();
return airport;
}
map<string, string> Read::AirportIdDictionary(const string & filename) {
// initialize the variables
map<string, string> ID;
ifstream dataSheet (filename);
string airportId;
string name;
string city;
string country;
string iata;
string icao;
string useless;
if (dataSheet.is_open()) {
while (dataSheet.good()) {
// given value
getline(dataSheet, airportId, ',');
getline(dataSheet, name, ',');
getline(dataSheet, city, ',');
getline(dataSheet, country, ',');
getline(dataSheet, iata, ',');
getline(dataSheet, icao, ',');
getline(dataSheet, useless, '\n');
// We just store the effective iata and icao so that we can map to airport_id
if (iata != "\\N" && icao != "\\N") {
if (ID.find(iata.substr(1, iata.size() - 2)) == ID.end()) {
ID[iata.substr(1, iata.size() - 2)] = airportId;
}
if (ID.find(icao.substr(1, icao.size() - 2)) == ID.end()) {
ID[icao.substr(1, icao.size() - 2)] = airportId;
}
} else if (iata != "\\N" && icao == "\\N") {
if (ID.find(iata.substr(1, iata.size() - 2)) == ID.end()) {
ID[iata.substr(1, iata.size() - 2)] = airportId;
}
} else if (iata == "\\N" && icao != "\\N") {
if (ID.find(icao.substr(1, icao.size() - 2)) == ID.end()) {
ID[icao.substr(1, icao.size() - 2)] = airportId;
}
} else { }
}
}
// open out of the function, close in the function
dataSheet.close();
return ID;
}