Skip to content

Commit

Permalink
fix(navigation): add set indexes after condition.resolve(values)
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 2ae3fb3 commit 962167a
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions rdmo/projects/progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ def evaluate_conditions(conditions: QuerySet, values: QuerySet[Value]) -> Dict[i
# return all true conditions for this project
condition_true_ids = defaultdict(set)
for condition in conditions:
resolved_value_set_indexes = {value.set_index for value in values if condition.resolve([value])}
if resolved_value_set_indexes:
if condition.resolve(values):
resolved_value_set_indexes = {value.set_index for value in values if condition.resolve([value])}
condition_true_ids[condition.id].update(resolved_value_set_indexes)
return condition_true_ids

Expand All @@ -57,7 +57,6 @@ def compute_navigation(section, project, snapshot=None):
condition_true_ids = evaluate_conditions(conditions, values)
# compute sets from values (including empty values)
sets = compute_sets_from_values(values)

# query distinct, non empty set values
values_list = values.exclude_empty().distinct_list()

Expand Down Expand Up @@ -164,27 +163,28 @@ def count_questions(element, sets, conditions):
child_conditions = set()

if not child_conditions or child_conditions.intersection(conditions):
if isinstance(child, Question) and child.attribute:
if isinstance(child, Question):
# for regular questions add the set_count to the counts dict, since the
# question should be answered in every set
# for optional questions add just the number of present answers, so that
# only answered questions count for the progress/navigation
# use the max function, since the same attribute could appear twice in the tree
if child.is_optional:
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:
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)
if child.attribute:
if child.is_optional:
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:
current_set_count = set_count
counts[child.attribute.id] = max(counts[child.attribute.id], current_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 962167a

Please sign in to comment.