Skip to content

Commit

Permalink
Fix bugs in handling empty inputs field (#375)
Browse files Browse the repository at this point in the history
* Update processor_parser.py

* Update processors_v3.py

* handle missing proctype

* Update processor_parser.py

* less confusing code
  • Loading branch information
bud42 authored May 23, 2022
1 parent 7bab298 commit 19702b5
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 28 deletions.
2 changes: 1 addition & 1 deletion dax/XnatUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2619,7 +2619,7 @@ def get(self, name):

def type(self):
if self.proctype is None:
self.proctype = self.info()['proctype']
self.proctype = self.info().get('proctype', None)
return self.proctype

def info(self):
Expand Down
35 changes: 22 additions & 13 deletions dax/processor_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -946,28 +946,37 @@ def compare_to_existing(csesses, proc_type, parameter_matrix):

assessors = [[] for _ in range(len(parameter_matrix))]

existing_assessors = []

# Get of list assessors that have already been
# created on xnat for this processor/proctype
for casr in csess.assessors():
try:
proc_type_matches = (casr.type() == proc_type)
if proc_type_matches:
existing_assessors.append(casr)
except:
LOGGER.error(f'Failed to check type of {casr.label()}')
continue

# Check for any missing inputs fields in the existing assessors
for casr in existing_assessors:
# Check for empty inputs. If ANY of the assessors on this session
# have an empty inputs, then we cannot determine which input sets
# need to be built. We refuse to do anything by returning
# an empty list.
inputs = casr.get_inputs()
if inputs is None:
LOGGER.warn('assessor with empty inputs field, cannot build processor for session' + casr.label())
LOGGER.warn('assessor with empty inputs field, cannot build processor for session:' + casr.label())
return list()

try:
proc_type_matches = (casr.type() == proc_type)
except:
LOGGER.error(f'Failed to check type of {casr.label()}')
continue

if proc_type_matches:
for pi, p in enumerate(parameter_matrix):
if inputs == p:
# BDB 6/5/21 do we ever have more than one assessor
# with the same set of inputs?
assessors[pi].append(casr)
# Compare existing to the "to build" assessors in parameter_matrix
for casr in existing_assessors:
for pi, p in enumerate(parameter_matrix):
if inputs == p:
# BDB 6/5/21 do we ever have more than one assessor
# with the same set of inputs?
assessors[pi].append(casr)

return list(zip(copy.deepcopy(parameter_matrix), assessors))

Expand Down
35 changes: 21 additions & 14 deletions dax/processors_v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -1235,11 +1235,23 @@ def _generate_parameter_matrix(self, artefacts, artefacts_by_input):
return final_matrix

def _compare_to_existing(self, csess, parameter_matrix):
proc_type = self.proctype

assessors = [[] for _ in range(len(parameter_matrix))]

# Get of list assessors that have already been
# created on xnat for this processor/proctype
existing_assessors = []
for casr in csess.assessors():
# Check that proc type matches this processor
try:
proc_type_matches = (casr.type() == self.proctype)
if proc_type_matches:
existing_assessors.append(casr)
except:
LOGGER.warning(f'Unable to check match of {casr.label()} - ignoring')
continue

# Check for any missing inputs fields in the existing assessors
for casr in existing_assessors:
# Check for empty inputs. If ANY of the assessors on this session
# have an empty inputs, then we cannot determine which input sets
# need to be built. We refuse to do anything by returning
Expand All @@ -1249,18 +1261,13 @@ def _compare_to_existing(self, csess, parameter_matrix):
LOGGER.warn('assessor with empty inputs field, cannot build processor for session' + casr.label())
return list()

try:
proc_type_matches = (casr.type() == proc_type)
except:
LOGGER.warning(f'Unable to check match of {casr.label()} - ignoring')
continue

if proc_type_matches:
for pi, p in enumerate(parameter_matrix):
if inputs == p:
# BDB 6/5/21 do we ever have more than one assessor
# with the same set of inputs?
assessors[pi].append(casr)
# Compare existing to the "to build" assessors in parameter_matrix
for casr in existing_assessors:
for pi, p in enumerate(parameter_matrix):
if inputs == p:
# BDB 6/5/21 do we ever have more than one assessor
# with the same set of inputs?
assessors[pi].append(casr)

return list(zip(copy.deepcopy(parameter_matrix), assessors))

Expand Down

0 comments on commit 19702b5

Please sign in to comment.