diff options
author | emkael <emkael@tlen.pl> | 2022-02-22 15:07:12 +0100 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2022-02-22 15:08:23 +0100 |
commit | 9ed9eec77d797cc62793357f2be7491adc0e39e9 (patch) | |
tree | df6a330708b8a73c1a19c73a850d3d8866a9ef05 | |
parent | a52352c13fe0c2a3745bbd7fa6e56aac8850bf9c (diff) |
Optional procedure for rounding carry-over in a "league-like" manner: up to the nearest 0.1, avoiding x.0 rounding
-rw-r--r-- | jfr_playoff/dto.py | 10 | ||||
-rw-r--r-- | jfr_playoff/generator.py | 8 |
2 files changed, 17 insertions, 1 deletions
diff --git a/jfr_playoff/dto.py b/jfr_playoff/dto.py index 169eda0..28aa446 100644 --- a/jfr_playoff/dto.py +++ b/jfr_playoff/dto.py @@ -1,3 +1,4 @@ +from math import ceil, floor import sys def coalesce(*arg): @@ -15,6 +16,15 @@ class Team(object): known_teams = 0 selected_team = -1 + @property + def league_carry_over(self): + if self.score == 0.0: + return 0.0 + carry_over = ceil(10 * self.score) / 10.0 + if carry_over.is_integer(): + carry_over = floor(10 * self.score) / 10.0 + return carry_over + def __init__(self): self.place = [] self.name = [] diff --git a/jfr_playoff/generator.py b/jfr_playoff/generator.py index e5b0493..8cc0093 100644 --- a/jfr_playoff/generator.py +++ b/jfr_playoff/generator.py @@ -97,7 +97,13 @@ class PlayoffGenerator(object): PlayoffLogger.get('generator').info( 'generating HTML for team object: %s', team) # the easy part: team score cell - score_html = self.p_temp.get('MATCH_SCORE', team.score) + # fuck you, snarky comment-maker. carry-over settings should apply below: + team_score = team.score + if match.running == 0 and self.team_box_settings.get('league_carryovers', 0): + team_score = team.league_carry_over + PlayoffLogger.get('generator').info( + 'calculated league-like carry-over from %.03f: %0.1f', team.score, team_score) + score_html = self.p_temp.get('MATCH_SCORE', team_score) PlayoffLogger.get('generator').info( 'score HTML for team object: %s', score_html.strip()) # the hard part begins here. |