Skip to content

Commit

Permalink
Fix an empty outcome bug
Browse files Browse the repository at this point in the history
  • Loading branch information
matijapretnar committed Jan 29, 2024
1 parent f55b97e commit 66d8326
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion web/attempts/outcome.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from collections import defaultdict
from dataclasses import dataclass

from django.db.models import Count
Expand Down Expand Up @@ -65,7 +66,10 @@ def percentage_summary(self):
def group_dict(cls, parts, users, parts_group_by, users_group_by):
part_group_sizes = _group_sizes(parts, *parts_group_by)
user_group_sizes = _group_sizes(users, *users_group_by)
outcomes = {}
# If the group does not have any parts (for example if a problem
# contains only an explanation text in the description), then it
# does not appear in the results, and we return an empty outcome for it.
outcomes = defaultdict(cls)
for part_group, part_group_size in part_group_sizes.items():
for user_group, user_group_size in user_group_sizes.items():
outcomes[part_group + user_group] = cls(
Expand Down

0 comments on commit 66d8326

Please sign in to comment.