From a680873c6a0773c285c15e58d1db9901c8092598 Mon Sep 17 00:00:00 2001 From: Joshua Augustinus Date: Thu, 9 Jan 2025 11:01:30 +1100 Subject: [PATCH] Add uncertainty to player page (#552) * Add uncertainty to player page * Put rating on left and add num matches --- lib/teiserver_web/live/battles/match/show.ex | 45 ++++++++++++------- .../live/battles/match/show.html.heex | 44 +++++++++++------- 2 files changed, 57 insertions(+), 32 deletions(-) diff --git a/lib/teiserver_web/live/battles/match/show.ex b/lib/teiserver_web/live/battles/match/show.ex index 9630c4d92..68798760a 100644 --- a/lib/teiserver_web/live/battles/match/show.ex +++ b/lib/teiserver_web/live/battles/match/show.ex @@ -78,16 +78,6 @@ defmodule TeiserverWeb.Battle.MatchLive.Show do match_name = MatchLib.make_match_name(match) - members = - match.members - |> Enum.map(fn member -> - Map.merge(member, %{ - exit_status: MatchLib.calculate_exit_status(member.left_after, match.game_duration) - }) - end) - |> 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( @@ -98,6 +88,16 @@ defmodule TeiserverWeb.Battle.MatchLive.Show do ) |> Map.new(fn log -> {log.user_id, get_prematch_log(log)} end) + members = + match.members + |> Enum.map(fn member -> + Map.merge(member, %{ + exit_status: MatchLib.calculate_exit_status(member.left_after, match.game_duration) + }) + end) + |> Enum.sort_by(fn m -> rating_logs[m.user.id].value["old_rating_value"] end, &>=/2) + |> Enum.sort_by(fn m -> m.team_id end, &<=/2) + prediction_text = get_prediction_text(rating_logs, members) # Creates a map where the party_id refers to an integer @@ -201,7 +201,7 @@ defmodule TeiserverWeb.Battle.MatchLive.Show do 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 -> rating_logs[m.user.id].value["old_rating_value"] end, &>=/2) |> Enum.sort_by(fn m -> m.team_id end, &<=/2) end @@ -262,8 +262,8 @@ defmodule TeiserverWeb.Battle.MatchLive.Show do %{ team_id: m.team_id, - old_skill: logs["skill"] - logs["skill_change"], - old_uncertainty: logs["uncertainty"] - logs["uncertainty_change"] + old_skill: logs["old_skill"], + old_uncertainty: logs["old_uncertainty"] } end) |> Enum.group_by(fn x -> x.team_id end) @@ -323,14 +323,27 @@ defmodule TeiserverWeb.Battle.MatchLive.Show do "rating_value" => rating_value, "uncertainty" => uncertainty, "rating_value_change" => rating_value_change, - "uncertainty_change" => uncertainty_change + "uncertainty_change" => uncertainty_change, + "skill" => skill, + "skill_change" => skill_change } = log.value + num_matches = Map.get(log.value, "num_matches", nil) + old_rating = rating_value - rating_value_change old_uncertainty = uncertainty - uncertainty_change + old_skill = skill - skill_change + + old_num_matches = + if num_matches, do: num_matches - 1, else: nil + + new_log_value = + Map.put(log.value, "old_rating_value", old_rating) + |> Map.put("old_uncertainty", old_uncertainty) + |> Map.put("old_skill", old_skill) + |> Map.put("old_num_matches", old_num_matches) - Map.put(log, :rating_value, old_rating) - |> Map.put(:uncertainty, old_uncertainty) + Map.put(log, :value, new_log_value) end def get_team_id(player_id, team_players) do diff --git a/lib/teiserver_web/live/battles/match/show.html.heex b/lib/teiserver_web/live/battles/match/show.html.heex index e8c2c0437..1632670d7 100644 --- a/lib/teiserver_web/live/battles/match/show.html.heex +++ b/lib/teiserver_web/live/battles/match/show.html.heex @@ -123,32 +123,33 @@   +   + Damage - Units Metal Energy -   +   Name & Party Team + + Rating + Uncertainty + Num Matches Play Done Taken - Killed - Prod - Prod Used Prod Used - Rating   @@ -183,6 +184,27 @@ <% end %> <%= m.team_id + 1 %> + + + <%= if rating != nil do %> + <%= rating.value["old_rating_value"] + |> round(2) %> + <% end %> + + + + <%= if rating != nil do %> + <%= rating.value["old_uncertainty"] + |> round(2) %> + <% end %> + + + + <%= if rating != nil do %> + <%= normalize(rating.value["old_num_matches"]) %> + <% end %> + + <%= case m.exit_status do %> <% :stayed -> %> @@ -200,22 +222,12 @@ <%= normalize(m.stats["damageDealt"]) %> <%= normalize(m.stats["damageReceived"]) %> - <%= normalize(m.stats["unitsKilled"]) %> - <%= normalize(m.stats["unitsProduced"]) %> - <%= normalize(m.stats["metalProduced"]) %> <%= normalize(m.stats["metalUsed"]) %> <%= normalize(m.stats["energyProduced"]) %> <%= normalize(m.stats["energyUsed"]) %> - - <%= if rating != nil do %> - <%= (rating.value["rating_value"] - rating.value["rating_value_change"]) - |> round(2) %> - <% end %> - -