Repository navigation
Expand file tree
/
Copy pathutility.cpp
More file actions
145 lines (121 loc) · 4.04 KB
/
Copy pathutility.cpp
File metadata and controls
145 lines (121 loc) · 4.04 KB
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
#include "utility.h"
//here we read the data from the file.
void airport::load_arv() {
string filePath = "./flightDB/" + icoa + "/" + icoa + ".arv";
ifstream file(filePath);
if (!file.is_open()) {
throw icoa;// Throw the airport icoa that not found
cout << "Error: could not open file" << endl;
}
else {
string line;
vector<string> row;
string field;
int table_index;
Flight arv_;
getline(file, line);//ignore the first line
while (getline(file, line)) {
stringstream ss(line);
table_index = 0;//table index
while (getline(ss, field, ',')) {
switch (table_index)
{
case 0: arv_.icoa24 = field; break;
case 1: arv_.dpt_time = (field == "null") ? -1 :stoi(field); break;
case 2: arv_.dpt = field; break;
case 3: arv_.arv_time = (field == "null") ? -1 :stoi(field); break;
case 4: arv_.arv = field; break;
case 5: arv_.callsign = field; break;
}
++table_index;
}
arv_flights.push_back(arv_);
table_index = 0;
}
}
file.close();
}
void airport::load_dpt() {
string filePath = "./flightDB/" + icoa + "/" + icoa + ".dpt";
ifstream file(filePath);
if (!file.is_open()) {
throw icoa;// Throw the airport icoa that not found
cout << "Error: could not open file" << endl;
}
else {
string line;
vector<string> row;
string field;
int table_index;
Flight dpt_;
getline(file, line);//ignore the first line
while (getline(file, line)) {
stringstream ss(line);
table_index = 0;//table index
while (getline(ss, field, ',')) {
switch (table_index)
{
case 0: dpt_.icoa24 = field; break;
case 1: dpt_.dpt_time = stoi(field); break;
case 2: dpt_.dpt = field; break;
case 3: dpt_.arv_time = stoi(field); break;
case 4: dpt_.arv = field; break;
case 5: dpt_.callsign = field; break;
}
++table_index;
}
dpt_flights.push_back(dpt_);
table_index = 0;
}
}
file.close();
}
const string airport::convertLocalTime(const int timeInSeconds){
if(timeInSeconds == -1){
return "unknown";
}
// convert to time_t
time_t time = timeInSeconds;
// convert to local time
struct tm* tm = localtime(&time);
// format the time as a string
char buffer[80];
strftime(buffer, 80, "%Y-%m-%d %H:%M:%S", tm);
return string(buffer);
}
//func that comper time and flight.
bool comp(const pair<const Flight,bool>& flight1, const pair<const Flight,bool>& flight2) {
if (flight1.second == IS_ARV && flight2.second == IS_ARV)
return (flight1.first.arv_time < flight2.first.arv_time);
else if (flight1.second == IS_DPT && flight2.second == IS_DPT)
return (flight1.first.dpt_time < flight2.first.dpt_time);
else if (flight1.second == IS_ARV && flight2.second == IS_DPT)
return (flight1.first.arv_time < flight2.first.dpt_time);
else
return (flight1.first.dpt_time < flight2.first.arv_time);
}
//sort with the func we build before.
vector<pair<Flight,bool>> airport::sort_full_sche() {
vector<pair<Flight,bool>> sortSche;
for(const Flight& f : arv_flights)
sortSche.push_back({f,IS_ARV});
for(const Flight& f : dpt_flights)
sortSche.push_back({f,IS_DPT});
sort(sortSche.begin(), sortSche.end(), comp);
return sortSche;
}
vector<Flight> airport::getFlightsByicoa24(string icoa24)
{
vector<Flight> flights;
for(Flight& f : arv_flights)
{
if(f.icoa24 == icoa24)
flights.push_back(f);
}
for(Flight& f : dpt_flights)
{
if(f.icoa24 == icoa24)
flights.push_back(f);
}
return flights;
}