haritsahm
commited on
Commit
·
8c5fd52
1
Parent(s):
b260939
Update filter to sort by cc first
Browse files- main.py +8 -1
- tests/test_file_filters.py +23 -2
main.py
CHANGED
@@ -67,13 +67,16 @@ def filter_files(files: List) -> List:
|
|
67 |
table = np.zeros((2, 2), dtype=bool)
|
68 |
bin_left = 0
|
69 |
bin_right = 0
|
70 |
-
|
|
|
71 |
|
72 |
splits = file.name.split('_')
|
73 |
|
74 |
# Check if view is present
|
75 |
if any(['cc' in part.lower() for part in splits]):
|
76 |
table[0, :] = [True, True]
|
|
|
|
|
77 |
if any(['mlo' in part.lower() for part in splits]):
|
78 |
table[1, :] = [True, True]
|
79 |
|
@@ -85,6 +88,10 @@ def filter_files(files: List) -> List:
|
|
85 |
table[:, 1] &= True
|
86 |
bin_right += 1
|
87 |
|
|
|
|
|
|
|
|
|
88 |
# Reset side that has not enough files
|
89 |
if bin_left < 2:
|
90 |
table[:, 0] &= False
|
|
|
67 |
table = np.zeros((2, 2), dtype=bool)
|
68 |
bin_left = 0
|
69 |
bin_right = 0
|
70 |
+
cc_first = False
|
71 |
+
for idx, file in enumerate(file_paths):
|
72 |
|
73 |
splits = file.name.split('_')
|
74 |
|
75 |
# Check if view is present
|
76 |
if any(['cc' in part.lower() for part in splits]):
|
77 |
table[0, :] = [True, True]
|
78 |
+
if idx == 0:
|
79 |
+
cc_first = True
|
80 |
if any(['mlo' in part.lower() for part in splits]):
|
81 |
table[1, :] = [True, True]
|
82 |
|
|
|
88 |
table[:, 1] &= True
|
89 |
bin_right += 1
|
90 |
|
91 |
+
# Ensure cc_first
|
92 |
+
if not cc_first:
|
93 |
+
file_paths.reverse()
|
94 |
+
|
95 |
# Reset side that has not enough files
|
96 |
if bin_left < 2:
|
97 |
table[:, 0] &= False
|
tests/test_file_filters.py
CHANGED
@@ -23,13 +23,16 @@ def filter_files(files: List[str]):
|
|
23 |
table = np.zeros((2, 2), dtype=bool)
|
24 |
bin_left = 0
|
25 |
bin_right = 0
|
26 |
-
|
|
|
27 |
|
28 |
splits = file.name.split('_')
|
29 |
|
30 |
# Check if view is present
|
31 |
if any(['cc' in part.lower() for part in splits]):
|
32 |
table[0, :] = [True, True]
|
|
|
|
|
33 |
if any(['mlo' in part.lower() for part in splits]):
|
34 |
table[1, :] = [True, True]
|
35 |
|
@@ -41,6 +44,10 @@ def filter_files(files: List[str]):
|
|
41 |
table[:, 1] &= True
|
42 |
bin_right += 1
|
43 |
|
|
|
|
|
|
|
|
|
44 |
# Reset side that has not enough files
|
45 |
if bin_left < 2:
|
46 |
table[:, 0] &= False
|
@@ -61,7 +68,7 @@ def filter_files(files: List[str]):
|
|
61 |
(['left_cc.png', 'left_cc.png'], False),
|
62 |
(['left_mlo.png', 'right_cc.png'], False),
|
63 |
(['no_mlo.png', 'left_cc.png'], False),
|
64 |
-
(['
|
65 |
(['right_cc.jpg', 'right_mlo.png'], True),
|
66 |
]
|
67 |
)
|
@@ -72,3 +79,17 @@ def test_filter_files(file_paths, expectation):
|
|
72 |
else:
|
73 |
with pytest.raises(Exception) as _:
|
74 |
_ = filter_files(file_paths)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
table = np.zeros((2, 2), dtype=bool)
|
24 |
bin_left = 0
|
25 |
bin_right = 0
|
26 |
+
cc_first = False
|
27 |
+
for idx, file in enumerate(file_paths):
|
28 |
|
29 |
splits = file.name.split('_')
|
30 |
|
31 |
# Check if view is present
|
32 |
if any(['cc' in part.lower() for part in splits]):
|
33 |
table[0, :] = [True, True]
|
34 |
+
if idx == 0:
|
35 |
+
cc_first = True
|
36 |
if any(['mlo' in part.lower() for part in splits]):
|
37 |
table[1, :] = [True, True]
|
38 |
|
|
|
44 |
table[:, 1] &= True
|
45 |
bin_right += 1
|
46 |
|
47 |
+
# Ensure cc_first
|
48 |
+
if not cc_first:
|
49 |
+
file_paths.reverse()
|
50 |
+
|
51 |
# Reset side that has not enough files
|
52 |
if bin_left < 2:
|
53 |
table[:, 0] &= False
|
|
|
68 |
(['left_cc.png', 'left_cc.png'], False),
|
69 |
(['left_mlo.png', 'right_cc.png'], False),
|
70 |
(['no_mlo.png', 'left_cc.png'], False),
|
71 |
+
(['left_mlo.png', 'left_cc.png'], True),
|
72 |
(['right_cc.jpg', 'right_mlo.png'], True),
|
73 |
]
|
74 |
)
|
|
|
79 |
else:
|
80 |
with pytest.raises(Exception) as _:
|
81 |
_ = filter_files(file_paths)
|
82 |
+
|
83 |
+
|
84 |
+
@pytest.mark.parametrize('unordered_paths,ordered_paths',
|
85 |
+
[
|
86 |
+
(['left_mlo.png', 'left_cc.png'],
|
87 |
+
['left_cc.png', 'left_mlo.png']),
|
88 |
+
(['right_cc.jpg', 'right_mlo.png'],
|
89 |
+
['right_cc.jpg', 'right_mlo.png']),
|
90 |
+
]
|
91 |
+
)
|
92 |
+
def test_sort_files(unordered_paths, ordered_paths):
|
93 |
+
filtered_paths = filter_files(unordered_paths)
|
94 |
+
filtered_paths = [str(path) for path in filtered_paths]
|
95 |
+
assert filtered_paths == ordered_paths
|