diff options
Diffstat (limited to 'jfr_playoff/data.py')
-rw-r--r-- | jfr_playoff/data.py | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/jfr_playoff/data.py b/jfr_playoff/data.py index 2c35191..f38cdee 100644 --- a/jfr_playoff/data.py +++ b/jfr_playoff/data.py @@ -1,3 +1,4 @@ +from cached_property import cached_property from urlparse import urljoin import mysql @@ -15,8 +16,8 @@ SWISS_TIE_WARNING = 'WARNING: tie detected in swiss %s.' + \ class PlayoffData(object): def __init__(self, settings): self.database = PlayoffDB(settings.get('database')) + self.team_settings = settings.get('teams') self.phases = settings.get('phases') - self.teams = settings.get('teams') self.swiss = [] if settings.has_section('swiss'): self.swiss = settings.get('swiss') @@ -24,6 +25,18 @@ class PlayoffData(object): self.match_info = {} self.leaderboard = [] + @cached_property + def teams(self): + if isinstance(self.team_settings, list): + return self.team_settings + db_teams = self.get_swiss_results( + self.team_settings['database'], + self.team_settings['ties'] if 'ties' in self.team_settings else []) + if 'final_positions' in self.team_settings: + for position in self.team_settings['final_positions']: + db_teams[position-1].append(position) + return db_teams + def generate_phases(self): self.grid = [] for phase in self.phases: |