Add countries visited to trip stats page

Closes: #160
This commit is contained in:
Edward Betts 2024-06-17 16:10:07 +01:00
parent 1e14a99419
commit d5bf004912
2 changed files with 9 additions and 0 deletions

View file

@ -20,8 +20,14 @@
{% endfor %}
{% for year, year_stats in yearly_stats | dictsort %}
{% set countries = year_stats.countries | sort(attribute="name") %}
<h4>{{ year }}</h4>
<div>Trips in {{ year }}: {{ year_stats.count }}</div>
<div>{{ countries | count }} countries visited in {{ year }}:
{% for c in countries %}
{{ c.flag }} {{ c.name }}
{% endfor %}
</div>
<div>Total distance in {{ year}}: {{ format_distance(year_stats.total_distance) }}</div>
{% for transport_type, distance in year_stats.distances_by_transport_type.items() %}
<div>

View file

@ -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)