Esempio n. 1
0
def test_bbb_iter_small_frame_window(tmpdir):
    """Tests that iter_frame returns frames if time window is small."""
    repo = Repository(str(tmpdir.join('frames_from_to_small_window')))
    repo_start = 0
    nFC = 10
    span = 1000
    nFrames = nFC * span
    repo_end = repo_start + nFrames
    begin_end_cam_id = [(ts, ts + span, 0)
                        for ts in range(repo_start, repo_end, span)]
    for begin, end, cam_id in begin_end_cam_id:
        fc = build_frame_container(begin, end, cam_id)
        fc.init('frames', span)
        for i, tstamp in enumerate(range(begin, end)):
            frame = fc.frames[i]
            frame.id = tstamp
            frame.timestamp = tstamp
        repo.add(fc)

    begin = 1
    end = 10
    fnames = list(repo.iter_frames(begin, end))
    assert (len(fnames) > 0)

    begin = 1001
    end = 1011
    fnames = list(repo.iter_fnames(begin, end))
    assert (len(fnames) > 0)
def test_bbb_repo_iter_frames_filtered(tmpdir):
    repo = Repository(str(tmpdir.join('frames_from_to_filtered')))
    repo_start = 0
    nFC = 10
    span = 1000
    nFrames = nFC * span
    repo_end = repo_start + nFrames
    begin_end_cam_id = [(ts, ts + span, 0)
                        for ts in range(repo_start, repo_end, span)]
    for begin, end, cam_id in begin_end_cam_id:
        fc = build_frame_container(begin, end, cam_id)
        fc.init('frames', span)
        for i, tstamp in enumerate(range(begin, end)):
            frame = fc.frames[i]
            frame.id = tstamp
            frame.timestamp = tstamp
        repo.add(fc)

    timestamps = [f[0].timestamp for f in repo.iter_frames(begin, end)]
    selected_timestamps = set(np.random.choice(timestamps, size=5, replace=False))

    class TimestepFilter():
        def __init__(self, timesteps):
            self.timesteps = timesteps

        def __call__(self, frame):
            return frame.timestamp in self.timesteps

    filtered_frames = list(repo.iter_frames(begin, end,
                                            frame_filter=TimestepFilter(selected_timestamps)))
    filtered_timestamps = set([f[0].timestamp for f in filtered_frames])

    assert(filtered_timestamps == selected_timestamps)
def test_bbb_iter_small_frame_window(tmpdir):
    """Tests that iter_frame returns frames if time window is small."""
    repo = Repository(str(tmpdir.join('frames_from_to_small_window')))
    repo_start = 0
    nFC = 10
    span = 1000
    nFrames = nFC * span
    repo_end = repo_start + nFrames
    begin_end_cam_id = [(ts, ts + span, 0)
                        for ts in range(repo_start, repo_end, span)]
    for begin, end, cam_id in begin_end_cam_id:
        fc = build_frame_container(begin, end, cam_id)
        fc.init('frames', span)
        for i, tstamp in enumerate(range(begin, end)):
            frame = fc.frames[i]
            frame.id = tstamp
            frame.timestamp = tstamp
        repo.add(fc)

    begin = 1
    end = 10
    fnames = list(repo.iter_frames(begin, end))
    assert(len(fnames) > 0)

    begin = 1001
    end = 1011
    fnames = list(repo.iter_fnames(begin, end))
    assert(len(fnames) > 0)
Esempio n. 4
0
def test_bbb_repo_open_frame_container(tmpdir):
    repo = Repository(str(tmpdir))
    cam_id = 1
    fc = build_frame_container(1000, 5000, cam_id)

    repo.add(fc)
    open_fc = repo.open(2000, 1)
    assert fc.fromTimestamp == open_fc.fromTimestamp
    assert fc.toTimestamp == open_fc.toTimestamp
def test_bbb_repo_open_frame_container(tmpdir):
    repo = Repository(str(tmpdir))
    cam_id = 1
    fc = build_frame_container(1000, 5000, cam_id)

    repo.add(fc)
    open_fc = repo.open(2000, 1)
    assert fc.fromTimestamp == open_fc.fromTimestamp
    assert fc.toTimestamp == open_fc.toTimestamp
Esempio n. 6
0
def test_bbb_iter_frames_from_to(tmpdir):
    """Tests that only frames in given range are iterated."""
    repo = Repository(str(tmpdir.join('frames_from_to')))
    repo_start = 0
    nFC = 10
    span = 1000
    nFrames = nFC * span
    repo_end = repo_start + nFrames
    begin_end_cam_id = [(ts, ts + span, 0)
                        for ts in range(repo_start, repo_end, span)]
    for begin, end, cam_id in begin_end_cam_id:
        fc = build_frame_container(begin, end, cam_id)
        fc.init('frames', span)
        for i, tstamp in enumerate(range(begin, end)):
            frame = fc.frames[i]
            frame.id = tstamp
            frame.timestamp = tstamp
        repo.add(fc)

    def check_tstamp_invariant(begin, end):
        """Helper to check if begin <= tstamp < end is true for all frames."""
        for frame, fc in repo.iter_frames(begin, end):
            # frame container invariant
            assert begin < fc.toTimestamp
            assert fc.fromTimestamp < end
            # frame invariant
            assert begin <= frame.timestamp < end

    # repo_start < start < end < repo_end
    check_tstamp_invariant(repo_start + 10, repo_end - 10)
    # start < repo_start < end < repo_end
    check_tstamp_invariant(repo_start - 10, repo_end - 10)
    # start < end < repo_start < repo_end
    check_tstamp_invariant(repo_start - 20, repo_start - 10)
    # repo_start < start < repo_end < end
    check_tstamp_invariant(repo_start + 10, repo_end + 10)
    # repo_start < repo_end < start < end
    check_tstamp_invariant(repo_end + 10, repo_end + 20)

    # check whole length
    all_frames = [f for f, _ in repo.iter_frames()]
    assert len(all_frames) == nFrames
    # check with begin = None
    skip_end = [f for f, _ in repo.iter_frames(end=repo_end - span)]
    assert len(skip_end) == nFrames - span
    # check with end = None
    skip_start = [f for f, _ in repo.iter_frames(begin=span)]
    assert len(skip_start) == nFrames - span
