forked from RoniCycode/embedded-programming-linux
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmyLibrary.cpp
More file actions
135 lines (115 loc) · 3.34 KB
/
myLibrary.cpp
File metadata and controls
135 lines (115 loc) · 3.34 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
#include <fstream>
#include <filesystem>
#include "myLibrary.h"
#include <iostream>
using namespace std;
namespace fs = filesystem;
void loadFromFile(vector<Node*>& database, const string& file_path){
ifstream file(file_path);
if (file) {
string firstLine;
bool fEof = false;
getline(file, firstLine);
while (!fEof)
{
Node* pNode = new Node;
file >> *pNode;
database.push_back(pNode);
if (file.eof())
{
fEof = true;
continue;
}
}
file.close();
}
}
vector<Node*> loadDatabase() {
vector<Node*> database;
const string parent_dir = fs::current_path().parent_path().string();
for (const auto& entry : fs::directory_iterator(parent_dir)) {
if (entry.is_directory()) {
const string icao_name = entry.path().filename().string();
if (icao_name[0] == '.') { // Skip directories that start with "."
continue;
}
const string dpt_file_path = entry.path() / (icao_name + ".dpt");
const string arv_file_path = entry.path() / (icao_name + ".arv");
loadFromFile(database, dpt_file_path);
loadFromFile(database, arv_file_path);
}
}
return database;
}
bool thereExistsAZipFile(const string& zipName)
{
const string parent_dir = fs::current_path().string();
for (const auto& entry : fs::directory_iterator(parent_dir)) {
if (entry.is_directory())
{
continue;
}
const string fileName = entry.path().filename().string();
if (fileName == zipName)
{
return true;
}
}
return false;
}
void fetchAirportsData(const vector<string>& icao_names)
{
string fileName = "/flightScanner.sh";
string command;
const string parent_dir = fs::current_path().parent_path().string();
command += "bash ";
command += parent_dir;
command += fileName;
int size = icao_names.size();
for (int i = 0; i < size; i++)
{
command += " ";
command += icao_names[i];
}
cout << "Running script command: " << command << endl;
system(command.c_str());
}
vector<Node*> get_flights_to_airport(string icao , vector<Node*>& arr)
{
int size = arr.size();
vector<Node*> arrivals;
for (int i = 0; i < size; i++)
if (arr[i]->getEstArrivalAirport() == icao)
arrivals.push_back(arr[i]);
return arrivals;
}
vector<Node*> get_flights_from_airport(string icao , vector<Node*>& arr)
{
int size = arr.size();
vector<Node*> departures;
for (int i = 0; i < size; i++)
if (arr[i]->getEstDepartureAirport() == icao)
departures.push_back(arr[i]);
return departures;
}
vector<Node*> get_flights_by_aircraft(string aircraft , vector<Node*>& arr)
{
int size = arr.size();
vector<Node*> flights;
for (int i = 0; i < size; i++)
if (arr[i]->getIcao24() == aircraft)
flights.push_back(arr[i]);
return flights;
}
void freeArr(vector<Node *>& arr)
{
for (Node* node : arr) {
delete node;
}
arr.clear();
}
string convertEpochToReadable(const time_t epoch_time) {
char buffer[80];
strftime(buffer, 80, "%Y-%m-%d %H:%M:%S", std::localtime(&epoch_time));
return string(buffer);
}