Skip to content

Commit

Permalink
fix(progress): add check for resolved conditions in dataset count (#1103
Browse files Browse the repository at this point in the history
)

Signed-off-by: David Wallace <[email protected]>
  • Loading branch information
MyPyDavid committed Aug 7, 2024
1 parent 2c93c66 commit 4e99174
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions rdmo/projects/progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ def resolve_conditions(project, values):
.distinct().select_related('source', 'target_option')

# evaluate conditions
conditions = set()
conditions = defaultdict(set)
for condition in catalog_conditions:
if condition.resolve(values):
conditions.add(condition.id)
resolved_value_set_indexes = {value.set_index for value in values if condition.resolve([value])}
conditions[condition.id].update(resolved_value_set_indexes)

# return all true conditions for this project
return conditions
Expand Down Expand Up @@ -141,6 +142,7 @@ def count_questions(element, sets, conditions):

set_count = len(counted_sets)
else:
counted_sets = set()
set_count = 1

# loop over all children of this element
Expand All @@ -149,7 +151,7 @@ def count_questions(element, sets, conditions):
if isinstance(child, (Page, QuestionSet, Question)):
child_conditions = {condition.id for condition in child.conditions.all()}
else:
child_conditions = []
child_conditions = set()

if not child_conditions or child_conditions.intersection(conditions):
if isinstance(child, Question):
Expand All @@ -163,7 +165,17 @@ def count_questions(element, sets, conditions):
child_count = sum(len(set_indexes) for set_indexes in sets[child.attribute.id].values())
counts[child.attribute.id] = max(counts[child.attribute.id], child_count)
else:
counts[child.attribute.id] = max(counts[child.attribute.id], set_count)
resolved_condition_sets = set()
condition_intersection = list(child_conditions.intersection(conditions))
# update the set_count for the current child element
# check for the sets that have conditions resolved to true
for child_condition in condition_intersection:
resolved_condition_sets.update(conditions[child_condition])
if condition_intersection:
current_set_count = len(counted_sets & resolved_condition_sets)
else:
current_set_count = set_count
counts[child.attribute.id] = max(counts[child.attribute.id], current_set_count)
else:
# for everything else, call this function recursively
counts.update(count_questions(child, sets, conditions))
Expand Down

0 comments on commit 4e99174

Please sign in to comment.