Ejemplo n.º 1
0
def evaluate_station_coverage(date_val1,
                              date_val2,
                              target_station,
                              day_part='monrning',
                              max_trips=10**6):
    # Scores each station by its averge wait+commute to the given target function
    # INPUT:
    # dateval1 - start date of trips
    # dateval2 - end date of trips
    # target_station_id - relative to this station all the shortest paths will be calculated
    # day_part- slice the statistics as 'all', 'morning', 'noon' or 'evening'
    # max_trips - limits the number of trips analyzed

    trips = get_samples_by_trip(date_val1, date_val2, max_trips)

    print("Got %d trip.." % (len(trips)))
    G = create_train_graph(trips)

    time_len = 60 * 24
    hour_vec = np.array(range(24 * 60)) / 60
    minuete_vec = np.array(range(24 * 60)) % 60
    time_indx_real = map(lambda x: '%04d' % x, hour_vec * 100 + minuete_vec)

    wait_vec, path_vec = dynamic_all_to_one(G, target_station, time_len)

    station_scores = OrderedDict()
    morning_indx = [7 * 60, 12 * 60]
    noon_indx = [12 * 60, 17 * 60]
    evening_indx = [17 * 60, 22 * 60]
    max_wait_val = 120.0

    for station in wait_vec:
        wait_vals = wait_vec[station]
        if day_part == 'all':
            wait_vals = filter(lambda x: not np.isinf(x), wait_vals)
        elif day_part == 'morning':
            wait_vals = filter(lambda x: not np.isinf(x),
                               wait_vals[morning_indx[0]:morning_indx[1]])
        elif day_part == 'noon':
            wait_vals = filter(lambda x: not np.isinf(x),
                               wait_vals[noon_indx[0]:noon_indx[1]])
        elif day_part == 'evening':
            wait_vals = filter(lambda x: not np.isinf(x),
                               wait_vals[evening_indx[0]:evening_indx[1]])
        wait_vals = np.array(list(wait_vals))
        if len(wait_vals) == 0:
            station_scores[station] = 0
        else:
            station_scores[station] = np.maximum(
                1 - np.median(wait_vals) / max_wait_val, 0)

    return station_scores
Ejemplo n.º 2
0
def evaluate_station_coverage(date_val1, date_val2, target_station,  day_part='monrning', max_trips=10**6):
    # Scores each station by its averge wait+commute to the given target function
    # INPUT:
    # dateval1 - start date of trips
    # dateval2 - end date of trips
    # target_station_id - relative to this station all the shortest paths will be calculated
    # day_part- slice the statistics as 'all', 'morning', 'noon' or 'evening'
    # max_trips - limits the number of trips analyzed

    trips = get_samples_by_trip(date_val1, date_val2, max_trips)

    print("Got %d trip.." % (len(trips)))
    G = create_train_graph(trips)

    time_len = 60 * 24
    hour_vec = np.array(range(24 * 60)) / 60
    minuete_vec = np.array(range(24 * 60)) % 60
    time_indx_real = map(lambda x: '%04d' % x, hour_vec * 100 + minuete_vec)

    wait_vec, path_vec = dynamic_all_to_one(G, target_station, time_len)

    station_scores = OrderedDict()
    morning_indx = [7 * 60, 12 * 60]
    noon_indx = [12 * 60, 17 * 60]
    evening_indx = [17 * 60, 22 * 60]
    max_wait_val = 120.0

    for station in wait_vec:
        wait_vals = wait_vec[station]
        if day_part == 'all':
            wait_vals = filter(lambda x: not np.isinf(x), wait_vals)
        elif day_part == 'morning':
            wait_vals = filter(lambda x: not np.isinf(x), wait_vals[morning_indx[0]:morning_indx[1]])
        elif day_part == 'noon':
            wait_vals = filter(lambda x: not np.isinf(x), wait_vals[noon_indx[0]:noon_indx[1]])
        elif day_part == 'evening':
            wait_vals = filter(lambda x: not np.isinf(x), wait_vals[evening_indx[0]:evening_indx[1]])
        wait_vals = np.array(list(wait_vals))
        if len(wait_vals) == 0:
            station_scores[station] = 0
        else:
            station_scores[station] = np.maximum(1 - np.median(wait_vals)/max_wait_val, 0)

    return station_scores
Ejemplo n.º 3
0
    # Create graph

    # time_len = 2
    # G = create_predefind_graph()

    date_val1 = datetime.date(2015, 1, 1)
    date_val2 = datetime.date(2015, 3, 12)


    max_trips = 100
    trips = get_samples_by_trip(date_val1, date_val2, max_trips)

    # for ind in range(len(trips_full)):
    # trips = {list(trips_full.keys())[ind] : trips_full[list(trips_full.keys())[ind]]}

    print( "Got %d trip.." % (len(trips)))
    G = create_train_graph(trips)

    target = 4600
    time_len = 60*24
    hour_vec = np.array(range(24*60))/60
    minuete_vec = np.array(range(24*60)) % 60
    time_indx_real = map(lambda x: '%04d'%x, hour_vec*100 + minuete_vec)

    # G = create_toy_graph(10, 25, time_len=time_len)

    # wait_vec, path_vec = dynamic_all_to_one(G, target, time_len)

    display_graph(G, draw_edge_label=False)

    print("Finished!")
Ejemplo n.º 4
0
    # Create graph

    # time_len = 2
    # G = create_predefind_graph()

    date_val1 = datetime.date(2015, 1, 1)
    date_val2 = datetime.date(2015, 3, 12)

    max_trips = 100
    trips = get_samples_by_trip(date_val1, date_val2, max_trips)

    # for ind in range(len(trips_full)):
    # trips = {list(trips_full.keys())[ind] : trips_full[list(trips_full.keys())[ind]]}

    print("Got %d trip.." % (len(trips)))
    G = create_train_graph(trips)

    target = 4600
    time_len = 60 * 24
    hour_vec = np.array(range(24 * 60)) / 60
    minuete_vec = np.array(range(24 * 60)) % 60
    time_indx_real = map(lambda x: '%04d' % x, hour_vec * 100 + minuete_vec)

    # G = create_toy_graph(10, 25, time_len=time_len)

    # wait_vec, path_vec = dynamic_all_to_one(G, target, time_len)

    display_graph(G, draw_edge_label=False)

    print("Finished!")