Calculate routes with IATA codes

This commit is contained in:
Emmy D'Anello 2023-02-13 00:24:43 +01:00
parent a41ce88b5f
commit 2251f2e6f7
Signed by: ynerant
GPG Key ID: 3A75C55819C8CF85
1 changed files with 9 additions and 9 deletions

18
app.py
View File

@ -166,19 +166,19 @@ def find_routes(day, origin, destination):
valid_routes = []
for train in tqdm(trains):
if train.orig == origin:
if train.orig_iata == origin:
it = [train]
if train.dest == destination:
if train.dest_iata == destination:
# We hope that we have a direct train
valid_routes.append(it)
else:
explore.append(it)
per_arr_explore.setdefault(train.dest, [])
per_arr_explore[train.dest].append(it)
per_arr_explore.setdefault(train.dest_iata, [])
per_arr_explore[train.dest_iata].append(it)
continue
for it in list(per_arr_explore.get(train.orig, [])):
if any(train.dest == tr.dest or train.dest == origin for tr in it):
for it in list(per_arr_explore.get(train.orig_iata, [])):
if any(train.dest_iata == tr.dest_iata or train.dest_iata == origin for tr in it):
# Avoid loops
continue
@ -186,13 +186,13 @@ def find_routes(day, origin, destination):
if last_train.arr <= train.dep:
new_it = it + [train]
if train.dest == destination:
if train.dest_iata == destination:
# Goal is achieved
valid_routes.append(new_it)
else:
explore.append(new_it)
per_arr_explore.setdefault(train.dest, [])
per_arr_explore[train.dest].append(new_it)
per_arr_explore.setdefault(train.dest_iata, [])
per_arr_explore[train.dest_iata].append(new_it)
return valid_routes