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
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
hop_str = str(station_id1) + '_' + str(station_id2) if not hop_str in edge_dict: edge_dict[hop_str] = time_vec_template.copy() edge_dict[hop_str][time_indx] = hop_time_expected # Insert edge dictionary into graph structure for hop in edge_dict: station_id1 = int(hop.partition('_')[0]) station_id2 = int(hop.partition('_')[2]) # post process time_vec into FIFO constraint time_vec = edge_dict[hop] time_vec_proc = fifo_time(time_vec) G.add_edge(station_id1, station_id2, w=time_vec_proc) return G ### ------------------------------------------------------------------------------------------------------------------------------- if __name__ == "__main__": max_trips = 10 date_val1 = datetime.datetime(2015, 5, 15) date_val2 = datetime.datetime(2015, 6, 15) trips = get_samples_by_trip(date_val1, date_val2, max_trips) G = create_train_graph(trips) print("Done")
### ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- if __name__ == '__main__': # 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)