Skip to content

Commit

Permalink
fix the route direction stuff in stop_time, thus resulting a list of …
Browse files Browse the repository at this point in the history
…headsigns that are nice and clean
  • Loading branch information
fpurcell committed May 29, 2015
1 parent b55c477 commit 5a09b12
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 22 deletions.
1 change: 0 additions & 1 deletion gtfsdb/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ def database_load(filename, **kwargs):
tables: limited list of tables to load
url: SQLAlchemy database url
'''

db = Database(**kwargs)
db.create()
gtfs = GTFS(filename)
Expand Down
29 changes: 20 additions & 9 deletions gtfsdb/model/stop_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from sqlalchemy.types import Boolean, Integer, Numeric, String

from gtfsdb import config
from gtfsdb import util
from gtfsdb.model.base import Base


Expand Down Expand Up @@ -54,21 +55,31 @@ def get_headsign(self):
ret_val = self.trip.trip_headsign
return ret_val

def get_direction_name(self):
headsign = self.get_headsign()
ret_val = headsign
def get_direction_name(self, def_val="", banned=['Shuttle', 'MAX Shuttle', 'Garage', 'Center Garage', 'Merlo Garage', 'Powell Garage']):
''' returns either the headsign (as long as headsign is not the same name as the route name)
or the route direction name
'''
ret_val = def_val
try:
route_long_name = self.trip.route.route_long_name
dir = self.trip.direction_id
self.trip.route.directions[dir]
get_route_direction_name(headsign, route_long_name, route_direction_name)
# step 0: create a banned list with the addition of our route_long_name
banned = banned + [self.trip.route.route_long_name]

headsign = self.get_headsign()
if headsign and not any([headsign in s for s in banned]):
# step 1: use the headsign as the direction name, just as long as the headsign is
# not null and not the same as the route name
ret_val = headsign
else:
# step 2: lets use the direction name, if available
dir = self.trip.direction_id
dir = self.trip.route.directions[dir]
if dir.direction_name and not any([dir.direction_name in s for s in banned]):
ret_val = dir.direction_name.lstrip('to ').lstrip('To ')
except Exception, e:
log.debug(e)
pass

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...
Expand Down
15 changes: 12 additions & 3 deletions gtfsdb/scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,21 @@ def route_stop_load():
RouteStop.load(db, **kwargs)

def db_connect_tester():
''' simple routine to connect to an existing database and list a few stops'''
from gtfsdb import Database, Stop
''' simple routine to connect to an existing database and list a few stops
bin/connect-tester --database_url sqlite:///gtfs.db _no_gtfs_zip_needed_
'''
from gtfsdb import Database, Stop, Route, StopTime
args, kwargs = get_args()
db = Database(**kwargs)
for s in db.session.query(Stop).limit(5):
for s in db.session.query(Stop).limit(2):
print s.stop_name
for r in db.session.query(Route).limit(2):
print r.route_name
#import pdb; pdb.set_trace()
stop_times = StopTime.get_departure_schedule(db.session, stop_id='11411')
for st in stop_times:
print st.get_direction_name()
break

def get_args():
''' database load command-line arg parser and help util...
Expand Down
9 changes: 0 additions & 9 deletions gtfsdb/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,3 @@ def __iter__(self):

def next(self):
return self.reader.next().encode('utf-8')


def get_route_direction_name(headsign, route_long_name, route_direction_name=None):
''' this routine will look first at the headsign for a route direction name '''
ret_val = headsign
if route_direction_name and headsign == route_long_name:
ret_val = self.trip.trip_headsign
return ret_val

0 comments on commit 5a09b12

Please sign in to comment.