Compare commits

...

2 commits

2 changed files with 11 additions and 2 deletions

View file

@ -7,7 +7,7 @@
{% block title %}{{ heading }} - Edward Betts{% endblock %} {% block title %}{{ heading }} - Edward Betts{% endblock %}
{% block content %} {% block content %}
<div class="container"> <div class="container-fluid">
<h1>Trip statistics</h1> <h1>Trip statistics</h1>
<div>Trips: {{ count }}</div> <div>Trips: {{ count }}</div>
<div>Total distance: {{ format_distance(total_distance) }}</div> <div>Total distance: {{ format_distance(total_distance) }}</div>
@ -25,9 +25,11 @@
<div>Trips in {{ year }}: {{ year_stats.count }}</div> <div>Trips in {{ year }}: {{ year_stats.count }}</div>
<div>{{ countries | count }} countries visited in {{ year }}: <div>{{ countries | count }} countries visited in {{ year }}:
{% for c in countries %} {% for c in countries %}
{{ c.flag }} {{ c.name }} <span class="text-nowrap">{{ c.flag }} {{ c.name }}</span>
{% endfor %} {% endfor %}
</div> </div>
<div>Flights in {{ year }}: {{ year_stats.flight_count }}</div>
<div>Trains in {{ year }}: {{ year_stats.train_count }}</div>
<div>Total distance in {{ year}}: {{ format_distance(year_stats.total_distance) }}</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() %} {% for transport_type, distance in year_stats.distances_by_transport_type.items() %}
<div> <div>

View file

@ -547,6 +547,13 @@ def calculate_yearly_stats(trips: list[Trip]) -> dict[int, StrDict]:
for country in trip.countries: for country in trip.countries:
yearly_stats[year].setdefault("countries", set()) yearly_stats[year].setdefault("countries", set())
yearly_stats[year]["countries"].add(country) 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) return dict(yearly_stats)