summaryrefslogtreecommitdiff
path: root/jfr_playoff/data
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2022-03-12 20:32:44 +0100
committeremkael <emkael@tlen.pl>2022-03-12 20:32:44 +0100
commita0b269284965c2a68d3b3bf32929b2ef22b285b2 (patch)
tree984121c33b6a01b5bf2d94d74f02392f3b80f84a /jfr_playoff/data
parent9ea9dba5dba306730e3fbdd3815c26f551032566 (diff)
Automatic carry-over calculations for not-yet-run matches
Diffstat (limited to 'jfr_playoff/data')
-rw-r--r--jfr_playoff/data/__init__.py6
-rw-r--r--jfr_playoff/data/info.py20
2 files changed, 24 insertions, 2 deletions
diff --git a/jfr_playoff/data/__init__.py b/jfr_playoff/data/__init__.py
index b5c9ceb..88e9f24 100644
--- a/jfr_playoff/data/__init__.py
+++ b/jfr_playoff/data/__init__.py
@@ -1,4 +1,5 @@
from cached_property import cached_property
+from decimal import Decimal
from jfr_playoff.db import PlayoffDB
from jfr_playoff.dto import Phase
@@ -34,6 +35,8 @@ class PlayoffData(object):
self.aliases = settings.get('team_aliases')
self._predict_teams = int(settings.get('page').get(
'team_boxes', {}).get('predict_teams', 0)) > 0
+ self._calculate_carry_over = Decimal(settings.get('page').get(
+ 'team_boxes', {}).get('auto_carryover', 0.0))
self.grid = []
self.match_info = {}
self.leaderboard = []
@@ -88,7 +91,8 @@ class PlayoffData(object):
match_info = MatchInfo(
match, teams, self.database,
self.aliases,
- certain_starting_positions)
+ certain_starting_positions,
+ self._calculate_carry_over)
if 'link' in phase:
match_info.set_phase_link(phase['link'])
self.match_info[match['id']] = match_info.get_info()
diff --git a/jfr_playoff/data/info.py b/jfr_playoff/data/info.py
index b3f5a00..fc5121a 100644
--- a/jfr_playoff/data/info.py
+++ b/jfr_playoff/data/info.py
@@ -1,4 +1,5 @@
import copy
+from decimal import Decimal
import inspect
from urlparse import urljoin
@@ -101,10 +102,11 @@ class MatchInfo(ResultInfo):
matches = {}
def __init__(self, match_config, teams, database,
- aliases=None, starting_positions_certain=True):
+ aliases=None, starting_positions_certain=True, auto_carryover=False):
ResultInfo.__init__(self, match_config, database)
self.config = match_config
self.teams = teams
+ self.teams_by_name = { team[0]: team for team in self.teams }
self.database = database
self.aliases = {}
if aliases:
@@ -112,6 +114,7 @@ class MatchInfo(ResultInfo):
for alias in team_aliases:
self.aliases[alias] = team
self._starting_positions_certain = starting_positions_certain
+ self._auto_carryover = auto_carryover
self.info = Match()
self._init_info()
self._fetch_match_link()
@@ -282,6 +285,21 @@ class MatchInfo(ResultInfo):
elif self.info.teams[0].score < self.info.teams[1].score:
self.info.possible_loser = teams[0]
self.info.possible_winner = teams[1]
+ elif self.info.running == 0:
+ if self._auto_carryover:
+ team_data = [self.teams_by_name[team] for team in teams]
+ if len(team_data[0]) > 4 and len(team_data[1]) > 4:
+ carry_over = self._auto_carryover / Decimal(100.0) * (team_data[0][4] - team_data[1][4])
+ if carry_over > 0:
+ self.info.teams[0].score = carry_over
+ self.info.teams[1].score = 0.0
+ else:
+ self.info.teams[0].score = 0.0
+ self.info.teams[1].score = -carry_over
+ PlayoffLogger.get('matchinfo').info(
+ 'calculated carry-over for match #%d: %s, team data: %s',
+ self.info.id, carry_over, self.info.teams)
+
def _determine_running_link(self):
if self.info.link is None: