diff --git a/formula10/controller/statistics_controller.py b/formula10/controller/statistics_controller.py index 915b925..8d49c83 100644 --- a/formula10/controller/statistics_controller.py +++ b/formula10/controller/statistics_controller.py @@ -1,9 +1,11 @@ from flask import render_template from formula10 import app +from formula10.domain.points_model import PointsModel from formula10.domain.template_model import TemplateModel @app.route("/graphs") def graphs_root() -> str: model = TemplateModel(active_user_name=None, active_result_race_name=None) + points = PointsModel() - return render_template("statistics.jinja", model=model) \ No newline at end of file + return render_template("statistics.jinja", model=model, points=points) \ No newline at end of file diff --git a/formula10/domain/points_model.py b/formula10/domain/points_model.py index f4cb02c..6517f95 100644 --- a/formula10/domain/points_model.py +++ b/formula10/domain/points_model.py @@ -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) - return dict() - return self._points_per_step 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. """ 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) diff --git a/formula10/domain/template_model.py b/formula10/domain/template_model.py index ebc6408..17f8c07 100644 --- a/formula10/domain/template_model.py +++ b/formula10/domain/template_model.py @@ -1,4 +1,5 @@ from typing import List, Callable +from formula10 import ENABLE_TIMING from formula10.domain.domain_model import Model 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) 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: - 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: return self.active_user.name if self.active_user is not None else "Everyone" diff --git a/formula10/templates/statistics.jinja b/formula10/templates/statistics.jinja index 22e2cab..44802ab 100644 --- a/formula10/templates/statistics.jinja +++ b/formula10/templates/statistics.jinja @@ -7,27 +7,50 @@ {% block body %}
-
-
Leaderboard
- - {# 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 #} -
-
- -
-
History
+
Leaderboard
+
Points only include race picks
- {# Line chart of point history with a line per user #} + + + + + + + + + + + + + {% for user in model.all_users() %} + + + + + + + + {% endfor %} + +
UserPointsTotal picksCorrect picksPoints per pick
{{ user.name }}{{ points.total_points_by(user.name) }}{{ points.picks_count(user.name) }}{{ points.picks_with_points_count(user.name) }}{{ "%0.2f" % points.points_per_pick(user.name) }}
-
-
-
Statistics
+ {#
#} + {#
#} + {#
History
#} - {# Various statistics: Driver voted most for DNF #} -
-
+ {# Line chart of point history with a line per user #} + {#
#} + {#
#} + + {#
#} + {#
#} + {#
Statistics
#} + + {# Various statistics: Driver voted most for DNF #} + {#
#} + {#
#} {% endblock body %}