Tuesday, June 16, 2009

Michi's first LACMTA GTFS application: Where's the bus??

I have designed a very simple application that is intended to show the next "timepoint" for every bus on a particular route.

It uses a pretty simple SQL statement:

SELECT gtfs_stops.stop_name, gtfs_stops.stop_lat, gtfs_stops.stop_lon,
gtfs_stop_times.departure_time, gtfs_stop_times.trip_id, gtfs_stop_times.stop_headsign,
gtfs_trips.route_id, gtfs_trips.block_id FROM gtfs_trips
LEFT JOIN gtfs_stop_times ON gtfs_trips.trip_id = gtfs_stop_times.trip_id
LEFT JOIN gtfs_stops on gtfs_stops.stop_id = gtfs_stop_times.stop_id
LEFT JOIN gtfs_calendar ON gtfs_trips.service_id = gtfs_calendar.service_id
WHERE route_id = '(route number)'
AND departure_time >= CURTIME()
AND departure_time <= ADDTIME(CURTIME(),'0:05:00') AND gtfs_calendar.(day of the week) = 1 AND start_date <= CURDATE() AND end_date >= CURDATE()
GROUP BY block_id;


This SQL statement will show the next timepoints for (route number) on the the specified (day of the week). Yes, I know it's pretty crude, but it works.

You can play with this toy at:
http://st.recnet.com/metro_next_bus.php

There is a pull down that shows all of the SFV sector routes (the descriptions were manually entered), an issue that I have with the routes.txt file. But you can send a value of rte and a valid route_id using a GET statement and it will return routes outside the SFV. It does not work for rail (801-805) because the Metro Rail trips are showin without a block_id. Rail will return just a single trip on the route.

I could use an SQL sort to rearrange the headsigns in order so you have an idea what direction the buses are going. I would have preferred if Metro was to include the direction_id in trips.txt which is a simple 0 or 1 value that would indicate a direction. In this case, I could just make two SQL calls and get each direction listed separately. Using direction_id would also make the data compatible with other tools including TriMet's Time Table Maker.

Without the direction_id data, I would have to manually build a table based on headsign readings what direction a bus is going and even with that, there may be a few possibilities that buses going in two different directions can have the same headsign (such as a mid-route terminal).

This little app does take into consideration that some trips only operate certain days of the week (school trippers) but I do not believe that the calendar.txt gives the ranges of the school year. Therefore, there's a possibility that it will display a trip that may not actually be running since it's a school holiday. MTA also has school holiday trips "H", which may be the school trip with some deviation on the schedule. These are very complex, but on some routes with infrequent service and school trippers (645 comes to mind) could cause confusion. Right now, I am not calling to the calendar_dates file to get the exceptions (holiday service). Therefore, transit holidays right now will show just like regular weekdays.

With that said, my wish list for Metro GTFS data improvements include:
  • Having the block_id be the known line-run numbers instead of a distinct number.
  • Include run numbers for the trains in block_id.
  • Use the direction_id field in trips.txt.
  • Move headsign data to trips.txt and only use stop_times.txt when there is a mid-line sign change. (such as the 242/243)
  • At the end of a trip at the last timepoint in stop_times.txt, set drop_off_type to 1. This will indicate the end of the route. It will also prevent apps from identifying that timepoint as a pick-up and showing two times at a particular stop (one for when the bus arrives from the previous trip and the time it departs for the next trip, hence, recovery time).
  • Better descriptions of the routes in routes.txt
As a fan of Metro scheduling (and someone who once got turned down for the Schedule Maker I position), I appreciate the publication of the GTFS data feed.

Sunday, June 14, 2009

Los Angeles MTA Google Transit: Some first thoughts about the GTFS feed

Just for a means of background, I have never worked for Metro but I have a great knowledge of how they schedule.

The way MTA schedules is very different than other transit properties that I have encountered.

I have been going through the GTFS data and I have noticed what some may consider bugs or disparities in the data but it's a part of the way MTA has been doing scheduling for decades. This is something, as transit developers, we need to get used to.

MTA (and the former SCRTD) uses what they call LINES. A "LINE" is a single schedule that may contain multiple "ROUTES". For example, Line 152 (Fallbrook/Roscoe) contains the schedule information for routes 152 (the main route), 153 (the alternate route via Sun Valley Station) and the 353 (the limited version of the 152). As mentioned already in the documentation, the limiteds (with the exception of 305) are not shown in the routes.txt because they mirror their parent local routes. But also, when a route has an alternate route under a different route number, it will appear under this line. For example, the 153 will appear with the 152. The route_id in the trips.txt will be 152 and the only way you will distinguish this trip as a 153 is by using the stop_headsign in stop_times.txt.

Another scheduling method that MTA uses is to create two different routes that are not branch or alternate routes but are "interlined" where most buses from one route continue via another route. A couple of good examples of this arrangement includes Line 230, which includes Route 230 (Laurel Canyon) and Route 239 (White Oak/Rinaldi) and Line 243 which includes routes 242 (Tampa) and 243 (Winnetka). In these cases, the trips for both streets show under one route_id. Like with the branch route example shown above, the only way you can distinguish the trips is through the use of the stop_headsign in stop_times.txt. Even worse, there is currently text in the stop_headsign field that says "change route to..." for these types of routes. This will drive confusion from both a developer and from a end-user point of view.

Now while this scheduling junkie does not mind the line level of scheduling, I think that for public facing applications, it would be better to put the route data in at the route level.

This is a new project for Metro. I am always available for consultation.

Thursday, June 11, 2009

KRXQ: Rob, Arnie and Dawn broadcast on in response to trans youth comments









or download MP3 directly: krxq-20090611.mp3 (17MB, 16/22, mono)


This is an aircheck from KRXQ Sacramento on June 11, 2009. On this 2 hour 30 minute show, the personalities reflect on the events of the past week after a broadcast where those in the GLBT community stated that condoned child abuse and intolerance to the plight of transgender youth.


While the beginning of the show gave the appearance of backpeddling on the show host's part, I feel that overall, the show was very informative and included many guests who have experience with transgender youth.


For me personally, this show brought to closure some recent memories that I had of being abused myself as a child for expressing my femininity.


Just know this, organizations like GLAAD are not out to "change" people but they are out there to educate. Not just the general public but also the corporations who also proudly serve the GLBT community.


Normally, I do not use recnet.com for making positions on GLBT issues, but since this one directly involved using the mass media to express intolerance towards a minority group, I felt it was appropriate to take action.


I am personally doing OK. I thank you for your thoughts.


=m