Add timeline car import and CO2 trip stats

This commit is contained in:
Edward Betts 2026-08-03 13:52:45 +01:00
parent 38dbb2b4e7
commit 3747e83ade
14 changed files with 1038 additions and 29 deletions

View file

@ -3,6 +3,7 @@
from datetime import date
import agenda
import pytest
from agenda.stats import calculate_yearly_stats
from agenda.types import Trip
@ -35,3 +36,22 @@ def test_new_country_respects_previously_visited() -> None:
yearly_stats = calculate_yearly_stats(trips, {"CZ"})
assert "new_countries" not in yearly_stats[2024]
def test_yearly_stats_tracks_co2_by_transport_type() -> None:
"""CO₂ stats should include a per-transport-type breakdown."""
trip = Trip(
start=date(2024, 5, 1),
travel=[
{"type": "car", "distance": 100.0, "co2_kg": 21.8},
{"type": "bus", "distance": 50.0, "co2_kg": 5.0},
],
)
yearly_stats = calculate_yearly_stats([trip])
assert yearly_stats[2024]["co2_kg"] == pytest.approx(26.8)
assert yearly_stats[2024]["co2_by_transport_type"] == {
"car": 21.8,
"bus": 5.0,
}