Skip to content

Commit d9c31b3

Browse files
committed
Mix format
1 parent 4a29e61 commit d9c31b3

File tree

5 files changed

+38
-56
lines changed

5 files changed

+38
-56
lines changed

services/app/apps/codebattle/lib/codebattle/tournament/helpers.ex

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,14 @@ defmodule Codebattle.Tournament.Helpers do
33
alias Codebattle.Tournament
44
alias Codebattle.User
55

6-
def get_player(%{players_table: nil} = tournament, id),
7-
do: Map.get(tournament.players, to_id(id))
6+
def get_player(%{players_table: nil} = tournament, id), do: Map.get(tournament.players, to_id(id))
87

98
def get_player(tournament, id), do: Tournament.Players.get_player(tournament, id)
109

1110
def get_players(%{players_table: nil} = tournament), do: Map.values(tournament.players)
1211
def get_players(tournament), do: Tournament.Players.get_players(tournament)
1312

14-
def get_players(%{players_table: nil} = tournament, ids),
15-
do: Enum.map(ids, &get_player(tournament, &1))
13+
def get_players(%{players_table: nil} = tournament, ids), do: Enum.map(ids, &get_player(tournament, &1))
1614

1715
def get_players(tournament, ids), do: Tournament.Players.get_players(tournament, ids)
1816

@@ -46,23 +44,20 @@ defmodule Codebattle.Tournament.Helpers do
4644
tournament |> get_team_players(team_id) |> Enum.count()
4745
end
4846

49-
def get_match(%{matches_table: nil} = tournament, id),
50-
do: Map.get(tournament.matches, to_id(id))
47+
def get_match(%{matches_table: nil} = tournament, id), do: Map.get(tournament.matches, to_id(id))
5148

5249
def get_match(tournament, id), do: Tournament.Matches.get_match(tournament, id)
5350

5451
def get_matches(%{matches_table: nil} = tournament), do: Map.values(tournament.matches)
5552
def get_matches(tournament), do: Tournament.Matches.get_matches(tournament)
5653

57-
def get_matches(tournament, ids) when is_list(ids),
58-
do: Enum.map(ids, &get_match(tournament, &1))
54+
def get_matches(tournament, ids) when is_list(ids), do: Enum.map(ids, &get_match(tournament, &1))
5955

6056
def get_matches(tournament, state) when is_binary(state) do
6157
tournament |> get_matches() |> Enum.filter(&(&1.state == state))
6258
end
6359

64-
def get_matches(tournament, ids_or_state),
65-
do: Tournament.Matches.get_matches(tournament, ids_or_state)
60+
def get_matches(tournament, ids_or_state), do: Tournament.Matches.get_matches(tournament, ids_or_state)
6661

6762
def get_matches_by_players(tournament, player_ids) do
6863
matches_ids =
@@ -130,9 +125,7 @@ defmodule Codebattle.Tournament.Helpers do
130125
def get_current_round_playing_matches(tournament) do
131126
tournament
132127
|> get_matches()
133-
|> Enum.filter(
134-
&(&1.round_position == tournament.current_round_position and &1.state == "playing")
135-
)
128+
|> Enum.filter(&(&1.round_position == tournament.current_round_position and &1.state == "playing"))
136129
end
137130

138131
def match_player?(match, player_id), do: Enum.any?(match.player_ids, &(&1 == player_id))
@@ -358,10 +351,7 @@ defmodule Codebattle.Tournament.Helpers do
358351
])
359352
end
360353

361-
def get_players_total_games_count(
362-
%{task_provider: "task_pack", task_strategy: "sequential"} = t,
363-
_player
364-
) do
354+
def get_players_total_games_count(%{task_provider: "task_pack", task_strategy: "sequential"} = t, _player) do
365355
t |> Tournament.Tasks.get_task_ids() |> Enum.count()
366356
end
367357

@@ -377,7 +367,7 @@ defmodule Codebattle.Tournament.Helpers do
377367
|> Map.values()
378368
|> Enum.sort_by(& &1.place)
379369

380-
top_8_ids = Enum.take(total_ranking, 8) |> Enum.map(& &1.id)
370+
top_8_ids = total_ranking |> Enum.take(8) |> Enum.map(& &1.id)
381371
user_history = Tournament.TournamentResult.get_users_history(tournament, top_8_ids)
382372

