Esempio n. 1
0
def output_pre_road_data(trail,
                         direction,
                         n,
                         type='cell',
                         interpolate_interval=1,
                         smoothing=0,
                         penalty=0.9,
                         direction_window=15):
    '''
    Output predicted road data with CTrack. For test wuhu data.
    :param trail: <Int> The i_th trail
    :param direction: <-1/1> -1 means reverse side; 1 means front.
    :param n: The n_th test of this trail. If None, return all the tests of the trail.
    :param type: 'cell' or 'GPS'. See details in function get_obs_data.
    :param interpolate_interval: Interval seconds of processed observables. Default = 1.
    :param smoothing: Window length of smoothing. If smoothing == 0, do not smooth.
    :param penalty:
    :param direction_window:
    :return: None.
    '''
    df = get_road_tests(trail, direction, n)
    graph = get_graph('../../data/road_test/link_baidu_wuhu.txt')
    obs = get_obs_data(df, type=type)
    track = CTrack(obs,
                   graph,
                   smoothing=smoothing,
                   interpolate_interval=interpolate_interval,
                   penalty=penalty,
                   direction_window=direction_window)
    states = track.viterbi()
    direction = u'正向' if direction == 1 else u'反向'
    output_data_js(
        states,
        '../../res/MapMatching_test/pre_%s/wuhu_pre_线路%d_%s%d_smoothing=%d_window=%d.js'
        % (type, trail, direction, n, smoothing, interpolate_interval))
Esempio n. 2
0
def test_multi_mm(user_number,
                  path_need,
                  smoothing=2,
                  interpolate_interval=15,
                  interpolate=True):
    '''
    Test Multi_mm class.
    :param user_number: Random User number use
    :param path_need: Path number used
    :param smoothing:
    :param interpolate_interval:
    :param interpolate:
    :return:
    '''

    # Get observations
    with open('../../res/work/0311_random_trajectories/random_user%d.json' %
              user_number) as data_file:
        data = json.load(data_file)

    obses = []
    for i in path_need:
        tmp = data['trajectories'][i]
        dates = [get_datetime(t) for t in tmp['dates']]
        obs = pd.DataFrame({
            'lon': tmp['lon'],
            'lat': tmp['lat'],
            'dates': dates
        })
        obses.append(obs)

    # Get graph
    graph = get_graph('../../data/hefei_road/link_baidu.txt')

    matched_obses = []
    mean_obs = Observations(obses).get_mean_obs(30)
    obses.append(mean_obs)
    for obs in obses:
        track = CTrack(obs,
                       g=graph,
                       smoothing=smoothing,
                       interpolate_interval=interpolate_interval,
                       interpolate=interpolate)
        matched_obs = track.viterbi()
        matched_obses.append(matched_obs)

    trajectories_tojson(
        matched_obses,
        data['user_id'],
        '../../res/work/0315_similar_trajectories/multiHMM_random_user%d.js' %
        user_number,
        is_json=False)
    trajectories_tojson(
        matched_obses,
        data['user_id'],
        '../../res/work/0315_similar_trajectories/multiHMM_random_user%d.json'
        % user_number,
        is_json=True)
Esempio n. 3
0
    def __init__(self, signal_dir=SIGNAL_DIR,
                 cells_path=CELLS_PATH,
                 user_path=USER_PATH,
                 work_dir=WORK_DIR,
                 graph_path=GRAPH_PATH,
                 user_num=None,
                 max_seconds=60.0 * 30,
                 min_set_len=5, max_distance=3000,
                 max_angle=5, max_speed=200 * 1000 / 3600):
        '''
        A BigEye system environment
        :param signal_dir: The directory saves signal data. Must end with '/'
                           Signal data is a csv, with columns ['cell_id', 'user_id', 'dates']
                           E.x: '../../res/work/0307_oneuser_alldata/'
        :param cells_path: The path of cells csv.
                           Cells data is a csv, with columns ['cell_id', 'lon', 'lat']
                           E.x: '../../res/[0926]cells_process.csv'
        :param user_path: The path of random users csv.
                          Random users data is a csv, with columns ['user_id']
                          E.x: '../../res/work/0307_oneuser_alldata/rand_users.csv'
        :param user_num: If user == None, signals is from the same user.
        :param max_seconds:
        :param min_set_len:
        :param max_distance:
        :param max_angle:
        :param max_speed:
        '''
        self.signal_dir = signal_dir
        self.work_dir = work_dir
        self.graph_path = graph_path
        self.random_user_signal_dir = work_dir + 'random_user_signals/'
        self.check_dir(self.random_user_signal_dir)

        self.user_num = user_num
        self.max_seconds = max_seconds
        self.min_set_len = min_set_len
        self.max_distance = max_distance
        self.max_angle = max_angle
        self.max_speed = max_speed

        # Get cells
        self.cells = self.get_cells(cells_path)

        # Get graph
        self.graph = get_graph(self.graph_path)

        # Random users
        self.users = self.get_users(user_path)
