Example #1
0
def HSR_main(date, ref_num=3):
    user_data_path = "./data/user_data/"+date+"/" #�s�Ҧ��ϥΪ̪��@�Ѫ���ƪ���Ƨ�
    result = []
    try:
        request_date = date[:4] + '-' + date[4:6] + '-' + date[6:]
    except:
        print('date format error')
    travel_time, travel_during_time = External.HSR_travel_time(request_date)
    stations = External.HSR_station()
    cell_file = "./data/all_tower.csv" #�s�Ҧ��򯸦�m���ɮ�(lon,lat)
    HSR_ref_sys = Preprocess.HSR_reference_system(cell_file, stations, ref_num)
    print("-----build up rail reference system-----")
    for file_name in os.listdir(user_data_path):
        f = open(os.path.join(user_data_path,file_name),"r")
        user_raw_data = [[row[0], row[4], row[2], row[3]] for row in
                         csv.reader(f, delimiter='|')]  # [imsi, unix_time, lon, lat]
        raw_data_df = pandas.DataFrame(user_raw_data, columns=['imsi', 'unix_time', 'lon', 'lat'])
        raw_data_df = raw_data_df.sort_values(['unix_time'])
        user_raw_data_sorted = raw_data_df.values.tolist()
        user_data = Preprocess.preprocessing(user_raw_data_sorted) #[imsi, start_time, end_time, lon, lat]
        r = Mode_Detection.HSR_trip_detection(user_data, travel_time, travel_during_time, stations, HSR_ref_sys)
        if len(r)!=0:
            result.extend(r)
    output_result = [(result,)]
    csv_output(output_result, ['hsr_'+date+'.csv'])
Example #2
0
def mrt_main(date):
    user_data_path = "./data/user_data/"+date+"/"
    rf_sys_path = "./data/external_data/mrt/reference system/entrance_tower_to_subway_k_1.csv"
    mrt_route_file = "./data/external_data/mrt/mrt_route.csv"
    mrt_entrance_file = "./data/external_data/mrt/mrt_station_entrance.csv"
    travel_time_file = "./data/external_data/mrt/mrt_travel_time.csv"
    result = []
    for file_name in os.listdir(user_data_path):
        #new part
        f = open(os.path.join(user_data_path,file_name),"r")
        user_raw_data = [[row[0], row[4], row[2], row[3]] for row in
                         csv.reader(f, delimiter='|')]  # [imsi, unix_time, lon, lat]
        raw_data_df = pandas.DataFrame(user_raw_data, columns=['imsi', 'unix_time', 'lon', 'lat'])
        raw_data_df = raw_data_df.sort_values(['unix_time'])
        user_raw_data_sorted = raw_data_df.values.tolist()
        f.close()
        user_data = Preprocess.preprocessing(user_raw_data_sorted) #[imsi, start_time, end_time, lon, lat]
        # print(user_data)
        r = Mode_Detection.MRT_trip_detection(user_data,rf_sys_path,mrt_route_file,mrt_entrance_file,travel_time_file)
        if len(r) == 0:
            continue
        if len(r[0]) == 0:
            continue
        result.append(r)
    csv_output(result, ['mrt_'+date+'.csv', 'mrt_path_'+date+'.csv'])
Example #3
0
def bus_main(date):
    user_data_path = "./data/user_data/"+date+"/"
    route = pickle.load(open("./data/external_data/bus/bus_route.pickle", "rb"))
    
    all_user_data = dict()
    for file_name in os.listdir(user_data_path):
        f = open(os.path.join(user_data_path, file_name),"r")
        user_raw_data = [[row[0], row[4], row[2], row[3]] for row in csv.reader(f, delimiter='|')] #[imsi, unix_time, lon, lat]
        raw_data_df = pandas.DataFrame(user_raw_data, columns=['imsi', 'time', 'lon', 'lat'])
        raw_data_df = raw_data_df.sort_values(['time'])
        user_raw_data_sorted = raw_data_df.values.tolist()
        user_data = Preprocess.preprocessing(user_raw_data_sorted) #[imsi, start_time, end_time, lon, lat]
        all_user_data[user_data[0][0]] = user_data
        f.close()

    '''
    TPE_route = External.bus_route('taipei')
    NWT_route = External.bus_route('newtaipei')
    route = TPE_route
    for key in NWT_route.keys():
        route[key] = NWT_route[key]

    pickle.dump(route, open("data/bus_route.pickle", "wb"))
    '''
    rid2user,user2rid,route2rid = Preprocess.bus_spatial_index(route, all_user_data)
    SpeedDis = [20]*24
    result = Mode_Detection.bus_trip_detection(rid2user, user2rid, route2rid, route, SpeedDis)
    #print result
    output_result = [(result,)]
    csv_output(output_result, ['bus_'+date+'.csv'])
Example #4
0
def rail_main(date):
    user_data_path = "./data/user_data/"+date+"/" 
    result = []
    # travel_time, travel_during_time = External.rail_travel_time(date)
    stations = External.rail_station()
    cell_file = "./data/all_tower.csv" #format (lon,lat)
    rail_ref_sys = Preprocess.rail_reference_system(cell_file, stations)
    #print("-----build up rail reference system-----")
    for file_name in os.listdir(user_data_path):
        f = open(os.path.join(user_data_path,file_name),"r")
        user_raw_data = [[row[0], row[4], row[2], row[3]] for row in
                         csv.reader(f, delimiter='|')]  # [imsi, unix_time, lon, lat]
        raw_data_df = pandas.DataFrame(user_raw_data, columns=['imsi', 'unix_time', 'lon', 'lat'])
        raw_data_df = raw_data_df.sort_values(['unix_time'])
        user_raw_data_sorted = raw_data_df.values.tolist()
        user_data = Preprocess.preprocessing(user_raw_data_sorted) #[imsi, start_time, end_time, lon, lat]
        r = Mode_Detection.rail_trip_detection(user_data, stations, rail_ref_sys)
        if len(r)!=0:
            result.extend(r)
    output_result = [(result,)]
    csv_output(output_result, ['train_'+date+'.csv'])