GTFS spec for reference: https://developers.google.com/transit/gtfs/reference/
I'm trying to create a program that counts the number of buses, trams, rails etc that pass through a certain
stop during a day, for a certain
route, and do a split-count for those that are end of lines.
My algorithm is as follows:
Given a route R Given a day D foreach R.trips as trip if trip.calendar_dates != D // skip all dates that we are not interested in continue endif endOfLines = 0 notEndOfLines = 0 foreach trip.stopTimes as stopTime // get all stop times of this trip, ordered by stop_sequence stopTimes = stopTime.trip.stopTimes.orderBy(stop_sequence) if stopTime.isFirstIn(stopTimes) or stopTime.isLastIn(stopTimes) endOfLines++ else notEndOfLines++ endif endforeach results[route.route_type][end] = endOfLines results[route.route_type][notEnd] = notEndOfLines endforeach
Explanation of what I'm trying to do:
Take all the trips of the given route. Use
calendar_datesto link the trips to the specific day and remove the trips that are not in our day of interest.
Loop all the trips and take their stoptimes. Then, determine if this stop time is the first or last in the trip. If it is, then we count it as an end of line, otherwise we count it as a simple stop.
Since the GTFS spec is somehow vague about how the tables should be used, I'm trying to figure if this logic is correct. Can someone validate and point out if I have any mistakes in my logic?