def plot_velocity_histogram(data):
    delta_time = extract_delta_time(data) 
    velocities = compute_velocities(data)
    plots.plot(delta_time)
    plots.show()

    plots.hist(velocities*ms_to_mph, 100)
    plots.show()
def merge_trajectories(raw_trajectories_folder, results_file):
    onlyfiles = [f for f in os.listdir(raw_trajectories_folder)
                 if os.path.isfile(os.path.join(raw_trajectories_folder, f))]
    
    contents = []
    for name in onlyfiles:
        full_name = os.path.join(raw_trajectories_folder, name)
        contents.append(read_compressed_trajectory(full_name))
     
    contents.sort(key=lambda p: p[0, 0], reverse=False)    
    merged_traj = np.vstack(contents)
    merged_traj = apply_filter(merged_traj, DuplicateTimeFilter())
    dt = extract_delta_time(merged_traj)
    assert((dt > 0).all())
    write_compressed_trajectory(merged_traj, results_file)
def find_endpoints_batch(data):
    # get delta time array in seconds
    delta_time = extract_delta_time(data) 

    # get indices on the trajectory where we spend a lot of time still
    stationary_threshold = (60*60) * 3  # hours
    stationary_points = np.where(delta_time>stationary_threshold)[0]
    
    # filter out stationary points that are driving-distance (1km) close to each other
    is_index_close = lambda index1, index2: distance(data[index1], data[index2]) < 1000

    unique_locations = [stationary_points[0]]
    for s in stationary_points:
        candidates = [u for u in unique_locations
                      if is_index_close(s, u)]
        # location is unique if no candidates found
        if len(candidates) == 0:
            unique_locations.append(s)

    return unique_locations