diff --git a/service/config.py b/service/config.py index b81ce60..2a50466 100644 --- a/service/config.py +++ b/service/config.py @@ -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) ) diff --git a/service/league_service/league_rater.py b/service/league_service/league_rater.py index 08384f6..f1d537c 100644 --- a/service/league_service/league_rater.py +++ b/service/league_service/league_rater.py @@ -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: diff --git a/tests/unit_tests/test_league_rater.py b/tests/unit_tests/test_league_rater.py index e3f2be0..136480a 100644 --- a/tests/unit_tests/test_league_rater.py +++ b/tests/unit_tests/test_league_rater.py @@ -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 ) @@ -113,14 +113,14 @@ 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 @@ -128,10 +128,7 @@ def test_new_score_victory_highest_division_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 + config.HIGHEST_DIVISION_BOOST - ) + assert new_score.score == 2 def test_placement_after_enough_games(example_league, unplaced_player_score): @@ -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