示例#1
0
def gdb_boardalight_load_bundle(gdb, agency_namespace, bundle, service_id, sc, tz, cursor):
    
    stop_time_bundles = bundle.stop_time_bundles(service_id)
    
    n_trips = len(bundle.trip_ids)    
    
    # If there's less than two stations on this trip bundle, the trip bundle doesn't actually span two places
    if len(stop_time_bundles)<2:
        return
        
    # If there are no stop_times in a bundle on this service day, there is nothing to load
    if n_trips==0:
        return
        
    print "inserting %d trips with %d stop_time bundles on service_id '%s'"%(len(stop_time_bundles[0]),len(stop_time_bundles),service_id)
    #print bundle.pattern.stop_ids

    #add board edges
    for i, stop_time_bundle in enumerate(stop_time_bundles[:-1]):
        
        trip_id, departure_time, arrival_time, stop_id, stop_sequence, stop_dist_traveled = stop_time_bundle[0]
        
        patternstop_vx_name = "psv-%s-%03d-%03d"%(agency_namespace,bundle.pattern.pattern_id,i)
        
        gdb.add_vertex( patternstop_vx_name, cursor )
        
        b = TripBoard(service_id, sc, tz, 0)
        for trip_id, departure_time, arrival_time, stop_id, stop_sequence, stop_dist_traveled in stop_time_bundle:
            b.add_boarding( trip_id, departure_time )
            
        gdb.add_edge( "sta-%s"%stop_id, patternstop_vx_name, b, cursor )
        
    #add alight edges
    for i, stop_time_bundle in enumerate(stop_time_bundles[1:]):

        trip_id, departure_time, arrival_time, stop_id, stop_sequence, stop_dist_traveled = stop_time_bundle[0]
        
        patternstop_vx_name = "psv-%s-%03d-%03d"%(agency_namespace,bundle.pattern.pattern_id,i+1)
        gdb.add_vertex( patternstop_vx_name, cursor )
        
        al = Alight(service_id, sc, tz, 0)
        for trip_id, departure_time, arrival_time, stop_id, stop_sequence, stop_dist_traveled in stop_time_bundle:
            al.add_alighting( trip_id.encode('ascii'), arrival_time )
            
        gdb.add_edge( patternstop_vx_name, "sta-%s"%stop_id, al, cursor )
    
    # add crossing edges
    for j, crossing_time in enumerate(bundle.pattern.crossings):
        c = Crossing( crossing_time )
        gdb.add_edge( "psv-%s-%03d-%03d"%(agency_namespace,bundle.pattern.pattern_id,j), 
                      "psv-%s-%03d-%03d"%(agency_namespace,bundle.pattern.pattern_id,j+1), c, cursor )
                      
    gdb.commit()
示例#2
0
def load_bundle_to_boardalight_graph(g, agency_namespace, bundle, service_id, sc, tz):
    stop_time_bundles = list(bundle.stop_time_bundles(service_id))

    # If there's less than two stations on this trip bundle, the trip bundle doesn't actually span two places
    if len(stop_time_bundles) < 2:
        return

    # If there are no stop_times in a bundle on this service day, there is nothing to load
    if len(stop_time_bundles[0]) == 0:
        return

    # add board edges
    for i, stop_time_bundle in enumerate(stop_time_bundles[:-1]):

        if len(stop_time_bundle) == 0:
            continue

        trip_id, departure_time, arrival_time, stop_id, stop_sequence, stop_dist_traveled = stop_time_bundle[0]

        patternstop_vx_name = "psv-%s-%03d-%03d" % (agency_namespace, bundle.pattern.pattern_id, i)

        g.add_vertex(patternstop_vx_name)

        b = TripBoard(service_id, sc, tz, 0)
        for trip_id, departure_time, arrival_time, stop_id, stop_sequence, stop_dist_traveled in stop_time_bundle:
            b.add_boarding(trip_id, departure_time)

        g.add_edge("sta-%s" % stop_id, patternstop_vx_name, b)

    # add alight edges
    for i, stop_time_bundle in enumerate(stop_time_bundles[1:]):
        if len(stop_time_bundle) == 0:
            continue

        trip_id, departure_time, arrival_time, stop_id, stop_sequence, stop_dist_traveled = stop_time_bundle[0]

        patternstop_vx_name = "psv-%s-%03d-%03d" % (agency_namespace, bundle.pattern.pattern_id, i + 1)
        g.add_vertex(patternstop_vx_name)

        al = Alight(service_id, sc, tz, 0)
        for trip_id, departure_time, arrival_time, stop_id, stop_sequence, stop_dist_traveled in stop_time_bundle:
            al.add_alighting(trip_id.encode("ascii"), arrival_time)

        g.add_edge(patternstop_vx_name, "sta-%s" % stop_id, al)

    # add crossing edges
    for j, crossing_time in enumerate(bundle.pattern.crossings):
        c = Crossing(crossing_time)
        g.add_edge(
            "psv-%s-%03d-%03d" % (agency_namespace, bundle.pattern.pattern_id, j),
            "psv-%s-%03d-%03d" % (agency_namespace, bundle.pattern.pattern_id, j + 1),
            c,
        )
