Skip to content

Commit

Permalink
Add uncertainty to player page (#552)
Browse files Browse the repository at this point in the history
* Add uncertainty to player page
* Put rating on left and add num matches
  • Loading branch information
jauggy authored Jan 9, 2025
1 parent f4e1556 commit a680873
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 32 deletions.
45 changes: 29 additions & 16 deletions lib/teiserver_web/live/battles/match/show.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
44 changes: 28 additions & 16 deletions lib/teiserver_web/live/battles/match/show.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -123,32 +123,33 @@
<thead>
<tr>
<th colspan="6">&nbsp;</th>
<th colspan="3">&nbsp;</th>

<th colspan="2" style="text-align: center; bbackground-color: #FEE;">Damage</th>
<th colspan="2" style="text-align: center; bbackground-color: #EFE;">Units</th>
<th colspan="2" style="text-align: center; bbackground-color: #EEF;">Metal</th>
<th colspan="2" style="text-align: center; bbackground-color: #FFE;">Energy</th>

<th colspan="2">&nbsp;</th>
<th colspan="1">&nbsp;</th>
</tr>

<tr>
<th colspan="4">Name & Party</th>
<th>Team</th>

<th>Rating</th>
<th>Uncertainty</th>
<th>Num Matches</th>
<th>Play</th>

<th>Done</th>
<th>Taken</th>

<th>Killed</th>
<th>Prod</th>

<th>Prod</th>
<th>Used</th>

<th>Prod</th>
<th>Used</th>

<th colspan="1">Rating</th>
<th colspan="1">&nbsp;</th>
</tr>
</thead>
Expand Down Expand Up @@ -183,6 +184,27 @@
<% end %>

<td><%= m.team_id + 1 %></td>

<td>
<%= if rating != nil do %>
<%= rating.value["old_rating_value"]
|> round(2) %>
<% end %>
</td>

<td>
<%= if rating != nil do %>
<%= rating.value["old_uncertainty"]
|> round(2) %>
<% end %>
</td>

<td>
<%= if rating != nil do %>
<%= normalize(rating.value["old_num_matches"]) %>
<% end %>
</td>

<td>
<%= case m.exit_status do %>
<% :stayed -> %>
Expand All @@ -200,22 +222,12 @@
<td><%= normalize(m.stats["damageDealt"]) %></td>
<td><%= normalize(m.stats["damageReceived"]) %></td>

<td><%= normalize(m.stats["unitsKilled"]) %></td>
<td><%= normalize(m.stats["unitsProduced"]) %></td>

<td><%= normalize(m.stats["metalProduced"]) %></td>
<td><%= normalize(m.stats["metalUsed"]) %></td>

<td><%= normalize(m.stats["energyProduced"]) %></td>
<td><%= normalize(m.stats["energyUsed"]) %></td>

<td>
<%= if rating != nil do %>
<%= (rating.value["rating_value"] - rating.value["rating_value_change"])
|> round(2) %>
<% end %>
</td>

<td>
<a
:if={m.user_id != @current_user.id}
Expand Down

0 comments on commit a680873

Please sign in to comment.