diff --git a/templates/accommodation.html b/templates/accommodation.html
index 4a5b7de..dda241d 100644
--- a/templates/accommodation.html
+++ b/templates/accommodation.html
@@ -37,9 +37,18 @@
Accommodation
+ Statistics
- - Total nights away in 2024: {{ total_nights_2024 }}
- - Total nights abroad in 2024: {{ nights_abroad_2024 }}
+ {% for year, stats in year_stats %}
+ {% set days_in_year = 366 if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0) else 365 %}
+ {% set total_percentage = (stats.total_nights / days_in_year) * 100 %}
+ {% set abroad_percentage = (stats.nights_abroad / days_in_year) * 100 %}
+ -
+ {{ year }}:
+ Total nights away: {{ stats.total_nights }} ({{ "%.1f"|format(total_percentage) }}%),
+ Total nights abroad: {{ stats.nights_abroad }} ({{ "%.1f"|format(abroad_percentage) }}%)
+
+ {% endfor %}
diff --git a/web_view.py b/web_view.py
index 91a0e94..6e7da53 100755
--- a/web_view.py
+++ b/web_view.py
@@ -374,22 +374,29 @@ def past_conference_list() -> str:
fx_rate=agenda.fx.get_rates(app.config),
)
-
@app.route("/accommodation")
def accommodation_list() -> str:
"""Page showing a list of past, present and future accommodation."""
data_dir = app.config["PERSONAL_DATA"]
items = travel.parse_yaml("accommodation", data_dir)
- stays_in_2024 = [item for item in items if item["from"].year == 2024]
- total_nights_2024 = sum(
- (stay["to"].date() - stay["from"].date()).days for stay in stays_in_2024
- )
+ # Create a dictionary to hold stats for each year
+ year_stats = defaultdict(lambda: {"total_nights": 0, "nights_abroad": 0})
- nights_abroad_2024 = sum(
- (stay["to"].date() - stay["from"].date()).days
- for stay in stays_in_2024
- if stay["country"] != "gb"
+ # Calculate stats for each year
+ for stay in items:
+ current_date = stay["from"].date()
+ end_date = stay["to"].date()
+ while current_date < end_date:
+ year = current_date.year
+ year_stats[year]["total_nights"] += 1
+ if stay.get("country") != "gb":
+ year_stats[year]["nights_abroad"] += 1
+ current_date += timedelta(days=1)
+
+ # Sort the stats by year in descending order
+ sorted_year_stats = sorted(
+ year_stats.items(), key=lambda item: item[0], reverse=True
)
trip_lookup = {}
@@ -415,8 +422,7 @@ def accommodation_list() -> str:
past=past,
current=current,
future=future,
- total_nights_2024=total_nights_2024,
- nights_abroad_2024=nights_abroad_2024,
+ year_stats=sorted_year_stats,
get_country=agenda.get_country,
fx_rate=agenda.fx.get_rates(app.config),
)