Add initial leaderboards page
All checks were successful
Build Formula10 Docker Image / build-docker (push) Successful in 38s
All checks were successful
Build Formula10 Docker Image / build-docker (push) Successful in 38s
This commit is contained in:
@ -1,9 +1,11 @@
|
|||||||
from flask import render_template
|
from flask import render_template
|
||||||
from formula10 import app
|
from formula10 import app
|
||||||
|
from formula10.domain.points_model import PointsModel
|
||||||
from formula10.domain.template_model import TemplateModel
|
from formula10.domain.template_model import TemplateModel
|
||||||
|
|
||||||
@app.route("/graphs")
|
@app.route("/graphs")
|
||||||
def graphs_root() -> str:
|
def graphs_root() -> str:
|
||||||
model = TemplateModel(active_user_name=None, active_result_race_name=None)
|
model = TemplateModel(active_user_name=None, active_result_race_name=None)
|
||||||
|
points = PointsModel()
|
||||||
|
|
||||||
return render_template("statistics.jinja", model=model)
|
return render_template("statistics.jinja", model=model, points=points)
|
@ -97,8 +97,6 @@ class PointsModel(Model):
|
|||||||
|
|
||||||
self._points_per_step[user_name][race_number] = standing_points(race_guess, race_result) + dnf_points(race_guess, race_result)
|
self._points_per_step[user_name][race_number] = standing_points(race_guess, race_result) + dnf_points(race_guess, race_result)
|
||||||
|
|
||||||
return dict()
|
|
||||||
|
|
||||||
return self._points_per_step
|
return self._points_per_step
|
||||||
|
|
||||||
def points_per_step_cumulative(self) -> Dict[str, List[int]]:
|
def points_per_step_cumulative(self) -> Dict[str, List[int]]:
|
||||||
@ -157,3 +155,28 @@ class PointsModel(Model):
|
|||||||
Returns the total number of points for a specific user.
|
Returns the total number of points for a specific user.
|
||||||
"""
|
"""
|
||||||
return sum(self.points_by(user_name=user_name))
|
return sum(self.points_by(user_name=user_name))
|
||||||
|
|
||||||
|
def picks_count(self, user_name: str) -> int:
|
||||||
|
# Treat standing + dnf picks separately
|
||||||
|
return len(self.race_guesses_by(user_name=user_name)) * 2
|
||||||
|
|
||||||
|
def picks_with_points_count(self, user_name: str) -> int:
|
||||||
|
count: int = 0
|
||||||
|
|
||||||
|
for race_guess in self.race_guesses_by(user_name=user_name):
|
||||||
|
race_result: RaceResult | None = self.race_result_by(race_name=race_guess.race.name)
|
||||||
|
if race_result is None:
|
||||||
|
continue
|
||||||
|
|
||||||
|
if standing_points(race_guess, race_result) > 0:
|
||||||
|
count = count + 1
|
||||||
|
if dnf_points(race_guess, race_result) > 0:
|
||||||
|
count = count + 1
|
||||||
|
|
||||||
|
return count
|
||||||
|
|
||||||
|
def points_per_pick(self, user_name: str) -> float:
|
||||||
|
if self.picks_count(user_name) == 0:
|
||||||
|
return 0.0
|
||||||
|
|
||||||
|
return self.total_points_by(user_name) / self.picks_count(user_name)
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
from typing import List, Callable
|
from typing import List, Callable
|
||||||
|
from formula10 import ENABLE_TIMING
|
||||||
|
|
||||||
from formula10.domain.domain_model import Model
|
from formula10.domain.domain_model import Model
|
||||||
from formula10.domain.model.driver import Driver
|
from formula10.domain.model.driver import Driver
|
||||||
@ -29,10 +30,13 @@ class TemplateModel(Model):
|
|||||||
self.active_result = self.race_result_by(race_name=active_result_race_name)
|
self.active_result = self.race_result_by(race_name=active_result_race_name)
|
||||||
|
|
||||||
def race_guess_open(self, race: Race) -> bool:
|
def race_guess_open(self, race: Race) -> bool:
|
||||||
return not race_has_started(race=race)
|
return not race_has_started(race=race) if ENABLE_TIMING else True
|
||||||
|
|
||||||
def season_guess_open(self) -> bool:
|
def season_guess_open(self) -> bool:
|
||||||
return not race_has_started(race_name="Bahrain")
|
return not race_has_started(race_name="Bahrain") if ENABLE_TIMING else True
|
||||||
|
|
||||||
|
def race_result_open(self, race_name: str) -> bool:
|
||||||
|
return race_has_started(race_name=race_name) if ENABLE_TIMING else True
|
||||||
|
|
||||||
def active_user_name_or_everyone(self) -> str:
|
def active_user_name_or_everyone(self) -> str:
|
||||||
return self.active_user.name if self.active_user is not None else "Everyone"
|
return self.active_user.name if self.active_user is not None else "Everyone"
|
||||||
|
@ -7,27 +7,50 @@
|
|||||||
{% block body %}
|
{% block body %}
|
||||||
|
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<div class="card-body">
|
|
||||||
<h5 class="card-title">Leaderboard</h5>
|
|
||||||
|
|
||||||
{# Table that lists each users + Total Points (?), Race guesses points, Season guesses points (missing overtakes + hottake), number of guesses that yielded points, average points per guess #}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="card mt-2">
|
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<h5 class="card-title">History</h5>
|
<h5 class="card-title">Leaderboard</h5>
|
||||||
|
<h6 class="card-subtitle">Points only include race picks</h6>
|
||||||
|
|
||||||
{# Line chart of point history with a line per user #}
|
<table class="table table-bordered table-sm table-responsive mt-3">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th scope="col" class="text-center" style="width: 1%;">User</th>
|
||||||
|
<th scope="col" class="text-center" style="width: 1%;">Points</th>
|
||||||
|
<th scope="col" class="text-center" style="width: 1%;">Total picks</th>
|
||||||
|
<th scope="col" class="text-center" style="width: 1%;">Correct picks</th>
|
||||||
|
<th scope="col" class="text-center" style="width: 1%;">Points per pick</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
|
||||||
|
<tbody>
|
||||||
|
{% for user in model.all_users() %}
|
||||||
|
<tr>
|
||||||
|
<td class="text-center text-nowrap">{{ user.name }}</td>
|
||||||
|
<td class="text-center text-nowrap">{{ points.total_points_by(user.name) }}</td>
|
||||||
|
<td class="text-center text-nowrap">{{ points.picks_count(user.name) }}</td>
|
||||||
|
<td class="text-center text-nowrap">{{ points.picks_with_points_count(user.name) }}</td>
|
||||||
|
<td class="text-center text-nowrap">{{ "%0.2f" % points.points_per_pick(user.name) }}</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="card mt-2">
|
{# <div class="card mt-2">#}
|
||||||
<div class="card-body">
|
{# <div class="card-body">#}
|
||||||
<h5 class="card-title">Statistics</h5>
|
{# <h5 class="card-title">History</h5>#}
|
||||||
|
|
||||||
{# Various statistics: Driver voted most for DNF #}
|
{# Line chart of point history with a line per user #}
|
||||||
</div>
|
{# </div>#}
|
||||||
</div>
|
{# </div>#}
|
||||||
|
|
||||||
|
{# <div class="card mt-2">#}
|
||||||
|
{# <div class="card-body">#}
|
||||||
|
{# <h5 class="card-title">Statistics</h5>#}
|
||||||
|
|
||||||
|
{# Various statistics: Driver voted most for DNF #}
|
||||||
|
{# </div>#}
|
||||||
|
{# </div>#}
|
||||||
|
|
||||||
{% endblock body %}
|
{% endblock body %}
|
||||||
|
Reference in New Issue
Block a user