示例#3
0
def gdb_boardalight_load_bundle(gdb, agency_namespace, gtfsdb, bundle, service_id, sc, tz, cursor, agency_id_int):
    
    stop_time_bundles = bundle.stop_time_bundles(service_id)
    
    n_trips = len(bundle.trip_ids)    
    
    # If there's less than two stations on this trip bundle, the trip bundle doesn't actually span two places
    if len(stop_time_bundles)<2:
        return
        
    # If there are no stop_times in a bundle on this service day, there is nothing to load
    if n_trips==0:
        return
        
    print "inserting %d trips with %d stop_time bundles on service_id '%s'"%(len(stop_time_bundles[0]),len(stop_time_bundles),service_id)
    #print bundle.pattern.stop_ids

    #add board edges
    for i, stop_time_bundle in enumerate(stop_time_bundles[:-1]):
        
        trip_id, arrival_time, departure_time, stop_id, stop_sequence, stop_dist_traveled = stop_time_bundle[0]
        
        board_stop_id, board_stop_name, board_stop_lat, board_stop_lon = gtfsdb.stop(stop_id)
        route_type = gtfsdb.route_type_for_trip_id(trip_id)
        wheelchair_boarding = gtfsdb.wheelchair_boarding_for_stop_id(stop_id)
        
        if arrival_time != departure_time:
            patternstop_vx_name = "psv-%s-%03d-%03d-depart"%(agency_namespace,bundle.pattern.pattern_id,i)
            
            # construct the board/alight/dwell triangle for this patternstop
            patternstop_arrival_vx_name = "psv-%s-%03d-%03d-arrive"%(agency_namespace,bundle.pattern.pattern_id,i)
            gdb.add_vertex( patternstop_arrival_vx_name, board_stop_lat, board_stop_lon, cursor )
            gdb.add_edge( patternstop_arrival_vx_name, 
                          patternstop_vx_name,
                          Crossing( (departure_time-arrival_time) ), 
                          cursor )
            
        else:
            patternstop_vx_name = "psv-%s-%03d-%03d"%(agency_namespace,bundle.pattern.pattern_id,i)
        
        gdb.add_vertex( patternstop_vx_name, board_stop_lat, board_stop_lon, cursor )
        
        b = TripBoard(service_id, sc, tz, agency_id_int, route_type, wheelchair_boarding)
        for trip_id, arrival_time, departure_time, stop_id, stop_sequence, stop_dist_traveled in stop_time_bundle:
            b.add_boarding( trip_id, departure_time )
            
        gdb.add_edge( "sta-%s"%stop_id, patternstop_vx_name, b, cursor )
        
    #add alight edges
    for i, stop_time_bundle in enumerate(stop_time_bundles[1:]):

        trip_id, arrival_time, departure_time, stop_id, stop_sequence, stop_dist_traveled = stop_time_bundle[0]
        
        alight_stop_id, alight_stop_name, alight_stop_lat, alight_stop_lon = gtfsdb.stop(stop_id)
        route_type = gtfsdb.route_type_for_trip_id(trip_id)
        wheelchair_boarding = gtfsdb.wheelchair_boarding_for_stop_id(stop_id)
        
        if arrival_time != departure_time:
            patternstop_vx_name = "psv-%s-%03d-%03d-arrive"%(agency_namespace,bundle.pattern.pattern_id,i+1)
        else:
            patternstop_vx_name = "psv-%s-%03d-%03d"%(agency_namespace,bundle.pattern.pattern_id,i+1)
        
        gdb.add_vertex( patternstop_vx_name, alight_stop_lat, alight_stop_lon, cursor )
        
        al = Alight(service_id, sc, tz, agency_id_int, route_type, wheelchair_boarding)
        for trip_id, arrival_time, departure_time, stop_id, stop_sequence, stop_dist_traveled in stop_time_bundle:
            al.add_alighting( trip_id.encode('ascii'), arrival_time )
            
        gdb.add_edge( patternstop_vx_name, "sta-%s"%stop_id, al, cursor )
    
    # add crossing edges
    for i, (from_stop_time_bundle, to_stop_time_bundle) in enumerate(cons(stop_time_bundles)):
        
        trip_id, from_arrival_time, from_departure_time, stop_id, stop_sequence, stop_dist_traveled = from_stop_time_bundle[0]
        trip_id, to_arrival_time, to_departure_time, stop_id, stop_sequence, stop_dist_traveled = to_stop_time_bundle[0]
        
        if from_arrival_time!=from_departure_time:
            from_patternstop_vx_name = "psv-%s-%03d-%03d-depart"%(agency_namespace,bundle.pattern.pattern_id,i)
        else:
            from_patternstop_vx_name = "psv-%s-%03d-%03d"%(agency_namespace,bundle.pattern.pattern_id,i)
            
        if to_arrival_time!=to_departure_time:
            to_patternstop_vx_name = "psv-%s-%03d-%03d-arrive"%(agency_namespace,bundle.pattern.pattern_id,i+1)
        else:
            to_patternstop_vx_name = "psv-%s-%03d-%03d"%(agency_namespace,bundle.pattern.pattern_id,i+1)
            
        gdb.add_edge( from_patternstop_vx_name, 
                      to_patternstop_vx_name, 
                      Crossing( (to_arrival_time-from_departure_time) ), 
                      cursor )
                      
    gdb.commit()