diff options
Diffstat (limited to 'jfr_playoff/data.py')
-rw-r--r-- | jfr_playoff/data.py | 67 |
1 files changed, 37 insertions, 30 deletions
diff --git a/jfr_playoff/data.py b/jfr_playoff/data.py index f4adf6f..6649e68 100644 --- a/jfr_playoff/data.py +++ b/jfr_playoff/data.py @@ -8,42 +8,49 @@ from jfr_playoff.logger import PlayoffLogger class PlayoffData(object): - def __init__(self, settings): - self.database = PlayoffDB(settings.get('database')) if settings.has_section('database') else None - if self.database is None: - PlayoffLogger.get('db').warning(PlayoffDB.DATABASE_NOT_CONFIGURED_WARNING) - self.team_settings = settings.get('teams') - self.custom_final_order = [] - if settings.has_section('custom_final_order'): - self.custom_final_order = settings.get('custom_final_order') - self.custom_final_order = [ - t for t in [ - self.teams[i-1] if isinstance(i, int) - else self.get_team_data_by_name(i) - for i in self.custom_final_order] - if t is not None] - self.phases = settings.get('phases') - self.swiss = [] - if settings.has_section('swiss'): - self.swiss = settings.get('swiss') - self.aliases = {} - if settings.has_section('team_aliases'): - self.aliases = settings.get('team_aliases') + def __init__(self, settings=None): + if settings is not None: + self.database = PlayoffDB(settings.get('database')) \ + if settings.has_section('database') else None + if self.database is None: + PlayoffLogger.get('db').warning( + PlayoffDB.DATABASE_NOT_CONFIGURED_WARNING) + self.team_settings = settings.get('teams') + self.custom_final_order = [] + if settings.has_section('custom_final_order'): + self.custom_final_order = settings.get('custom_final_order') + self.custom_final_order = [ + t for t in [ + self.teams[i-1] if isinstance(i, int) + else self.get_team_data_by_name(i) + for i in self.custom_final_order] + if t is not None] + self.phases = settings.get('phases') + self.swiss = [] + if settings.has_section('swiss'): + self.swiss = settings.get('swiss') + self.aliases = {} + if settings.has_section('team_aliases'): + self.aliases = settings.get('team_aliases') self.grid = [] self.match_info = {} self.leaderboard = [] - @cached_property - def teams(self): - if isinstance(self.team_settings, list): + def fetch_team_list(self, settings, db_interface): + if isinstance(settings, list): PlayoffLogger.get('data').info( - 'team list pre-defined: %s', self.team_settings) - return self.team_settings - tournament_info = TournamentInfo(self.team_settings, self.database) + 'team list pre-defined: %s', settings) + return settings + tournament_info = TournamentInfo(settings, db_interface) team_list = tournament_info.get_tournament_results() if len(team_list) == 0: PlayoffLogger.get('data').warning('team list is empty!') - return team_list if 'max_teams' not in self.team_settings else team_list[0:self.team_settings['max_teams']] + return team_list if 'max_teams' not in settings \ + else team_list[0:settings['max_teams']] + + @cached_property + def teams(self): + return self.fetch_team_list(self.team_settings, self.database) def generate_phases(self): self.grid = [] @@ -91,7 +98,7 @@ class PlayoffData(object): def prefill_leaderboard(self, teams): self.leaderboard = [None] * len(teams) for team in teams: - if len(team) > 3: + if len(team) > 3 and team[3] is not None: self.leaderboard[team[3]-1] = team[0] self.fill_swiss_leaderboard(self.swiss, teams) PlayoffLogger.get('data').info('leaderboard pre-filled: %s', self.leaderboard) @@ -176,7 +183,7 @@ class PlayoffData(object): max([ len(phase['matches']) + len(phase.get('dummies', [])) for phase in self.phases - ]) + ] or [0]) ) PlayoffLogger.get('data').info('grid dimensions: %s', dimensions) return dimensions |