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 %}