Skip to content

Commit

Permalink
Merge pull request #58 from EboMike/cleanup
Browse files Browse the repository at this point in the history
Rewrote Laserball game page to use the LB helper.
  • Loading branch information
spookybear0 authored Apr 25, 2024
2 parents 30e0b36 + d35079d commit 39e8307
Show file tree
Hide file tree
Showing 4 changed files with 404 additions and 125 deletions.
136 changes: 36 additions & 100 deletions assets/html/game/laserball.html
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,9 @@
<div style="clear: both;"></div>

<div id="teams">
<div id="fire_team" class="team">
<h2 style="font-size: 20px; color: orangered;" class="team_score">Fire Team: {{ fire_score }}</h2>
{% 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>

<div class="outer-scrolling-table">
<div class="inner-scrolling-table">
Expand All @@ -288,94 +289,38 @@ <h2 style="font-size: 20px; color: orangered;" class="team_score">Fire Team: {{
<th><p title="Goal = 1, Assist = 0.75, Steal = 0.5, Clear = 0.25, Block = 0.3">MVP Points</p></th>
<th><p>Accuracy</p></th>
<th><p>K/D</p></th>
{% for entity in game.entity_starts %}
{% if entity.type == "player" and entity.team.index == 0 %}
{% set entity_end = get_entity_end(entity) %}
{% set laserball_stats = get_laserballstats(entity) %}
<tr>
{% if entity.entity_id.startswith("@") %}
<td class="fixed-column"><p>{{ entity.name }}</p></td>
<td><p>{{ laserball_stats.score }}</p></td>
{% else %}
<td class="fixed-column"><a href="/player/{{entity.name}}"><p>{{ entity.name }}</p></a></td>
<td><a href="/game/laserball/{{game.id}}/scorecard/{{entity_end.id}}">{{ laserball_stats.score }}</a></td>
{% endif %}
{% if entity_end.current_rating_mu and game.ranked %}
<td title="mu: {{ entity_end.current_rating_mu|round(2) }}, sigma: {{ entity_end.current_rating_sigma|round(2) }}">{{ (entity_end.current_rating_mu - 3 * entity_end.current_rating_sigma)|round(2) }}</td>
{% endif %}
<td><p>{{ laserball_stats.goals }}</p></td>
<td><p>{{ laserball_stats.assists }}</p></td>
<td><p>{{ laserball_stats.steals }}</p></td>
<td><p>{{ laserball_stats.clears }}</p></td>
<td><p>{{ laserball_stats.passes }}</p></td>
<td><p>{{ laserball_stats.blocks }}</p></td>
<td><p>{{ laserball_stats.times_stolen }}</p></td>
<td><p>{{ laserball_stats.times_blocked }}</p></td>
<td><p>{{ "%.2f" % (laserball_stats.mvp_points|round(2)) }}</p></td>
<td title="{{laserball_stats.shots_hit}}/{{laserball_stats.shots_fired}}"><p>{{ laserball_stats.shots_fired and "%.2f" % (((laserball_stats.shots_hit/laserball_stats.shots_fired)*100)|round(2)) }}%</p></td>
<td title="{{laserball_stats.blocks}}/{{laserball_stats.times_blocked}}"><p>{{ laserball_stats.times_blocked and "%.2f" % ((laserball_stats.blocks/laserball_stats.times_blocked) | round(2)) }}</p></td>
</tr>
{% endif %}
{% endfor %}
</table>
</div>
</div>
</div>
<div id="ice_team" class="team">
<h2 style="font-size: 20px; color: #0096FF;" class="team_score">Ice Team: {{ ice_score }}</h2>

<div class="outer-scrolling-table">
<div class="inner-scrolling-table">
<table id="ice_table">
<th class="fixed-column"><p>Codename</p></th>
<th><p title="Score = (Goals + Assists) * 10000 + Steals * 100 + Blocks">Score</p></th>
{% if game.ranked %}
<th><p>Current Rating</p></th>
{% endif %}
<th><p>Goals</p></th>
<th><p>Assists</p></th>
<th><p>Steals</p></th>
<th><p>Clears</p></th>
<th><p>Passes</p></th>
<th><p>Blocks</p></th>
<th><p>Stolen</p></th>
<th><p>Blocked</p></th>
<th><p title="Goal = 1, Assist = 0.75, Steal = 0.5, Clear = 0.25, Block = 0.3">MVP Points</p></th>
<th><p>Accuracy</p></th>
<th><p>K/D</p></th>
{% for entity in game.entity_starts %}
{% if entity.type == "player" and entity.team.index == 1 %}
{% set entity_end = get_entity_end(entity) %}
{% set laserball_stats = get_laserballstats(entity) %}
<tr>
{% if entity.entity_id.startswith("@") %}
<td class="fixed-column"><p>{{ entity.name }}</p></td>
<td><p>{{ laserball_stats.score }}</p></td>
{% else %}
<td class="fixed-column"><a href="/player/{{entity.name}}"><p>{{ entity.name }}</p></a></td>
<td><a href="/game/laserball/{{game.id}}/scorecard/{{entity_end.id}}">{{ laserball_stats.score }}</a></td>
{% endif %}
{% if entity_end.current_rating_mu and game.ranked %}
<td title="mu: {{ entity_end.current_rating_mu|round(2) }}, sigma: {{ entity_end.current_rating_sigma|round(2) }}">{{ (entity_end.current_rating_mu - 3 * entity_end.current_rating_sigma)|round(2) }}</td>
{% endif %}
<td><p>{{ laserball_stats.goals }}</p></td>
<td><p>{{ laserball_stats.assists }}</p></td>
<td><p>{{ laserball_stats.steals }}</p></td>
<td><p>{{ laserball_stats.clears }}</p></td>
<td><p>{{ laserball_stats.passes }}</p></td>
<td><p>{{ laserball_stats.blocks }}</p></td>
<td><p>{{ laserball_stats.times_stolen }}</p></td>
<td><p>{{ laserball_stats.times_blocked }}</p></td>
<td><p>{{ "%.2f" % (laserball_stats.mvp_points|round(2)) }}</p></td>
<td title="{{laserball_stats.shots_hit}}/{{laserball_stats.shots_fired}}"><p>{{ laserball_stats.shots_fired and "%.2f" % (((laserball_stats.shots_hit/laserball_stats.shots_fired)*100)|round(2)) }}%</p></td>
<td title="{{laserball_stats.blocks}}/{{laserball_stats.times_blocked}}"><p>{{ laserball_stats.times_blocked and (laserball_stats.blocks/laserball_stats.times_blocked) | round(2) }}</p></td>
</tr>
{% endif %}
{% for player in team.players_with_sum %}
{% set entity_end = player.entity_end %}
<tr class="{{ player.css_class }}">
<td class="fixed-column">{{ player_reference(player) }}</td>
{% if player.player_info.is_member %}
<td><a href="/game/laserball/{{game.id}}/scorecard/{{entity_end.id}}">{{ player.score }}</a></td>
{% else %}
<td><p>{{ player.score }}</p></td>
{% endif %}
{% if entity_end.current_rating_mu and game.ranked %}
<td title="mu: {{ entity_end.current_rating_mu|round(2) }}, sigma: {{ entity_end.current_rating_sigma|round(2) }}">{{ (entity_end.current_rating_mu - 3 * entity_end.current_rating_sigma)|round(2) }}</td>
{% else %}
<td><p>&nbsp;</p></td>
{% endif %}
<td><p>{{ player.goals }}</p></td>
<td><p>{{ player.assists }}</p></td>
<td><p>{{ player.steals }}</p></td>
<td><p>{{ player.clears }}</p></td>
<td><p>{{ player.passes }}</p></td>
<td><p>{{ player.blocks }}</p></td>
<td><p>{{ player.times_stolen }}</p></td>
<td><p>{{ player.times_blocked }}</p></td>
<td><p>{{ "%.2f" % (player.mvp_points|round(2)) }}</p></td>
<td title="{{player.shots_hit}}/{{player.shots_fired}}"><p>{{ player.accuracy_str }}</p></td>
<td title="{{player.blocks}}/{{player.times_blocked}}"><p>{{ player.kd_ratio_str }}</p></td>
</tr>
{% endfor %}
</table>
</div>
</div>
</div>
{% endfor %}
</div>
<div id="stats">
<canvas class="inline-block" id="score_chart" style="clear: both;"></canvas>
Expand All @@ -386,8 +331,6 @@ <h2 style="font-size: 20px; color: #0096FF;" class="team_score">Ice Team: {{ ice
</div>

<div style="clear: both;"></div>

<h1 class="desktop_notif">For more detailed stats, please view the website on desktop.</h1>
</div>
</div>

Expand All @@ -399,24 +342,17 @@ <h1 class="desktop_notif">For more detailed stats, please view the website on de
data: {
labels: {{score_chart_labels}},
datasets: [
{% for team in teams %}
{
label: "Fire Team Goals",
data: {{score_chart_data_red}},
borderColor: "orangered",
label: "{{ team.element }} Team Goals",
data: {{score_chart_data[team.team]}},
borderColor: "{{ team.css_color_name }}",
fill: false,
tension: 0.2,
pointRadius: 0,
pointHitRadius: 10
},
{
label: "Ice Team Goals",
data: {{score_chart_data_blue}},
borderColor: "#0096FF",
fill: false,
tension: 0.2,
pointRadius: 0,
pointHitRadius: 10
}
}{{ "," if not loop.last }}
{% endfor %}
]
},
options: {
Expand Down
36 changes: 11 additions & 25 deletions handlers/game/game.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from sanic import Request

from helpers.laserballhelper import get_laserball_player_stats
from helpers.sm5helper import get_sm5_player_stats
from helpers.tooltips import TOOLTIP_INFO
from shared import app
Expand All @@ -11,7 +12,7 @@
from db.types import Team
from sanic import exceptions
from helpers.statshelper import sentry_trace, get_sm5_team_score_graph_data, \
millis_to_time
millis_to_time, get_ticks_for_time_graph
from numpy import arange
from typing import Optional
from sanic.log import logger
Expand Down Expand Up @@ -76,7 +77,8 @@ async def game_index(request: Request, type: str, id: int) -> str:
is_admin=is_admin(request)
)
elif type == "laserball":
game = await LaserballGame.filter(id=id).prefetch_related("entity_starts").first()
game = await LaserballGame.filter(id=id).prefetch_related("entity_starts", "entity_ends").first()
game_duration = game.mission_duration

logger.debug(f"Fetching laserball game with ID {id}")

Expand All @@ -87,27 +89,15 @@ async def game_index(request: Request, type: str, id: int) -> str:

logger.debug("Fetching team rosters")

team_rosters = await get_team_rosters(await game.entity_starts.all(), await game.entity_ends.all())
full_stats = await get_laserball_player_stats(game)

logger.debug("Fetching team scores")

scores = {
team: await game.get_team_score(team) for team in team_rosters.keys()
}

logger.debug("Fetching team score graph data")

score_chart_data = await get_sm5_team_score_graph_data(game, list(team_rosters.keys()))

logger.debug("Fetching matchmaking teams")

players_matchmake_team1, players_matchmake_team2 = get_matchmaking_teams(team_rosters)
players_matchmake_team1, players_matchmake_team2 = get_matchmaking_teams(full_stats.get_team_rosters())

logger.debug("Fetching win chances")

# Sort the teams in order of their score.
team_ranking = sorted(scores.keys(), key=lambda team: scores[team], reverse=True)

if game.ranked:
win_chance_after_game = await game.get_win_chance_after_game()
win_chance_before_game = await game.get_win_chance_before_game()
Expand All @@ -120,19 +110,15 @@ async def game_index(request: Request, type: str, id: int) -> str:
return await render_cached_template(
request, "game/laserball.html",
game=game,
get_entity_end=get_entity_end,
get_laserballstats=get_laserballstats,
fire_score=await game.get_team_score(Team.RED),
ice_score=await game.get_team_score(Team.BLUE),
score_chart_labels=[{"x": t, "y": await game.get_rounds_at_time(t*60*1000)} for t in arange(0, 900000//1000//60+0.5, 0.5)],
score_chart_data_red=[await game.get_team_score_at_time(Team.RED, t) for t in range(0, 900000+30000, 30000)],
score_chart_data_blue=[await game.get_team_score_at_time(Team.BLUE, t) for t in range(0, 900000+30000, 30000)],
score_chart_data_rounds=[await game.get_rounds_at_time(t) for t in range(0, 900000+30000, 30000)],
teams=full_stats.teams,
score_chart_labels=[{"x": t, "y": await game.get_rounds_at_time(t*60*1000)} for t in arange(0, game_duration//1000//60+0.5, 0.5)],
score_chart_data=full_stats.score_chart_data,
score_chart_data_rounds=full_stats.score_chart_data_rounds,
win_chance_before_game=win_chance_before_game,
win_chance_after_game=win_chance_after_game,
players_matchmake_team1=players_matchmake_team1,
players_matchmake_team2=players_matchmake_team2,
is_admin=is_admin(request)
)
else:
raise exceptions.BadRequest("Invalid game type")
raise exceptions.BadRequest("Invalid game type")
Loading

0 comments on commit 39e8307

Please sign in to comment.