Calculate routes with IATA codes
This commit is contained in:
parent
a41ce88b5f
commit
2251f2e6f7
18
app.py
18
app.py
@ -166,19 +166,19 @@ def find_routes(day, origin, destination):
|
|||||||
valid_routes = []
|
valid_routes = []
|
||||||
|
|
||||||
for train in tqdm(trains):
|
for train in tqdm(trains):
|
||||||
if train.orig == origin:
|
if train.orig_iata == origin:
|
||||||
it = [train]
|
it = [train]
|
||||||
if train.dest == destination:
|
if train.dest_iata == destination:
|
||||||
# We hope that we have a direct train
|
# We hope that we have a direct train
|
||||||
valid_routes.append(it)
|
valid_routes.append(it)
|
||||||
else:
|
else:
|
||||||
explore.append(it)
|
explore.append(it)
|
||||||
per_arr_explore.setdefault(train.dest, [])
|
per_arr_explore.setdefault(train.dest_iata, [])
|
||||||
per_arr_explore[train.dest].append(it)
|
per_arr_explore[train.dest_iata].append(it)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
for it in list(per_arr_explore.get(train.orig, [])):
|
for it in list(per_arr_explore.get(train.orig_iata, [])):
|
||||||
if any(train.dest == tr.dest or train.dest == origin for tr in it):
|
if any(train.dest_iata == tr.dest_iata or train.dest_iata == origin for tr in it):
|
||||||
# Avoid loops
|
# Avoid loops
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@ -186,13 +186,13 @@ def find_routes(day, origin, destination):
|
|||||||
|
|
||||||
if last_train.arr <= train.dep:
|
if last_train.arr <= train.dep:
|
||||||
new_it = it + [train]
|
new_it = it + [train]
|
||||||
if train.dest == destination:
|
if train.dest_iata == destination:
|
||||||
# Goal is achieved
|
# Goal is achieved
|
||||||
valid_routes.append(new_it)
|
valid_routes.append(new_it)
|
||||||
else:
|
else:
|
||||||
explore.append(new_it)
|
explore.append(new_it)
|
||||||
per_arr_explore.setdefault(train.dest, [])
|
per_arr_explore.setdefault(train.dest_iata, [])
|
||||||
per_arr_explore[train.dest].append(new_it)
|
per_arr_explore[train.dest_iata].append(new_it)
|
||||||
|
|
||||||
return valid_routes
|
return valid_routes
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user