From f6d715e52ae67436a53d4ab044b21931179f50d0 Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Sun, 8 Dec 2024 14:12:36 +0000 Subject: [PATCH 1/2] Check flight bookings are in chronological order. --- validate_yaml.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/validate_yaml.py b/validate_yaml.py index 818840d..4e3ed1d 100755 --- a/validate_yaml.py +++ b/validate_yaml.py @@ -43,14 +43,20 @@ def check_trips() -> None: def check_flights(airlines: set[str]) -> None: - """Check flights.""" + """Check flights and ensure they are in chronological order.""" bookings = agenda.travel.parse_yaml("flights", data_dir) + + prev_first_depart = None for booking in bookings: assert all(flight["airline"] in airlines for flight in booking["flights"]) - - for booking in bookings: check_currency(booking) + if prev_first_depart: + assert ( + booking["flights"][0]["depart"] > prev_first_depart + ), "Bookings are not in chronological order by first flight's departure." + prev_first_depart = booking["flights"][0]["depart"] + print(len(bookings), "flights") From 77f0b17b37742592178d20c7bbb593d4ab8cd28f Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Thu, 12 Dec 2024 20:47:21 +0000 Subject: [PATCH 2/2] Bug fix trip stats page --- templates/trip/stats.html | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/templates/trip/stats.html b/templates/trip/stats.html index 8a117ef..7d81a3d 100644 --- a/templates/trip/stats.html +++ b/templates/trip/stats.html @@ -31,20 +31,24 @@ {% endfor %}
- Flight segments in {{ year }}: {{ year_stats.flight_count }} + Flight segments in {{ year }}: {{ year_stats.flight_count or 0 }} + {% if year_stats.airlines %} [ by airline: - {% for airline, count in year_stats.airlines.most_common() %} - {{ airline }}: {{ count }}{% if not loop.last %},{% endif %} - {% endfor %} ] + {% for airline, count in year_stats.airlines.most_common() %} + {{ airline }}: {{ count }}{% if not loop.last %},{% endif %} + {% endfor %} ] + {% endif %}
-
Trains segments in {{ year }}: {{ year_stats.train_count }}
-
Total distance in {{ year}}: {{ format_distance(year_stats.total_distance) }}
+
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 %} {% for transport_type, distance in year_stats.distances_by_transport_type.items() %}
{{ transport_type | title }} distance: {{format_distance(distance) }}
{% endfor %} + {% endif %} {% endfor %} {% endblock %}