Add overall airline, airport, and station stats to trip summary
Aggregate yearly stats into overall totals so the trip stats page shows flight segments by airline, airports used, and stations used in the summary section at the top. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
bc5e595bb0
commit
523dc78b35
4 changed files with 59 additions and 0 deletions
|
|
@ -61,6 +61,29 @@ def conferences(trip: Trip, yearly_stats: Mapping[int, StrDict]) -> None:
|
|||
yearly_stats[c["start"].year]["conferences"] += 1
|
||||
|
||||
|
||||
def calculate_overall_stats(yearly_stats: dict[int, StrDict]) -> StrDict:
|
||||
"""Aggregate yearly stats into overall stats for airlines, airports, stations."""
|
||||
overall: StrDict = {
|
||||
"airlines": Counter(),
|
||||
"airports": Counter(),
|
||||
"stations": Counter(),
|
||||
"flight_count": 0,
|
||||
"train_count": 0,
|
||||
}
|
||||
|
||||
for year_stats in yearly_stats.values():
|
||||
if "airlines" in year_stats:
|
||||
overall["airlines"] += year_stats["airlines"]
|
||||
if "airports" in year_stats:
|
||||
overall["airports"] += year_stats["airports"]
|
||||
if "stations" in year_stats:
|
||||
overall["stations"] += year_stats["stations"]
|
||||
overall["flight_count"] += year_stats.get("flight_count", 0)
|
||||
overall["train_count"] += year_stats.get("train_count", 0)
|
||||
|
||||
return overall
|
||||
|
||||
|
||||
def calculate_yearly_stats(
|
||||
trips: list[Trip], previously_visited: set[str] | None = None
|
||||
) -> dict[int, StrDict]:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue