diff options
author | emkael <emkael@tlen.pl> | 2019-02-20 21:13:21 +0100 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2019-02-20 21:13:21 +0100 |
commit | 93e5bac872f3b4729ad36bea358cbbd5b0829c11 (patch) | |
tree | 9a2b0c4d8cfc62717ff1348582dc29901026c3e1 /jfr_playoff | |
parent | be06f2599161d30ab8a9587bd4db2a8422ebf933 (diff) |
Allowing to specify selected team in config before the match is published, without changing the bracket connections
Diffstat (limited to 'jfr_playoff')
-rw-r--r-- | jfr_playoff/dto.py | 1 | ||||
-rw-r--r-- | jfr_playoff/generator.py | 42 | ||||
-rw-r--r-- | jfr_playoff/matchinfo.py | 1 |
3 files changed, 28 insertions, 16 deletions
diff --git a/jfr_playoff/dto.py b/jfr_playoff/dto.py index 8c04901..169eda0 100644 --- a/jfr_playoff/dto.py +++ b/jfr_playoff/dto.py @@ -13,6 +13,7 @@ class Team(object): score = 0.0 place = None known_teams = 0 + selected_team = -1 def __init__(self): self.place = [] diff --git a/jfr_playoff/generator.py b/jfr_playoff/generator.py index b151af1..ca1905d 100644 --- a/jfr_playoff/generator.py +++ b/jfr_playoff/generator.py @@ -124,6 +124,11 @@ class PlayoffGenerator(object): # count how many teams are eligible (how many non-predicted teams are there) known_teams = len(is_label_predicted) - sum(is_label_predicted) PlayoffLogger.get('generator').info('detected %d known team(s), predicted mask: %s', known_teams, is_label_predicted) + # the team's already selected, cut the label list to single entry + if team.selected_team > -1: + PlayoffLogger.get('generator').info('pre-selected team #%d, label: %s', team.selected_team, labels[team.selected_team]) + labels = [labels[team.selected_team]] + is_label_predicted = [False] if self.team_box_settings.get('sort_eligible_first', True): # sort labels to move eligible teams in front of predicted teams labels = [label for i, label in enumerate(labels) if not is_label_predicted[i]] \ @@ -147,24 +152,29 @@ class PlayoffGenerator(object): team_label.append(self.__get_team_label( labels[l], 'MATCH_PREDICTED_TEAM_LABEL' if is_label_predicted[l] else 'MATCH_TEAM_LABEL')) - # team names for tooltip - for name in team.name: - if name: - # every non-empty name gets some indentation - team_name.append(name_prefix + name) - if self.team_box_settings.get('predict_teams', False): - # remember where the list of eligible teams ends - known_teams = len(team_name) - for name in team.possible_name: - # append predicted team names, with indentation as well + # the team's already selected, cut the tooltip list to single entry + if team.selected_team > -1: + PlayoffLogger.get('generator').info('pre-selected team #%d, name: %s', team.selected_team, team.name[team.selected_team]) + team_name = [team.name[team.selected_team]] + else: + # team names for tooltip + for name in team.name: if name: + # every non-empty name gets some indentation team_name.append(name_prefix + name) - if len(team_name) != known_teams: - # we've added some predicted team names, so we add a header - team_name.insert(known_teams, self.p_temp.get('MATCH_POSSIBLE_TEAM_LIST_HEADER')) - if (len(team_label) > 1) and (match.running == 0) and (known_teams > 0): - # and we add a header for matches that haven't started yet and have multiple options for teams - team_name.insert(0, self.p_temp.get('MATCH_TEAM_LIST_HEADER')) + if self.team_box_settings.get('predict_teams', False): + # remember where the list of eligible teams ends + known_teams = len(team_name) + for name in team.possible_name: + # append predicted team names, with indentation as well + if name: + team_name.append(name_prefix + name) + if len(team_name) > known_teams: + # we've added some predicted team names, so we add a header + team_name.insert(known_teams, self.p_temp.get('MATCH_POSSIBLE_TEAM_LIST_HEADER')) + if (len(team_label) > 1) and (match.running == 0) and (known_teams > 0): + # and we add a header for matches that haven't started yet and have multiple options for teams + team_name.insert(0, self.p_temp.get('MATCH_TEAM_LIST_HEADER')) # glue it all together team_label = label_separator.join(team_label) PlayoffLogger.get('generator').info('output teams label HTML: %s', team_label) diff --git a/jfr_playoff/matchinfo.py b/jfr_playoff/matchinfo.py index 7b7af0b..b1fae4f 100644 --- a/jfr_playoff/matchinfo.py +++ b/jfr_playoff/matchinfo.py @@ -189,6 +189,7 @@ class MatchInfo: teams[i].name = match_teams teams[i].possible_name = possible_teams teams[i].known_teams = len([team for team in match_teams if team is not None]) + teams[i].selected_team = self.config['selected_teams'][i] if 'selected_teams' in self.config else -1 PlayoffLogger.get('matchinfo').info( 'config scores for match #%d: %s', self.info.id, teams) |