agenda/templates/trip/stats.html
Edward Betts 523dc78b35 Add overall airline, airport, and station stats to trip summary
Aggregate yearly stats into overall totals so the trip stats page
shows flight segments by airline, airports used, and stations used
in the summary section at the top.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-03 09:25:10 +00:00

133 lines
4.6 KiB
HTML

{% extends "base.html" %}
{% from "macros.html" import format_distance with context %}
{% set heading = "Trip statistics" %}
{% block title %}{{ heading }} - Edward Betts{% endblock %}
{% block content %}
<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 %}
<div>
{{ transport_type | title }}
distance: {{format_distance(distance) }}
</div>
{% endfor %}
<div>
Flight segments: {{ overall_stats.flight_count }}
{% if overall_stats.airlines %}
({{ overall_stats.airlines | count }} airlines)
[ by airline:
{% for airline, count in overall_stats.airlines.most_common() %}
{{ airline }}: {{ count }}{% if not loop.last %},{% endif %}
{% endfor %} ]
{% endif %}
</div>
{% if overall_stats.airports %}
<div>
Airports used: {{ overall_stats.airports | count }}
[ by airport:
{% for airport, count in overall_stats.airports.most_common() %}
{{ airport }}: {{ count }}{% if not loop.last %},{% endif %}
{% endfor %} ]
</div>
{% endif %}
<div>Train segments: {{ overall_stats.train_count }}</div>
{% if overall_stats.stations %}
<div>
Stations used: {{ overall_stats.stations | count }}
[ by station:
{% for station, count in overall_stats.stations.most_common() %}
{{ station }}: {{ count }}{% if not loop.last %},{% endif %}
{% endfor %} ]
</div>
{% endif %}
{% for year, year_stats in yearly_stats | dictsort(reverse=True) %}
{% set countries = year_stats.countries | default([]) | sort(attribute="name") %}
{% set new_countries = year_stats.new_countries | default([]) %}
<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 }}:
{% if new_countries %}
({{ new_countries | count }} new)
{% endif %}
{% for c in countries %}
<span class="d-inline-block border border-2 p-1 m-1">
{{ c.flag }} {{ c.name }} ({{ c.alpha_2 }})
{% if c in new_countries %}
<span class="badge text-bg-info">new</span>
{% endif %}
</span>
{% endfor %}
</div>
<div>
Flight segments in {{ year }}: {{ year_stats.flight_count or 0 }}
{% if year_stats.airlines %}
({{ year_stats.airlines | count }} airlines)
[ by airline:
{% for airline, count in year_stats.airlines.most_common() %}
{{ airline }}: {{ count }}{% if not loop.last %},{% endif %}
{% endfor %} ]
{% endif %}
</div>
{% if year_stats.airports %}
<div>
Airports used in {{ year }}: {{ year_stats.airports | count }}
[ by airport:
{% for airport, count in year_stats.airports.most_common() %}
{{ airport }}: {{ count }}{% if not loop.last %},{% endif %}
{% endfor %} ]
</div>
{% endif %}
{% if year_stats.co2_kg %}
<div>Total CO₂:
{% if year_stats.co2_kg >= 1000 %}
{{ "{:,.2f}".format(year_stats.co2_kg / 1000.0) }} tonnes
{% else %}
{{ "{:,.0f}".format(year_stats.co2_kg) }} kg
{% endif %}
</div>
{% if year_stats.co2_by_transport_type %}
{% for transport_type, co2_kg in year_stats.co2_by_transport_type.items() %}
<div style="margin-left: 20px;">
{{ transport_type | title }} CO₂:
{% if co2_kg >= 1000 %}
{{ "{:,.2f}".format(co2_kg / 1000.0) }} tonnes
{% else %}
{{ "{:,.0f}".format(co2_kg) }} kg
{% endif %}
</div>
{% endfor %}
{% endif %}
{% endif %}
<div>Trains segments in {{ year }}: {{ year_stats.train_count or 0 }}</div>
{% if year_stats.stations %}
<div>
Stations used in {{ year }}: {{ year_stats.stations | count }}
[ by station:
{% for station, count in year_stats.stations.most_common() %}
{{ station }}: {{ count }}{% if not loop.last %},{% endif %}
{% endfor %} ]
</div>
{% endif %}
<div>Total distance in {{ year}}: {{ format_distance(year_stats.total_distance or 0) }}</div>
{% if year_stats.distances_by_transport_type %}
{% for transport_type, distance in year_stats.distances_by_transport_type.items() %}
<div>
{{ transport_type | title }}
distance: {{format_distance(distance) }}
</div>
{% endfor %}
{% endif %}
{% endfor %}
</div>
{% endblock %}