From 40578196bcc56927aca09d64598fee44e6215940 Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Mon, 17 Jun 2024 16:28:14 +0100 Subject: [PATCH 1/2] 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) From 0079f46a80d47ed2082daf022b08341bd5c256cf Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Mon, 17 Jun 2024 16:28:45 +0100 Subject: [PATCH 2/2] Improve display of countries on stats page --- templates/trip/stats.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/trip/stats.html b/templates/trip/stats.html index baae8ea..6fe8a18 100644 --- a/templates/trip/stats.html +++ b/templates/trip/stats.html @@ -7,7 +7,7 @@ {% block title %}{{ heading }} - Edward Betts{% endblock %} {% block content %} -
+

Trip statistics

Trips: {{ count }}
Total distance: {{ format_distance(total_distance) }}
@@ -25,7 +25,7 @@
Trips in {{ year }}: {{ year_stats.count }}
{{ countries | count }} countries visited in {{ year }}: {% for c in countries %} - {{ c.flag }} {{ c.name }} + {{ c.flag }} {{ c.name }} {% endfor %}
Flights in {{ year }}: {{ year_stats.flight_count }}