-
Notifications
You must be signed in to change notification settings - Fork 1
/
get_stops.py
77 lines (63 loc) · 2.38 KB
/
get_stops.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
70
71
72
73
74
75
76
77
from concurrent.futures import ThreadPoolExecutor
import numpy as np
import matplotlib.pyplot as plt
import sqlite3
from tqdm import tqdm
from datetime import datetime
from random import choice
from glob import glob
import gmplot
from utils import get_route_details, get_stops_details, haversine_dist
import os
from random import choice
stops_data = get_stops_details()
routes_data = get_route_details()
def task(tree_file):
if os.path.exists(
"assets/processed/stops_super/{}".format(tree_file.split("/")[-1])
):
print("passed", tree_file)
return
try:
tree = np.load(tree_file, allow_pickle=True)["arr_0"].item()
except:
print(tree_file)
stop_tree = {}
for route_id in tqdm(tree):
stop_tree[route_id] = {}
for trip_id in tree[route_id]:
stop_tree[route_id][trip_id] = [None] * len(routes_data[route_id])
stop_id = 0
for each_click in tree[route_id][trip_id]:
prev_distance = haversine_dist(
stops_data[routes_data[route_id][stop_id]][0],
stops_data[routes_data[route_id][stop_id]][1],
each_click[2],
each_click[3],
)
for each_stop in range(
stop_id + 1, len(routes_data[route_id])
):
cur_distance = haversine_dist(
stops_data[routes_data[route_id][each_stop]][0],
stops_data[routes_data[route_id][each_stop]][1],
each_click[2],
each_click[3],
)
if cur_distance > 500:
continue
if cur_distance < prev_distance:
prev_distance = cur_distance
stop_id = each_stop
else:
break
if prev_distance < 250:
if stop_tree[route_id][trip_id][stop_id] == None:
stop_tree[route_id][trip_id][stop_id] = []
stop_tree[route_id][trip_id][stop_id].append(each_click)
np.savez_compressed(
"assets/processed/stops_super/{}".format(tree_file.split("/")[-1]),
stop_tree,
)
executor = ThreadPoolExecutor(max_workers=8)
list(tqdm(map(task, glob("./assets/processed/tree/*"))))