def analyze_average_commute(date_val):
    # Display a contiguous commute time from a source station to a target station

    # Get DB data
    session = manage.get_session()
    stop_names = manage.get_stop_names()
    station_id_dict = station_id2name('../data/stops_ids_and_names.txt')
    # Create a graph representation of the train stops
    G = create_train_graph(session, stop_names, station_id_dict, date_val)

    target = 4600   # station_id for Tel-Aviv Hashalom
    time_len = 60*24
    hour_vec = np.array(range(24*60))/60
    minute_vec = np.array(range(24*60)) % 60
    time_indx_real = map(lambda x: '%04d'%x, hour_vec*100 + minute_vec)

    # Calculation of the DOT graph algorithms
    dist_vec, path_vec = dynamic_all_to_one(G, target, time_len)

    display_graph(G, draw_edge_label=False)

    station_id = 5410
    xindx = range(len(time_indx_real))
    plt.xticks(xindx[240::240], time_indx_real[240::240]), plt.plot(xindx[240:], dist_vec[station_id][240:], label=station_id_dict[station_id], linewidth=2.5), plt.grid(),  plt.ylim(0, 150)
    plt.xlabel('time of day'), plt.ylabel('time of commute in minutes'), plt.title(('Commute Time to %s') % (station_id_dict[4600]))
    station_id = 3500
    plt.plot(xindx[240:], dist_vec[station_id][240:], label=station_id_dict[station_id], linewidth=2.5)
    station_id=8700
    plt.plot(xindx[240:], dist_vec[station_id][240:], label=station_id_dict[station_id], linewidth=2.5)
    plt.legend()
    plt.show()
Пример #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
Пример #3
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
Пример #4
0
def analyze_average_commute(date_val):
    # Display a contiguous commute time from a source station to a target station

    # Get DB data
    session = manage.get_session()
    stop_names = manage.get_stop_names()
    station_id_dict = station_id2name('../data/stops_ids_and_names.txt')
    # Create a graph representation of the train stops
    G = create_train_graph(session, stop_names, station_id_dict, date_val)

    target = 4600  # station_id for Tel-Aviv Hashalom
    time_len = 60 * 24
    hour_vec = np.array(range(24 * 60)) / 60
    minute_vec = np.array(range(24 * 60)) % 60
    time_indx_real = map(lambda x: '%04d' % x, hour_vec * 100 + minute_vec)

    # Calculation of the DOT graph algorithms
    dist_vec, path_vec = dynamic_all_to_one(G, target, time_len)

    display_graph(G, draw_edge_label=False)

    station_id = 5410
    xindx = range(len(time_indx_real))
    plt.xticks(xindx[240::240], time_indx_real[240::240]), plt.plot(
        xindx[240:],
        dist_vec[station_id][240:],
        label=station_id_dict[station_id],
        linewidth=2.5), plt.grid(), plt.ylim(0, 150)
    plt.xlabel('time of day'), plt.ylabel(
        'time of commute in minutes'), plt.title(
            ('Commute Time to %s') % (station_id_dict[4600]))
    station_id = 3500
    plt.plot(xindx[240:],
             dist_vec[station_id][240:],
             label=station_id_dict[station_id],
             linewidth=2.5)
    station_id = 8700
    plt.plot(xindx[240:],
             dist_vec[station_id][240:],
             label=station_id_dict[station_id],
             linewidth=2.5)
    plt.legend()
    plt.show()