From d7df6d3d168415d4932b4b6605063743e48be969 Mon Sep 17 00:00:00 2001 From: Lexon <44340857+L-e-x-o-n@users.noreply.github.com> Date: Fri, 6 Dec 2024 15:07:29 +0100 Subject: [PATCH] Rate early leavers (#534) --- lib/teiserver/game/libs/match_rating_lib.ex | 114 +------------------- 1 file changed, 2 insertions(+), 112 deletions(-) diff --git a/lib/teiserver/game/libs/match_rating_lib.ex b/lib/teiserver/game/libs/match_rating_lib.ex index 590c792f4..258ceae35 100644 --- a/lib/teiserver/game/libs/match_rating_lib.ex +++ b/lib/teiserver/game/libs/match_rating_lib.ex @@ -198,17 +198,6 @@ defmodule Teiserver.Game.MatchRatingLib do # Run the actual calculation rate_result = rate_with_ids([winner_ratings, loser_ratings], as_map: true) - status_lookup = - if match.game_type in ["Small Team", "Large Team"] do - match.members - |> Map.new(fn membership -> - {membership.user_id, - MatchLib.calculate_exit_status(membership.left_after, match.game_duration)} - end) - else - %{} - end - # Save the results win_ratings = winners @@ -216,16 +205,7 @@ defmodule Teiserver.Game.MatchRatingLib do rating_update = rate_result[user_id] user_rating = rating_lookup[user_id] || BalanceLib.default_rating(rating_type_id) - case Map.get(status_lookup, user_id, nil) do - :abandoned -> - do_abandoned_rating(user_id, match, user_rating, rating_update) - - :noshow -> - do_noshow_rating(user_id, match, user_rating, rating_update) - - _ -> - do_update_rating(user_id, match, user_rating, rating_update) - end + do_update_rating(user_id, match, user_rating, rating_update) end) loss_ratings = @@ -364,17 +344,6 @@ defmodule Teiserver.Game.MatchRatingLib do [win_result | _lose_result] = rate_with_ids([winner_ratings | loser_ratings]) win_result = Map.new(win_result) - status_lookup = - if Enum.member?(["Small Team", "Large Team", "Team FFA"], match.game_type) do - match.members - |> Map.new(fn membership -> - {membership.user_id, - MatchLib.calculate_exit_status(membership.left_after, match.game_duration)} - end) - else - %{} - end - # Save the results win_ratings = winners @@ -382,16 +351,7 @@ defmodule Teiserver.Game.MatchRatingLib do rating_update = win_result[user_id] user_rating = rating_lookup[user_id] || BalanceLib.default_rating(rating_type_id) - case Map.get(status_lookup, user_id, nil) do - :abandoned -> - do_abandoned_rating(user_id, match, user_rating, rating_update) - - :noshow -> - do_noshow_rating(user_id, match, user_rating, rating_update) - - _ -> - do_update_rating(user_id, match, user_rating, rating_update) - end + do_update_rating(user_id, match, user_rating, rating_update) end) # If you lose you just count as losing against the winner @@ -481,76 +441,6 @@ defmodule Teiserver.Game.MatchRatingLib do {new_skill, u} end - defp do_noshow_rating(user_id, match, user_rating, _rating_update) do - user_rating = - if Map.get(user_rating, :user_id) do - user_rating - else - {:ok, rating} = - Account.create_rating( - Map.merge(user_rating, %{ - user_id: user_id, - last_updated: match.finished - }) - ) - - rating - end - - rating_type_id = user_rating.rating_type_id - - %{ - user_id: user_id, - rating_type_id: rating_type_id, - match_id: match.id, - inserted_at: match.finished, - value: %{ - reason: "No show", - rating_value: user_rating.rating_value, - skill: user_rating.skill, - uncertainty: user_rating.uncertainty, - rating_value_change: 0, - skill_change: 0, - uncertainty_change: 0 - } - } - end - - defp do_abandoned_rating(user_id, match, user_rating, _rating_update) do - user_rating = - if Map.get(user_rating, :user_id) do - user_rating - else - {:ok, rating} = - Account.create_rating( - Map.merge(user_rating, %{ - user_id: user_id, - last_updated: match.finished - }) - ) - - rating - end - - rating_type_id = user_rating.rating_type_id - - %{ - user_id: user_id, - rating_type_id: rating_type_id, - match_id: match.id, - inserted_at: match.finished, - value: %{ - reason: "Abandoned match", - rating_value: user_rating.rating_value, - skill: user_rating.skill, - uncertainty: user_rating.uncertainty, - rating_value_change: 0, - skill_change: 0, - uncertainty_change: 0 - } - } - end - @spec do_update_rating(T.userid(), map(), map(), {number(), number()}) :: any defp do_update_rating(user_id, match, user_rating, rating_update) do # It's possible they don't yet have a rating