Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions scoring/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,15 +473,19 @@ def assign_ranks(
def assign_prize_percentages(
entries: list[LeaderboardEntry], minimum_prize_percent: float
) -> list[LeaderboardEntry]:
total_take = sum(e.take for e in entries if not e.excluded and e.take is not None)
for entry in entries:
# Distribute prize % according to take
# anyone who takes less than the minimum gets redistributed up iteratively
scoring_take = sum((e.take or 0) * int(not e.excluded) for e in entries)
for entry in entries[::-1]: # start in reverse
entry.percent_prize = 0
if total_take and not entry.excluded and entry.take is not None:
percent_prize = entry.take / total_take
if percent_prize >= minimum_prize_percent:
# only give percent prize if it's above the minimum
entry.percent_prize = percent_prize
# renormalize percent_prize to sum to 1
if entry.excluded or not entry.take:
continue
percent_prize = entry.take / (scoring_take or 1)
if percent_prize < minimum_prize_percent:
# remove take from pool since they don't get prize
scoring_take -= entry.take
else:
entry.percent_prize = percent_prize
percent_prize_sum = sum(entry.percent_prize for entry in entries) or 1
for entry in entries:
entry.percent_prize /= percent_prize_sum
Expand Down
1 change: 1 addition & 0 deletions tests/unit/test_scoring/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class TestScoringUtilsHelpers:
([6, 3, 1, 0], 0, [0.6, 0.3, 0.1, 0]),
([6, 3, 1, 0, -1], 0, [0.6, 0.3, 0.1, 0, 0]),
([6, 3, 1, 0, -1], 0.25, [2 / 3, 1 / 3, 0, 0, 0]),
([0.90, 0.049, 0.041, 0.01], 0.05, [0.90 / 0.949, 0.049 / 0.949, 0, 0]),
],
)
def test_prize_percentages(self, entry_takes, minimum_prize_percent, expected):
Expand Down