Example #1
0
 def _load_routes(self, rdr):
     """Fetch the routes table, creating :class:`Route_Definition` objects."""
     Route_Definition.set_db( settings.db )
     for row in rdr:
         for r in Route_Definition.view( 'service/route', key=row['route_id'] ):
             r.delete()
         route= Route_Definition(**row)
         route.save()
Example #2
0
def get_route_from_stop_time( stop_time ):
    """Query the route that contains a given stop_time value.
    This does a stop_times JOIN trips JOIN routes query.

    This is ill-constrained, since it can provide lots of
    routes all over the transit system.

    :param stop_time: a :class:`Stop_Time` instance.
    :return: a :class:`Route` instance.
    """
    Route_Definition.set_db( settings.db )
    return list( Route_Definition.view( 'service/stop_time', key_start= stop_time ) )
Example #3
0
def get_route( id=None ):
    """Returns route or list of routes.

    If ``id`` is None, it returns all route definitions.

    Otherwise, it returns the requested route definition.

    :param id: Optional route id.  If no route id, all routes are returned.
    :return: route definition or list of route definitions.
    """
    Route_Definition.set_db( settings.db )
    if id:
        return list( Route_Definition.view( 'service/route', key=id ) )
    else:
        return list(Route_Definition.view( 'service/route' ))
Example #4
0
def get_route_stops( id, dir=None, date=None ):
    """Returns a route with a list of stops on that route.

    The route ID is required.
    Either a direction or a date must be given to filter the stops
    along the route.

    If direction is given,

        All stops in a particular direction along the route.  The direction is
        more-or-less inoound or outbound, and is actually a foreign key to a direction
        table.

    If date is given,

        All stops along the route filtered by services available on the given date.
        Day of week is generally sufficient, but there are calendar overrides,
        so full date is required.

    :param id: route id.
    :param dir: optional direction, codes are '1' and '0'.
    :param date: a datetime.date object; the services available on this date
        are used to filter the results.

    :returns: a :class:`Route_Definition` instance.
    """
    Route_Definition.set_db( settings.db )
    route= list( Route_Definition.view('service/route',key=id) )[0]
    if date:
        services= set(get_services_today( date ))
        for s in route.trips:
            if s not in services:
                del route.trips[s]
    if dir:
        for svc in route.trips:
            for trip in route.trips[svc]:
                if route.trips[svc][trip]['direction_id'] != dir:
                    del route.trips[svc][trip]
    return route