@@ -16,10 +16,15 @@ defmodule TeiserverWeb.Battle.MatchLive.Show do
16
16
end
17
17
18
18
@ 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
+
20
24
socket =
21
25
socket
22
26
|> assign ( :id , String . to_integer ( id ) )
27
+ |> assign ( :balancer , balancer )
23
28
|> get_match ( )
24
29
|> assign ( :tab , socket . assigns . live_action )
25
30
@@ -59,7 +64,7 @@ defmodule TeiserverWeb.Battle.MatchLive.Show do
59
64
# {:noreply, assign(socket, :tab, tab)}
60
65
# end
61
66
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
63
68
if connected? ( socket ) do
64
69
match =
65
70
Battle . get_match! ( id ,
@@ -128,13 +133,11 @@ defmodule TeiserverWeb.Battle.MatchLive.Show do
128
133
|> List . flatten ( )
129
134
130
135
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 )
134
137
|> Map . put ( :balance_mode , :grouped )
135
138
136
139
# What about new balance?
137
- new_balance = generate_new_balance_data ( match )
140
+ new_balance = generate_new_balance_data ( match , balancer )
138
141
139
142
raw_events =
140
143
Telemetry . list_simple_match_events ( where: [ match_id: match . id ] , preload: [ :event_types ] )
@@ -185,6 +188,7 @@ defmodule TeiserverWeb.Battle.MatchLive.Show do
185
188
|> assign ( :new_balance , new_balance )
186
189
|> assign ( :events_by_type , events_by_type )
187
190
|> assign ( :events_by_team_and_type , events_by_team_and_type )
191
+ |> assign ( :balancer , balancer )
188
192
else
189
193
socket
190
194
|> assign ( :match , nil )
@@ -196,10 +200,11 @@ defmodule TeiserverWeb.Battle.MatchLive.Show do
196
200
|> assign ( :new_balance , % { } )
197
201
|> assign ( :events_by_type , % { } )
198
202
|> assign ( :events_by_team_and_type , % { } )
203
+ |> assign ( :balancer , balancer )
199
204
end
200
205
end
201
206
202
- defp generate_new_balance_data ( match ) do
207
+ defp generate_new_balance_data ( match , balancer ) do
203
208
rating_type = MatchLib . game_type ( match . team_size , match . team_count )
204
209
205
210
partied_players =
@@ -225,14 +230,7 @@ defmodule TeiserverWeb.Battle.MatchLive.Show do
225
230
end )
226
231
|> List . flatten ( )
227
232
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 )
231
234
|> Map . put ( :balance_mode , :grouped )
232
235
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
238
236
end
0 commit comments