From d0d3702a0a065ae057b983bc2d6d9b6d38c45cb5 Mon Sep 17 00:00:00 2001 From: Ebo Date: Mon, 23 Sep 2024 22:37:56 -0700 Subject: [PATCH] Show penalties in SM5 games and scorecards. --- assets/css/app.css | 10 ++++++++++ assets/html/base.html | 19 ++++++++++++++++--- assets/html/game/scorecard_sm5.html | 2 +- assets/html/game/sm5.html | 2 +- helpers/sm5helper.py | 13 +++++++++++++ helpers/tooltiphelper.py | 1 + 6 files changed, 42 insertions(+), 5 deletions(-) diff --git a/assets/css/app.css b/assets/css/app.css index 529f141..d45eab4 100644 --- a/assets/css/app.css +++ b/assets/css/app.css @@ -659,4 +659,14 @@ a { padding: 0.01rem; text-align: center; font-size: 0.5rem; +} + +.yellow-card { + background-color: yellow; + display: inline-block; + width: 0.75em; + height: 1.5em; + border-radius: 6px; + vertical-align: center; + margin-right: 0px; } \ No newline at end of file diff --git a/assets/html/base.html b/assets/html/base.html index 481d936..2d4c77e 100644 --- a/assets/html/base.html +++ b/assets/html/base.html @@ -71,12 +71,12 @@ {% macro player_reference(player) -%} {% if not player.player_info %} -

{{ player.name }}

+ {{ player.name }} {% else %} {% if player.player_info.is_member %} -

{{ player.player_info.display_name }}

+ {{ player.player_info.display_name }} {% else %} -

{{ player.player_info.display_name }}

+ {{ player.player_info.display_name }} {% endif %} {% endif %} {%- endmacro %} @@ -85,6 +85,19 @@ {{ tooltip_info.insert_tooltip(tooltip_id) }} {%- endmacro %} + {% macro player_penalties(player) -%} + {% if player.penalties > 0 %} +
+ {% if player.penalties > 1 %} + x{{ player.penalties }} + {% endif %} + {% endif %} + {%- endmacro %} + + {% macro player_with_penalties(player) -%} + {{ player_reference(player) }} {{ player_penalties(player) }} + {%- endmacro %} + {% macro uptime_chart(entity_id, state_distribution) -%} new Chart("uptime_{{entity_id}}", { diff --git a/assets/html/game/scorecard_sm5.html b/assets/html/game/scorecard_sm5.html index 6ead7e6..eeb39d8 100644 --- a/assets/html/game/scorecard_sm5.html +++ b/assets/html/game/scorecard_sm5.html @@ -333,7 +333,7 @@

{{ team.name }}: {{ team.score {% for player in team.players_with_sum %} {{ sm5_role_icon(player) }} - {{ player_reference(player) }} + {{ player_with_penalties(player) }} {{ player.score }} {{ player.get_gross_positive_score() }} {{ player.points_per_minute }} diff --git a/assets/html/game/sm5.html b/assets/html/game/sm5.html index 4506b9c..6aefd56 100644 --- a/assets/html/game/sm5.html +++ b/assets/html/game/sm5.html @@ -268,7 +268,7 @@

{{ team.ele

{{ sm5_role_icon(player) }}

- {{ player_reference(player) }} + {{ player_with_penalties(player) }} {% if game.ranked %} {% if player.entity_end %} {{ (player.entity_end.current_rating_mu - 3 * player.entity_end.current_rating_sigma)|round(2) }} diff --git a/helpers/sm5helper.py b/helpers/sm5helper.py index d32e436..c4612e8 100644 --- a/helpers/sm5helper.py +++ b/helpers/sm5helper.py @@ -98,6 +98,10 @@ def nuke_cancels(self) -> int: def medic_hits(self) -> int: return self.stats.medic_hits + @property + def penalties(self) -> int: + return self.stats.penalties + @property def role(self) -> Optional[IntRole]: return self.entity_start.role if self.entity_start else None @@ -134,6 +138,8 @@ class Sm5PlayerGameStatsSum(PlayerSm5GameStats): average_time_alive_millis: int + total_penalties: int + @property def name(self) -> str: return "Total" @@ -185,6 +191,10 @@ def medic_hits(self) -> int: def time_in_game_millis(self) -> int: return self.average_time_alive_millis + @property + def penalties(self) -> int: + return self.total_penalties + @dataclass class TeamSm5GameStats(TeamCoreGameStats): @@ -295,6 +305,7 @@ async def get_sm5_player_stats(game: SM5Game, main_player: Optional[EntityStarts sum_missiled_main_player = 0 sum_missiled_by_main_player = 0 sum_score = 0 + sum_penalties = 0 sum_points_per_minute = 0 sum_gross_positive_score = 0 sum_shot_team = 0 @@ -368,6 +379,7 @@ async def get_sm5_player_stats(game: SM5Game, main_player: Optional[EntityStarts # Run a tally so we can compute the sum/average for the team. sum_score += player.score + sum_penalties += player.penalties sum_gross_positive_score += player.get_gross_positive_score() sum_points_per_minute += player.points_per_minute sum_mvp_points += player.mvp_points @@ -413,6 +425,7 @@ async def get_sm5_player_stats(game: SM5Game, main_player: Optional[EntityStarts css_class="team_totals", total_score=sum_score, total_gross_positive_score=sum_gross_positive_score, + total_penalties=sum_penalties, average_points_per_minute=int(sum_points_per_minute / average_divider), state_distribution=avg_state_distribution, score_components=avg_score_components, diff --git a/helpers/tooltiphelper.py b/helpers/tooltiphelper.py index dbc08fa..3a52c43 100644 --- a/helpers/tooltiphelper.py +++ b/helpers/tooltiphelper.py @@ -25,6 +25,7 @@ "sm5_hit_ratio": "The ratio between you zapping the player and they zapping you", "sm5_you_missiled": "How many times you missiled this particular player", "sm5_missiled_you": "How many times this particular player missiled you", + "sm5_penalty": "Penalty", } # Tooltips that are complex that they're implemented as separate DIV tags. The value is the ID of the tag.