Skip to content

Commit

Permalink
Fix credo
Browse files Browse the repository at this point in the history
  • Loading branch information
vtm9 committed Apr 3, 2024
1 parent 04f5098 commit 2a3d15d
Showing 1 changed file with 25 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -314,29 +314,7 @@ defmodule Codebattle.Tournament.Base do
finished_at = TimeHelper.utc_now()
duration_sec = NaiveDateTime.diff(match.started_at, finished_at)

player_results =
case Game.Context.fetch_game(match.game_id) do
{:ok, game = %{is_live: true}} ->
game
|> Game.Helpers.get_player_results()
|> Map.new(fn {player_id, result} ->
{player_id,
Map.put(
result,
:score,
get_score(
tournament.score_strategy,
match.level,
result.result_percent,
duration_sec
)
)}
end)

{:error, _reason} ->
%{}
end

player_results = improve_player_results(tournament, match, duration_sec)
Game.Context.trigger_timeout(match.game_id)

Tournament.Matches.put_match(tournament, %{
Expand Down Expand Up @@ -371,6 +349,30 @@ defmodule Codebattle.Tournament.Base do
do_finish_round_and_next_step(tournament)
end

defp improve_player_results(tournament, match, duration_sec) do
case Game.Context.fetch_game(match.game_id) do
{:ok, game = %{is_live: true}} ->
game
|> Game.Helpers.get_player_results()
|> Map.new(fn {player_id, result} ->
{player_id,
Map.put(
result,
:score,
get_score(
tournament.score_strategy,
match.level,
result.result_percent,
duration_sec
)
)}
end)

{:error, _reason} ->
%{}
end
end

def do_finish_round_and_next_step(tournament) do
tournament
|> update_struct(%{
Expand Down

0 comments on commit 2a3d15d

Please sign in to comment.