diff --git a/assets/html/base.html b/assets/html/base.html index d53a5d8..21a4805 100644 --- a/assets/html/base.html +++ b/assets/html/base.html @@ -59,6 +59,18 @@ replaysOnErrorSampleRate: 1.0, }); } + + // Converts milliseconds to an MM:SS string. + function ms_to_mmss(milliseconds) { + const seconds = Math.floor(milliseconds / 1000); + const minutes = Math.floor(seconds / 60); + const remainingSeconds = seconds % 60; + + const formattedMinutes = minutes.toString().padStart(2, "0"); + const formattedSeconds = remainingSeconds.toString().padStart(2, "0"); + + return `${formattedMinutes}:${formattedSeconds}`; + } {% endblock %} @@ -282,6 +287,7 @@

{{ team.name }} ({{ team.score }}) Player Role Score + Uptime K/D Lives You zapped @@ -299,6 +305,7 @@

{{ team.name }} ({{ team.score }}) alt="role image" width="30" height="30"> {{ player.score }} + {{ player.kd_ratio }} {{ player.lives_left }} {{ player.you_zapped }} @@ -379,19 +386,11 @@

{{ team.name }} ({{ team.score }}) tooltips: { callbacks: { label: function(tooltipItem, data) { - // convert milliseconds to MM:SS - const index = tooltipItem["index"]; - const milliseconds = data.datasets[0].data[index]; - const seconds = Math.floor(milliseconds / 1000); - const minutes = Math.floor(seconds / 60); - const remainingSeconds = seconds % 60; - - const formattedMinutes = minutes.toString().padStart(2, "0"); - const formattedSeconds = remainingSeconds.toString().padStart(2, "0"); const label = data.labels[index]; + const milliseconds = data.datasets[0].data[index]; - return `${label}: ${formattedMinutes}:${formattedSeconds}`; + return `${label}: ${ms_to_mmss(milliseconds)}`; } } }, @@ -474,6 +473,43 @@

{{ team.name }} ({{ team.score }}) } }); + {% for team in teams %} + {% for player in team.players %} + new Chart("uptime_{{player.entity_end_id}}", { + type: "pie", + data: { + labels: {{ state_distribution_labels }}, + datasets: [{ + backgroundColor: {{ state_distribution_colors }}, + data: {{ player.state_distribution_values }} + }] + }, + options: { + legend: { + display: false, + fullSize: false + }, + title: { + display: false, + text: "Time spent in each state", + fontColor: "white" + }, + 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)}`; + } + } + }, + } + }); + {% endfor %} + {% endfor %} + {% endblock %} \ No newline at end of file diff --git a/handlers/game/scorecard.py b/handlers/game/scorecard.py index 52a1e68..7229c91 100644 --- a/handlers/game/scorecard.py +++ b/handlers/game/scorecard.py @@ -110,10 +110,10 @@ async def scorecard(request: Request, type: str, id: int, entity_end_id: int) -> "Active": "#11dd11", "Down": "#993202", "Down (Resup)": "#8702ab", - "Resettable": "#430103", + "Resettable": "#cbd103", } - state_distribution = await get_player_state_distribution(entity_start,entity_end, game.player_states, game.events, + state_distribution = await get_player_state_distribution(entity_start, entity_end, game.player_states, game.events, state_label_map) state_distribution_labels = list(state_distribution.keys()) @@ -150,6 +150,8 @@ async def scorecard(request: Request, type: str, id: int, entity_end_id: int) -> "zapped_you": await count_zaps(game, player.entity_id, entity_start.entity_id), "you_missiled": await count_missiles(game, entity_start.entity_id, player.entity_id), "missiled_you": await count_missiles(game, player.entity_id, entity_start.entity_id), + "state_distribution_values": list((await get_player_state_distribution(player, player_entity_ends[player.id], + game.player_states, game.events, state_label_map)).values()) } for player in player_entities ]) all_players.sort(key=lambda x: x["score"], reverse=True)