More specific types.
This commit is contained in:
parent
02350ef4db
commit
135476b59f
|
@ -84,9 +84,9 @@ def get_busy_events(
|
||||||
def get_location_for_date(
|
def get_location_for_date(
|
||||||
target_date: date,
|
target_date: date,
|
||||||
trips: list[Trip],
|
trips: list[Trip],
|
||||||
bookings: list[dict],
|
bookings: list[StrDict],
|
||||||
accommodations: list[dict],
|
accommodations: list[StrDict],
|
||||||
airports: dict,
|
airports: StrDict,
|
||||||
) -> tuple[str | None, pycountry.db.Country | None]:
|
) -> tuple[str | None, pycountry.db.Country | None]:
|
||||||
"""Get location (city, country) for a specific date using travel history."""
|
"""Get location (city, country) for a specific date using travel history."""
|
||||||
# UK airports that indicate being home
|
# UK airports that indicate being home
|
||||||
|
@ -211,17 +211,17 @@ def get_location_for_date(
|
||||||
if len(locations) == 1:
|
if len(locations) == 1:
|
||||||
city, country = locations[0]
|
city, country = locations[0]
|
||||||
return (city, country)
|
return (city, country)
|
||||||
|
|
||||||
# Multiple locations: use progression through the trip
|
# Multiple locations: use progression through the trip
|
||||||
trip_duration = (trip.end - trip.start).days + 1
|
trip_duration = (trip.end - trip.start).days + 1
|
||||||
days_into_trip = (target_date - trip.start).days
|
days_into_trip = (target_date - trip.start).days
|
||||||
|
|
||||||
# Simple progression: first half at first location, second half at last location
|
# Simple progression: first half at first location, second half at last location
|
||||||
if days_into_trip <= trip_duration // 2:
|
if days_into_trip <= trip_duration // 2:
|
||||||
city, country = locations[0]
|
city, country = locations[0]
|
||||||
else:
|
else:
|
||||||
city, country = locations[-1]
|
city, country = locations[-1]
|
||||||
|
|
||||||
return (city, country)
|
return (city, country)
|
||||||
|
|
||||||
# Find most recent flight or accommodation before this date
|
# Find most recent flight or accommodation before this date
|
||||||
|
|
Loading…
Reference in a new issue