Example #1
0
def route_stop_load():
    ''' written as a test / debug method for RS table loader '''
    from gtfsdb import Database, RouteStop
    args, kwargs = get_args()
    db = Database(**kwargs)
    #import pdb; pdb.set_trace()
    RouteStop.load(db, **kwargs)
Example #2
0
def route_stop_load():
    """
    written as a test / debug method for RS table loader
    """
    from gtfsdb import Database, RouteStop
    kwargs = get_args()[1]
    db = Database(**kwargs)
    RouteStop.load(db, **kwargs)
Example #3
0
    def stop_routes_factory(cls, session, stop_id, date=None, agency_id=None):
        """
        :return a list of all route(s) serving a given stop

        http://localhost:54445/ti/stops/TriMet:2/routes
        STOP's ROUTES RESPONSE:
        [
          {
            "id": "TriMet:10",
            "shortName": "10",
            "longName": "Harold St",
            "mode": "BUS",
            "agencyName": "TriMet"
          }
        ]
        """
        # import pdb; pdb.set_trace()
        if date:
            from gtfsdb import RouteStop
            routes = RouteStop.unique_routes_at_stop(session,
                                                     stop_id=stop_id,
                                                     agency_id=agency_id,
                                                     date=date)
        else:
            from gtfsdb import CurrentRouteStops
            routes = CurrentRouteStops.unique_routes_at_stop(
                session, stop_id=stop_id, agency_id=agency_id)

        ret_val = cls._route_list_from_gtfsdb_orm_list(routes, agency_id)
        return ret_val
Example #4
0
    def from_route_direction(cls, session, route_id, direction_id, agency_id=None, detailed=False, show_geo=False, active_stops_only=True):
        ''' make a RouteStopsDao from route_id, direction_id and session
        '''
        ret_val = None

        #import pdb; pdb.set_trace()
        log.info("query RouteStop table")
        rs = RouteStop.active_stops(session, route_id, direction_id) #, agency_id) #TODO ... fix agency id
        if rs and len(rs) > 1:
            route = RouteDao.from_route_orm(route=rs[0].route, agency=agency_id, detailed=detailed, show_geo=show_geo)
            stops = StopListDao.from_routestops_orm(route_stops=rs, agency=agency_id, detailed=detailed, show_geo=show_geo, active_stops_only=active_stops_only)
            ret_val = RouteStopDao(route, stops, rs[0].direction_id)

        return ret_val
Example #5
0
    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
Example #6
0
 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
Example #7
0
    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
Example #8
0
def route_stop_load():
    ''' written as a test / debug method for RS table loader '''
    from gtfsdb import Database, RouteStop
    kwargs = get_args()[1]
    db = Database(**kwargs)
    RouteStop.load(db, **kwargs)