#!/usr/bin/env python3 """Recompute server-side trip boundaries from stored tracking_points. Run after migrating to Phase 24 schema, or any time you want to refresh trips from raw data: docker compose exec server python scripts/recompute_trips.py """ import sys, os sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from modules import db def main(): with db.get_cursor() as cur: cur.execute("SELECT id, name FROM devices ORDER BY id") devices = cur.fetchall() if not devices: print("No devices found in database.") return for device_id, device_name in devices: print(f"Recomputing trips for device '{device_name}' (id={device_id})…", end=" ", flush=True) n = db.compute_trips_for_device(device_id) print(f"{n} trips computed.") if __name__ == "__main__": main()