diff --git a/agenda/stats.py b/agenda/stats.py index c3c8e4f..f9002a1 100644 --- a/agenda/stats.py +++ b/agenda/stats.py @@ -3,7 +3,8 @@ from collections import defaultdict from typing import Counter, Mapping -from agenda.types import StrDict, Trip +import agenda +from agenda.types import StrDict, Trip, airport_label def travel_legs(trip: Trip, stats: StrDict) -> None: @@ -19,11 +20,38 @@ def travel_legs(trip: Trip, stats: StrDict) -> None: if leg["type"] == "flight": stats.setdefault("flight_count", 0) stats.setdefault("airlines", Counter()) + stats.setdefault("airports", Counter()) stats["flight_count"] += 1 stats["airlines"][leg["airline_detail"]["name"]] += 1 + for field in ("from_airport", "to_airport"): + airport = leg.get(field) + if airport: + country = agenda.get_country(airport.get("country")) + label = airport_label(airport) + display = f"{country.flag} {label}" if country else label + stats["airports"][display] += 1 if leg["type"] == "train": stats.setdefault("train_count", 0) stats["train_count"] += 1 + stats.setdefault("stations", Counter()) + train_legs = leg.get("legs", []) + if train_legs: + for train_leg in train_legs: + for field in ("from_station", "to_station"): + station = train_leg.get(field) + if station: + country = agenda.get_country(station.get("country")) + label = station["name"] + display = f"{country.flag} {label}" if country else label + stats["stations"][display] += 1 + else: + for field in ("from_station", "to_station"): + station = leg.get(field) + if station: + country = agenda.get_country(station.get("country")) + label = station["name"] + display = f"{country.flag} {label}" if country else label + stats["stations"][display] += 1 def conferences(trip: Trip, yearly_stats: Mapping[int, StrDict]) -> None: diff --git a/templates/trip/stats.html b/templates/trip/stats.html index e07766d..e7eb51e 100644 --- a/templates/trip/stats.html +++ b/templates/trip/stats.html @@ -42,12 +42,22 @@