From d5bf00491253be5dc95863d5858b2ce25d2fb795 Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Mon, 17 Jun 2024 16:10:07 +0100 Subject: [PATCH] Add countries visited to trip stats page Closes: #160 --- templates/trip/stats.html | 6 ++++++ web_view.py | 3 +++ 2 files changed, 9 insertions(+) diff --git a/templates/trip/stats.html b/templates/trip/stats.html index 4b535d5..bbfa044 100644 --- a/templates/trip/stats.html +++ b/templates/trip/stats.html @@ -20,8 +20,14 @@ {% endfor %} {% for year, year_stats in yearly_stats | dictsort %} + {% set countries = year_stats.countries | sort(attribute="name") %}

{{ year }}

Trips in {{ year }}: {{ year_stats.count }}
+
{{ countries | count }} countries visited in {{ year }}: + {% for c in countries %} + {{ c.flag }} {{ c.name }} + {% endfor %} +
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 5c39a50..76440f7 100755 --- a/web_view.py +++ b/web_view.py @@ -544,6 +544,9 @@ def calculate_yearly_stats(trips: list[Trip]) -> dict[int, StrDict]: yearly_stats[year]["distances_by_transport_type"].get(transport_type, 0) + distance ) + for country in trip.countries: + yearly_stats[year].setdefault("countries", set()) + yearly_stats[year]["countries"].add(country) return dict(yearly_stats)