diff --git a/rdmo/projects/progress.py b/rdmo/projects/progress.py index 15c88e1f18..fc0eaa8955 100644 --- a/rdmo/projects/progress.py +++ b/rdmo/projects/progress.py @@ -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 @@ -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() @@ -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))