generated from Applied-Machine-Learning-2022/final-project
-
Notifications
You must be signed in to change notification settings - Fork 1
/
helper_func.py
32 lines (23 loc) · 823 Bytes
/
helper_func.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
from collections import defaultdict
def get_stopid(node_name):
return node_name.split('_')[-1]
def namify_stop(g_name,stop_id):
return "{0}_{1}".format(g_name,stop_id)
def invert_dict(d):
inverted_d = defaultdict(set)
for k in d.keys():
for v in d[k]:
inverted_d[v].add(k)
return inverted_d
# I don't think this is useful
def get_routes_per_stop_id(stop_id):
for stop_id in time_table.stop_id.unique():
routes = time_table[time_table.stop_id == stop_id].route_id.unique()
return set(routes)
def get_time_to_next_departure(current_time, departure_list):
try:
next_departure = min(v for v in departure_list if v >= current_time)
wait_time = next_departure - current_time
except:
wait_time = None
return wait_time