Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show the team score adjustment on score cards. #103

Merged
merged 1 commit into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion assets/html/game/scorecard_sm5.html
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ <h2 style="font-size: 20px;">&nbsp;{{entity_start.name}}</h2>
<div class="scorecard_player_stats">
{% for team in teams %}
<div class="scorecard_team_stats">
<h2 class="{{ team.team.css_class }} team-header">{{ team.name }} ({{ team.score }})</h2>
<h2 class="{{ team.team.css_class }} team-header">{{ team.name }}: {{ team.score }}{{ team.score_adjustment_string }}</h2>
<div class="outer-scrolling-table">
<div class="inner-scrolling-table">
<table class="scorecard_player_stats_table">
Expand Down
2 changes: 1 addition & 1 deletion assets/html/game/sm5.html
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@
<div id="teams">
{% for team in teams %}
<div id="{{ team.color }}_team" class="team">
<h2 style="font-size: 20px;" class="team_score {{ team.css_class }}">{{ team.element }} Team: {{ team.score }}</h2>
<h2 style="font-size: 20px;" class="team_score {{ team.css_class }}">{{ team.element }} Team: {{ team.score }}{{team.score_adjustment_string}}</h2>

<div class="outer-scrolling-table">
<div class="inner-scrolling-table">
Expand Down
8 changes: 7 additions & 1 deletion db/sm5.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,17 @@ def __repr__(self) -> str:

async def get_team_score(self, team: Team) -> int:
# Add 10,000 extra points if this team eliminated the opposition.
adjustment = 10000 if team == self.last_team_standing else 0
adjustment = self.get_team_score_adjustment(team)
return adjustment + sum(map(lambda x: x[0],
await self.entity_ends.filter(entity__team__color_name=team.element).values_list(
"score")))

def get_team_score_adjustment(self, team: Team) -> int:
"""Returns how many points should be added to the team score in addition to the sum of the players' scores."""
# The only adjustment currently is the 10k bonus for a team that eliminates another team.
return 10000 if team == self.last_team_standing else 0


async def get_entity_start_from_token(self, token: str) -> Optional["EntityStarts"]:
return await self.entity_starts.filter(entity_id=token).first()

Expand Down
1 change: 1 addition & 0 deletions helpers/sm5helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ async def get_sm5_player_stats(game: SM5Game, main_player: Optional[EntityStarts
TeamSm5GameStats(
team=team,
score=await game.get_team_score(team),
score_adjustment=game.get_team_score_adjustment(team),
players=players,
sum_player=sum_player,
lives_over_time=lives_over_time_team_average
Expand Down
18 changes: 18 additions & 0 deletions helpers/statshelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ class TeamCoreGameStats:
"""The stats for a team for one game that apply to most game formats (at least both SM5 and LB)."""
# Final team score, including adjustments.
score: int

# The score adjustment on top of the players' scores.
score_adjustment: int

team: Team

@property
Expand All @@ -179,6 +183,20 @@ def element(self) -> str:
def color(self) -> str:
return self.team.value.color

@property
def score_adjustment_string(self):
"""Returns the team score adjustment as a string. Empty string if there
was no adjustment, otherwise in the format of
" (+10000)"
" (-5000)"
"""
if self.score_adjustment == 0:
return ""

sign = "+" if self.score_adjustment > 0 else ""

return f" ({sign}{self.score_adjustment})"


"""

Expand Down
Loading