How to use the schema.getSchemaAsObject function in schema

To help you get started, we’ve selected a few schema examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github noisecapella / bostonbusmap / tools / generate / gtfs.py View on Github external
shape_rows = list(sorted(shape_rows, key=lambda shape: shape[shapes_header["shape_id"]]))
        for shape_id, group_rows in itertools.groupby(shape_rows, lambda shape: shape[shapes_header["shape_id"]]):
            path = [(float(row[shapes_header["shape_pt_lat"]]), float(row[shapes_header["shape_pt_lon"]])) for row in group_rows]
            paths.append(path)

        stop_times_rows = [stop_times_row for stop_times_row in stop_times
                           if stop_times_row[stop_times_header["trip_id"]] in trip_ids]
        stop_times_ids = set([stop_times_row[stop_times_header["stop_id"]] for stop_times_row in stop_times_rows])
        stop_rows = [stop_row for stop_row in stops
                     if stop_row[stops_header["stop_id"]] in stop_times_ids]

    
        pathblob = schema.Box(paths).get_blob_string()
    
        # insert route information
        obj = schema.getSchemaAsObject()
        if route not in routes_already_inserted:
            routes_already_inserted.add(route)

            obj.routes.route.value = route
            obj.routes.routetitle.value = route_title
            obj.routes.color.value = default_color
            obj.routes.oppositecolor.value = default_color
            obj.routes.listorder.value = startorder
            obj.routes.agencyid.value = schema.BusAgencyId
            obj.routes.pathblob.value = pathblob
            cur.execute(obj.routes.insert())

        for stop_row in stop_rows:
            stop_id = stop_row[stops_header["stop_id"]]
            if stop_id not in stops_already_inserted:
                stops_already_inserted.add(stop_id)
github noisecapella / bostonbusmap / tools / generate / mbta_commuter_rail.py View on Github external
shape_rows = gtfs_map.find_sorted_shapes_by_route(route_id)

            # this stores a list of list of lat, lon pairs
            paths = []
            for shape_id, group_rows in itertools.groupby(shape_rows, lambda shape: shape["shape_id"]):
                path = [(float(row["shape_pt_lat"]), float(row["shape_pt_lon"])) for row in group_rows]
                path = simplify_path(path)
                paths.append(path)

            stop_rows = gtfs_map.find_stops_by_route(route_id)

            pathblob = schema.Box(paths).get_blob_string()

            # insert route information
            obj = schema.getSchemaAsObject()
            obj.routes.route.value = route_id
            obj.routes.routetitle.value = route_title
            obj.routes.color.value = purple
            obj.routes.oppositecolor.value = purple
            obj.routes.listorder.value = startorder + route_order[route_id] - 1
            obj.routes.agencyid.value = schema.CommuterRailAgencyId
            obj.routes.pathblob.value = pathblob
            cur.execute(obj.routes.insert())

            for stop_row in stop_rows:
                stop_id = stop_row["stop_id"]
                if stop_id not in stops_inserted:
                    stops_inserted.add(stop_id)

                    obj.stops.tag.value = stop_id
                    obj.stops.title.value = stop_row["stop_name"]
github noisecapella / bostonbusmap / tools / generate / citibike.py View on Github external
def generate(self, conn, start_index):
        url = "http://appservices.citibikenyc.com//data2/stations.php"

        obj = schema.getSchemaAsObject()

        data = yield getPage(url)
        json_obj = json.loads(data)

        cur = conn.cursor()
        
        obj.routes.route.value = "Citibike"
        obj.routes.routetitle.value = "Citibike"
        obj.routes.color.value = default_color
        obj.routes.oppositecolor.value = default_color
        obj.routes.listorder.value = start_index
        obj.routes.agencyid.value = schema.HubwayAgencyId
        obj.routes.pathblob.value = schema.Box([]).get_blob_string()
        cur.execute(obj.routes.insert())

        for result in json_obj["results"]:
github noisecapella / bostonbusmap / tools / generate / create_tables.py View on Github external
def get_create_table_sql():
    obj = schema.getSchemaAsObject()
    for tableName in (each[0] for each in inspect.getmembers(obj)):
        if tableName[:2] != "__":
            table = getattr(obj, tableName)
            yield table.create()
            
            for index in table.index():
                yield index
github noisecapella / bostonbusmap / tools / heavyrail_tosql.py View on Github external
shape_rows = list(sorted(shape_rows, key=lambda shape: shape[shapes_header["shape_id"]]))
    for shape_id, group_rows in itertools.groupby(shape_rows, lambda shape: shape[shapes_header["shape_id"]]):
        path = [(float(row[shapes_header["shape_pt_lat"]]), float(row[shapes_header["shape_pt_lon"]])) for row in group_rows]
        paths.append(path)

    stop_times_rows = [stop_times_row for stop_times_row in stop_times
                       if stop_times_row[stop_times_header["trip_id"]] in trip_ids]
    stop_times_ids = set([stop_times_row[stop_times_header["stop_id"]] for stop_times_row in stop_times_rows])
    stop_rows = [stop_row for stop_row in stops
                 if stop_row[stops_header["stop_id"]] in stop_times_ids]

    
    pathblob = schema.Box(paths).get_blob_string()
    
    # insert route information
    obj = schema.getSchemaAsObject()
    obj.routes.route.value = route
    obj.routes.routetitle.value = route
    obj.routes.color.value = subway_color[route]
    obj.routes.oppositecolor.value = subway_color[route]
    obj.routes.listorder.value = startorder
    obj.routes.agencyid.value = schema.SubwayAgencyId
    obj.routes.pathblob.value = pathblob
    obj.routes.insert()

    for stop_row in stop_rows:
        tup = (float(stop_row[stops_header["stop_lat"]]),
               float(stop_row[stops_header["stop_lon"]]))

        if tup not in latlonmap:
            groupid = len(latlonmap)
            obj.stopgroup.lat.value = tup[0]
github noisecapella / bostonbusmap / tools / tosql.py View on Github external
def __init__(self, routeKeysToTitles, startingOrder, sharedLatLon):
        self.currentDirection = None
        self.currentRoute = None
        self.sharedStops = {}
        self.sharedLatLon = sharedLatLon
        self.table = schema.getSchemaAsObject()
        self.routeKeysToTitles = routeKeysToTitles
        self.startingOrder = startingOrder
        self.inPath = False
        self.paths = []