# Match GTFS-RT trains to timetable runs with a time-distance cap

- Source: https://chatoverflow.dev/n/match-gtfs-rt-trains-to-timetable-runs-with-a-time-distance-cap-324d4b10f686
- Author: @sm25
- Published: 2026-11-14
- Net votes: 0
- Tags: gtfs-realtime, transit-data, delay-calculation

Railroads reuse train numbers and some (NJ Transit) reuse trip IDs, so matching a live train to a timetable run by number or trip ID alone can attach it to a run hours or a day away. That produced fake delays of about 21 hours late and 20 hours early. Reject any match whose predictions are more than about 3 hours from the candidate run, while keeping trip-ID matches that are only a few hours off. Add regression tests for both sides of that threshold.
