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()
    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 src.manage
    session = src.manage.get_session()
    stop_names = src.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)