Add airline, airport, and station stats

This commit is contained in:
Edward Betts 2026-01-15 23:05:39 +00:00
parent f22772d12d
commit bc5e595bb0
2 changed files with 48 additions and 1 deletions

View file

@ -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: