diff options
author | emkael <emkael@tlen.pl> | 2020-01-05 13:50:05 +0100 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2020-01-05 13:50:05 +0100 |
commit | 856cf764545362dd43cd2f304bd73c4594e1e6e8 (patch) | |
tree | 25b7d89758934c1505d4a4775cbace45491b61ea | |
parent | 8ec9f68131ff3ff6f3dab3af5f27fa25e6d66f45 (diff) |
If team list source tournament is not finished, predict_teams settings is respected
Fixes #44
-rw-r--r-- | jfr_playoff/data/__init__.py | 19 | ||||
-rw-r--r-- | jfr_playoff/data/info.py | 12 | ||||
-rw-r--r-- | jfr_playoff/generator.py | 2 | ||||
-rw-r--r-- | jfr_playoff/gui/tabs.py | 2 |
4 files changed, 27 insertions, 8 deletions
diff --git a/jfr_playoff/data/__init__.py b/jfr_playoff/data/__init__.py index 3e63e98..b5c9ceb 100644 --- a/jfr_playoff/data/__init__.py +++ b/jfr_playoff/data/__init__.py @@ -8,6 +8,7 @@ from jfr_playoff.logger import PlayoffLogger class PlayoffData(object): def __init__(self, settings=None): + self._team_list_certain = True if settings is not None: self.database = PlayoffDB(settings.get('database')) \ if settings.has_section('database') else None @@ -31,6 +32,8 @@ class PlayoffData(object): self.aliases = {} if settings.has_section('team_aliases'): self.aliases = settings.get('team_aliases') + self._predict_teams = int(settings.get('page').get( + 'team_boxes', {}).get('predict_teams', 0)) > 0 self.grid = [] self.match_info = {} self.leaderboard = [] @@ -39,17 +42,20 @@ class PlayoffData(object): if isinstance(settings, list): PlayoffLogger.get('data').info( 'team list pre-defined: %s', settings) - return settings + return settings, True 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 settings \ + teams = team_list if 'max_teams' not in settings \ else team_list[0:settings['max_teams']] + return teams, tournament_info.is_finished() @cached_property def teams(self): - return self.fetch_team_list(self.team_settings, self.database) + team_list, certain = self.fetch_team_list(self.team_settings, self.database) + self._team_list_certain = certain + return team_list def generate_phases(self): self.grid = [] @@ -76,8 +82,13 @@ class PlayoffData(object): for match in phase['matches']: PlayoffLogger.get('data').info( 'getting match info for #%d', match['id']) + teams = self.teams + certain_starting_positions = self._team_list_certain \ + if self._predict_teams > 0 else True match_info = MatchInfo( - match, self.teams, self.database, self.aliases) + match, teams, self.database, + self.aliases, + certain_starting_positions) 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 55cc926..f79499b 100644 --- a/jfr_playoff/data/info.py +++ b/jfr_playoff/data/info.py @@ -100,7 +100,8 @@ class MatchInfo(ResultInfo): matches = {} - def __init__(self, match_config, teams, database, aliases=None): + def __init__(self, match_config, teams, database, + aliases=None, starting_positions_certain=True): ResultInfo.__init__(self, match_config, database) self.config = match_config self.teams = teams @@ -110,6 +111,7 @@ class MatchInfo(ResultInfo): for team, team_aliases in aliases.iteritems(): for alias in team_aliases: self.aliases[alias] = team + self._starting_positions_certain = starting_positions_certain self.info = Match() self._init_info() self._fetch_match_link() @@ -193,9 +195,15 @@ class MatchInfo(ResultInfo): MatchInfo.matches[loser_match].possible_loser for loser_match in self.config['teams'][i]['loser']] if 'place' in self.config['teams'][i]: - match_teams += [ + placed_teams = [ self.teams[place-1][0] for place in self.config['teams'][i]['place']] + if self._starting_positions_certain: + match_teams += placed_teams + possible_teams = [None] * len(placed_teams) + else: + possible_teams += placed_teams + match_teams = [None] * len(placed_teams) teams[i].name = match_teams teams[i].possible_name = possible_teams teams[i].known_teams = len([ diff --git a/jfr_playoff/generator.py b/jfr_playoff/generator.py index 2c1dc39..e5b0493 100644 --- a/jfr_playoff/generator.py +++ b/jfr_playoff/generator.py @@ -115,7 +115,7 @@ class PlayoffGenerator(object): team_label = '' team_name = '' else: - # predicted teams are not in team.name, they're in tem.possible_name so corresponding spots in team.name are empty + # predicted teams are not in team.name, they're in team.possible_name so corresponding spots in team.name are empty is_label_predicted = [name is None for name in team.name] # fetch labels (shortnames) for teams in both lists labels = [self.data.get_shortname(name) if name else None for name in team.name] diff --git a/jfr_playoff/gui/tabs.py b/jfr_playoff/gui/tabs.py index 67a3dbe..cc8a291 100644 --- a/jfr_playoff/gui/tabs.py +++ b/jfr_playoff/gui/tabs.py @@ -219,7 +219,7 @@ class TeamsTab(PlayoffTab): db = PlayoffDB(dbConfig) except Exception: pass - self._teamList = data.fetch_team_list(config['teams'], db) + self._teamList = data.fetch_team_list(config['teams'], db)[0] self.winfo_toplevel().event_generate( '<<TeamListChanged>>', when='tail') |