Compare commits
No commits in common. "e1688629a36822afa452a09fc95ba4dc74110f6f" and "ab60721e154675227847fd297ea7da3771c8af96" have entirely different histories.
e1688629a3
...
ab60721e15
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
import typing
|
import typing
|
||||||
from collections import Counter
|
|
||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
|
|
||||||
from pycountry.db import Country
|
from pycountry.db import Country
|
||||||
|
@ -142,25 +141,6 @@ class Trip:
|
||||||
else None
|
else None
|
||||||
)
|
)
|
||||||
|
|
||||||
def distances_by_transport_type(self) -> list[tuple[str, float]]:
|
|
||||||
"""Calculate the total distance travelled for each type of transport.
|
|
||||||
|
|
||||||
Any travel item with a missing or None 'distance' field is ignored.
|
|
||||||
"""
|
|
||||||
transport_distances: Counter[float] = Counter()
|
|
||||||
|
|
||||||
for item in self.travel:
|
|
||||||
distance = item.get("distance")
|
|
||||||
if distance:
|
|
||||||
transport_type = item.get("type", "unknown")
|
|
||||||
transport_distances[transport_type] += distance
|
|
||||||
|
|
||||||
return list(transport_distances.items())
|
|
||||||
|
|
||||||
|
|
||||||
# Example usage:
|
|
||||||
# You would call the function with your travel list here to get the results.
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Holiday:
|
class Holiday:
|
||||||
|
|
|
@ -61,7 +61,6 @@
|
||||||
|
|
||||||
{% set end = trip.end %}
|
{% set end = trip.end %}
|
||||||
{% set total_distance = trip.total_distance() %}
|
{% set total_distance = trip.total_distance() %}
|
||||||
{% set distances_by_transport_type = trip.distances_by_transport_type() %}
|
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
@ -88,14 +87,6 @@
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if distances_by_transport_type %}
|
|
||||||
{% for transport_type, distance in distances_by_transport_type %}
|
|
||||||
<div>{{ transport_type | title }} distance:
|
|
||||||
{{ "{:,.0f} km / {:,.0f} miles".format(distance, distance / 1.60934) }}
|
|
||||||
</div>
|
|
||||||
{% endfor %}
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
|
|
||||||
{% set delta = human_readable_delta(trip.start) %}
|
{% set delta = human_readable_delta(trip.start) %}
|
||||||
{% if delta %}
|
{% if delta %}
|
||||||
|
@ -257,22 +248,23 @@
|
||||||
<div class="mt-3">
|
<div class="mt-3">
|
||||||
<h4>Holidays</h4>
|
<h4>Holidays</h4>
|
||||||
{% if holidays %}
|
{% if holidays %}
|
||||||
<table class="table table-hover w-auto">
|
|
||||||
{% for item in holidays %}
|
<table class="table table-hover w-auto">
|
||||||
{% set country = get_country(item.country) %}
|
{% for item in holidays %}
|
||||||
<tr>
|
{% set country = get_country(item.country) %}
|
||||||
{% if loop.first or item.date != loop.previtem.date %}
|
<tr>
|
||||||
<td class="text-end">{{ display_date(item.date) }}</td>
|
{% if loop.first or item.date != loop.previtem.date %}
|
||||||
{% else %}
|
<td class="text-end">{{ display_date(item.date) }}</td>
|
||||||
<td></td>
|
{% else %}
|
||||||
{% endif %}
|
<td></td>
|
||||||
<td>{{ country.flag }} {{ country.name }}</td>
|
{% endif %}
|
||||||
<td>{{ item.display_name }}</td>
|
<td>{{ country.flag }} {{ country.name }}</td>
|
||||||
</tr>
|
<td>{{ item.display_name }}</td>
|
||||||
{% endfor %}
|
</tr>
|
||||||
</table>
|
{% endfor %}
|
||||||
|
</table>
|
||||||
{% else %}
|
{% else %}
|
||||||
<p>No public holidays during trip.</p>
|
<p>No public holidays during trip.</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue