Skip to content

Commit

Permalink
Change rule from measurements to classification
Browse files Browse the repository at this point in the history
  • Loading branch information
nagem committed Feb 21, 2017
1 parent c1b57a9 commit b93d806
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
17 changes: 8 additions & 9 deletions api/jobs/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# "any": [
# ["file.type", "dicom" ] # Match the file's type
# ["file.name", "*.dcm" ] # Match a shell glob for the file name
# ["file.measurements", "diffusion" ] # Match any of the file's measurements
# ["file.classification", "diffusion" ] # Match any of the file's classifications
# ["container.has-type", "bvec" ] # Match the container having any file (including this one) with this type
# ]
#
Expand All @@ -31,7 +31,7 @@
MATCH_TYPES = [
'file.type',
'file.name',
'file.measurements',
'file.classification',
'container.has-type'
]

Expand Down Expand Up @@ -62,13 +62,12 @@ def eval_match(match_type, match_param, file_, container):
elif match_type == 'file.name':
return fnmatch.fnmatch(file_['name'], match_param)

# Match any of the file's measurements
elif match_type == 'file.measurements':
try:
return match_param in file_['measurements']
except KeyError:
_log_file_key_error(file_, container, 'has no measurements key')
return False
# Match any of the file's classifications
elif match_type == 'file.classification':
for v in file_.get('classification', {}).itervalues():
if match_param in v:
return True
return False

# Match the container having any file (including this one) with this type
elif match_type == 'container.has-type':
Expand Down
4 changes: 2 additions & 2 deletions test/unit_tests/python/test_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ def test_eval_match_file_name_match_relative():
result = rules.eval_match(*args)
assert result == False

def test_eval_match_file_measurements():
part = rulePart(match_type='file.measurements', file_={'measurements': ['a', 'diffusion', 'b'] })
def test_eval_match_file_classification():
part = rulePart(match_type='file.classification', file_={'classification': {'custom': ['a', 'diffusion', 'b'] }})

args = part.gen(match_param='diffusion')
result = rules.eval_match(*args)
Expand Down

0 comments on commit b93d806

Please sign in to comment.