From 24c32421894896928bc5cc46b6946ca65211a7fc Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Thu, 30 Jan 2025 13:34:36 +0000 Subject: [PATCH] =?UTF-8?q?Show=20CO=E2=82=82=20on=20stats=20page.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- agenda/stats.py | 3 +++ templates/trip/stats.html | 3 +++ 2 files changed, 6 insertions(+) diff --git a/agenda/stats.py b/agenda/stats.py index d9bdc51..c98cce9 100644 --- a/agenda/stats.py +++ b/agenda/stats.py @@ -9,6 +9,9 @@ from agenda.types import StrDict, Trip def travel_legs(trip: Trip, stats: StrDict) -> None: """Calculate stats for travel legs.""" for leg in trip.travel: + stats.setdefault("co2_kg", 0) + if "co2_kg" in leg: + stats["co2_kg"] += leg["co2_kg"] if leg["type"] == "flight": stats.setdefault("flight_count", 0) stats.setdefault("airlines", Counter()) diff --git a/templates/trip/stats.html b/templates/trip/stats.html index 8644aff..b463fd0 100644 --- a/templates/trip/stats.html +++ b/templates/trip/stats.html @@ -44,6 +44,9 @@ {% endfor %} ] {% endif %} + {% if year_stats.co2_kg %} +
Flight CO₂: {{ "{:,.1f}".format(year_stats.co2_kg / 1000.0) }} tonnes
+ {% endif %}
Trains segments in {{ year }}: {{ year_stats.train_count or 0 }}
Total distance in {{ year}}: {{ format_distance(year_stats.total_distance or 0) }}
{% if year_stats.distances_by_transport_type %}