Add maps to trip pages

Closes: #102
This commit is contained in:
Edward Betts 2024-01-12 15:04:08 +00:00
parent a9c9c719a4
commit 60070d07fd
2 changed files with 65 additions and 1 deletions

View file

@ -235,6 +235,26 @@ def trip_list() -> str:
)
def collect_station_coordinates(trip: Trip) -> list[tuple[float, float]]:
"""Extract and deduplicate station coordinates from trip."""
stations = {}
station_list = []
for t in trip.travel:
if t["type"] != "train":
continue
station_list += [t["from_station"], t["to_station"]]
for leg in t["legs"]:
station_list.append(leg["from_station"])
station_list.append(leg["to_station"])
for s in station_list:
if s["uic"] in stations:
continue
stations[s["uic"]] = s
return [(s["latitude"], s["longitude"]) for s in stations.values()]
@app.route("/trip/<start>")
def trip_page(start: str) -> str:
"""Individual trip page."""
@ -246,10 +266,13 @@ def trip_page(start: str) -> str:
if not trip:
flask.abort(404)
station_coordinates = collect_station_coordinates(trip)
return flask.render_template(
"trip_page.html",
trip=trip,
today=today,
station_coordinates=station_coordinates,
get_country=agenda.get_country,
format_list_with_ampersand=format_list_with_ampersand,
)