Skip to content

Commit

Permalink
add logging; also set lazy val for stop features
Browse files Browse the repository at this point in the history
  • Loading branch information
fpurcell committed May 25, 2014
1 parent e829141 commit bdd14ad
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion gtfsdb/model/stop.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from collections import defaultdict
import logging
log = logging.getLogger(__name__)

from sqlalchemy import Column, Integer, Numeric, String
from sqlalchemy.orm import joinedload, object_session, relationship
Expand Down Expand Up @@ -48,7 +50,8 @@ def headsigns(self):
except AttributeError:
self._headsigns = defaultdict(int)
session = object_session(self)
q = session.query(StopTime).options(joinedload('trip'))
log.info("QUERY StopTime")
q = session.query(StopTime).options(joinedload(StopTime.trip), joinedload(StopTime.trip.route))
q = q.filter_by(stop_id=self.stop_id)
for r in q:
headsign = r.stop_headsign or r.trip.trip_headsign
Expand Down
2 changes: 1 addition & 1 deletion gtfsdb/model/stop_feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ class StopFeature(Base):
stop_feature_type = relationship('StopFeatureType',
primaryjoin='StopFeature.feature_type==StopFeatureType.feature_type',
foreign_keys='(StopFeature.feature_type)',
uselist=False, viewonly=True)
uselist=False, viewonly=True, lazy='joined')
3 changes: 3 additions & 0 deletions gtfsdb/model/stop_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def post_process(cls, db, **kwargs):
log.debug('{0}.post_process'.format(cls.__name__))

# remove the departure times at the end of a trip
log.info("QUERY StopTime")
sq = db.session.query(StopTime.trip_id, func.max(StopTime.stop_sequence).label('end_sequence'))
sq = sq.group_by(StopTime.trip_id).subquery()
q = db.session.query(StopTime)
Expand All @@ -88,6 +89,7 @@ def post_process(cls, db, **kwargs):
r.departure_time = None

# remove the arrival times at the start of a trip
log.info("QUERY StopTime")
sq = db.session.query(StopTime.trip_id, func.min(StopTime.stop_sequence).label('start_sequence'))
sq = sq.group_by(StopTime.trip_id).subquery()
q = db.session.query(StopTime)
Expand All @@ -109,6 +111,7 @@ def get_departure_schedule(cls, session, stop_id, date=None, route_id=None):


# step 1: get stop times based on date
log.info("QUERY StopTime")
q = session.query(StopTime)
q = q.filter_by(stop_id=stop_id)
q = q.filter(StopTime.departure_time!=None)
Expand Down

0 comments on commit bdd14ad

Please sign in to comment.