Skip to content

Commit dacd9fd

Browse files
committed
Handle balancer via url
Add comment Undo changes
1 parent 093c8e4 commit dacd9fd

File tree

5 files changed

+18
-22
lines changed

5 files changed

+18
-22
lines changed

config/dev.exs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,7 @@ config :teiserver, Teiserver,
6060
heartbeat_timeout: nil,
6161
enable_discord_bridge: false,
6262
enable_hailstorm: true,
63-
accept_all_emails: true,
64-
65-
# The balance algorithm to use on the admin/matches/match/:id page
66-
# It is purely used for analysis and not for actual games
67-
# TODO move this into dropdown on admin/matches/match/:id page
68-
analysis_balance_algorithm: "loser_picks"
63+
accept_all_emails: true
6964

7065
# Watch static and templates for browser reloading.
7166
config :teiserver, TeiserverWeb.Endpoint,

lib/teiserver_web/live/battles/match/show.ex

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,15 @@ defmodule TeiserverWeb.Battle.MatchLive.Show do
1616
end
1717

1818
@impl true
19-
def handle_params(%{"id" => id} = params, _url, socket) do
19+
def handle_params(params, _url, socket) do
20+
id = Map.get(params, "id")
21+
balancer = Map.get(params, "balancer", "loser_picks")
22+
# TODO Handle use case when given an invalid balancer
23+
2024
socket =
2125
socket
2226
|> assign(:id, String.to_integer(id))
27+
|> assign(:balancer, balancer)
2328
|> get_match()
2429
|> assign(:tab, socket.assigns.live_action)
2530

@@ -59,7 +64,7 @@ defmodule TeiserverWeb.Battle.MatchLive.Show do
5964
# {:noreply, assign(socket, :tab, tab)}
6065
# end
6166

62-
defp get_match(%{assigns: %{id: id, current_user: _current_user}} = socket) do
67+
defp get_match(%{assigns: %{id: id, balancer: balancer, current_user: _current_user}} = socket) do
6368
if connected?(socket) do
6469
match =
6570
Battle.get_match!(id,
@@ -128,13 +133,11 @@ defmodule TeiserverWeb.Battle.MatchLive.Show do
128133
|> List.flatten()
129134

130135
past_balance =
131-
BalanceLib.create_balance(groups, match.team_count,
132-
algorithm: get_analysis_balance_algorithm()
133-
)
136+
BalanceLib.create_balance(groups, match.team_count, algorithm: balancer)
134137
|> Map.put(:balance_mode, :grouped)
135138

136139
# What about new balance?
137-
new_balance = generate_new_balance_data(match)
140+
new_balance = generate_new_balance_data(match, balancer)
138141

139142
raw_events =
140143
Telemetry.list_simple_match_events(where: [match_id: match.id], preload: [:event_types])
@@ -185,6 +188,7 @@ defmodule TeiserverWeb.Battle.MatchLive.Show do
185188
|> assign(:new_balance, new_balance)
186189
|> assign(:events_by_type, events_by_type)
187190
|> assign(:events_by_team_and_type, events_by_team_and_type)
191+
|> assign(:balancer, balancer)
188192
else
189193
socket
190194
|> assign(:match, nil)
@@ -196,10 +200,11 @@ defmodule TeiserverWeb.Battle.MatchLive.Show do
196200
|> assign(:new_balance, %{})
197201
|> assign(:events_by_type, %{})
198202
|> assign(:events_by_team_and_type, %{})
203+
|> assign(:balancer, balancer)
199204
end
200205
end
201206

202-
defp generate_new_balance_data(match) do
207+
defp generate_new_balance_data(match, balancer) do
203208
rating_type = MatchLib.game_type(match.team_size, match.team_count)
204209

205210
partied_players =
@@ -225,14 +230,7 @@ defmodule TeiserverWeb.Battle.MatchLive.Show do
225230
end)
226231
|> List.flatten()
227232

228-
BalanceLib.create_balance(groups, match.team_count,
229-
algorithm: get_analysis_balance_algorithm()
230-
)
233+
BalanceLib.create_balance(groups, match.team_count, algorithm: balancer)
231234
|> Map.put(:balance_mode, :grouped)
232235
end
233-
234-
defp get_analysis_balance_algorithm() do
235-
# TODO move this from config into a dropdown so it can be selected on this page
236-
Application.get_env(:teiserver, Teiserver)[:analysis_balance_algorithm] || "loser_picks"
237-
end
238236
end

lib/teiserver_web/live/battles/match/show.html.heex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,9 @@
284284

285285
<%= if allow?(@current_user, "Overwatch") do %>
286286
<div :if={@tab == :balance} class="p-4">
287+
<p>Balancer: <%= @balancer %></p>
287288
<h4>Based on data at the time</h4>
289+
288290
<table class="table">
289291
<tbody>
290292
<tr>

lib/teiserver_web/router.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ defmodule TeiserverWeb.Router do
304304
live "/:id/players", MatchLive.Show, :players
305305
live "/:id/ratings", MatchLive.Show, :ratings
306306
live "/:id/balance", MatchLive.Show, :balance
307+
live "/:id/balance/:balancer", MatchLive.Show, :balance
307308
live "/:id/events", MatchLive.Show, :events
308309
end
309310
end

lib/teiserver_web/templates/battle/match/section_menu.html.heex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
active: @active,
3838
icon: Teiserver.Admin.AdminLib.icon(),
3939
bsname: bsname,
40-
url: ~p"/teiserver/admin/matches/#{@match.id}"
40+
url: ~p"/battle/#{@match.id}"
4141
) %>
4242
<% end %>
4343
</div>

0 commit comments

Comments
 (0)