Esempio n. 1
0
def get_ontime_percentage_report_for_given_minutes(minutes, session, exclude_stops=None):
  stop_names = manage.get_stop_names()
  stop_passenger_ratio = get_stop_passenger_ratio()  
  stops = stop_names.keys()

  data, trainstops = calc_ontime_data(stops, session, minutes, stop_names)

  all_vals = [data[x]['all'] for x in stops]  
  rush = [data[x]['rush'] for x in stops]
  non_rush = [data[x]['non_rush'] for x in stops]
  stop_names_list = [stop_names[x] for x in stops]

  exclude_inds = [stops.index(x) for x in exclude_stops]
  order = np.argsort(all_vals)[::-1]
  order = [i for i in order if i not in exclude_inds]
  all_vals_ordered = [all_vals[i] for i in order]
  rush_ordered = [rush[i] for i in order]
  stop_names_list_ordered = [stop_names_list[i] for i in order]

  title = 'Percentage of on-time trains per station. On time is when delay < {} minutes'.format(minutes)
  vals_dict = {"all":all_vals_ordered, "rush":rush_ordered}  
  display_station_delay_bar_graph(vals_dict, stop_names_list_ordered, title, (22.0, 16.0))
  print title
  print "Name\tAll\tRush-hour"
  for val in reversed(zip(stop_names_list_ordered, all_vals_ordered, rush_ordered)):
    print val[0] + '\t' + str(val[1]) + '\t' + str(val[2])
  print ""

  passenger_weighted_all, passenger_weighted_rush = calc_passenger_weighted_ontime_percent(stops, stop_passenger_ratio, data)
  print "Passenger ontime={}%, rush={}% (up to {} minutes delay)".format(passenger_weighted_all, passenger_weighted_rush, minutes)
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()
Esempio n. 3
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()
Esempio n. 4
0
def get_ontime_percentage_report_for_given_minutes(minutes,
                                                   session,
                                                   exclude_stops=None):
    stop_names = manage.get_stop_names()
    stop_passenger_ratio = get_stop_passenger_ratio()
    stops = stop_names.keys()

    data, trainstops = calc_ontime_data(stops, session, minutes, stop_names)

    all_vals = [data[x]['all'] for x in stops]
    rush = [data[x]['rush'] for x in stops]
    non_rush = [data[x]['non_rush'] for x in stops]
    stop_names_list = [stop_names[x] for x in stops]

    exclude_inds = [stops.index(x) for x in exclude_stops]
    order = np.argsort(all_vals)[::-1]
    order = [i for i in order if i not in exclude_inds]
    all_vals_ordered = [all_vals[i] for i in order]
    rush_ordered = [rush[i] for i in order]
    stop_names_list_ordered = [stop_names_list[i] for i in order]

    title = 'Percentage of on-time trains per station. On time is when delay < {} minutes'.format(
        minutes)
    vals_dict = {"all": all_vals_ordered, "rush": rush_ordered}
    display_station_delay_bar_graph(vals_dict, stop_names_list_ordered, title,
                                    (22.0, 16.0))
    print title
    print "Name\tAll\tRush-hour"
    for val in reversed(
            zip(stop_names_list_ordered, all_vals_ordered, rush_ordered)):
        print val[0] + '\t' + str(val[1]) + '\t' + str(val[2])
    print ""

    passenger_weighted_all, passenger_weighted_rush = calc_passenger_weighted_ontime_percent(
        stops, stop_passenger_ratio, data)
    print "Passenger ontime={}%, rush={}% (up to {} minutes delay)".format(
        passenger_weighted_all, passenger_weighted_rush, minutes)
                path_vec[i][t] = [i] + path_vec[j][time_next]

    return dist_vec, path_vec

### -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

if __name__ == '__main__':

    # Create graph
    # time_len = 2
    # G = create_toy_graph(10, 25, time_len=time_len)
    # G = create_predefind_graph()

    import manage
    session = manage.get_session()
    stop_names = manage.get_stop_names()
    station_id_dict = station_id2name('../data/stops_ids_and_names.txt')


    date_val = datetime.date(2014, 1, 1)
    G = create_train_graph(session, stop_names, station_id_dict, date_val)

    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)

    dist_vec, path_vec = dynamic_all_to_one(G, target, time_len)

    display_graph(G, draw_edge_label=False)