Adjust European short trip heuristic from >3 days to >1 day to correctly detect when user has returned home from European trips. This fixes the April 29-30, 2023 case where the location incorrectly showed "Sankt Georg, Hamburg" instead of "Bristol" when the user was free (no events scheduled) after the foss-north trip ended on April 27. The previous logic required more than 3 days to pass before assuming return home from European countries, but for short European trips by rail/ferry, users typically return within 1-2 days. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
95 lines
3.8 KiB
Python
95 lines
3.8 KiB
Python
from datetime import date, datetime, timedelta
|
|
|
|
import agenda.travel as travel
|
|
import agenda.trip
|
|
from web_view import app
|
|
|
|
|
|
def test_get_location_for_date() -> None:
|
|
app.config["SERVER_NAME"] = "test"
|
|
with app.app_context():
|
|
today = datetime.now().date()
|
|
start = date(2023, 1, 1)
|
|
trips = agenda.trip.build_trip_list()
|
|
|
|
data_dir = app.config["PERSONAL_DATA"]
|
|
|
|
busy_events = agenda.busy.get_busy_events(start, app.config, trips)
|
|
weekends = agenda.busy.weekends(start, busy_events, trips, data_dir)
|
|
|
|
# Debug the specific failing case
|
|
for weekend in weekends:
|
|
weekend_date = weekend["date"]
|
|
if weekend_date == date(2023, 4, 29):
|
|
print(f"\nDEBUG April 29-30, 2023:")
|
|
print(f"Saturday {weekend_date}: location={weekend['saturday_location']}, events={weekend['saturday']}")
|
|
print(f"Sunday {weekend_date + timedelta(days=1)}: location={weekend['sunday_location']}, events={weekend['sunday']}")
|
|
|
|
# Find trips around this time
|
|
print("\nTrips around this time:")
|
|
for trip in trips:
|
|
if trip.start and abs((trip.start - weekend_date).days) < 60:
|
|
print(f" {trip.start} to {trip.end}: {trip.title}")
|
|
|
|
for weekend in weekends:
|
|
for day in "saturday", "sunday":
|
|
if not (weekend[day + "_location"][0] == "Bristol" or bool(weekend[day])):
|
|
weekend_date = weekend["date"]
|
|
day_date = weekend_date if day == "saturday" else weekend_date + timedelta(days=1)
|
|
print(f"FAILING: {day_date} ({day}): location='{weekend[day + '_location'][0]}', events={len(weekend[day])}")
|
|
|
|
assert weekend[day + "_location"][0] == "Bristol" or bool(weekend[day])
|
|
|
|
# Parse YAML files once for the test
|
|
bookings = travel.parse_yaml("flights", data_dir)
|
|
accommodations = travel.parse_yaml("accommodation", data_dir)
|
|
airports = travel.parse_yaml("airports", data_dir)
|
|
|
|
# Debug the April 29 issue
|
|
april_29_location = agenda.busy.get_location_for_date(
|
|
date(2023, 4, 29), trips, bookings, accommodations, airports
|
|
)
|
|
print(f"\nDirect call for April 29: {april_29_location}")
|
|
|
|
# Check what the foss-north trip looks like
|
|
foss_north_trip = None
|
|
for trip in trips:
|
|
if trip.title == "foss-north" and trip.start == date(2023, 4, 22):
|
|
foss_north_trip = trip
|
|
print(f"foss-north trip: {trip.start} to {trip.end}")
|
|
print(f"foss-north locations: {trip.locations()}")
|
|
break
|
|
|
|
l1 = agenda.busy.get_location_for_date(
|
|
date(2025, 2, 15), trips, bookings, accommodations, airports
|
|
)
|
|
assert l1[0] == "Hackettstown"
|
|
|
|
l2 = agenda.busy.get_location_for_date(
|
|
date(2025, 7, 1), trips, bookings, accommodations, airports
|
|
)
|
|
assert l2[0] == "Bristol"
|
|
|
|
l2 = agenda.busy.get_location_for_date(
|
|
date(2023, 12, 2), trips, bookings, accommodations, airports
|
|
)
|
|
assert l2[0] == "Bristol"
|
|
|
|
l2 = agenda.busy.get_location_for_date(
|
|
date(2023, 10, 7), trips, bookings, accommodations, airports
|
|
)
|
|
assert l2[0] == "Bristol"
|
|
|
|
l2 = agenda.busy.get_location_for_date(
|
|
date(2023, 2, 18), trips, bookings, accommodations, airports
|
|
)
|
|
assert l2[0] == "Bristol"
|
|
|
|
l2 = agenda.busy.get_location_for_date(
|
|
date(2025, 8, 2), trips, bookings, accommodations, airports
|
|
)
|
|
assert l2[0] == "Bristol"
|
|
|
|
# Fix the April 29 case
|
|
assert april_29_location[0] == "Bristol"
|