Hi. Firstly it’s great to have such a complete public API for TFL. Bravo!
I am trying to build a realtime Tube train visualisation from the API and
whilst I’ve made good progress there seems to be some noise behaviour which I
am struggling to understand.
Currently my app makes a Line/Arrivals request every 10 seconds to determine
the progress of each train. I take the shortest timeToStation for each vehicle
to work out which section of track the train is in. E.g. if the next station is
Oakwood and the direction is outbound I know the train is somewhere between
Southgate and Oakwood.
E.g. here are some updates for train 357:
Time: 2024-01-21 18:44:18.635507 +00:00, Train: piccadilly-357, next/dest: 940GZZLUCGN / 940GZZLUASG, ttn: 21, current: At Leicester Square Platform 2
Time: 2024-01-21 18:44:28.726488 +00:00, Train: piccadilly-357, next/dest: 940GZZLUCGN / 940GZZLUASG, ttn: 21, current: At Leicester Square Platform 2
Time: 2024-01-21 18:44:38.826605 +00:00, Train: piccadilly-357, next/dest: 940GZZLUCGN / 940GZZLUASG, ttn: 31, current: At Leicester Square Platform 2
Time: 2024-01-21 18:44:49.000192 +00:00, Train: piccadilly-357, next/dest: 940GZZLUHBN / 940GZZLUASG, ttn: 96, current: At Covent Garden Platform 2
Time: 2024-01-21 18:44:59.132799 +00:00, Train: piccadilly-357, next/dest: 940GZZLUCGN / 940GZZLUASG, ttn: 21, current: At Leicester Square Platform 2
Time: 2024-01-21 18:45:09.232881 +00:00, Train: piccadilly-357, next/dest: 940GZZLUHBN / 940GZZLUASG, ttn: 96, current: At Covent Garden Platform 2
Time: 2024-01-21 18:45:19.405646 +00:00, Train: piccadilly-357, next/dest: 940GZZLUHBN / 940GZZLUASG, ttn: 66, current: At Covent Garden Platform 2
Time: 2024-01-21 18:45:29.536193 +00:00, Train: piccadilly-357, next/dest: 940GZZLUHBN / 940GZZLUASG, ttn: 56, current: At Covent Garden Platform 2
Time: 2024-01-21 18:45:39.628180 +00:00, Train: piccadilly-357, next/dest: 940GZZLUHBN / 940GZZLUASG, ttn: 96, current: At Covent Garden Platform 2
Time: 2024-01-21 18:45:49.788447 +00:00, Train: piccadilly-357, next/dest: 940GZZLUHBN / 940GZZLUASG, ttn: 26, current: Between Covent Garden and Holborn
Time: 2024-01-21 18:46:00.016988 +00:00, Train: piccadilly-357, next/dest: 940GZZLUHBN / 940GZZLUASG, ttn: 66, current: At Covent Garden Platform 2
Time: 2024-01-21 18:46:10.091751 +00:00, Train: piccadilly-357, next/dest: 940GZZLUHBN / 940GZZLUASG, ttn: 56, current: At Covent Garden Platform 2
Time: 2024-01-21 18:46:20.263479 +00:00, Train: piccadilly-357, next/dest: 940GZZLURSQ / 940GZZLUASG, ttn: 116, current: Between Covent Garden and Holborn
Time: 2024-01-21 18:46:30.381379 +00:00, Train: piccadilly-357, next/dest: 940GZZLURSQ / 940GZZLUASG, ttn: 106, current: Between Covent Garden and Holborn
Time: 2024-01-21 18:46:40.515043 +00:00, Train: piccadilly-357, next/dest: 940GZZLURSQ / 940GZZLUASG, ttn: 106, current: Between Covent Garden and Holborn
Time: 2024-01-21 18:46:50.616769 +00:00, Train: piccadilly-357, next/dest: 940GZZLURSQ / 940GZZLUASG, ttn: 116, current: Between Covent Garden and Holborn
Time: 2024-01-21 18:47:00.745937 +00:00, Train: piccadilly-357, next/dest: 940GZZLURSQ / 940GZZLUASG, ttn: 106, current: Between Covent Garden and Holborn
Time: 2024-01-21 18:47:11.047562 +00:00, Train: piccadilly-357, next/dest: 940GZZLURSQ / 940GZZLUASG, ttn: 68, current: At Holborn Platform 4
Time: 2024-01-21 18:47:21.413901 +00:00, Train: piccadilly-357, next/dest: 940GZZLURSQ / 940GZZLUASG, ttn: 58, current: At Holborn Platform 4
Time: 2024-01-21 18:47:31.586210 +00:00, Train: piccadilly-357, next/dest: 940GZZLURSQ / 940GZZLUASG, ttn: 48, current: At Holborn Platform 4
-
Predications go backwards.
You can see at 18:44:49 I am told the train’s next station is HBN, but then
10 seconds later it switches back to CGN.Is this expected?
At present I just ignore these udpates and assume there is some eventual
consistency behaviour across the API servers I am finding. Is this right? If
so, is there a way to request a consistent set of updates? -
Can I use current_location?
My current approach does not really allow me to know how long a train is
dwelling at a station. As soon as the next station changes, I start
animating the train leaving the station. I had hoped to parse
current_location to help with this, but I see it often looks stale or out of
sync.E.g at 18:46:20 the train is showing its next station is RSQ but the current
location is indicating its between CGN and HBN.Can I assume that the naptanId (next station, when looking at the shortest
timeToStation) is authoritative here?
Finally, is there any material on how this API works? What are the data sources
and how does the API deliver these?
Thanks,
Frank.