Skip to content

Commit

Permalink
Fix up route stop_time to add a method that checks whether it's a boa…
Browse files Browse the repository at this point in the history
…rding stop...fix route_stops to only add boarding stops to the list of route_stops shown.
  • Loading branch information
Frank Purcell committed May 12, 2014
1 parent f49ef0f commit 8aeaeb5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
18 changes: 10 additions & 8 deletions gtfsdb/model/route.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,15 +201,17 @@ def load(cls, db, **kwargs):
# further, let's try to find the best position of that stop (e.g., look for where the stop patterns breaks)
last_pos = None
for i, st in enumerate(t.stop_times):
if st.stop_id in unique_stops_ids:
last_pos = unique_stops_ids.index(st.stop_id)
else:
# step 5: add ths stop id to our unique list ... either in position, or appended to the end of the list
if last_pos:
last_pos += 1
unique_stops_ids.insert(last_pos, st.stop_id)
# step 5a: make sure this stop that customers can actually board...
if st.is_boarding_stop():
if st.stop_id in unique_stops_ids:
last_pos = unique_stops_ids.index(st.stop_id)
else:
unique_stops_ids.append(st.stop_id)
# step 5b: add ths stop id to our unique list ... either in position, or appended to the end of the list
if last_pos:
last_pos += 1
unique_stops_ids.insert(last_pos, st.stop_id)
else:
unique_stops_ids.append(st.stop_id)

# PART B: add records to the database ...
if len(unique_stops_ids) > 0:
Expand Down
24 changes: 22 additions & 2 deletions gtfsdb/model/stop_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,40 @@ def __init__(self, *args, **kwargs):
if 'timepoint' not in kwargs:
self.timepoint = 'arrival_time' in kwargs


def get_headsign(self):
''' get the headsign at this stop ... rule is that if stop is empty, use trip headsign '''
ret_val = self.stop_headsign
if not ret_val:
ret_val = self.trip.trip_headsign
return ret_val

def is_boarding_stop(self):
''' return whether the vehicle that is stopping at this stop, and at this time, is an
in-revenue vehicle that a customer can actually board...
pickup_type = 1 - No pickup available
departure_time = None
NOTE: in gtfsdb, we NULL out the departure times when the vehicle doesn't
pick up anyone (e.g., at route end points, there are no departures...)
@see: https://developers.google.com/transit/gtfs/reference#stop_times_fields
'''
ret_val = True
if self.pickup_type == 1 or self.departure_time is None:
ret_val = False
return ret_val


@classmethod
def post_process(cls, db, **kwargs):
''' delete all 'depature_time' values that appear for the last stop
time of a given trip (e.g., the trip ends there, so there isn't a
further vehicle departure for that stop time / trip pair)
further vehicle departure for that stop time / trip pair)...
NOTE: we know this breaks the current GTFS spec, which states that departure &
arrival times must both exist for every stop time. Sadly, GTFS is wrong...
'''
log.debug('{0}.post_process'.format(cls.__name__))

Expand Down

0 comments on commit 8aeaeb5

Please sign in to comment.