Show number of flights and trains on travel stats page

Closes: #161
This commit is contained in:
Edward Betts 2024-06-17 16:28:14 +01:00
parent d5bf004912
commit 40578196bc
2 changed files with 9 additions and 0 deletions

View file

@ -547,6 +547,13 @@ def calculate_yearly_stats(trips: list[Trip]) -> dict[int, StrDict]:
for country in trip.countries:
yearly_stats[year].setdefault("countries", set())
yearly_stats[year]["countries"].add(country)
for leg in trip.travel:
if leg["type"] == "flight":
yearly_stats[year].setdefault("flight_count", 0)
yearly_stats[year]["flight_count"] += 1
if leg["type"] == "train":
yearly_stats[year].setdefault("train_count", 0)
yearly_stats[year]["train_count"] += 1
return dict(yearly_stats)