383373
%{

services/app/apps/codebattle/lib/codebattle/tournament/ranking/by_percentile.ex

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ defmodule Codebattle.Tournament.Ranking.ByPercentile do
6060
:ok
6161
end
6262

63-
def add_new_player(%{state: state} = tournament, player)
64-
when state in ["waiting_participants", "active"] do
63+
def add_new_player(%{state: state} = tournament, player) when state in ["waiting_participants", "active"] do
6564
place = Ranking.count(tournament) + 1
6665

6766
Ranking.put_single_record(tournament, place, %{
@@ -85,8 +84,7 @@ defmodule Codebattle.Tournament.Ranking.ByPercentile do
8584
end
8685

8786
def set_places_with_score(tournament, ranking) do
88-
ranking
89-
|> Enum.each(fn %{id: id, place: place, score: score} ->
87+
Enum.each(ranking, fn %{id: id, place: place, score: score} ->
9088
tournament
9189
|> Players.get_player(id)
9290
|> case do

services/app/apps/codebattle/lib/codebattle/tournament/strategy/top200.ex

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -419,10 +419,7 @@ defmodule Codebattle.Tournament.Top200 do
419419
end
420420
end
421421

422-
defp has_more_games_in_round?(
423-
%{task_provider: "task_pack_per_round", round_task_ids: round_task_ids},
424-
game_params
425-
) do
422+
defp has_more_games_in_round?(%{task_provider: "task_pack_per_round", round_task_ids: round_task_ids}, game_params) do
426423
game_params.task_id != List.last(round_task_ids)
427424
end
428425

services/app/apps/codebattle/lib/codebattle/tournament/tournament_result.ex

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,7 @@ defmodule Codebattle.Tournament.TournamentResult do
151151
tournament
152152
end
153153

154-
def upsert_results(%{type: type, ranking_type: "by_win_loss"} = tournament)
155-
when type in ["swiss", "arena"] do
154+
def upsert_results(%{type: type, ranking_type: "by_win_loss"} = tournament) when type in ["swiss", "arena"] do
156155
clean_results(tournament.id)
157156

158157
Repo.query!("""
@@ -229,33 +228,32 @@ defmodule Codebattle.Tournament.TournamentResult do
229228
end
230229

231230
def get_users_history(tournament, user_ids) do
232-
Repo.all(
233-
from(tr in __MODULE__,
234-
where: tr.tournament_id == ^tournament.id,
235-
where: tr.user_id in ^user_ids,
236-
inner_join: tr2 in __MODULE__,
237-
on: tr.game_id == tr2.game_id and tr2.user_id != tr.user_id,
238-
group_by: [tr.round_position, tr.user_id, tr2.user_id],
239-
select: %{
240-
user_id: tr.user_id,
241-
user_name: max(tr.user_name),
242-
opponent_id: tr2.user_id,
243-
round_position: tr.round_position,
244-
score: coalesce(sum(tr.score), 0),
245-
opponent_score: coalesce(sum(tr2.score), 0),
246-
game_details:
247-
fragment(
248-
"array_agg(json_build_object('task_id', ?, 'game_id', ?, 'result_percent', ?, 'opponent_result_percent', ?))",
249-
tr.task_id,
250-
tr.game_id,
251-
tr.result_percent,
252-
tr2.result_percent
253-
),
254-
opponent_name: max(tr2.user_name),
255-
opponent_clan_id: max(tr2.clan_id)
256-
}
257-
)
231+
from(tr in __MODULE__,
232+
where: tr.tournament_id == ^tournament.id,
233+
where: tr.user_id in ^user_ids,
234+
inner_join: tr2 in __MODULE__,
235+
on: tr.game_id == tr2.game_id and tr2.user_id != tr.user_id,
236+
group_by: [tr.round_position, tr.user_id, tr2.user_id],
237+
select: %{
238+
user_id: tr.user_id,
239+
user_name: max(tr.user_name),
240+
opponent_id: tr2.user_id,
241+
round_position: tr.round_position,
242+
score: coalesce(sum(tr.score), 0),
243+
opponent_score: coalesce(sum(tr2.score), 0),
244+
game_details:
245+
fragment(
246+
"array_agg(json_build_object('task_id', ?, 'game_id', ?, 'result_percent', ?, 'opponent_result_percent', ?))",
247+
tr.task_id,
248+
tr.game_id,
249+
tr.result_percent,
250+
tr2.result_percent
251+
),
252+
opponent_name: max(tr2.user_name),
253+
opponent_clan_id: max(tr2.clan_id)
254+
}
258255
)
256+
|> Repo.all()
259257
|> Enum.reduce(%{}, fn result, acc ->
260258
task_history = %{
261259
score: result.score,

services/app/apps/codebattle/lib/codebattle_web/channels/tournament_admin_channel.ex

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,8 +413,7 @@ defmodule CodebattleWeb.TournamentAdminChannel do
413413

414414
defp cast_game_params(%{"task_level" => level}), do: %{task_level: level}
415415

416-
defp cast_game_params(%{"task_id" => id, "timeout_seconds" => seconds}),
417-
do: %{task_id: id, timeout_seconds: seconds}
416+
defp cast_game_params(%{"task_id" => id, "timeout_seconds" => seconds}), do: %{task_id: id, timeout_seconds: seconds}
418417

419418
defp cast_game_params(%{"task_id" => id}), do: %{task_id: id}
420419
defp cast_game_params(_params), do: %{}

0 commit comments

Comments
 (0)