From 5c5bba5f7b672ae54cd30845bdb360bcb6f9aeaa Mon Sep 17 00:00:00 2001 From: cuom1999 Date: Wed, 2 Jun 2021 08:31:58 -0500 Subject: [PATCH] Fix out of index in stat page --- judge/views/contests.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/judge/views/contests.py b/judge/views/contests.py index 5875875..eea60b8 100644 --- a/judge/views/contests.py +++ b/judge/views/contests.py @@ -561,16 +561,16 @@ class ContestStats(TitleMixin, ContestMixin, DetailView): result_data[category['code']][i] = category['count'] problem_points = [[] for _ in range(num_problems)] - point_count = queryset.values('contest__problem__order', 'contest__points')\ - .annotate(count=Count('contest__points')) \ - .filter(points__isnull=False) \ - .order_by('contest__problem__order', 'contest__points') - + point_count_queryset = list(queryset.values('problem__code', 'contest__points', 'contest__problem__points') + .annotate(count=Count('contest__points')) + .filter(points__isnull=False) + .order_by('problem__code', 'contest__points') + .values_list('problem__code', 'contest__points', 'contest__problem__points', 'count')) counter = [[0 for _ in range(self.POINT_BIN + 1)] for _ in range(num_problems)] - for sub in point_count.iterator(): - problem_idx = sub['contest__problem__order'] - 1 - bin_idx = math.floor(sub['contest__points'] * self.POINT_BIN / 100) - counter[problem_idx][bin_idx] += sub['count'] + for problem_code, point, max_point, count in point_count_queryset: + problem_idx = codes.index(problem_code) + bin_idx = math.floor(point * self.POINT_BIN / max_point) + counter[problem_idx][bin_idx] += count for i in range(num_problems): problem_points[i] = [(j * 100 / self.POINT_BIN, counter[i][j]) for j in range(len(counter[i]))]