Add train route distance info

This commit is contained in:
Edward Betts 2024-04-05 15:58:44 +02:00
parent 5964899a00
commit 8ef67e0cee
6 changed files with 70 additions and 7 deletions

View file

@ -117,6 +117,15 @@ def travel_list() -> str:
if isinstance(item["depart"], datetime)
]
route_distances = agenda.travel.load_route_distances(app.config["DATA_DIR"])
for train in trains:
for leg in train["legs"]:
agenda.travel.add_leg_route_distance(leg, route_distances)
if all("distance" in leg for leg in train["legs"]):
train["distance"] = sum(leg["distance"] for leg in train["legs"])
return flask.render_template("travel.html", flights=flights, trains=trains)
@ -300,7 +309,6 @@ def human_readable_delta(future_date: date) -> str | None:
@app.route("/trip/<start>")
def trip_page(start: str) -> str:
"""Individual trip page."""
trip_list = [
trip
for trip in agenda.trip.build_trip_list()
@ -341,7 +349,9 @@ def trip_page(start: str) -> str:
for route in routes:
if "geojson_filename" in route:
route["geojson"] = agenda.trip.read_geojson(route.pop("geojson_filename"))
route["geojson"] = agenda.trip.read_geojson(
app.config["PERSONAL_DATA"], route.pop("geojson_filename")
)
if trip.end:
countries = {c.alpha_2 for c in trip.countries}