Live data from Hacker News

MTA Releases Subway Time App

mta.info

1–10 of 43 posts

Re: MTA Releases Subway Time App

#4
I was looking at this earlier, there's an API too that seems pretty simple to use:

-----

(1) Developer key: http://datamine.mta.info/user/register

(2) The data is in Protocol Buffer format, so get that: http://code.google.com/p/protobuf/downloads/list

(3) The proto definition of the GTFS-realtime feed: https://developers.google.com/transit/gtfs-realtime/gtfs-rea...

(4) Some static data (which has IDs for each station, etc). http://www.mta.info/developers/data/nyct/subway/google_trans...

(5) You can just curl the URL for all the current data (with your developer key):

  curl http://datamine.mta.info/mta_esi.php?key= -o /tmp/mtafeed
(6) And you can decode it using protobuffers (protoc is from 2 & gtfs-realtime.proto is from 3)

  cat /tmp/mtafeed | /usr/bin/protoc -I /tmp /tmp/gtfs-realtime.proto  --decode=transit_realtime.FeedMessage > /tmp/decodedmtafeed
(7) Now you have a file full of messages like this:

  entity {                                                                                                                                                                                                                            
    id: "000170"                                                                                                                                                                                                                      
    trip_update {                                                                                                                                                                                                                     
      trip {                                                                                                                                                                                                                          
        trip_id: "078600_4..S44R"                                                                                                                                                                                                     
        start_date: "20121228"                                                                                                                                                                                                        
        route_id: "4"                                                                                                                                                                                                                 
        1001 {                                                                                                                                                                                                                        
          1: "04 1306  WDL/UTI"
          2: 1
          3: 3
        }
      }
  [ some data removed ]
      stop_time_update {
        arrival {
          time: 1356720373
        }
        departure {
          time: 1356720373
        }
        stop_id: "635S"
        1001 {
          1: "2"
        }
      }                 
  [ some data removed ]
Each "entity" looks like a "trip", i.e. a train. It says where the train is and when it will arrive at various stops. I found more documentation here: https://developers.google.com/transit/gtfs-realtime/referenc... and here: http://httqa.mta.info/developers/pdfs/GTFS-Realtime-NYC-Subw... But still need to parse it all. It seems to be basically like this:

In the "entity" - trip_id: "078600_4..S44R" * 078600 is a train id or something * _4.. means it's a 4 train (this is also available on the route_id field) * S means it's heading south * 44R describes the stops this train will make. I'm not entirely sure how to parse this.

In the stop_time_update: - stop_id: "635S" * you can find the stop codes in stops.txt from (4). This one is "635S,,14 St - Union Sq,,40.734673,-73.989951,,,0,635" - arrival / time: 1356720373 $ date -d @1356720373 Fri Dec 28 13:46:13 EST 2012

So, I guess there was a Downtown 4 train, scheduled to stop at union square at 1:46:13. (I downloaded this about about 1:30 Eastern, so that seems right).

Re: MTA Releases Subway Time App

#6
> “This is what generations of dreamers and futurists have waited for,” said MTA Chairman and CEO Joseph J. Lhota. “The ability to get subway arrival time at street level is here.

The breathlessness of the coverage of this app makes me wonder how much money was spent on it? First of all, the main problem for New Yorkers is the lack of this data for all the other train lines (i.e A-Z). Second, the MTA has, to their credit, made this data easy to get as others have posted. And apparently Android maps already use this information...so why build an app except for getting some public goodwill. Not that public gestures are bad, but it depends on the cost (puts 'file information request for app dev contract' on things to do sometime)

Re: MTA Releases Subway Time App

#9
post #6

> “This is what generations of dreamers and futurists have waited for,” said MTA Chairman and CEO Joseph J. Lhota. “The ability to get subway arrival time at street level is here. The breathlessness of the coverage of this app makes me wonder how much money was spent on it? First of all, the main problem for New Yorkers is the lack of this data for all the other train lines (i.e A-Z). Second, the MTA has, to their cr…

> " First of all, the main problem for New Yorkers is the lack of this data for all the other train lines (i.e A-Z)."

Unfortunately this is not going to be fixed any time soon. BMT/IND trains have a distributed command and control system. Multiple signal towers control train movement within their own sectors of the system - and each signal tower has no information about the rest of the system.

This was necessary in the early days, before electronics existed.

So to this day there is no centralized snapshot of the entire system state, unlike the numbered lines, and thus no ability to provide an API.

This is a great step forward. I look forward to the day we can have a big jumbotron with real time locations of trains.

Re: MTA Releases Subway Time App

#10
post #6

> “This is what generations of dreamers and futurists have waited for,” said MTA Chairman and CEO Joseph J. Lhota. “The ability to get subway arrival time at street level is here. The breathlessness of the coverage of this app makes me wonder how much money was spent on it? First of all, the main problem for New Yorkers is the lack of this data for all the other train lines (i.e A-Z). Second, the MTA has, to their cr…

> " First of all, the main problem for New Yorkers is the lack of this data for all the other train lines (i.e A-Z)." Unfortunately this is not going to be fixed any time soon. BMT/IND trains have a distributed command and control system. Multiple signal towers control train movement within their own sectors of the system - and each signal tower has no information about the rest of the system. This was necessary in t…

What legacy system could possibly prevent one from simply recording the position of every train every few seconds? This is not a particularly difficult problem for a billion-dollar business to solve.
Post reply on HN