Skip to content

Commit

Permalink
Added SM5 uptime 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 f1f618f commit 50d2f8c
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 12 deletions.
12 changes: 12 additions & 0 deletions assets/html/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
}
</script>

<style>
Expand Down
56 changes: 46 additions & 10 deletions assets/html/game/scorecard_sm5.html
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,11 @@
max-width: 50%;
display: flex;
}

.mini-chart {
max-width: 64px;
display: flex;
}
</style>

{% endblock %}
Expand Down Expand Up @@ -282,6 +287,7 @@ <h2 class="{{ team.class_name }}_team_header">{{ team.name }} ({{ team.score }})
<th>Player</th>
<th>Role</th>
<th>Score</th>
<th>Uptime</th>
<th>K/D</th>
<th>Lives</th>
<th>You zapped</th>
Expand All @@ -299,6 +305,7 @@ <h2 class="{{ team.class_name }}_team_header">{{ team.name }} ({{ team.score }})
alt="role image" width="30"
height="30"></td>
<td class="scorecard_player_stat">{{ player.score }}</td>
<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">{{ player.you_zapped }}</td>
Expand Down Expand Up @@ -379,19 +386,11 @@ <h2 class="{{ team.class_name }}_team_header">{{ 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)}`;
}
}
},
Expand Down Expand Up @@ -474,6 +473,43 @@ <h2 class="{{ team.class_name }}_team_header">{{ 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 %}

</script>

{% endblock %}
6 changes: 4 additions & 2 deletions handlers/game/scorecard.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 50d2f8c

Please sign in to comment.