-
Notifications
You must be signed in to change notification settings - Fork 0
/
2023-12-01-list-equipment.py
69 lines (57 loc) · 2.14 KB
/
2023-12-01-list-equipment.py
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
#!/usr/bin/env python3
import pandas as pd
import subprocess
import os
from collections import defaultdict
import matplotlib.pyplot as plt
from math import sqrt
def get_arrivals(day, month):
if not os.path.exists("flight_data"):
os.makedirs("flight_data")
flight_data_path = f"flight_data/2023-{month:02d}-{day:02d}.csv"
if not os.path.exists(flight_data_path):
subprocess.check_call(
[
"aws",
"s3",
"cp",
f"s3://nao-bostraffic/Data/Arrivals/2023-{month:02d}-{day:02d}_BOS_Arrivals.csv",
flight_data_path,
]
)
return flight_data_path
def plot_flight_origins():
month_range = range(4, 13)
day_range = range(1, 32)
arrivals_dict = defaultdict(int)
for month in month_range:
for day in day_range:
try:
flight_data_path = get_arrivals(day, month)
except:
print("No arrivals for %s-%s" % (month, day))
continue
with open(flight_data_path) as arrivals:
for index, line in enumerate(arrivals):
items = line.strip().split(",")
if index == 0:
cols = items
origin_city_index = cols.index("Origin")
continue
if items[0].isdigit():
items = items[1:]
origin_city = items[origin_city_index - 1]
equipment = items[-1]
arrivals_dict[(origin_city, equipment)] += 1
else:
origin_city = items[origin_city_index]
equipment = items[-1]
arrivals_dict[(origin_city, equipment)] += 1
with open("arrival_and_equipment.tsv", "w") as tsv:
tsv.write("location\tequipment\tn_flights\n")
for (location, equipment), n_flights in arrivals_dict.items():
tsv.write("%s\t%s\t%s\n" % (location, equipment, n_flights))
def start():
plot_flight_origins()
if __name__ == "__main__":
start()