PocketTrack: Tracking subway trains is hard
Harder than shuttle buses, too.
PocketTrack (formerly SammDOT Tracker) is a web-based tracker for Toronto Transit Commission surface vehicles (buses and streetcars).
PocketTrack users have only been able to track buses and streetcars so far. Subway tracking is currently a work in progress, and has been for months. Quite a few have emailed me to ask how long it would take to implement subway tracking, and let me just say, it’s much harder than you think.
Below is the TTC’s Next Train Arrivals system (NTAS). When you pick a station, it shows the estimated arrival times, in minutes, of the next three trains in each direction. This is the same information shown on the OneStop screens at subway stations.
I attempted to scrape the data behind the NTAS page, and ran into my first problem. The data only gives estimated arrival times in minutes, not actual locations of the trains. Since most people only care about when their train is coming anyway, it makes sense, but I am not most people. If you want to be able to track locations having your data in minutes is hard to work with.
Nevertheless, I’ve attempted to work this data into location reports, and this is what I have so far. Note that each train is identified by its run number, which is also included in the NTAS data.
Train Locations
It takes approximately three and a half minutes to travel between York Mills and Lawrence stations on a typical run. So if you’re waiting for a train southbound at Lawrence, and NTAS says the next train is 3 minutes away, it must have just left York Mills, right?
Not necessarily.
The naïve approach to finding a train’s location given its ETA would be to interpolate the distance along the line based on the length of time it typically takes between the station it just left and the station it’s heading towards. So if a northbound train was one minute away from, say, Dupont station, it must be halfway between Spadina and Dupont, since it typically takes two minutes to travel between those stations.
Sure, it works for most cases, but what if there’s a delay down the line and it actually takes, say, ten minutes to get from York Mills to Lawrence? The train halfway between would report an ETA of five minutes, which, using the approach above, would indicate that the train is only heading to York Mills from Sheppard–Yonge.
Car Numbers
Say I want to look for trainset 5901–5906, the train with the prototype side signs. I want a way to track it down without knowing its run number.
The NTAS data gives no information at all on the car numbers on each train. This should be doable on a Toronto Rocket train, since all of the cars are numbered the same way for all trainsets (1–2–3–4–5–6 on a 6-car set, or 1–2–5–6 on a 4-car set), but a T1 train makes it a bit harder. Either way, there is no way to map run numbers to car numbers and vice versa, so this isn’t happening.
Subway Closures
When the subway is closed, NTAS is down for the entire line, not just the closed section, which means no trains are trackable across the entire line. Note that in the image above, no trains are visible on Line 1, since this was taken on a Sunday afternoon during a Line 1 closure.
I don’t know for sure why, but NTAS probably depends on schedules and calculations based on the usual termini for its predictions. During a closure, the line is incomplete, so these calculations can’t happen.
Overnight
The end of the service day somehow poses an issue that I did not expect. At around 2 am, all trains stop running and all stations close, and in the morning PocketTrack just stops working. I suspect it has to do with that NTAS is also down during subway downtime, making the system somehow crash and stop tracking trains in the morning.
PocketTrack’s subway tracking so far is a good start, but there’s still a long way to go for it to really be usable.
Tracking subway trains is hard.