Compare commits

..

2 commits

2 changed files with 19 additions and 9 deletions

View file

@ -31,20 +31,24 @@
{% endfor %} {% endfor %}
</div> </div>
<div> <div>
Flight segments in {{ year }}: {{ year_stats.flight_count }} Flight segments in {{ year }}: {{ year_stats.flight_count or 0 }}
{% if year_stats.airlines %}
[ by airline: [ by airline:
{% for airline, count in year_stats.airlines.most_common() %} {% for airline, count in year_stats.airlines.most_common() %}
{{ airline }}: {{ count }}{% if not loop.last %},{% endif %} {{ airline }}: {{ count }}{% if not loop.last %},{% endif %}
{% endfor %} ] {% endfor %} ]
{% endif %}
</div> </div>
<div>Trains segments in {{ year }}: {{ year_stats.train_count }}</div> <div>Trains segments in {{ year }}: {{ year_stats.train_count or 0 }}</div>
<div>Total distance in {{ year}}: {{ format_distance(year_stats.total_distance) }}</div> <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() %} {% for transport_type, distance in year_stats.distances_by_transport_type.items() %}
<div> <div>
{{ transport_type | title }} {{ transport_type | title }}
distance: {{format_distance(distance) }} distance: {{format_distance(distance) }}
</div> </div>
{% endfor %} {% endfor %}
{% endif %}
{% endfor %} {% endfor %}
</div> </div>
{% endblock %} {% endblock %}

View file

@ -43,14 +43,20 @@ def check_trips() -> None:
def check_flights(airlines: set[str]) -> 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) bookings = agenda.travel.parse_yaml("flights", data_dir)
prev_first_depart = None
for booking in bookings: for booking in bookings:
assert all(flight["airline"] in airlines for flight in booking["flights"]) assert all(flight["airline"] in airlines for flight in booking["flights"])
for booking in bookings:
check_currency(booking) 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") print(len(bookings), "flights")