From 40578196bcc56927aca09d64598fee44e6215940 Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Mon, 17 Jun 2024 16:28:14 +0100 Subject: [PATCH] Show number of flights and trains on travel stats page Closes: #161 --- templates/trip/stats.html | 2 ++ web_view.py | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/templates/trip/stats.html b/templates/trip/stats.html index bbfa044..baae8ea 100644 --- a/templates/trip/stats.html +++ b/templates/trip/stats.html @@ -28,6 +28,8 @@ {{ c.flag }} {{ c.name }} {% endfor %} +
Flights in {{ year }}: {{ year_stats.flight_count }}
+
Trains in {{ year }}: {{ year_stats.train_count }}
Total distance in {{ year}}: {{ format_distance(year_stats.total_distance) }}
{% for transport_type, distance in year_stats.distances_by_transport_type.items() %}
diff --git a/web_view.py b/web_view.py index 76440f7..8c81927 100755 --- a/web_view.py +++ b/web_view.py @@ -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)