Skip to content

Commit

Permalink
Fix error when unprocessed match (#517)
Browse files Browse the repository at this point in the history
  • Loading branch information
jauggy authored Nov 4, 2024
1 parent 0e86f4e commit 4219d22
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions lib/teiserver_web/live/battles/match/show.ex
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ defmodule TeiserverWeb.Battle.MatchLive.Show do
|> Enum.sort_by(fn m -> m.user.name end, &<=/2)
|> Enum.sort_by(fn m -> m.team_id end, &<=/2)

# For unprocessed or unrated matches this will return %{}
rating_logs =
Game.list_rating_logs(
search: [
Expand Down Expand Up @@ -186,12 +187,19 @@ defmodule TeiserverWeb.Battle.MatchLive.Show do
|> Enum.sort_by(fn v -> v end, &<=/2)

balanced_members =
Enum.map(members, fn x ->
team_id = get_team_id(x.user_id, past_balance.team_players)
Map.put(x, :team_id, team_id)
end)
|> Enum.sort_by(fn m -> rating_logs[m.user.id].value["rating_value"] end, &>=/2)
|> Enum.sort_by(fn m -> m.team_id end, &<=/2)
cond do
# It will go here if the match is unprocessed or if there are no rating logs e.g. unrated match
rating_logs == %{} ->
[]

true ->
Enum.map(members, fn x ->
team_id = get_team_id(x.user_id, past_balance.team_players)
Map.put(x, :team_id, team_id)
end)
|> Enum.sort_by(fn m -> rating_logs[m.user.id].value["rating_value"] end, &>=/2)
|> Enum.sort_by(fn m -> m.team_id end, &<=/2)
end

game_id =
cond do
Expand Down

0 comments on commit 4219d22

Please sign in to comment.