def test_bbb_repo_iter_fnames_filtered(tmpdir): repo = Repository(str(tmpdir.join('complex_from_to_and_cam'))) span = 200 begin_end_cam_id0 = [(ts, ts + span, 0) for ts in range(0, 10000, span)] begin_end_cam_id1 = [(ts, ts + span, 1) for ts in range(0, 10000, span)] begin_end_cam_id = begin_end_cam_id0 + begin_end_cam_id1 fill_repository(repo, begin_end_cam_id) begin = 2500 end = 5000 cam = 0 fnames = list(repo.iter_fnames(begin, end, cam)) selected_fnames = np.random.choice(fnames, size=5, replace=False) selected_fnames = set([os.path.basename(f) for f in selected_fnames]) class FnameFilter(): def __init__(self, fnames): self.fnames = fnames def __call__(self, fname): return fname in self.fnames filtered_fnames = set( repo.iter_fnames(begin, end, cam, fname_filter=FnameFilter(selected_fnames))) filtered_fnames = set([os.path.basename(f) for f in filtered_fnames]) assert (filtered_fnames == selected_fnames)
def test_bbb_repo_iter_fnames_filtered(tmpdir): repo = Repository(str(tmpdir.join('complex_from_to_and_cam'))) span = 200 begin_end_cam_id0 = [(ts, ts + span, 0) for ts in range(0, 10000, span)] begin_end_cam_id1 = [(ts, ts + span, 1) for ts in range(0, 10000, span)] begin_end_cam_id = begin_end_cam_id0 + begin_end_cam_id1 fill_repository(repo, begin_end_cam_id) begin = 2500 end = 5000 cam = 0 fnames = list(repo.iter_fnames(begin, end, cam)) selected_fnames = np.random.choice(fnames, size=5, replace=False) selected_fnames = set([os.path.basename(f) for f in selected_fnames]) class FnameFilter(): def __init__(self, fnames): self.fnames = fnames def __call__(self, fname): return fname in self.fnames filtered_fnames = set(repo.iter_fnames(begin, end, cam, fname_filter=FnameFilter(selected_fnames))) filtered_fnames = set([os.path.basename(f) for f in filtered_fnames]) assert(filtered_fnames == selected_fnames)
def test_bbb_repo_iter_fnames_from_to_and_cam(tmpdir): repo = Repository(str(tmpdir.join('complex_from_to_and_cam'))) span = 200 begin_end_cam_id0 = [(ts, ts + span, 0) for ts in range(0, 10000, span)] begin_end_cam_id1 = [(ts, ts + span, 1) for ts in range(0, 10000, span)] begin_end_cam_id = begin_end_cam_id0 + begin_end_cam_id1 fill_repository(repo, begin_end_cam_id) begin = 2500 end = 5000 cam = 0 fnames = list(repo.iter_fnames(begin, end, cam)) for fname in fnames: assert os.path.isabs(fname) fbasenames = [os.path.basename(f) for f in fnames] print(begin_end_cam_id) slice_begin_end_cam_id = list( filter(lambda p: begin <= p[1] and p[0] < end and p[2] == cam, begin_end_cam_id)) expected_fnames = [ os.path.basename(repo._get_filename(*p, extension='bbb')) for p in slice_begin_end_cam_id ] assert fbasenames == expected_fnames
def test_bbb_repo_find_single_file_per_timestamp(tmpdir): repo = Repository(str(tmpdir)) span = 60*10 begin_end_cam_id = [(ts, ts + span, 0) for ts in range(0, 100000, span)] fill_repository(repo, begin_end_cam_id) assert repo.find(0)[0] == repo._get_filename(0, span, 0, 'bbb') assert repo.find(60*10)[0] == repo._get_filename(60*10, 60*10+span, 0, 'bbb') assert repo.find(1000000) == []
def test_bbb_repo_find_single_file_per_timestamp(tmpdir): repo = Repository(str(tmpdir)) span = 60 * 10 begin_end_cam_id = [(ts, ts + span, 0) for ts in range(0, 100000, span)] fill_repository(repo, begin_end_cam_id) assert repo.find(0)[0] == repo._get_filename(0, span, 0, 'bbb') assert repo.find(60 * 10)[0] == repo._get_filename(60 * 10, 60 * 10 + span, 0, 'bbb') assert repo.find(1000000) == []
def test_bbb_repo_end_after_last_file(tmpdir): repo = Repository(str(tmpdir.join('complex_from_to'))) span = 1500 begin_end_cam_id = [(ts, ts + span, 0) for ts in range(0, 10000, span)] fill_repository(repo, begin_end_cam_id) begin = 2500 end = 11000 fnames = list(repo.iter_fnames(begin, end)) for fname in fnames: assert os.path.isabs(fname)
def test_bbb_repo_iter_fnames_2_files_and_1_symlink_per_directory(tmpdir): repo = Repository(str(tmpdir.join('2_files_and_1_symlink_per_directory'))) span = 500 begin_end_cam_id = [(ts, ts + span + 100, 0) for ts in range(0, 10000, span)] fill_repository(repo, begin_end_cam_id) fnames = [os.path.basename(f) for f in repo.iter_fnames()] expected_fnames = [os.path.basename( repo._get_filename(*p, extension='bbb')) for p in begin_end_cam_id] assert fnames == expected_fnames
def test_bbb_repo_find_multiple_file_per_timestamp(tmpdir): repo = Repository(str(tmpdir)) span = 500 begin = 1000 end = 100000 begin_end_cam_id = [(ts, ts + span, 0) for ts in range(begin, end, span)] begin_end_cam_id += [(ts, ts + span, 1) for ts in range(begin, end, span)] fill_repository(repo, begin_end_cam_id) find_and_assert_begin(repo, 0, expect_begin=0, nb_files_found=0) find_and_assert_begin(repo, 1050, expect_begin=1000, nb_files_found=2) find_and_assert_begin(repo, 1499, expect_begin=1000, nb_files_found=2) find_and_assert_begin(repo, 1500, expect_begin=1500, nb_files_found=2)
def test_bbb_repo_iter_fnames_missing_directories(tmpdir): repo = Repository(str(tmpdir.join('missing_directories'))) span = 1500 begin_end_cam_id = [(ts, ts + span, 0) for ts in range(0, 10000, span)] fill_repository(repo, begin_end_cam_id) fnames = list(repo.iter_fnames()) for fname in fnames: assert os.path.isabs(fname) fbasenames = [os.path.basename(f) for f in fnames] expected_fnames = [os.path.basename( repo._get_filename(*p, extension='bbb')) for p in begin_end_cam_id] assert fbasenames == expected_fnames
def test_bbb_repo_iter_fnames_2_files_and_1_symlink_per_directory(tmpdir): repo = Repository(str(tmpdir.join('2_files_and_1_symlink_per_directory'))) span = 500 begin_end_cam_id = [(ts, ts + span + 100, 0) for ts in range(0, 10000, span)] fill_repository(repo, begin_end_cam_id) fnames = [os.path.basename(f) for f in repo.iter_fnames()] expected_fnames = [ os.path.basename(repo._get_filename(*p, extension='bbb')) for p in begin_end_cam_id ] assert fnames == expected_fnames
def test_bbb_repo_iter_fnames_missing_directories(tmpdir): repo = Repository(str(tmpdir.join('missing_directories'))) span = 1500 begin_end_cam_id = [(ts, ts + span, 0) for ts in range(0, 10000, span)] fill_repository(repo, begin_end_cam_id) fnames = list(repo.iter_fnames()) for fname in fnames: assert os.path.isabs(fname) fbasenames = [os.path.basename(f) for f in fnames] expected_fnames = [ os.path.basename(repo._get_filename(*p, extension='bbb')) for p in begin_end_cam_id ] assert fbasenames == expected_fnames
def example_experiment_repo(request): tmpdir = tempfile.mkdtemp(prefix=os.path.dirname(__file__) + "_tmpdir_") repo = Repository(tmpdir) experiment_duration = 6 * 7 * 24 * 3600 one_video = int(1024 / 3) begin = int(time.time()) end = begin + experiment_duration begin_end_cam_id = [] for cam_id in range(4): begin_end_cam_id.extend([(ts, ts + one_video, cam_id) for ts in range(begin, end, one_video)]) fill_repository(repo, begin_end_cam_id) def fin(): shutil.rmtree(tmpdir) request.addfinalizer(fin) return repo, begin, end
def test_bbb_repo_iter_fnames_from_to(tmpdir): repo = Repository(str(tmpdir.join('complex_from_to'))) span = 1500 begin_end_cam_id = [(ts, ts + span, 0) for ts in range(0, 10000, span)] fill_repository(repo, begin_end_cam_id) begin = 2500 end = 5000 fnames = list(repo.iter_fnames(begin, end)) for fname in fnames: assert os.path.isabs(fname) fbasenames = [os.path.basename(f) for f in fnames] slice_begin_end_cam_id = list( filter(lambda p: begin <= p[1] and p[0] < end, begin_end_cam_id)) print(slice_begin_end_cam_id) expected_fnames = [ os.path.basename(repo._get_filename(*p, extension='bbb')) for p in slice_begin_end_cam_id ] print(expected_fnames) print(fbasenames) assert fbasenames == expected_fnames
def test_bbb_repo_iter_fnames_from_to(tmpdir): repo = Repository(str(tmpdir.join('complex_from_to'))) span = 1500 begin_end_cam_id = [(ts, ts + span, 0) for ts in range(0, 10000, span)] fill_repository(repo, begin_end_cam_id) begin = 2500 end = 5000 fnames = list(repo.iter_fnames(begin, end)) for fname in fnames: assert os.path.isabs(fname) fbasenames = [os.path.basename(f) for f in fnames] slice_begin_end_cam_id = list(filter(lambda p: begin <= p[1] and p[0] < end, begin_end_cam_id)) print(slice_begin_end_cam_id) expected_fnames = [ os.path.basename(repo._get_filename(*p, extension='bbb')) for p in slice_begin_end_cam_id] print(expected_fnames) print(fbasenames) assert fbasenames == expected_fnames
def test_bbb_repo_iter_fnames_from_to_and_cam(tmpdir): repo = Repository(str(tmpdir.join('complex_from_to_and_cam'))) span = 200 begin_end_cam_id0 = [(ts, ts + span, 0) for ts in range(0, 10000, span)] begin_end_cam_id1 = [(ts, ts + span, 1) for ts in range(0, 10000, span)] begin_end_cam_id = begin_end_cam_id0 + begin_end_cam_id1 fill_repository(repo, begin_end_cam_id) begin = 2500 end = 5000 cam = 0 fnames = list(repo.iter_fnames(begin, end, cam)) for fname in fnames: assert os.path.isabs(fname) fbasenames = [os.path.basename(f) for f in fnames] print(begin_end_cam_id) slice_begin_end_cam_id = list(filter( lambda p: begin <= p[1] and p[0] < end and p[2] == cam, begin_end_cam_id)) expected_fnames = [ os.path.basename(repo._get_filename(*p, extension='bbb')) for p in slice_begin_end_cam_id] assert fbasenames == expected_fnames