diff --git a/config/dev.exs b/config/dev.exs index cec09588c..5931816ed 100644 --- a/config/dev.exs +++ b/config/dev.exs @@ -60,12 +60,7 @@ config :teiserver, Teiserver, heartbeat_timeout: nil, enable_discord_bridge: false, enable_hailstorm: true, - accept_all_emails: true, - - # The balance algorithm to use on the admin/matches/match/:id page - # It is purely used for analysis and not for actual games - # TODO move this into dropdown on admin/matches/match/:id page - analysis_balance_algorithm: "loser_picks" + accept_all_emails: true # Watch static and templates for browser reloading. config :teiserver, TeiserverWeb.Endpoint, diff --git a/lib/teiserver_web/live/battles/match/show.ex b/lib/teiserver_web/live/battles/match/show.ex index ade438e52..000216abb 100644 --- a/lib/teiserver_web/live/battles/match/show.ex +++ b/lib/teiserver_web/live/battles/match/show.ex @@ -16,10 +16,15 @@ defmodule TeiserverWeb.Battle.MatchLive.Show do end @impl true - def handle_params(%{"id" => id} = params, _url, socket) do + def handle_params(params, _url, socket) do + id = Map.get(params, "id") + balancer = Map.get(params, "balancer", "loser_picks") + # TODO Handle use case when given an invalid balancer + socket = socket |> assign(:id, String.to_integer(id)) + |> assign(:balancer, balancer) |> get_match() |> assign(:tab, socket.assigns.live_action) @@ -59,7 +64,7 @@ defmodule TeiserverWeb.Battle.MatchLive.Show do # {:noreply, assign(socket, :tab, tab)} # end - defp get_match(%{assigns: %{id: id, current_user: _current_user}} = socket) do + defp get_match(%{assigns: %{id: id, balancer: balancer, current_user: _current_user}} = socket) do if connected?(socket) do match = Battle.get_match!(id, @@ -128,13 +133,11 @@ defmodule TeiserverWeb.Battle.MatchLive.Show do |> List.flatten() past_balance = - BalanceLib.create_balance(groups, match.team_count, - algorithm: get_analysis_balance_algorithm() - ) + BalanceLib.create_balance(groups, match.team_count, algorithm: balancer) |> Map.put(:balance_mode, :grouped) # What about new balance? - new_balance = generate_new_balance_data(match) + new_balance = generate_new_balance_data(match, balancer) raw_events = Telemetry.list_simple_match_events(where: [match_id: match.id], preload: [:event_types]) @@ -185,6 +188,7 @@ defmodule TeiserverWeb.Battle.MatchLive.Show do |> assign(:new_balance, new_balance) |> assign(:events_by_type, events_by_type) |> assign(:events_by_team_and_type, events_by_team_and_type) + |> assign(:balancer, balancer) else socket |> assign(:match, nil) @@ -196,10 +200,11 @@ defmodule TeiserverWeb.Battle.MatchLive.Show do |> assign(:new_balance, %{}) |> assign(:events_by_type, %{}) |> assign(:events_by_team_and_type, %{}) + |> assign(:balancer, balancer) end end - defp generate_new_balance_data(match) do + defp generate_new_balance_data(match, balancer) do rating_type = MatchLib.game_type(match.team_size, match.team_count) partied_players = @@ -225,14 +230,7 @@ defmodule TeiserverWeb.Battle.MatchLive.Show do end) |> List.flatten() - BalanceLib.create_balance(groups, match.team_count, - algorithm: get_analysis_balance_algorithm() - ) + BalanceLib.create_balance(groups, match.team_count, algorithm: balancer) |> Map.put(:balance_mode, :grouped) end - - defp get_analysis_balance_algorithm() do - # TODO move this from config into a dropdown so it can be selected on this page - Application.get_env(:teiserver, Teiserver)[:analysis_balance_algorithm] || "loser_picks" - end end diff --git a/lib/teiserver_web/live/battles/match/show.html.heex b/lib/teiserver_web/live/battles/match/show.html.heex index a38abbee4..44e348d6c 100644 --- a/lib/teiserver_web/live/battles/match/show.html.heex +++ b/lib/teiserver_web/live/battles/match/show.html.heex @@ -284,7 +284,9 @@ <%= if allow?(@current_user, "Overwatch") do %>
Balancer: <%= @balancer %>