Travel stats to show number of conference stats

Closes: #167
This commit is contained in:
Edward Betts 2024-07-10 19:28:56 +01:00
parent efae1b9b14
commit 17eca6a95a
3 changed files with 9 additions and 0 deletions

View file

@ -388,6 +388,11 @@ def calculate_yearly_stats(trips: list[Trip]) -> dict[int, StrDict]:
dist = trip.total_distance()
yearly_stats[year].setdefault("count", 0)
yearly_stats[year]["count"] += 1
for c in trip.conferences:
yearly_stats[c["start"].year].setdefault("conferences", 0)
yearly_stats[c["start"].year]["conferences"] += 1
if dist:
yearly_stats[year]["total_distance"] = (
yearly_stats[year].get("total_distance", 0) + trip.total_distance()

View file

@ -10,6 +10,7 @@
<div class="container-fluid">
<h1>Trip statistics</h1>
<div>Trips: {{ count }}</div>
<div>Conferences: {{ conferences }}</div>
<div>Total distance: {{ format_distance(total_distance) }}</div>
{% for transport_type, distance in distances_by_transport_type %}
@ -23,6 +24,7 @@
{% set countries = year_stats.countries | sort(attribute="name") %}
<h4>{{ year }}</h4>
<div>Trips in {{ year }}: {{ year_stats.count }}</div>
<div>Conferences in {{ year }}: {{ year_stats.conferences }}</div>
<div>{{ countries | count }} countries visited in {{ year }}:
{% for c in countries %}
<span class="text-nowrap">{{ c.flag }} {{ c.name }}</span>

View file

@ -590,6 +590,7 @@ def trip_stats() -> str:
today = date.today()
past = [item for item in trip_list if (item.end or item.start) < today]
conferences = sum(len(item.conferences) for item in past)
yearly_stats = agenda.trip.calculate_yearly_stats(past)
@ -599,6 +600,7 @@ def trip_stats() -> str:
total_distance=calc_total_distance(past),
distances_by_transport_type=sum_distances_by_transport_type(past),
yearly_stats=yearly_stats,
conferences=conferences,
)