Esempio n. 4
0
def output_obs_data(trail,
                    direction,
                    n,
                    type='cell',
                    interpolate_interval=5,
                    smoothing=20,
                    interpolate=True):
    '''
    Output observables data after pre-processing. For test wuhu data
    :param trail: <Int> The i_th trail
    :param direction: <-1/1> -1 means reverse side; 1 means front.
    :param n: The n_th test of this trail. If None, return all the tests of the trail.
    :param type: 'cell' or 'GPS'. See details in function get_obs_data.
    :param interpolate_interval: Interval seconds of processed observables. Default = 1.
    :param smoothing: Window length of smoothing. If smoothing == 0, do not smooth.
    :param interpolate:
    :return: None.
    '''
    df = get_road_tests(trail, direction, n)
    graph = get_graph('../../data/road_test/link_baidu_wuhu.txt')
    obs = get_obs_data(df, type=type)
    track = CTrack(obs,
                   graph,
                   smoothing=smoothing,
                   interpolate_interval=interpolate_interval,
                   interpolate=interpolate)
    out = track.obs
    out['dates'] = out.time
    direction = u'正向' if direction == 1 else u'反向'
    if interpolate:
        output_data_js(
            out,
            '../../res/MapMatching_test/processed_%s/wuhu_线路%d_%s%d_smoothing=%d_window=%d.js'
            % (type, trail, direction, n, smoothing, interpolate_interval))
    else:
        output_data_js(
            out, '../../res/MapMatching_test/raw_%s/wuhu_线路%d_%s%d.js' %
            (type, trail, direction, n))
Esempio n. 5
0
def read_js(file):
    f = open(file)
    content = f.read()
    content = re.search(r'\[\[(.*?)\]\]', content).groups(0)[0]
    pos = content.split('], [')
    lon = []
    lat = []
    for p in pos:
        lon.append(float(p.split(', ')[0]))
        lat.append(float(p.split(', ')[1]))
    f.close()
    res1 = ['%.5f|%.5f' % (lon[i], lat[i]) for i in range(len(lon))]
    # res2 = [[lon[i], [lat[i]]] for i in range(len(lon))]
    return res1


if __name__ == '__main__':
    graph = get_graph('../../data/road_test/link_baidu_wuhu.txt')
    for n in range(1, 11):
        for direction in [-1, 1]:
            for trail in range(1, 9):
                evaluate_test(trail,
                              direction,
                              n,
                              graph,
                              smoothing=20,
                              interpolate_interval=5)
    # df = get_road_tests(9, -1, 1)
    # print(df.head())
Esempio n. 6
0
    file_date = '2017%.2d%.2d' % (mon, dd)
    '''Get Data'''
    # get signals data
    filename = (
        '../../data/signals_pro/%.2d%.2d/%.2dt%.2d/signals_%.2dt%.2d_within_users.csv'
        % (mon, dd, hh_start, hh_end, hh_start, hh_end))
    signals = get_signals_from_csv(filename)
    signals = signals[['cell_id', 'user_id', 'dates']]

    # get cells data
    cells = pd.read_csv('../../res/[0926]cells_process.csv')
    cells_loc = cells[['cell_id', 'lat', 'lon']]

    users = signals['user_id'].unique()

    graph = get_graph('../../data/hefei_road/link_baidu.txt')
    user_id = users[10]
    signal, ind_sets, signal_sets = get_trajectory(signals, cells_loc, user_id)
    print(cal_rough_speed_per_cell2(signal))
    for i in range(len(signal_sets)):
        if i != 1: continue
        obs = pd.DataFrame({
            'time': signal_sets[i]['dates'],
            'lon': signal_sets[i]['lon'],
            'lat': signal_sets[i]['lat']
        })
        # print(obs)
        obs = deal_same_obs(obs)[0:8]
        check_directory('../../res/MapMatching/%s' % user_id)
        output_data_js(
            obs, '../../res/MapMatching/%s/raw_trajectory%d.js' % (user_id, i))