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>
82 lines
2.4 KiB
Python
Executable file
82 lines
2.4 KiB
Python
Executable file
#!/usr/bin/python3
|
|
|
|
import json
|
|
|
|
import agenda.travel
|
|
import agenda.trip
|
|
|
|
# from rich.pretty import pprint
|
|
|
|
|
|
config = __import__("config.default", fromlist=[""])
|
|
|
|
|
|
def get_rail_route_distances() -> agenda.travel.RouteDistances:
|
|
"""Rail journey route distances."""
|
|
route_distances = agenda.travel.load_route_distances(config.DATA_DIR)
|
|
|
|
trains = agenda.trip.load_trains(
|
|
config.PERSONAL_DATA, route_distances=route_distances
|
|
)
|
|
for train in trains:
|
|
for leg in train["legs"]:
|
|
train_from, train_to = leg["from_station"], leg["to_station"]
|
|
assert leg["from"] != leg["to"]
|
|
s1, s2 = sorted((leg["from"], leg["to"]))
|
|
if (s1, s2) in route_distances:
|
|
continue
|
|
|
|
filename = train_from.get("routes", {}).get(train_to["uic"])
|
|
if not filename:
|
|
continue
|
|
geojson = agenda.trip.read_geojson(
|
|
config.PERSONAL_DATA, "train_routes/" + filename
|
|
)
|
|
dist = agenda.travel.train_leg_distance(json.loads(geojson))
|
|
route_distances[(s1, s2)] = dist
|
|
|
|
return route_distances
|
|
|
|
|
|
def get_ferry_route_distances() -> agenda.travel.RouteDistances:
|
|
"""Rail journey route distances."""
|
|
route_distances: agenda.travel.RouteDistances = {}
|
|
|
|
items = agenda.trip.load_ferries(
|
|
config.PERSONAL_DATA, route_distances=route_distances
|
|
)
|
|
for item in items:
|
|
item_from, item_to = item["from_terminal"], item["to_terminal"]
|
|
assert item["from"] != item["to"]
|
|
s1, s2 = sorted((item["from"], item["to"]))
|
|
if (s1, s2) in route_distances:
|
|
continue
|
|
|
|
filename = item_from.get("routes", {}).get(item_to["name"])
|
|
if not filename:
|
|
continue
|
|
geojson = agenda.trip.read_geojson(
|
|
config.PERSONAL_DATA, "ferry_routes/" + filename
|
|
)
|
|
dist = agenda.travel.train_leg_distance(json.loads(geojson))
|
|
route_distances[(s1, s2)] = dist
|
|
|
|
return route_distances
|
|
|
|
|
|
def get_flight_distances():
|
|
flights = agenda.trip.load_flights(
|
|
config.PERSONAL_DATA,
|
|
)
|
|
|
|
for item in flights:
|
|
# pprint(item)
|
|
print(item["from"], item["to"], agenda.travel.flight_distance(item))
|
|
|
|
|
|
# route_distances = get_rail_route_distances()
|
|
route_distances = get_ferry_route_distances()
|
|
print(agenda.travel.route_distances_as_json(route_distances))
|
|
|
|
# get_flight_distances()
|