diff --git a/pretalx_musicrate/__init__.py b/pretalx_musicrate/__init__.py index 745162e..23f0070 100644 --- a/pretalx_musicrate/__init__.py +++ b/pretalx_musicrate/__init__.py @@ -1 +1 @@ -__version__ = "0.14.2" +__version__ = "0.14.3" diff --git a/pretalx_musicrate/management/commands/computescores.py b/pretalx_musicrate/management/commands/computescores.py index 56c74e9..0f057de 100644 --- a/pretalx_musicrate/management/commands/computescores.py +++ b/pretalx_musicrate/management/commands/computescores.py @@ -1,6 +1,6 @@ import math import statistics -from operator import itemgetter +from operator import attrgetter, itemgetter from django.core.management.base import BaseCommand, CommandError from django_scopes import scope @@ -31,12 +31,19 @@ class Command(BaseCommand): with scope(event=event): submissions = {} - for juror in event.jurors.prefetch_related("ratings"): - ratings = { - r.submission.code: int(r.rating) - for r in juror.ratings.exclude(rating="") - } - values = list(ratings.values()) + for juror in event.jurors.prefetch_related("ratings__submission").order_by( + "token" + ): + ratings = list( + juror.ratings.exclude(rating="").order_by("submission__created") + ) + values = list(map(int, map(attrgetter("rating"), ratings))) + ratings = dict( + zip( + map(attrgetter("code"), map(attrgetter("submission"), ratings)), + values, + ) + ) if len(values) < RATINGS_MIN: mean = MEAN @@ -52,7 +59,7 @@ class Command(BaseCommand): submissions[code] = [] submissions[code].append((ratings[code] - mean) / std * STD + MEAN) - for submission in Submission.objects.prefetch_related("score").filter( + for submission in Submission.objects.select_related("score").filter( code__in=submissions.keys() ): try: