Skip to content

Commit 9490a9f

Browse files
committed
add perf_ceiling in rating computation
1 parent 4d1b682 commit 9490a9f

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

judge/ratings.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from bisect import bisect
2-
from math import pi, sqrt, tanh
2+
from math import inf, pi, sqrt, tanh
33
from operator import attrgetter, itemgetter
44

55
from django.db import transaction
@@ -19,6 +19,7 @@
1919
VAR_LIM = (sqrt(VAR_PER_CONTEST**2 + 4 * BETA2 * VAR_PER_CONTEST) - VAR_PER_CONTEST) / 2
2020
SD_LIM = sqrt(VAR_LIM)
2121
TANH_C = sqrt(3) / pi
22+
PERF_CEILING_INCREMENT = 400
2223

2324

2425
def tie_ranker(iterable, key=attrgetter('points')):
@@ -77,7 +78,7 @@ def get_var(times_ranked, cache=[VAR_INIT]):
7778
return cache[times_ranked]
7879

7980

80-
def recalculate_ratings(ranking, old_mean, times_ranked, historical_p):
81+
def recalculate_ratings(ranking, old_mean, times_ranked, historical_p, perf_ceiling):
8182
n = len(ranking)
8283
new_p = [0.] * n
8384
new_mean = [0.] * n
@@ -96,7 +97,7 @@ def solve_idx(i, bounds=VALID_RANGE):
9697
elif s < r: # s beats r
9798
y_tg -= 1. / d
9899
# Otherwise, this is a tie that counts as half a win, as per Elo-MMR.
99-
new_p[i] = solve(p_tanh_terms, y_tg, bounds=bounds)
100+
new_p[i] = min(perf_ceiling, solve(p_tanh_terms, y_tg, bounds=bounds))
100101

101102
# Fill all indices between i and j, inclusive. Use the fact that new_p is non-increasing.
102103
def divconq(i, j):
@@ -160,6 +161,9 @@ def rate_contest(contest):
160161
users = users.exclude(last_rating__lt=contest.rating_floor)
161162
if contest.rating_ceiling is not None:
162163
users = users.exclude(last_rating__gt=contest.rating_ceiling)
164+
perf_ceiling = contest.rating_ceiling + PERF_CEILING_INCREMENT
165+
else:
166+
perf_ceiling = inf
163167

164168
users = list(users)
165169
participation_ids = list(map(itemgetter('id'), users))
@@ -176,7 +180,7 @@ def rate_contest(contest):
176180
idx = user_id_to_idx[h['user_id']]
177181
historical_p[idx].append(h['performance'])
178182

179-
rating, mean, performance = recalculate_ratings(ranking, old_mean, times_ranked, historical_p)
183+
rating, mean, performance = recalculate_ratings(ranking, old_mean, times_ranked, historical_p, perf_ceiling)
180184

181185
now = timezone.now()
182186
ratings = [Rating(user_id=i, contest=contest, rating=r, mean=m, performance=perf,

0 commit comments

Comments
 (0)