diff --git a/formula10/__init__.py b/formula10/__init__.py index 84e6ee8..728bf5c 100644 --- a/formula10/__init__.py +++ b/formula10/__init__.py @@ -35,15 +35,18 @@ import formula10.controller.error_controller # TODO -# Leaderboard - +# Large DB Update # - For season guess calc there is missing: Fastest laps + sprint points + sprint DNFs (in race result) +# - Decouple names from IDs in each object + Fix Valtteri/Russel spelling errors +# - Mask to allow changing usernames (easy if name is not used as ID) +# - Maybe even masks for races + drivers + teams? +# - DB fields for links to F1 site +# - DB fields for qualifying dates -# - Auto calculate season points (display season points?) -# - Interesting stats: -# - Which driver was voted most for dnf (top 5)? +# Leaderboards/Points +# - Auto calculate season points (display season points in table + season guess card title?) # General -# - Decouple names from IDs + Fix Valtteri/Russel spelling errors -# - Unit testing (as much as possible, but especially points calculation) -# - Add links to the official F1 stats page (for quali/result), probably best to store entire link in DB (because they are not entirely regular)? \ No newline at end of file +# - Export all data to CSV (already have that), but downloadable via browser +# - Add links to the official F1 stats page (for quali/result), probably best to store entire link in DB (because they are not entirely regular)? +# - Unit testing (as much as possible, but especially points calculation) \ No newline at end of file diff --git a/formula10/domain/points_model.py b/formula10/domain/points_model.py index 42eb1bd..30ca67e 100644 --- a/formula10/domain/points_model.py +++ b/formula10/domain/points_model.py @@ -243,6 +243,10 @@ class PointsModel(Model): def total_driver_points_by(self, driver_name: str) -> int: return sum(self.driver_points_by(driver_name=driver_name)) + def drivers_sorted_by_points(self) -> List[Driver]: + comparator: Callable[[Driver], int] = lambda driver: self.total_driver_points_by(driver.name) + return sorted(self.all_drivers(include_none=False), key=comparator, reverse=True) + def wdc_standing_by_position(self) -> Dict[int, List[str]]: standing: Dict[int, List[str]] = dict() @@ -252,7 +256,7 @@ class PointsModel(Model): position: int = 1 last_points: int = 0 - for driver in self.all_drivers(include_none=False): + for driver in self.drivers_sorted_by_points(): points: int = self.total_driver_points_by(driver.name) if points < last_points: position += 1 @@ -268,7 +272,7 @@ class PointsModel(Model): position: int = 1 last_points: int = 0 - for driver in self.all_drivers(include_none=False): + for driver in self.drivers_sorted_by_points(): points: int = self.total_driver_points_by(driver.name) if points < last_points: position += 1 @@ -331,10 +335,6 @@ class PointsModel(Model): return most_lost_names - def drivers_sorted_by_points(self) -> List[Driver]: - comparator: Callable[[Driver], int] = lambda driver: self.wdc_standing_by_driver()[driver.name] - return sorted(self.all_drivers(include_none=False), key=comparator) - # # Team points # @@ -353,6 +353,10 @@ class PointsModel(Model): teammates: List[Driver] = self.drivers_by(team_name=team_name) return sum(self.driver_points_by(driver_name=teammates[0].name)) + sum(self.driver_points_by(driver_name=teammates[1].name)) + def teams_sorted_by_points(self) -> List[Team]: + comparator: Callable[[Team], int] = lambda team: self.total_team_points_by(team.name) + return sorted(self.all_teams(include_none=False), key=comparator, reverse=True) + def wcc_standing_by_position(self) -> Dict[int, List[str]]: standing: Dict[int, List[str]] = dict() @@ -362,7 +366,7 @@ class PointsModel(Model): position: int = 1 last_points: int = 0 - for team in self.all_teams(include_none=False): + for team in self.teams_sorted_by_points(): points: int = self.total_team_points_by(team.name) if points < last_points: position += 1 @@ -378,7 +382,7 @@ class PointsModel(Model): position: int = 1 last_points: int = 0 - for team in self.all_teams(include_none=False): + for team in self.teams_sorted_by_points(): points: int = self.total_team_points_by(team.name) if points < last_points: position += 1 @@ -391,10 +395,6 @@ class PointsModel(Model): def wcc_diff_2023_by(self, team_name: str) -> int: return WCC_STANDING_2023[team_name] - self.wcc_standing_by_team()[team_name] - def teams_sorted_by_points(self) -> List[Team]: - comparator: Callable[[Team], int] = lambda team: self.wcc_standing_by_team()[team.name] - return sorted(self.all_teams(include_none=False), key=comparator) - # # User stats #