Skip to content

Commit

Permalink
Pin score in highest division to rating (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
BlackYps authored Jun 23, 2024
1 parent 88a65fe commit 05663d5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
1 change: 0 additions & 1 deletion service/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
SCORE_GAIN = int(os.getenv("SCORE_GAIN", 1))
POSITIVE_BOOST = int(os.getenv("POSITIVE_BOOST", 1))
NEGATIVE_BOOST = int(os.getenv("NEGATIVE_BOOST", 1))
HIGHEST_DIVISION_BOOST = int(os.getenv("HIGHEST_DIVISION_BOOST", 1))
POINT_BUFFER_AFTER_DIVISION_CHANGE = int(
os.getenv("POINT_BUFFER_AFTER_DIVISION_CHANGE", 2)
)
13 changes: 8 additions & 5 deletions service/league_service/league_rater.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,18 @@ def _calculate_new_score(cls, league, current_score, outcome, rating, player_div
reduction = 0
higher_div = league.get_next_higher_division(player_div.id)

# Return score based on rating to have players in top division sorted by rating
if higher_div is None:
return (
player_div.highest_score
* (rating - player_div.min_rating)
/ (player_div.max_rating - player_div.min_rating)
)

if rating > player_div.max_rating:
boost = config.POSITIVE_BOOST
elif rating < player_div.min_rating:
reduction = config.NEGATIVE_BOOST
# Boost for high rated players with low score to have players in top division sorted by rating
elif higher_div is None and current_score.score < player_div.highest_score * (
rating - player_div.min_rating
) / (player_div.max_rating - player_div.min_rating):
boost = config.HIGHEST_DIVISION_BOOST

new_score = current_score.score
if outcome is GameOutcome.VICTORY:
Expand Down
15 changes: 6 additions & 9 deletions tests/unit_tests/test_league_rater.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def test_new_score_defeat_boost(example_league):
)


def test_new_score_victory_highest_division_no_boost(example_league):
def test_new_score_defeat_highest_division(example_league):
current_score = LeagueScore(
division_id=3, score=5, game_count=30, returning_player=False
)
Expand All @@ -113,25 +113,22 @@ def test_new_score_victory_highest_division_no_boost(example_league):

assert new_score.division_id == current_score.division_id
assert new_score.game_count == current_score.game_count + 1
assert new_score.score == current_score.score + config.SCORE_GAIN
assert new_score.score == 2


def test_new_score_victory_highest_division_boost(example_league):
def test_new_score_victory_highest_division(example_league):
current_score = LeagueScore(
division_id=3, score=5, game_count=30, returning_player=False
)
player_rating = (380.0, 0.0)
player_rating = (240.0, 0.0)

new_score = LeagueRater.rate(
example_league, current_score, GameOutcome.VICTORY, player_rating
)

assert new_score.division_id == current_score.division_id
assert new_score.game_count == current_score.game_count + 1
assert (
new_score.score
== current_score.score + config.SCORE_GAIN + config.HIGHEST_DIVISION_BOOST
)
assert new_score.score == 2


def test_placement_after_enough_games(example_league, unplaced_player_score):
Expand Down Expand Up @@ -315,7 +312,7 @@ def test_promote_in_highest_division(example_league):
current_score = LeagueScore(
division_id=3, score=10, game_count=30, returning_player=False
)
player_rating = (380.0, 0.0)
player_rating = (420.0, 0.0)

new_score = LeagueRater.rate(
example_league, current_score, GameOutcome.VICTORY, player_rating
Expand Down

0 comments on commit 05663d5

Please sign in to comment.