luqmaan/Instabus

Compute estimated delay (or advance) of each bus

Closed this issue · 1 comments

I love this web app. It's quite beautiful and very easy to get information about the bus system. I even find it easier to view routes and find stop information than from CapMetro or Google Maps.

However, one feature I've been wanting after using this app for the past few weeks is an estimated delay computation for each bus. Here's a simple algorithm:

[time,lat,lon,route] = get_bus_information(bus);
[stop1,stop2] = find_nearest_two_stops(route,lat,lon);
[lat1,lon1] = get_stop_location(stop1);
[lat2,lon2] = get_stop_location(stop2);
[time1] = find_nearest_stop_time(stop1,time);
[time2] = find_nearest_stop_time(stop2,time);
% lat2m and lon2m convert latitude/longitude to meters
sx = lon2m(lat,lon-lon1);
sy = lat2m(lat,lat-lat1);
tx = lon2m(lat,lon2-lon1);
ty = lat2m(lat,lat2-lat1);
tr2 = tx^2 + ty^2;
% compute percent of path traveled between stop1 and stop2 with vector projection
per = (sx*tx + sy*ty)/tr2;
% compute predicted time of the bus with linear interpolation
timep = time1 + per*(time2-time1);
delay = time-timep;

Note that the algorithm assumes a linear interpolation between stops, which should be a good approximation for a route with enough stops.

Hi jahshan, glad to hear Instabus has been useful to you. This seems like a good idea, and I think it's worth trying just to see if the location of a bus changes linearly. I won't have time to test this out for a while though.

On that note, if you're interested in looking at the behavior of the buses, I have been publishing the location data for all the vehicles for the past month or so in a separate repo in JSON or CSV format.