Skip to content

Commit

Permalink
Fix prematch ratings on balance tab (#542)
Browse files Browse the repository at this point in the history
  • Loading branch information
jauggy authored Dec 20, 2024
1 parent 06f936c commit 5dcc6bd
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
34 changes: 27 additions & 7 deletions lib/teiserver/battle/libs/balance_lib.ex
Original file line number Diff line number Diff line change
Expand Up @@ -207,21 +207,41 @@ defmodule Teiserver.Battle.BalanceLib do
|> Enum.map(fn group ->
# Iterate over our map
Map.new(group, fn {user_id, value} ->
case value do
x when is_number(x) ->
{user_id, get_user_rating_rank_old(user_id, x)}
cond do
is_number(value) ->
{user_id, get_user_rating_rank_old(user_id, value)}

# match_controller will use this condition when balancing using old data from game_rating_logs table
match?(%{"rating_value" => _}, value) ->
pre_match_stats = get_prematch_stats(value)

# match_controller will use this condition when balancing using old data
%{"rating_value" => rating_value, "uncertainty" => uncertainty} ->
{user_id, get_user_rating_rank_old(user_id, rating_value, uncertainty)}
{user_id,
get_user_rating_rank_old(
user_id,
pre_match_stats.rating_value,
pre_match_stats.uncertainty
)}

_ ->
true ->
{user_id, value}
end
end)
end)
end

# Rating logs use post match data so we must adjust to get prematch data
defp get_prematch_stats(rating_log_value) do
new_rating_value = rating_log_value["rating_value"]
rating_value_change = rating_log_value["rating_value_change"]
new_uncertainty = rating_log_value["uncertainty"]
uncertainty_change = rating_log_value["uncertainty_change"]

%{
rating_value: new_rating_value - rating_value_change,
uncertainty: new_uncertainty - uncertainty_change
}
end

# Removes various keys we don't care about
defp cleanup_result(result) do
Map.take(
Expand Down
6 changes: 4 additions & 2 deletions lib/teiserver_web/live/battles/match/show.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -387,12 +387,14 @@
<td><%= m.team_id + 1 %></td>
<td>
<%= if rating != nil do %>
<%= rating.value["rating_value"] |> round(2) %>
<%= (rating.value["rating_value"] - rating.value["rating_value_change"])
|> round(2) %>
<% end %>
</td>
<td>
<%= if rating != nil do %>
<%= rating.value["uncertainty"] |> round(2) %>
<%= (rating.value["uncertainty"] - rating.value["uncertainty_change"])
|> round(2) %>
<% end %>
</td>
</tr>
Expand Down

0 comments on commit 5dcc6bd

Please sign in to comment.