Skip to content

Commit

Permalink
Added SM5 time alive for each player on score cards.
Browse files Browse the repository at this point in the history
  • Loading branch information
EboMike committed Mar 23, 2024
1 parent 50d2f8c commit 23b2955
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
37 changes: 34 additions & 3 deletions assets/html/game/scorecard_sm5.html
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ <h2 class="{{ team.class_name }}_team_header">{{ team.name }} ({{ team.score }})
<th>Uptime</th>
<th>K/D</th>
<th>Lives</th>
<th>Time in game</th>
<th>You zapped</th>
<th>Zapped you</th>
<th>You missiled</th>
Expand All @@ -308,6 +309,7 @@ <h2 class="{{ team.class_name }}_team_header">{{ team.name }} ({{ team.score }})
<td class="scorecard_player_stat"><canvas class="mini-chart" id="uptime_{{player.entity_end_id}}"></canvas></td>
<td class="scorecard_player_stat">{{ player.kd_ratio }}</td>
<td class="scorecard_player_stat">{{ player.lives_left }}</td>
<td class="scorecard_player_stat"><canvas class="mini-chart" id="time_in_game_{{player.entity_end_id}}"></canvas></td>
<td class="scorecard_player_stat">{{ player.you_zapped }}</td>
<td class="scorecard_player_stat">{{ player.zapped_you }}</td>
<td class="scorecard_player_stat">{{ player.you_missiled }}</td>
Expand Down Expand Up @@ -490,9 +492,38 @@ <h2 class="{{ team.class_name }}_team_header">{{ team.name }} ({{ team.score }})
fullSize: false
},
title: {
display: false,
text: "Time spent in each state",
fontColor: "white"
display: false,
},
tooltips: {
callbacks: {
label: function(tooltipItem, data) {
const index = tooltipItem["index"];
const label = data.labels[index];
const milliseconds = data.datasets[0].data[index];

return `${label}: ${ms_to_mmss(milliseconds)}`;
}
}
},
}
});

new Chart("time_in_game_{{player.entity_end_id}}", {
type: "pie",
data: {
labels: ["In game", "Eliminated"],
datasets: [{
backgroundColor: ["#00ff00", "#000000"],
data: {{ player.time_in_game_values }}
}]
},
options: {
legend: {
display: false,
fullSize: false
},
title: {
display: false,
},
tooltips: {
callbacks: {
Expand Down
9 changes: 9 additions & 0 deletions db/sm5.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@ async def get_entity_score_at_time(self, entity_id: int, time_seconds: int) -> i

return scores[-1].new if scores else 0

async def get_actual_game_duration(self) -> int:
"""Returns the actual mission duration time in milliseconds.
Returns the expected duration time unless the game terminated early, for example because one entire team was
eliminated."""
end_event = await self.events.filter(type=EventType.MISSION_END).first()

return end_event.time if end_event else self.mission_duration

# funcs for getting total score at a certain time for a team

async def get_team_score_at_time(self, team: Team, time: int) -> int: # time in seconds
Expand Down
3 changes: 3 additions & 0 deletions handlers/game/scorecard.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ async def scorecard(request: Request, type: str, id: int, entity_end_id: int) ->
player.id: await SM5Stats.filter(entity_id=player.id).first() for player in player_entities
}

game_duration = await game.get_actual_game_duration()

all_players = ([
{
"name": player.name,
Expand All @@ -143,6 +145,7 @@ async def scorecard(request: Request, type: str, id: int, entity_end_id: int) ->
" eliminated_player" if player_sm5_stats[player.id] or player_sm5_stats[player.id].lives_left == 0 else ""),
"score": player_entity_ends[player.id].score,
"lives_left": player_sm5_stats[player.id].lives_left if player.id in player_sm5_stats else "",
"time_in_game_values": [player_entity_ends[player.id].time, game_duration - player_entity_ends[player.id].time],
"kd_ratio": ("%.2f" % (player_sm5_stats[player.id].shot_opponent / player_sm5_stats[player.id].times_zapped
if player_sm5_stats[player.id].times_zapped > 0 else 1)) if player.id in player_sm5_stats else "",
"mvp_points": "%.2f" % await player_sm5_stats[player.id].mvp_points(),
Expand Down

0 comments on commit 23b2955

Please sign in to comment.