From fd341903684ce5064b020423175e1e33340e591f Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Sun, 14 Jan 2024 10:31:51 +0000 Subject: [PATCH] Map of all upcoming travel on trips page Closes: #107 --- agenda/trip.py | 46 +++++++++++++++------------- templates/trips.html | 72 +++++++++++++++++++++++++++++++++++++++++++- web_view.py | 27 +++++++++++++++++ 3 files changed, 123 insertions(+), 22 deletions(-) diff --git a/agenda/trip.py b/agenda/trip.py index 6bc4a7d..a306bee 100644 --- a/agenda/trip.py +++ b/agenda/trip.py @@ -143,38 +143,42 @@ def get_trip_routes(trip: Trip) -> list[StrDict]: if "from_airport" not in t or "to_airport" not in t: continue fly_from, fly_to = t["from_airport"], t["to_airport"] + key = "_".join(["flight"] + sorted([fly_from["iata"], fly_to["iata"]])) routes.append( { "type": "flight", + "key": key, "from": latlon_tuple(fly_from), "to": latlon_tuple(fly_to), } ) - - else: - assert t["type"] == "train" - for leg in t["legs"]: - train_from, train_to = leg["from_station"], leg["to_station"] - geojson_filename = train_from.get("routes", {}).get(train_to["uic"]) - if not geojson_filename: - routes.append( - { - "type": "train", - "from": latlon_tuple(train_from), - "to": latlon_tuple(train_to), - } - ) - continue - - if geojson_filename in seen_geojson: - continue - seen_geojson.add(geojson_filename) - + continue + assert t["type"] == "train" + for leg in t["legs"]: + train_from, train_to = leg["from_station"], leg["to_station"] + geojson_filename = train_from.get("routes", {}).get(train_to["uic"]) + key = "_".join(["train"] + sorted([train_from["name"], train_to["name"]])) + if not geojson_filename: routes.append( { "type": "train", - "geojson": read_geojson(geojson_filename), + "key": key, + "from": latlon_tuple(train_from), + "to": latlon_tuple(train_to), } ) + continue + + if geojson_filename in seen_geojson: + continue + seen_geojson.add(geojson_filename) + + routes.append( + { + "type": "train", + "key": key, + "geojson_filename": geojson_filename, + } + ) return routes diff --git a/templates/trips.html b/templates/trips.html index 7da70cb..d0f5624 100644 --- a/templates/trips.html +++ b/templates/trips.html @@ -5,6 +5,11 @@ {% set row = { "flight": flight_row, "train": train_row } %} {% block style %} + + + {% set conference_column_count = 6 %} {% set accommodation_column_count = 7 %} {% set travel_column_count = 7 %} @@ -33,6 +38,13 @@ .grid-item { /* Additional styling for grid items can go here */ } + +#map { + height: 80vh; +} + + + {% endblock %} @@ -79,11 +91,69 @@ {% block content %}
+

Trips

{{ section("Current", current, "attending") }} {{ section("Future", future, "going") }} {{ section("Past", past|reverse, "went") }}
- +{% endblock %} + +{% block scripts %} + + + + {% endblock %} diff --git a/web_view.py b/web_view.py index 9def860..1b57fb9 100755 --- a/web_view.py +++ b/web_view.py @@ -170,11 +170,35 @@ def trip_list() -> str: past = [item for item in trip_list if (item.end or item.start) < today] future = [item for item in trip_list if item.start > today] + future_coordinates = [] + seen_future_coordinates: set[tuple[str, str]] = set() + future_routes = [] + seen_future_routes: set[str] = set() + for trip in future: + for stop in agenda.trip.collect_trip_coordinates(trip): + key = (stop["type"], stop["name"]) + if key in seen_future_coordinates: + continue + future_coordinates.append(stop) + seen_future_coordinates.add(key) + + for route in agenda.trip.get_trip_routes(trip): + if route["key"] in seen_future_routes: + continue + future_routes.append(route) + seen_future_routes.add(route["key"]) + + for route in future_routes: + if "geojson_filename" in route: + route["geojson"] = agenda.trip.read_geojson(route.pop("geojson_filename")) + return flask.render_template( "trips.html", current=current, past=past, future=future, + future_coordinates=future_coordinates, + future_routes=future_routes, today=today, get_country=agenda.get_country, format_list_with_ampersand=format_list_with_ampersand, @@ -194,6 +218,9 @@ def trip_page(start: str) -> str: coordinates = agenda.trip.collect_trip_coordinates(trip) routes = agenda.trip.get_trip_routes(trip) + for route in routes: + if "geojson_filename" in route: + route["geojson"] = agenda.trip.read_geojson(route.pop("geojson_filename")) return flask.render_template( "trip_page.html",