The accommodation page has been updated to provide a more comprehensive and dynamic view of travel statistics. Previously, the page only displayed hard-coded statistics for total nights away and abroad for the year 2024. This required manual updates each year and didn't provide historical context. This commit introduces the following changes: * **Dynamically Calculate Yearly Stats:** The `accommodation_list` view in `web_view.py` now calculates statistics for every year found in the accommodation data. It correctly handles stays that span across multiple years. * **Display All Years:** The `accommodation.html` template now iterates through a list of all calculated yearly stats, displaying a summary for each year automatically. * **Add Percentage of Year:** The template also calculates and displays what percentage of the year the "total nights" and "nights abroad" represent. This includes logic to correctly account for leap years (366 days) for an accurate calculation. These changes make the statistics more informative and ensure the page remains relevant over time without needing further manual code adjustments.
62 lines
1.7 KiB
HTML
62 lines
1.7 KiB
HTML
{% extends "base.html" %}
|
|
{% from "macros.html" import trip_link, accommodation_row with context %}
|
|
{% block title %}Accommodation - Edward Betts{% endblock %}
|
|
{% block style %}
|
|
{% set column_count = 9 %}
|
|
<style>
|
|
.grid-container {
|
|
display: grid;
|
|
grid-template-columns: repeat({{ column_count }}, auto);
|
|
gap: 10px;
|
|
justify-content: start;
|
|
}
|
|
|
|
.grid-item {
|
|
/* Additional styling for grid items can go here */
|
|
}
|
|
|
|
.heading {
|
|
grid-column: 1 / {{ column_count + 1 }}; /* Spans from the 1st line to the 7th line */
|
|
}
|
|
</style>
|
|
{% endblock %}
|
|
|
|
{% macro section(heading, item_list, badge) %}
|
|
{% if item_list %}
|
|
<div class="heading"><h2>{{heading}}</h2></div>
|
|
{% for item in item_list %}
|
|
{{ accommodation_row(item, badge) }}
|
|
<div class="grid-item">{% if item.linked_trip %} trip: {{ trip_link(item.linked_trip) }} {% endif %}</div>
|
|
{% endfor %}
|
|
{% endif %}
|
|
{% endmacro %}
|
|
|
|
{% block content %}
|
|
|
|
<div class="container-fluid mt-2">
|
|
|
|
<h1>Accommodation</h1>
|
|
|
|
<h3>Statistics</h3>
|
|
<ul>
|
|
{% 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 %}
|
|
<li>
|
|
<strong>{{ year }}:</strong>
|
|
Total nights away: {{ stats.total_nights }} ({{ "%.1f"|format(total_percentage) }}%),
|
|
Total nights abroad: {{ stats.nights_abroad }} ({{ "%.1f"|format(abroad_percentage) }}%)
|
|
</li>
|
|
{% endfor %}
|
|
</ul>
|
|
|
|
<div class="grid-container">
|
|
{{ section("Current", current) }}
|
|
{{ section("Future", future) }}
|
|
{{ section("Past", past) }}
|
|
</div>
|
|
</div>
|
|
|
|
{% endblock %}
|