Compare commits
No commits in common. "f4fc8399260227b8058fee9481893d9ed5f3a6b1" and "1caf2330756a78ee636251bc70c60f1b22a56988" have entirely different histories.
f4fc839926
...
1caf233075
|
@ -3,30 +3,11 @@
|
||||||
import collections
|
import collections
|
||||||
from datetime import date, timedelta
|
from datetime import date, timedelta
|
||||||
|
|
||||||
import flask
|
|
||||||
|
|
||||||
import agenda.uk_holiday
|
import agenda.uk_holiday
|
||||||
import holidays
|
import holidays
|
||||||
|
|
||||||
from .event import Event
|
from .event import Event
|
||||||
from .types import Holiday, Trip
|
from .types import Holiday
|
||||||
|
|
||||||
|
|
||||||
def get_trip_holidays(trip: Trip) -> list[Holiday]:
|
|
||||||
"""Get holidays happening during trip."""
|
|
||||||
if not trip.end:
|
|
||||||
return []
|
|
||||||
countries = {c.alpha_2 for c in trip.countries}
|
|
||||||
return sorted(
|
|
||||||
(
|
|
||||||
hol
|
|
||||||
for hol in get_all(
|
|
||||||
trip.start, trip.end, flask.current_app.config["DATA_DIR"]
|
|
||||||
)
|
|
||||||
if hol.country.upper() in countries
|
|
||||||
),
|
|
||||||
key=lambda item: (item.date, item.country),
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def us_holidays(start_date: date, end_date: date) -> list[Holiday]:
|
def us_holidays(start_date: date, end_date: date) -> list[Holiday]:
|
||||||
|
|
|
@ -42,11 +42,6 @@ def timedelta_display(delta: timedelta) -> str:
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def plural(value: int, unit: str) -> str:
|
|
||||||
"""Value + unit with unit written as singular or plural as appropriate."""
|
|
||||||
return f"{value} {unit}{'s' if value > 1 else ''}"
|
|
||||||
|
|
||||||
|
|
||||||
def human_readable_delta(future_date: date) -> str | None:
|
def human_readable_delta(future_date: date) -> str | None:
|
||||||
"""
|
"""
|
||||||
Calculate the human-readable time delta for a given future date.
|
Calculate the human-readable time delta for a given future date.
|
||||||
|
@ -69,11 +64,14 @@ def human_readable_delta(future_date: date) -> str | None:
|
||||||
weeks, days = divmod(days, 7)
|
weeks, days = divmod(days, 7)
|
||||||
|
|
||||||
# Formatting the output
|
# Formatting the output
|
||||||
parts = [
|
parts = []
|
||||||
plural(value, unit)
|
if months > 0:
|
||||||
for value, unit in ((months, "month"), (weeks, "week"), (days, "days"))
|
parts.append(f"{months} month{'s' if months > 1 else ''}")
|
||||||
if value > 0
|
if weeks > 0:
|
||||||
]
|
parts.append(f"{weeks} week{'s' if weeks > 1 else ''}")
|
||||||
|
if days > 0:
|
||||||
|
parts.append(f"{days} day{'s' if days > 1 else ''}")
|
||||||
|
|
||||||
return " ".join(parts) if parts else None
|
return " ".join(parts) if parts else None
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -53,7 +53,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.half-map {
|
.half-map {
|
||||||
height: 90vh;
|
height: 100vh;
|
||||||
}
|
}
|
||||||
|
|
||||||
.full-window-map {
|
.full-window-map {
|
||||||
|
|
|
@ -5,6 +5,7 @@ from decimal import Decimal
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from agenda import (
|
from agenda import (
|
||||||
|
get_gbpusd,
|
||||||
get_next_bank_holiday,
|
get_next_bank_holiday,
|
||||||
get_next_timezone_transition,
|
get_next_timezone_transition,
|
||||||
next_economist,
|
next_economist,
|
||||||
|
@ -13,7 +14,6 @@ from agenda import (
|
||||||
timedelta_display,
|
timedelta_display,
|
||||||
uk_financial_year_end,
|
uk_financial_year_end,
|
||||||
)
|
)
|
||||||
from agenda.fx import get_gbpusd
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
|
|
26
web_view.py
26
web_view.py
|
@ -486,15 +486,13 @@ def get_prev_current_and_next_trip(
|
||||||
"""Get previous trip, this trip and next trip."""
|
"""Get previous trip, this trip and next trip."""
|
||||||
trip_iter = iter(trip_list)
|
trip_iter = iter(trip_list)
|
||||||
prev_trip = None
|
prev_trip = None
|
||||||
current_trip = None
|
|
||||||
for trip in trip_iter:
|
for trip in trip_iter:
|
||||||
if trip.start.isoformat() == start:
|
if trip.start.isoformat() == start:
|
||||||
current_trip = trip
|
|
||||||
break
|
break
|
||||||
prev_trip = trip
|
prev_trip = trip
|
||||||
next_trip = next(trip_iter, None)
|
next_trip = next(trip_iter, None)
|
||||||
|
|
||||||
return (prev_trip, current_trip, next_trip)
|
return (prev_trip, trip, next_trip)
|
||||||
|
|
||||||
|
|
||||||
@app.route("/trip/<start>")
|
@app.route("/trip/<start>")
|
||||||
|
@ -507,6 +505,8 @@ def trip_page(start: str) -> str:
|
||||||
if not trip:
|
if not trip:
|
||||||
flask.abort(404)
|
flask.abort(404)
|
||||||
|
|
||||||
|
today = date.today()
|
||||||
|
|
||||||
coordinates = agenda.trip.collect_trip_coordinates(trip)
|
coordinates = agenda.trip.collect_trip_coordinates(trip)
|
||||||
routes = agenda.trip.get_trip_routes(trip, app.config["PERSONAL_DATA"])
|
routes = agenda.trip.get_trip_routes(trip, app.config["PERSONAL_DATA"])
|
||||||
|
|
||||||
|
@ -518,17 +518,30 @@ def trip_page(start: str) -> str:
|
||||||
app.config["PERSONAL_DATA"], route.pop("geojson_filename")
|
app.config["PERSONAL_DATA"], route.pop("geojson_filename")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if trip.end:
|
||||||
|
countries = {c.alpha_2 for c in trip.countries}
|
||||||
|
holidays = [
|
||||||
|
hol
|
||||||
|
for hol in agenda.holidays.get_all(
|
||||||
|
trip.start, trip.end, app.config["DATA_DIR"]
|
||||||
|
)
|
||||||
|
if hol.country.upper() in countries
|
||||||
|
]
|
||||||
|
holidays.sort(key=lambda item: (item.date, item.country))
|
||||||
|
else:
|
||||||
|
holidays = []
|
||||||
|
|
||||||
return flask.render_template(
|
return flask.render_template(
|
||||||
"trip_page.html",
|
"trip_page.html",
|
||||||
trip=trip,
|
trip=trip,
|
||||||
prev_trip=prev_trip,
|
prev_trip=prev_trip,
|
||||||
next_trip=next_trip,
|
next_trip=next_trip,
|
||||||
today=date.today(),
|
today=today,
|
||||||
coordinates=coordinates,
|
coordinates=coordinates,
|
||||||
routes=routes,
|
routes=routes,
|
||||||
get_country=agenda.get_country,
|
get_country=agenda.get_country,
|
||||||
format_list_with_ampersand=format_list_with_ampersand,
|
format_list_with_ampersand=format_list_with_ampersand,
|
||||||
holidays=agenda.holidays.get_trip_holidays(trip),
|
holidays=holidays,
|
||||||
human_readable_delta=agenda.utils.human_readable_delta,
|
human_readable_delta=agenda.utils.human_readable_delta,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -567,6 +580,9 @@ def trip_stats() -> str:
|
||||||
route_distances = agenda.travel.load_route_distances(app.config["DATA_DIR"])
|
route_distances = agenda.travel.load_route_distances(app.config["DATA_DIR"])
|
||||||
trip_list = get_trip_list(route_distances)
|
trip_list = get_trip_list(route_distances)
|
||||||
|
|
||||||
|
# today = date.today()
|
||||||
|
# past = [item for item in trip_list if (item.end or item.start) < today]
|
||||||
|
|
||||||
conferences = sum(len(item.conferences) for item in trip_list)
|
conferences = sum(len(item.conferences) for item in trip_list)
|
||||||
|
|
||||||
yearly_stats = agenda.stats.calculate_yearly_stats(trip_list)
|
yearly_stats = agenda.stats.calculate_yearly_stats(trip_list)
|
||||||
|
|
Loading…
Reference in a new issue