From 6fa172aed2f008ef601386387aaa2e149e64e0dd Mon Sep 17 00:00:00 2001 From: emkael Date: Mon, 22 Jan 2018 14:43:51 +0100 Subject: Team list can now be retrieved from tournament standings --- jfr_playoff/data.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) 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: -- cgit v1.2.3