diff --git a/assets/html/game/scorecard_sm5.html b/assets/html/game/scorecard_sm5.html index c9db1b1..a26eb21 100644 --- a/assets/html/game/scorecard_sm5.html +++ b/assets/html/game/scorecard_sm5.html @@ -290,6 +290,7 @@

{{ team.name }} ({{ team.score }}) Uptime K/D Lives + Time in game You zapped Zapped you You missiled @@ -308,6 +309,7 @@

{{ team.name }} ({{ team.score }}) {{ player.kd_ratio }} {{ player.lives_left }} + {{ player.you_zapped }} {{ player.zapped_you }} {{ player.you_missiled }} @@ -490,9 +492,38 @@

{{ 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: { diff --git a/db/sm5.py b/db/sm5.py index 687d5d8..b35a646 100644 --- a/db/sm5.py +++ b/db/sm5.py @@ -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 diff --git a/handlers/game/scorecard.py b/handlers/game/scorecard.py index 7229c91..30a7d4a 100644 --- a/handlers/game/scorecard.py +++ b/handlers/game/scorecard.py @@ -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, @@ -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(),