def test_interpolate_single_missing_frame(): previous = Frame(1, 1.00, 3.00) following = Frame(3, 2.00, 6.00) expected = [Frame(2, 1.5, 4.5)] actual = interpolate_missing_frames(previous, following) assert expected == actual
def test_interpolate_multiple_missing_frames(): previous = Frame(1, 1.00, 5.00) following = Frame(5, 5.00, 1.00) expected = [Frame(2, 2.0, 4.0), Frame(3, 3.0, 3.0), Frame(4, 4.0, 2.0)] actual = interpolate_missing_frames(previous, following) assert expected == actual
def add_padding(frames, n): first_id = (frames[0].id % 15) if len(frames) > 0 else 0 padded_frames = [] padded_frames += [Frame(0, None, None, 0)] * first_id padded_frames += frames padded_frames += [Frame(0, None, None, 0)] * (n - len(padded_frames)) assert len(padded_frames) == n return padded_frames
def test_create_frames_interpolates_missing_frame(): trajectory = [(1, datetime.datetime(2017, 1, 1, 0, 0, 0), 100.0, 100.0, 0, 0), (1, datetime.datetime(2017, 1, 1, 0, 1, 0), 200.0, 200.0, 0, 0)] expected_frames = [ Frame(0, 100.0, 100.0), Frame(1, 150.0, 150.0), Frame(2, 200.0, 200.0) ] actual_frames = create_frames(trajectory) assert actual_frames == expected_frames
def test_create_frames_groups_sample_in_same_minute(): trajectory = [ (1, datetime.datetime(2017, 1, 1, 0, 0, 0), 100.0, 100.5, 0, 0), (1, datetime.datetime(2017, 1, 1, 0, 0, 30), 100.0, 100.5, 0, 0), (1, datetime.datetime(2017, 1, 1, 0, 0, 59), 100.0, 100.5, 0, 0), (1, datetime.datetime(2017, 1, 1, 0, 1, 0), 105.0, 105.5, 0, 0) ] expected_frames = [ Frame(0, 100.0, 100.5), Frame(1, 100.0, 100.5), Frame(2, 105.0, 105.5) ] actual_frames = create_frames(trajectory) assert actual_frames == expected_frames
def test_create_frames_performs_sed_to_select_samples_in_same_frame(): trajectory = [ (1, datetime.datetime(2017, 1, 1, 0, 1, 0), 100.0, 100.0, 0, 0), (1, datetime.datetime(2017, 1, 1, 0, 1, 30), 100.0, 100.5, 0, 0), (1, datetime.datetime(2017, 1, 1, 0, 1, 40), 200.0, 100.5, 0, 0), (1, datetime.datetime(2017, 1, 1, 0, 1, 59), 149.0, 104.5, 0, 0), (1, datetime.datetime(2017, 1, 1, 0, 2, 0), 150.0, 105.5, 0, 0) ] expected_frames = [ Frame(2, 100.0, 100.0), Frame(3, 200.0, 100.5), Frame(4, 150.0, 105.5) ] actual_frames = create_frames(trajectory) assert actual_frames == expected_frames
def test_create_frame_groups(): trajectory_id = 1 frames = [ Frame(1, 100.0, 100.0), Frame(2, 200.0, 100.0), Frame(3, 150.0, 150.0) ] i_frame = Frame(1, 100.0, 100.0) p_frames = [Frame(0, 0.0, 0.0), Frame(2, 100.0, 0.0), Frame(3, 50.0, 50.0)] p_frames += [Frame(0, 0.0, 0.0)] * 56 expected_frame_groups = [FrameGroup(trajectory_id, 1, i_frame, p_frames)] actual_frame_groups = create_frame_groups(trajectory_id, frames) assert actual_frame_groups == expected_frame_groups
def test_add_padding_fills_missing_frames_for_n_minutes_at_beginning_and_end(): frames = [Frame(2, 200.0, 100.0), Frame(3, 150.0, 150.0)] expected_frames = [ Frame(0, 0.0, 0.0), Frame(2, 200.0, 100.0), Frame(3, 150.0, 150.0) ] expected_frames += [Frame(0, 0.0, 0.0)] * 56 actual_frames = add_padding(frames, 59) assert actual_frames == expected_frames
def to_frame(self): return Frame(self.frame_id(), self.x, self.y, self.occupancy)
def test_create_frames_does_not_interpolate_last_missing_frames(): trajectory = [(1, datetime.datetime(2017, 1, 1, 0, 57, 0), 100.0, 100.0, 0, 0)] expected_frames = [Frame(114, 100.0, 100.0)] actual_frames = create_frames(trajectory) assert actual_frames == expected_frames
def test_delta_encoding(): i_frame = Frame(1, 100.0, 100.0) frame = Frame(1, 150.0, 50.0) expected_p_frame = Frame(1, 50.0, -50.0) actual_p_frame = delta_encode(i_frame, frame) assert actual_p_frame == expected_p_frame
def test_add_full_padding_frame(): frames = [] expected_frames = [Frame(0, 0, 0)] * 59 actual_frames = add_padding(frames, 59) assert actual_frames == expected_frames
def test_add_no_padding_if_frame_is_full(): frames = [Frame(1, 200.0, 100.0)] * 59 actual_frames = add_padding(frames, 59) assert actual_frames == frames
def test_error_on_interpolating_subsequent_frames(): previous = Frame(1, 1.00, 5.00) following = Frame(2, 5.00, 1.00) with pytest.raises(AssertionError): interpolate_missing_frames(previous, following)
def interpolate_missing_frames(previous, following): # assert (following.id - previous.id) > 1 missing_ids = range(previous.id + 1, following.id) longitudes = np.interp(missing_ids, (previous.id, following.id), (previous.x, following.x)) latitudes = np.interp(missing_ids, (previous.id, following.id), (previous.y, following.y)) return [Frame(missing_ids[i], longitudes[i], latitudes[i], previous.occupancy) for i in range(len(longitudes))]
def delta_encode(i_frame, frame): if any(frame.x is None for frame in [i_frame, frame]): return frame x = frame.x - i_frame.x y = frame.y - i_frame.y return Frame(frame.id, x, y, frame.occupancy)