def test_bbb_iter_frames_from_to(tmpdir):
    """Tests that only frames in given range are iterated."""
    repo = Repository(str(tmpdir.join('frames_from_to')))
    repo_start = 0
    nFC = 10
    span = 1000
    nFrames = nFC * span
    repo_end = repo_start + nFrames
    begin_end_cam_id = [(ts, ts + span, 0)
                        for ts in range(repo_start, repo_end, span)]
    for begin, end, cam_id in begin_end_cam_id:
        fc = build_frame_container(begin, end, cam_id)
        fc.init('frames', span)
        for i, tstamp in enumerate(range(begin, end)):
            frame = fc.frames[i]
            frame.id = tstamp
            frame.timestamp = tstamp
        repo.add(fc)

    def check_tstamp_invariant(begin, end):
        """Helper to check if begin <= tstamp < end is true for all frames."""
        for frame, fc in repo.iter_frames(begin, end):
            # frame container invariant
            assert begin < fc.toTimestamp
            assert fc.fromTimestamp < end
            # frame invariant
            assert begin <= frame.timestamp < end

    # repo_start < start < end < repo_end
    check_tstamp_invariant(repo_start + 10, repo_end - 10)
    # start < repo_start < end < repo_end
    check_tstamp_invariant(repo_start - 10, repo_end - 10)
    # start < end < repo_start < repo_end
    check_tstamp_invariant(repo_start - 20, repo_start - 10)
    # repo_start < start < repo_end < end
    check_tstamp_invariant(repo_start + 10, repo_end + 10)
    # repo_start < repo_end < start < end
    check_tstamp_invariant(repo_end + 10, repo_end + 20)

    # check whole length
    all_frames = [f for f, _ in repo.iter_frames()]
    assert len(all_frames) == nFrames
    # check with begin = None
    skip_end = [f for f, _ in repo.iter_frames(end=repo_end - span)]
    assert len(skip_end) == nFrames - span
    # check with end = None
    skip_start = [f for f, _ in repo.iter_frames(begin=span)]
    assert len(skip_start) == nFrames - span
Esempio n. 8
0
def test_bbb_repo_add_frame_container(tmpdir):
    repo = Repository(str(tmpdir))
    cam_id = 1
    fc = build_frame_container(1000, 5000, 1)

    repo.add(fc)
    fnames = repo.find(1000)
    expected_fname = repo._get_filename(fc.fromTimestamp, fc.toTimestamp,
                                        cam_id, 'bbb')
    expected_fname = os.path.basename(expected_fname)
    assert os.path.basename(fnames[0]) == expected_fname

    fnames = repo.find(1500)
    assert os.path.basename(fnames[0]) == expected_fname

    fnames = repo.find(2500)
    assert os.path.basename(fnames[0]) == expected_fname
def test_bbb_repo_add_frame_container(tmpdir):
    repo = Repository(str(tmpdir))
    cam_id = 1
    fc = build_frame_container(1000, 5000, 1)

    repo.add(fc)
    fnames = repo.find(1000)
    expected_fname = repo._get_filename(fc.fromTimestamp,
                                        fc.toTimestamp, cam_id, 'bbb')
    expected_fname = os.path.basename(expected_fname)
    assert os.path.basename(fnames[0]) == expected_fname

    fnames = repo.find(1500)
    assert os.path.basename(fnames[0]) == expected_fname

    fnames = repo.find(2500)
    assert os.path.basename(fnames[0]) == expected_fname
Esempio n. 10
0
def test_bbb_repo_iter_frames_filtered(tmpdir):
    repo = Repository(str(tmpdir.join('frames_from_to_filtered')))
    repo_start = 0
    nFC = 10
    span = 1000
    nFrames = nFC * span
    repo_end = repo_start + nFrames
    begin_end_cam_id = [(ts, ts + span, 0)
                        for ts in range(repo_start, repo_end, span)]
    for begin, end, cam_id in begin_end_cam_id:
        fc = build_frame_container(begin, end, cam_id)
        fc.init('frames', span)
        for i, tstamp in enumerate(range(begin, end)):
            frame = fc.frames[i]
            frame.id = tstamp
            frame.timestamp = tstamp
        repo.add(fc)

    timestamps = [f[0].timestamp for f in repo.iter_frames(begin, end)]
    selected_timestamps = set(
        np.random.choice(timestamps, size=5, replace=False))

    class TimestepFilter():
        def __init__(self, timesteps):
            self.timesteps = timesteps

        def __call__(self, frame):
            return frame.timestamp in self.timesteps

    filtered_frames = list(
        repo.iter_frames(begin,
                         end,
                         frame_filter=TimestepFilter(selected_timestamps)))
    filtered_timestamps = set([f[0].timestamp for f in filtered_frames])

    assert (filtered_timestamps == selected_timestamps)