From f2b76e7beee22876c08bb93e7a6608f22ef13e4c Mon Sep 17 00:00:00 2001 From: L-e-x-o-n <44340857+L-e-x-o-n@users.noreply.github.com> Date: Sun, 9 Jun 2024 18:25:18 +0200 Subject: [PATCH] Cleanup and formatting --- lib/teiserver/battle/libs/match_lib.ex | 16 ++- lib/teiserver/coordinator/consul_server.ex | 2 +- lib/teiserver/game/servers/balancer_server.ex | 7 +- lib/teiserver/libs/test_lib.ex | 1 - lib/teiserver/mix_tasks/team_rating.ex | 101 ------------------ .../controllers/api/spads_controller.ex | 20 ++-- .../live/moderation/report_user/index.ex | 11 +- .../templates/admin/match/search.html.heex | 14 ++- 8 files changed, 46 insertions(+), 126 deletions(-) delete mode 100644 lib/teiserver/mix_tasks/team_rating.ex diff --git a/lib/teiserver/battle/libs/match_lib.ex b/lib/teiserver/battle/libs/match_lib.ex index 93c86d52d..9e26f1a0f 100644 --- a/lib/teiserver/battle/libs/match_lib.ex +++ b/lib/teiserver/battle/libs/match_lib.ex @@ -35,7 +35,6 @@ defmodule Teiserver.Battle.MatchLib do end end - def list_game_types() do [ "Duel", @@ -137,10 +136,17 @@ defmodule Teiserver.Battle.MatchLib do def make_match_name(match) do case match.game_type do - "Duel" -> "Duel on #{match.map}" - type when type in ["Small Team", "Big Team"] -> "#{match.team_size}v#{match.team_size} on #{match.map}" - "FFA" -> "#{match.team_count} way FFA on #{match.map}" - t -> "#{t} game on #{match.map}" + "Duel" -> + "Duel on #{match.map}" + + type when type in ["Small Team", "Big Team"] -> + "#{match.team_size}v#{match.team_size} on #{match.map}" + + "FFA" -> + "#{match.team_count} way FFA on #{match.map}" + + t -> + "#{t} game on #{match.map}" end end diff --git a/lib/teiserver/coordinator/consul_server.ex b/lib/teiserver/coordinator/consul_server.ex index a0c700001..715050fc8 100644 --- a/lib/teiserver/coordinator/consul_server.ex +++ b/lib/teiserver/coordinator/consul_server.ex @@ -838,7 +838,7 @@ defmodule Teiserver.Coordinator.ConsulServer do rating_type = MatchLib.game_type(state.host_teamsize, state.host_teamcount) {player_rating, player_uncertainty} = - BalanceLib.get_user_rating_value_uncertainty_pair(user.id, "Big Team") + BalanceLib.get_user_rating_value_uncertainty_pair(user.id, rating_type) player_rating = max(player_rating, 1) avoid_status = Account.check_avoid_status(user.id, player_list) diff --git a/lib/teiserver/game/servers/balancer_server.ex b/lib/teiserver/game/servers/balancer_server.ex index 8b855b8ac..dcf54027e 100644 --- a/lib/teiserver/game/servers/balancer_server.ex +++ b/lib/teiserver/game/servers/balancer_server.ex @@ -165,6 +165,7 @@ defmodule Teiserver.Game.BalancerServer do teams = players |> Enum.group_by(fn c -> c.team_number end) + team_size = Enum.max(Enum.map(teams, fn {_, t} -> Enum.count(t) end), fn -> 0 end) game_type = MatchLib.game_type(team_size, team_count) @@ -205,8 +206,7 @@ defmodule Teiserver.Game.BalancerServer do player_id_list |> Enum.map(fn userid -> %{ - userid => - BalanceLib.get_user_rating_rank(userid, game_type, opts[:fuzz_multiplier]) + userid => BalanceLib.get_user_rating_rank(userid, game_type, opts[:fuzz_multiplier]) } end) @@ -229,8 +229,7 @@ defmodule Teiserver.Game.BalancerServer do players |> Enum.map(fn %{userid: userid} -> %{ - userid => - BalanceLib.get_user_rating_rank(userid, game_type, opts[:fuzz_multiplier]) + userid => BalanceLib.get_user_rating_rank(userid, game_type, opts[:fuzz_multiplier]) } end) diff --git a/lib/teiserver/libs/test_lib.ex b/lib/teiserver/libs/test_lib.ex index 70c070d3d..de170a19b 100644 --- a/lib/teiserver/libs/test_lib.ex +++ b/lib/teiserver/libs/test_lib.ex @@ -1,7 +1,6 @@ defmodule Teiserver.TeiserverTestLib do @moduledoc false alias Teiserver.{Client, CacheUser, Account} - alias Teiserver.Lobby.LobbyLib alias Teiserver.Account.AccoladeLib alias Teiserver.Protocols.TachyonLib alias Teiserver.Coordinator.CoordinatorServer diff --git a/lib/teiserver/mix_tasks/team_rating.ex b/lib/teiserver/mix_tasks/team_rating.ex deleted file mode 100644 index 8b03b82bf..000000000 --- a/lib/teiserver/mix_tasks/team_rating.ex +++ /dev/null @@ -1,101 +0,0 @@ -defmodule Mix.Tasks.Teiserver.Teamrating do - @moduledoc """ - Run with mix teiserver.teamrating - Goes through every existing 'Team' rating and sorts it into either 'Small Team' or 'Big Team' rating category based on team size. - Recalculates 'Small Team' and 'Big Team' ratings for affected players. - """ - - use Mix.Task - - alias Teiserver.Battle - require Logger - - @spec run(list()) :: :ok - def run(args) do - Application.ensure_all_started(:teiserver) - - rating_type_id = Teiserver.Game.MatchRatingLib.rating_type_name_lookup()["Team"] - Teiserver.Game.MatchRatingLib.reset_player_ratings(rating_type_id) - - Logger.debug("Starting to process small team games..") - process_small_team_games() - Logger.debug("Finished processing small team games") - - Logger.debug("Starting to process big team games") - process_big_team_games(0, 0) - Logger.debug("Finished processing big team games") - end - - defp process_small_team_games() do - # Get all small team matches - small_team_matches = - Battle.list_matches( - search: [ - server_uuid_not_nil: true, - game_type_in: ["Team", "Small Team"], - has_finished: true, - processed: true, - team_size_less_than: 5 - ], - order_by: "Oldest first", - limit: :infinity, - preload: [:members] - ) - - Logger.debug("Found #{Enum.count(small_team_matches)} small team game matches") - - # For small team games change game type and update rating - small_team_matches - |> Enum.chunk_every(50) - |> Enum.each(fn chunk -> - chunk - |> Enum.each(fn match -> - Battle.update_match(match, %{ - game_type: "Small Team" - }) - - Teiserver.rate_match(match.id) - end) - end) - end - - defp process_big_team_games(offset, i) do - batch_size = 50_000 - - big_team_matches = - Battle.list_matches( - search: [ - server_uuid_not_nil: true, - game_type_in: ["Team", "Big Team"], - has_finished: true, - processed: true, - team_size_greater_than: 4 - ], - order_by: "Oldest first", - limit: batch_size, - offset: offset, - preload: [:members] - ) - - match_count = Enum.count(big_team_matches) - Logger.debug("Batch #{i} - Found #{match_count} big team game matches") - - if match_count > 0 do - big_team_matches - |> Enum.chunk_every(50) - |> Enum.each(fn chunk -> - chunk - |> Enum.each(fn match -> - Battle.update_match(match, %{ - game_type: "Big Team" - }) - Teiserver.rate_match(match.id) - end) - end) - - # Fetch and process the next batch - process_big_team_games(offset + batch_size, i+1) - end - end - -end diff --git a/lib/teiserver_web/controllers/api/spads_controller.ex b/lib/teiserver_web/controllers/api/spads_controller.ex index 98b2852fb..f8786fb42 100644 --- a/lib/teiserver_web/controllers/api/spads_controller.ex +++ b/lib/teiserver_web/controllers/api/spads_controller.ex @@ -19,20 +19,21 @@ defmodule TeiserverWeb.API.SpadsController do def get_rating(conn, %{ "target_id" => target_id_str, "type" => type - } - ) do - + }) do target_id = int_parse(target_id_str) lobby = get_member_lobby(target_id) - host_ip = case lobby do - nil -> nil - _ -> Account.get_client_by_id(lobby.founder_id).ip - end + + host_ip = + case lobby do + nil -> nil + _ -> Account.get_client_by_id(lobby.founder_id).ip + end actual_type = case type do "Team" -> get_team_subtype(lobby) - "TeamFFA" -> "Big Team" # Team FFA uses Big Team rating + # Team FFA uses Big Team rating + "TeamFFA" -> "Big Team" v -> v end @@ -247,7 +248,8 @@ defmodule TeiserverWeb.API.SpadsController do end cond do - Enum.count(teams) == 2 and max_team_size <= 5 -> "Small Team" # 2v2, 3v3, 4v4, 5v5 + # 2v2, 3v3, 4v4, 5v5 + Enum.count(teams) == 2 and max_team_size <= 5 -> "Small Team" true -> "Big Team" end end diff --git a/lib/teiserver_web/live/moderation/report_user/index.ex b/lib/teiserver_web/live/moderation/report_user/index.ex index 18ee41a84..c3d32ff6c 100644 --- a/lib/teiserver_web/live/moderation/report_user/index.ex +++ b/lib/teiserver_web/live/moderation/report_user/index.ex @@ -191,9 +191,14 @@ defmodule TeiserverWeb.Moderation.ReportUserLive.Index do |> Enum.map(fn match -> label = case match.game_type do - type when type in ["Small Team", "Big Team"] -> "#{match.team_size} vs #{match.team_size} on #{match.map}" - "FFA" -> "#{match.team_count} way FFA on #{match.map}" - v -> v + type when type in ["Small Team", "Big Team"] -> + "#{match.team_size} vs #{match.team_size} on #{match.map}" + + "FFA" -> + "#{match.team_count} way FFA on #{match.map}" + + v -> + v end time_ago = diff --git a/lib/teiserver_web/templates/admin/match/search.html.heex b/lib/teiserver_web/templates/admin/match/search.html.heex index 83dedb8ba..504bb8c52 100644 --- a/lib/teiserver_web/templates/admin/match/search.html.heex +++ b/lib/teiserver_web/templates/admin/match/search.html.heex @@ -78,8 +78,18 @@ enumerable: [ %{id: "", name: "Any", icon: "fa-solid fa-square", colour: "#AA0000"}, %{id: "Duel", name: "Duel", icon: "fa-solid fa-square", colour: "#AA0000"}, - %{id: "Small Team", name: "Small Team", icon: "fa-solid fa-square", colour: "#AA0000"}, - %{id: "Big Team", name: "Big Team", icon: "fa-solid fa-square", colour: "#AA0000"}, + %{ + id: "Small Team", + name: "Small Team", + icon: "fa-solid fa-square", + colour: "#AA0000" + }, + %{ + id: "Big Team", + name: "Big Team", + icon: "fa-solid fa-square", + colour: "#AA0000" + }, %{id: "FFA", name: "FFA", icon: "fa-solid fa-square", colour: "#AA0000"}, %{ id: "Team FFA",