Add timeline car import and CO2 trip stats
This commit is contained in:
parent
38dbb2b4e7
commit
3747e83ade
14 changed files with 1038 additions and 29 deletions
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
import json
|
||||
import pathlib
|
||||
from datetime import date
|
||||
from datetime import date, datetime, timezone
|
||||
|
||||
import agenda.trip
|
||||
import pytest
|
||||
|
|
@ -203,6 +203,9 @@ def test_load_cars_infers_route_labels_and_home_marker(
|
|||
assert cars[0]["to"] == "EMF"
|
||||
assert cars[0]["geojson_filename"] == "PCH_to_EMF"
|
||||
assert cars[0]["distance"] > 0
|
||||
assert cars[0]["co2_kg"] == pytest.approx(
|
||||
cars[0]["distance"] * agenda.trip.CAR_CO2_KG_PER_KM
|
||||
)
|
||||
assert cars[0]["from_location"] == {
|
||||
"name": "PCH",
|
||||
"type": "home",
|
||||
|
|
@ -274,3 +277,49 @@ def test_get_trip_routes_includes_car_geojson() -> None:
|
|||
"geojson_filename": "car_routes/PCH_to_EMF",
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
def test_trip_title_ignores_generated_drive_stop_labels() -> None:
|
||||
"""Fallback trip titles should ignore synthetic split-car stop labels."""
|
||||
trip = Trip(
|
||||
start=date(2025, 12, 29),
|
||||
travel=[
|
||||
{
|
||||
"type": "car",
|
||||
"depart": datetime(2025, 12, 29, 11, 4, tzinfo=timezone.utc),
|
||||
"arrive": datetime(2025, 12, 29, 11, 10, tzinfo=timezone.utc),
|
||||
"from": "PCH",
|
||||
"to": "Drive stop 1",
|
||||
},
|
||||
{
|
||||
"type": "car",
|
||||
"depart": datetime(2025, 12, 29, 11, 27, tzinfo=timezone.utc),
|
||||
"arrive": datetime(2025, 12, 29, 11, 40, tzinfo=timezone.utc),
|
||||
"from": "Drive stop 1",
|
||||
"to": "Drive stop 2",
|
||||
},
|
||||
{
|
||||
"type": "car",
|
||||
"depart": datetime(2025, 12, 29, 14, 6, tzinfo=timezone.utc),
|
||||
"arrive": datetime(2025, 12, 29, 15, 22, tzinfo=timezone.utc),
|
||||
"from": "Drive stop 2",
|
||||
"to": "St Ives",
|
||||
},
|
||||
{
|
||||
"type": "car",
|
||||
"depart": datetime(2026, 1, 5, 12, 46, tzinfo=timezone.utc),
|
||||
"arrive": datetime(2026, 1, 5, 13, 0, tzinfo=timezone.utc),
|
||||
"from": "St Ives",
|
||||
"to": "Drive stop 1",
|
||||
},
|
||||
{
|
||||
"type": "car",
|
||||
"depart": datetime(2026, 1, 5, 16, 58, tzinfo=timezone.utc),
|
||||
"arrive": datetime(2026, 1, 5, 17, 29, tzinfo=timezone.utc),
|
||||
"from": "Drive stop 3",
|
||||
"to": "PCH",
|
||||
},
|
||||
],
|
||||
)
|
||||
|
||||
assert trip.title == "St Ives"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue