def from_stop_orm(cls, stop_orm, distance=0.0, order=0, agency="TODO", detailed=False, show_geo=False, show_alerts=False, date=None): """ make a StopDao from a stop object and session note that certain pages only need the simple stop info ... so we can avoid queries of detailed stop info (like routes hitting a stop, alerts, etc...) """ ret_val = None amenities = [] routes = [] alerts = [] # step 1: if we want full details on this stop, include features and amenities, etc... if detailed: # step 2: get list of stop amenities amenities = [] for f in stop_orm.stop_features: if f and f.feature_name: amenities.append(f.feature_name) # step 3a: get the routes for a stop route_stops = RouteStop.active_unique_routes_at_stop(stop_orm.session, stop_id=stop_orm.stop_id, date=date) for r in route_stops: rs = None # step 3b: build the route object for the stop's route (could be detailed and with alerts) try: rs = RouteDao.from_route_orm(route=r, agency=agency, detailed=detailed, show_alerts=show_alerts) except Exception as e: log.info(e) # step 3c: we got an error above, so let's try to get minimal route information try: rs = RouteDao.from_route_orm(route=r) except Exception as e: log.info(e) log.info("couldn't get route information") # step 3d: build the list of routes if rs: routes.append(rs) routes.sort(key=lambda x: x.sort_order, reverse=False) # TODO: shut off, as TriMet doesn't use route alerts right now (and I can't afford more /q) #if show_alerts: # alerts = AlertsDao.get_stop_alerts(object_session(stop), stop.stop_id) # step 4: query db for route ids serving this stop... ret_val = StopDao(stop_orm, amenities, routes, alerts, distance, order, date, show_geo) return ret_val
def make_short_names(cls, stop_orm): """ get route sort names serving this stop :param stop_orm: :return list of short names: TODO: move to Stop in gtfsdb """ ret_val = [] routes = RouteStop.active_unique_routes_at_stop(stop_orm.session, stop_id=stop_orm.stop_id) routes.sort(key=lambda x: x.route_sort_order, reverse=False) for r in routes: sn = {'route_id': r.route_id, 'route_short_name': transit_utils.make_short_name(r)} ret_val.append(sn) return ret_val
def get_route_short_names(self, stop_orm): """ add an array of short names to this DAO """ # step 1: create a short_names list if we haven't already if not self.short_names: self.short_names = [] # step 2: use either route-dao list or find the active stops routes = self.routes if routes is None or len(routes) == 0: routes = RouteStop.active_unique_routes_at_stop(stop_orm.session, stop_id=stop_orm.stop_id) routes.sort(key=lambda x: x.route_sort_order, reverse=False) # step 3: build the short names list for r in routes: sn = {'route_id': r.route_id, 'route_short_name': transit_utils.make_short_name(r)} self.short_names.append(sn) return self.short_names