From 7a5d55639aea156674dfeec2542622f5b8e8c3de Mon Sep 17 00:00:00 2001 From: jauggy Date: Fri, 11 Oct 2024 11:28:03 +1100 Subject: [PATCH 1/3] Better balance display Sort players by rating desc Add trophy icon Fix the team id --- .../account/libs/relationship_lib.ex | 8 ++- .../controllers/admin/user_controller.ex | 2 +- lib/teiserver_web/live/battles/match/show.ex | 37 +++++++++++++- .../live/battles/match/show.html.heex | 49 ++++++++++++++++++- .../live/battles/match/show_live_test.exs | 15 ++++++ 5 files changed, 106 insertions(+), 5 deletions(-) create mode 100644 test/teiserver_web/live/battles/match/show_live_test.exs diff --git a/lib/teiserver/account/libs/relationship_lib.ex b/lib/teiserver/account/libs/relationship_lib.ex index e31de9b5e..c5c72fa4b 100644 --- a/lib/teiserver/account/libs/relationship_lib.ex +++ b/lib/teiserver/account/libs/relationship_lib.ex @@ -302,7 +302,9 @@ defmodule Teiserver.Account.RelationshipLib do userid_count = Enum.count(userid_list) |> max(1) block_count_needed = Config.get_site_config_cache("lobby.Block count to prevent join") - block_percentage_needed = Config.get_site_config_cache("lobby.Block percentage to prevent join") + + block_percentage_needed = + Config.get_site_config_cache("lobby.Block percentage to prevent join") being_blocked_count = userid @@ -334,7 +336,9 @@ defmodule Teiserver.Account.RelationshipLib do userid_count = Enum.count(userid_list) |> max(1) avoid_count_needed = Config.get_site_config_cache("lobby.Avoid count to prevent playing") - avoid_percentage_needed = Config.get_site_config_cache("lobby.Avoid percentage to prevent playing") + + avoid_percentage_needed = + Config.get_site_config_cache("lobby.Avoid percentage to prevent playing") being_avoided_count = userid diff --git a/lib/teiserver_web/controllers/admin/user_controller.ex b/lib/teiserver_web/controllers/admin/user_controller.ex index 53792b50f..5e84ad77a 100644 --- a/lib/teiserver_web/controllers/admin/user_controller.ex +++ b/lib/teiserver_web/controllers/admin/user_controller.ex @@ -84,7 +84,7 @@ defmodule TeiserverWeb.Admin.UserController do ip: params["ip"], lobby_client: params["lobby_client"], previous_names: params["previous_names"], - mod_action: params["mod_action"], + mod_action: params["mod_action"] ], limit: params["limit"] || 50, order_by: params["order"] || "Name (A-Z)" diff --git a/lib/teiserver_web/live/battles/match/show.ex b/lib/teiserver_web/live/battles/match/show.ex index f5cf385a8..22502de9c 100644 --- a/lib/teiserver_web/live/battles/match/show.ex +++ b/lib/teiserver_web/live/battles/match/show.ex @@ -93,7 +93,7 @@ defmodule TeiserverWeb.Battle.MatchLive.Show do match_id: match.id ] ) - |> Map.new(fn log -> {log.user_id, log} end) + |> Map.new(fn log -> {log.user_id, get_prematch_log(log)} end) # Creates a map where the party_id refers to an integer # but only includes parties with 2 or more members @@ -182,10 +182,19 @@ defmodule TeiserverWeb.Battle.MatchLive.Show do end) |> Enum.sort_by(fn v -> v end, &<=/2) + balanced_members = + Enum.map(members, fn x -> + team_id = get_team_id(x.user_id, past_balance.team_players) + Map.put(x, :team_id, team_id) + end) + |> Enum.sort_by(fn m -> rating_logs[m.user.id].value["rating_value"] end, &>=/2) + |> Enum.sort_by(fn m -> m.team_id end, &<=/2) + socket |> assign(:match, match) |> assign(:match_name, match_name) |> assign(:members, members) + |> assign(:balanced_members, balanced_members) |> assign(:rating_logs, rating_logs) |> assign(:parties, parties) |> assign(:past_balance, past_balance) @@ -206,6 +215,32 @@ defmodule TeiserverWeb.Battle.MatchLive.Show do end end + # Adjust the logs so that we use the prematch values of rating/uncertainty + # Prematch values are more relevant to understanding balance logs + defp get_prematch_log(log) do + %{ + "rating_value" => rating_value, + "uncertainty" => uncertainty, + "rating_value_change" => rating_value_change, + "uncertainty_change" => uncertainty_change + } = log.value + + old_rating = rating_value - rating_value_change + old_uncertainty = uncertainty - uncertainty_change + + Map.put(log, :rating_value, old_rating) + |> Map.put(:uncertainty, old_uncertainty) + end + + def get_team_id(player_id, team_players) do + {team_id, _players} = + Enum.find(team_players, fn {_k, player_ids} -> + Enum.any?(player_ids, fn x -> x == player_id end) + end) + + team_id - 1 + end + defp generate_new_balance_data(match, algorithm) do # For the section "If balance we made using current ratings", do not fuzz ratings # This means the rating used is exactly equal to what is stored in database diff --git a/lib/teiserver_web/live/battles/match/show.html.heex b/lib/teiserver_web/live/battles/match/show.html.heex index 30009a8a5..f6f230474 100644 --- a/lib/teiserver_web/live/battles/match/show.html.heex +++ b/lib/teiserver_web/live/battles/match/show.html.heex @@ -320,9 +320,56 @@ -
+ + + + + + + + + + + <%= for m <- @balanced_members do %> + <% rating = @rating_logs[m.user_id] + {party_colour, party_idx} = Map.get(@parties, m.party_id, {nil, nil}) %> + + + + <%= if party_colour do %> + + <% else %> + + <% end %> + + + + + <% end %> + +
Name & PartyTeamRatingUncertainty
+ <%= if m.team_id == @match.winning_team do %> + + <% end %> + + <%= m.user.name %> + + + +   + <%= m.team_id + 1 %> + <%= if rating != nil do %> + <%= rating.value["rating_value"] |> round(2) %> + <% end %> + + <%= if rating != nil do %> + <%= rating.value["uncertainty"] |> round(2) %> + <% end %> +
+
+

If balance we made using current ratings

diff --git a/test/teiserver_web/live/battles/match/show_live_test.exs b/test/teiserver_web/live/battles/match/show_live_test.exs new file mode 100644 index 000000000..e1aceb030 --- /dev/null +++ b/test/teiserver_web/live/battles/match/show_live_test.exs @@ -0,0 +1,15 @@ +defmodule TeiserverWeb.Battle.MatchLive.ShowTest do + alias TeiserverWeb.Battle.MatchLive.Show + use ExUnit.Case + + test "get team id" do + team_players = %{1 => [1, 4], 2 => [2, 3]} + player_id = 4 + result = Show.get_team_id(player_id, team_players) + assert result == 1 + + player_id = 3 + result = Show.get_team_id(player_id, team_players) + assert result == 2 + end +end From d2809ee6b8b04609341a195284262c1221acaa9c Mon Sep 17 00:00:00 2001 From: Joshua Augustinus Date: Fri, 18 Oct 2024 00:23:22 +1100 Subject: [PATCH 2/3] Show stdev and fix bug in respect_avoids Fix failing tests --- .../battle/balance/respect_avoids.ex | 10 +++--- lib/teiserver_web/live/battles/match/show.ex | 2 ++ .../live/battles/match/show.html.heex | 32 +++++++++++-------- test/teiserver/battle/respect_avoids_test.exs | 4 +-- .../live/battles/match/show_live_test.exs | 4 +-- 5 files changed, 30 insertions(+), 22 deletions(-) diff --git a/lib/teiserver/battle/balance/respect_avoids.ex b/lib/teiserver/battle/balance/respect_avoids.ex index 73371ddcd..d51c54ed2 100644 --- a/lib/teiserver/battle/balance/respect_avoids.ex +++ b/lib/teiserver/battle/balance/respect_avoids.ex @@ -53,7 +53,7 @@ defmodule Teiserver.Battle.Balance.RespectAvoids do players = flatten_members(expanded_group) parties = get_parties(expanded_group) - noobs = get_noobs(players) |> sort_noobs() + noobs = get_solo_noobs(players) |> sort_noobs() experienced_players = get_experienced_players(players, noobs) experienced_player_ids = experienced_players |> Enum.map(fn x -> x.id end) players_in_parties_count = parties |> List.flatten() |> Enum.count() @@ -140,7 +140,7 @@ defmodule Teiserver.Battle.Balance.RespectAvoids do ] true -> - "New players: None" + "Solo new players: None" end logs = @@ -514,10 +514,10 @@ defmodule Teiserver.Battle.Balance.RespectAvoids do end # Noobs have high uncertainty and chev 1,2,3 - @spec get_noobs([RA.player()]) :: any() - def get_noobs(players) do + @spec get_solo_noobs([RA.player()]) :: any() + def get_solo_noobs(players) do Enum.filter(players, fn player -> - is_newish_player?(player.rank, player.uncertainty) + is_newish_player?(player.rank, player.uncertainty) && !player.in_party? end) end diff --git a/lib/teiserver_web/live/battles/match/show.ex b/lib/teiserver_web/live/battles/match/show.ex index bffd96932..01917f920 100644 --- a/lib/teiserver_web/live/battles/match/show.ex +++ b/lib/teiserver_web/live/battles/match/show.ex @@ -192,6 +192,7 @@ defmodule TeiserverWeb.Battle.MatchLive.Show do end) |> Enum.sort_by(fn m -> rating_logs[m.user.id].value["rating_value"] end, &>=/2) |> Enum.sort_by(fn m -> m.team_id end, &<=/2) + game_id = cond do match.game_id -> match.game_id @@ -255,6 +256,7 @@ defmodule TeiserverWeb.Battle.MatchLive.Show do Enum.any?(player_ids, fn x -> x == player_id end) end) + # team_id should start at 0 even though first key is 1 team_id - 1 end diff --git a/lib/teiserver_web/live/battles/match/show.html.heex b/lib/teiserver_web/live/battles/match/show.html.heex index c23916a11..2ebe41ead 100644 --- a/lib/teiserver_web/live/battles/match/show.html.heex +++ b/lib/teiserver_web/live/battles/match/show.html.heex @@ -303,19 +303,30 @@ - + + - + + + - + - +
Team 1<%= @past_balance.ratings[1] |> round(2) %> + Rating: <%= @past_balance.ratings[1] |> round(2) %> + + St Dev: <%= @past_balance.stdevs[1] |> round(2) %> +
Team 2<%= @past_balance.ratings[2] |> round(2) %> + Rating: <%= @past_balance.ratings[2] |> round(2) %> + + St Dev: <%= @past_balance.stdevs[2] |> round(2) %> +
Deviation<%= @past_balance.deviation %><%= @past_balance.deviation %>
Time Taken (ms)<%= @past_balance.time_taken / 1000 %><%= @past_balance.time_taken / 1000 %>
@@ -326,7 +337,7 @@ - + @@ -336,13 +347,8 @@ <%= for m <- @balanced_members do %> <% rating = @rating_logs[m.user_id] {party_colour, party_idx} = Map.get(@parties, m.party_id, {nil, nil}) %> - - - + <%= if party_colour do %> @@ -350,7 +356,7 @@ <% else %> - <% end %> diff --git a/test/teiserver/battle/respect_avoids_test.exs b/test/teiserver/battle/respect_avoids_test.exs index 635c8ef59..f7fe0b0d0 100644 --- a/test/teiserver/battle/respect_avoids_test.exs +++ b/test/teiserver/battle/respect_avoids_test.exs @@ -114,7 +114,7 @@ defmodule Teiserver.Battle.RespectAvoidsTest do "Avoid min time required: 2 h", "Avoids considered: 0", "------------------------------------------------------", - "New players: None", + "Solo new players: None", "------------------------------------------------------", "Perform brute force with the following players to get the best score.", "Players: Dixinormus, fbots1998, kyutoryu, HungDaddy, jauggy, Aposis, [DTG]BamBin0, reddragon2010, Noody, SLOPPYGAGGER, MaTThiuS_82, barmalev", @@ -250,7 +250,7 @@ defmodule Teiserver.Battle.RespectAvoidsTest do "Avoid min time required: 2 h", "Avoids considered: 1", "------------------------------------------------------", - "New players: None", + "Solo new players: None", "------------------------------------------------------", "Perform brute force with the following players to get the best score.", "Players: fbots1998, kyutoryu, jauggy, reddragon2010, Aposis, [DTG]BamBin0, Dixinormus, Noody, SLOPPYGAGGER, MaTThiuS_82, barmalev, HungDaddy", diff --git a/test/teiserver_web/live/battles/match/show_live_test.exs b/test/teiserver_web/live/battles/match/show_live_test.exs index e1aceb030..8992ce4a4 100644 --- a/test/teiserver_web/live/battles/match/show_live_test.exs +++ b/test/teiserver_web/live/battles/match/show_live_test.exs @@ -6,10 +6,10 @@ defmodule TeiserverWeb.Battle.MatchLive.ShowTest do team_players = %{1 => [1, 4], 2 => [2, 3]} player_id = 4 result = Show.get_team_id(player_id, team_players) - assert result == 1 + assert result == 0 player_id = 3 result = Show.get_team_id(player_id, team_players) - assert result == 2 + assert result == 1 end end From 8674ebaf1e62120ea9853240639c52f9c5f65399 Mon Sep 17 00:00:00 2001 From: Joshua Augustinus Date: Sat, 19 Oct 2024 14:44:09 +1100 Subject: [PATCH 3/3] Better display on balance tab --- lib/teiserver_web/live/battles/match/show.ex | 2 ++ .../live/battles/match/show.html.heex | 32 +++++++++++-------- .../live/battles/match/show_live_test.exs | 4 +-- 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/lib/teiserver_web/live/battles/match/show.ex b/lib/teiserver_web/live/battles/match/show.ex index bffd96932..01917f920 100644 --- a/lib/teiserver_web/live/battles/match/show.ex +++ b/lib/teiserver_web/live/battles/match/show.ex @@ -192,6 +192,7 @@ defmodule TeiserverWeb.Battle.MatchLive.Show do end) |> Enum.sort_by(fn m -> rating_logs[m.user.id].value["rating_value"] end, &>=/2) |> Enum.sort_by(fn m -> m.team_id end, &<=/2) + game_id = cond do match.game_id -> match.game_id @@ -255,6 +256,7 @@ defmodule TeiserverWeb.Battle.MatchLive.Show do Enum.any?(player_ids, fn x -> x == player_id end) end) + # team_id should start at 0 even though first key is 1 team_id - 1 end diff --git a/lib/teiserver_web/live/battles/match/show.html.heex b/lib/teiserver_web/live/battles/match/show.html.heex index c23916a11..2ebe41ead 100644 --- a/lib/teiserver_web/live/battles/match/show.html.heex +++ b/lib/teiserver_web/live/battles/match/show.html.heex @@ -303,19 +303,30 @@ - + + - + + + - + - +
Name & PartyName & Party Team Rating Uncertainty
- <%= if m.team_id == @match.winning_team do %> - - <% end %> - +
<%= m.user.name %> +  
Team 1<%= @past_balance.ratings[1] |> round(2) %> + Rating: <%= @past_balance.ratings[1] |> round(2) %> + + St Dev: <%= @past_balance.stdevs[1] |> round(2) %> +
Team 2<%= @past_balance.ratings[2] |> round(2) %> + Rating: <%= @past_balance.ratings[2] |> round(2) %> + + St Dev: <%= @past_balance.stdevs[2] |> round(2) %> +
Deviation<%= @past_balance.deviation %><%= @past_balance.deviation %>
Time Taken (ms)<%= @past_balance.time_taken / 1000 %><%= @past_balance.time_taken / 1000 %>
@@ -326,7 +337,7 @@ - + @@ -336,13 +347,8 @@ <%= for m <- @balanced_members do %> <% rating = @rating_logs[m.user_id] {party_colour, party_idx} = Map.get(@parties, m.party_id, {nil, nil}) %> - - - + <%= if party_colour do %> @@ -350,7 +356,7 @@ <% else %> - <% end %> diff --git a/test/teiserver_web/live/battles/match/show_live_test.exs b/test/teiserver_web/live/battles/match/show_live_test.exs index e1aceb030..8992ce4a4 100644 --- a/test/teiserver_web/live/battles/match/show_live_test.exs +++ b/test/teiserver_web/live/battles/match/show_live_test.exs @@ -6,10 +6,10 @@ defmodule TeiserverWeb.Battle.MatchLive.ShowTest do team_players = %{1 => [1, 4], 2 => [2, 3]} player_id = 4 result = Show.get_team_id(player_id, team_players) - assert result == 1 + assert result == 0 player_id = 3 result = Show.get_team_id(player_id, team_players) - assert result == 2 + assert result == 1 end end
Name & PartyName & Party Team Rating Uncertainty
- <%= if m.team_id == @match.winning_team do %> - - <% end %> - +
<%= m.user.name %> +