From 6f147d1b37de5c12b77c51ca2f80031cbec6ae20 Mon Sep 17 00:00:00 2001 From: emkael Date: Mon, 1 Oct 2018 14:54:58 +0200 Subject: Refactoring team name list in matches as actual list --- jfr_playoff/dto.py | 5 ++++- jfr_playoff/generator.py | 12 ++++++------ jfr_playoff/matchinfo.py | 37 +++++++++++++++++++------------------ 3 files changed, 29 insertions(+), 25 deletions(-) (limited to 'jfr_playoff') diff --git a/jfr_playoff/dto.py b/jfr_playoff/dto.py index a88cd2b..ad70735 100644 --- a/jfr_playoff/dto.py +++ b/jfr_playoff/dto.py @@ -8,9 +8,12 @@ def coalesce(*arg): class Team(object): - name = '' + name = None score = 0.0 + def __init__(self): + self.name = [] + def __unicode__(self): return u'%s (%.1f)' % (coalesce(self.name, ''), self.score) diff --git a/jfr_playoff/generator.py b/jfr_playoff/generator.py index d358d86..a1b519e 100644 --- a/jfr_playoff/generator.py +++ b/jfr_playoff/generator.py @@ -55,23 +55,23 @@ class PlayoffGenerator(object): for team in match.teams: score_html = self.p_temp.get('MATCH_SCORE', team.score) team_label = ' / '.join([ - self.data.get_shortname(name) for name in - team.name.split('
')]) + self.data.get_shortname(name) for name in team.name]) + team_name = '
'.join(team.name) label_max_length = self.page.get('label_length_limit', 0) if label_max_length: team_label = team_label[:label_max_length] + (team_label[label_max_length:] and '(...)') team_html = self.p_temp.get( 'MATCH_TEAM_LINK', - match.link, team.name, team_label) \ + match.link, team_name, team_label) \ if match.link is not None \ else self.p_temp.get( 'MATCH_TEAM_NON_LINK', - team.name, team_label) + team_name, team_label) rows += self.p_temp.get( 'MATCH_TEAM_ROW', ' '.join([ - 'winner' if team.name == match.winner else '', - 'loser' if team.name == match.loser else '' + 'winner' if match.winner in team.name else '', + 'loser' if match.loser in team.name else '' ]).strip(), team_html, self.p_temp.get( diff --git a/jfr_playoff/matchinfo.py b/jfr_playoff/matchinfo.py index ab742d4..e9854c5 100644 --- a/jfr_playoff/matchinfo.py +++ b/jfr_playoff/matchinfo.py @@ -58,9 +58,9 @@ class MatchInfo: teams[i].score = self.config['score'][score] try: team_no = int(score) - teams[i].name = self.teams[team_no-1][0] + teams[i].name = [self.teams[team_no-1][0]] except ValueError: - teams[i].name = score + teams[i].name = [score] teams_fetched = True else: teams[i].score = score @@ -77,8 +77,8 @@ class MatchInfo: row = self.database.fetch( self.config['database'], p_sql.MATCH_RESULTS, (self.config['table'], self.config['round'])) - teams[0].name = row[0] - teams[1].name = row[1] + teams[0].name = [row[0]] + teams[1].name = [row[1]] if fetch_scores: teams[0].score = row[3] + row[5] teams[1].score = row[4] + row[6] @@ -147,7 +147,7 @@ class MatchInfo: if isinstance(text, unicode)][0].strip(u'\xa0') for link in row.select('a[onmouseover]')] for i in range(0, 2): - teams[i].name = team_names[i] + teams[i].name = [team_names[i]] teams[i].score = scores[i] PlayoffLogger.get('matchinfo').info( 'HTML scores for match #%d: %s', @@ -158,9 +158,9 @@ class MatchInfo: for i in range(0, 2): match_teams = [] if isinstance(self.config['teams'][i], basestring): - teams[i].name = self.config['teams'][i] + teams[i].name = [self.config['teams'][i]] elif isinstance(self.config['teams'][i], list): - teams[i].name = '
'.join(self.config['teams'][i]) + teams[i].name = self.config['teams'][i] else: if 'winner' in self.config['teams'][i]: match_teams += [ @@ -176,11 +176,10 @@ class MatchInfo: for place in self.config['teams'][i]['place']] known_teams = [team for team in match_teams if team is not None] if len(known_teams) > 0: - teams[i].name = '
'.join([ - team if team is not None - else '??' for team in match_teams]) + teams[i].name = [team if team is not None + else '??' for team in match_teams] else: - teams[i].name = '' + teams[i].name = [''] PlayoffLogger.get('matchinfo').info( 'config scores for match #%d: %s', self.info.id, teams) @@ -341,13 +340,15 @@ class MatchInfo: else boards_played def __determine_outcome(self): - if (self.info.running == -1): - if self.info.teams[0].score > self.info.teams[1].score: - self.info.winner = self.info.teams[0].name - self.info.loser = self.info.teams[1].name - else: - self.info.loser = self.info.teams[0].name - self.info.winner = self.info.teams[1].name + if (len(self.info.teams[0].name) == 1) \ + and (len(self.info.teams[1].name) == 1): + if self.info.running == -1: + if self.info.teams[0].score > self.info.teams[1].score: + self.info.winner = self.info.teams[0].name[0] + self.info.loser = self.info.teams[1].name[0] + else: + self.info.loser = self.info.teams[0].name[0] + self.info.winner = self.info.teams[1].name[0] def __get_db_running_link(self, prefix, round_no): current_segment = int( -- cgit v1.2.3 From 03ab8b041179daa2ed75966a3c2255e239f8fde7 Mon Sep 17 00:00:00 2001 From: emkael Date: Mon, 1 Oct 2018 16:09:07 +0200 Subject: Explicitly counting known teams for match boxes --- jfr_playoff/dto.py | 1 + jfr_playoff/generator.py | 11 +++++++---- jfr_playoff/matchinfo.py | 18 ++++++++---------- 3 files changed, 16 insertions(+), 14 deletions(-) (limited to 'jfr_playoff') diff --git a/jfr_playoff/dto.py b/jfr_playoff/dto.py index ad70735..58b08c1 100644 --- a/jfr_playoff/dto.py +++ b/jfr_playoff/dto.py @@ -10,6 +10,7 @@ def coalesce(*arg): class Team(object): name = None score = 0.0 + known_teams = 0 def __init__(self): self.name = [] diff --git a/jfr_playoff/generator.py b/jfr_playoff/generator.py index a1b519e..f2a2c55 100644 --- a/jfr_playoff/generator.py +++ b/jfr_playoff/generator.py @@ -1,5 +1,6 @@ from datetime import datetime +from jfr_playoff.dto import coalesce from jfr_playoff.template import PlayoffTemplate from jfr_playoff.data import PlayoffData from jfr_playoff.logger import PlayoffLogger @@ -54,9 +55,11 @@ class PlayoffGenerator(object): rows = '' for team in match.teams: score_html = self.p_temp.get('MATCH_SCORE', team.score) + teams = [coalesce(name, '??') for name in team.name] team_label = ' / '.join([ - self.data.get_shortname(name) for name in team.name]) - team_name = '
'.join(team.name) + self.data.get_shortname(name) if name is not None else '??' for name in team.name]) \ + if team.known_teams > 0 else '' + team_name = '
'.join(teams) label_max_length = self.page.get('label_length_limit', 0) if label_max_length: team_label = team_label[:label_max_length] + (team_label[label_max_length:] and '(...)') @@ -70,8 +73,8 @@ class PlayoffGenerator(object): rows += self.p_temp.get( 'MATCH_TEAM_ROW', ' '.join([ - 'winner' if match.winner in team.name else '', - 'loser' if match.loser in team.name else '' + 'winner' if match.winner in teams else '', + 'loser' if match.loser in teams else '' ]).strip(), team_html, self.p_temp.get( diff --git a/jfr_playoff/matchinfo.py b/jfr_playoff/matchinfo.py index e9854c5..f7a156d 100644 --- a/jfr_playoff/matchinfo.py +++ b/jfr_playoff/matchinfo.py @@ -77,8 +77,9 @@ class MatchInfo: row = self.database.fetch( self.config['database'], p_sql.MATCH_RESULTS, (self.config['table'], self.config['round'])) - teams[0].name = [row[0]] - teams[1].name = [row[1]] + for i in range(0, 2): + teams[i].name = [row[i]] + teams[i].known_teams = 1 if fetch_scores: teams[0].score = row[3] + row[5] teams[1].score = row[4] + row[6] @@ -148,6 +149,7 @@ class MatchInfo: for link in row.select('a[onmouseover]')] for i in range(0, 2): teams[i].name = [team_names[i]] + teams[i].known_teams = 1 teams[i].score = scores[i] PlayoffLogger.get('matchinfo').info( 'HTML scores for match #%d: %s', @@ -174,12 +176,8 @@ class MatchInfo: match_teams += [ self.teams[place-1][0] for place in self.config['teams'][i]['place']] - known_teams = [team for team in match_teams if team is not None] - if len(known_teams) > 0: - teams[i].name = [team if team is not None - else '??' for team in match_teams] - else: - teams[i].name = [''] + teams[i].name = match_teams + teams[i].known_teams = len([team for team in match_teams if team is not None]) PlayoffLogger.get('matchinfo').info( 'config scores for match #%d: %s', self.info.id, teams) @@ -340,8 +338,8 @@ class MatchInfo: else boards_played def __determine_outcome(self): - if (len(self.info.teams[0].name) == 1) \ - and (len(self.info.teams[1].name) == 1): + if (self.info.teams[0].known_teams == 1) \ + and (self.info.teams[1].known_teams == 1): if self.info.running == -1: if self.info.teams[0].score > self.info.teams[1].score: self.info.winner = self.info.teams[0].name[0] -- cgit v1.2.3 From 62fe5244beb1a859b86aae86d784a86b30d86ca9 Mon Sep 17 00:00:00 2001 From: emkael Date: Tue, 2 Oct 2018 12:41:31 +0200 Subject: Fetching info about possible outcomes of matches in progress --- jfr_playoff/dto.py | 4 ++++ jfr_playoff/matchinfo.py | 15 +++++++++++++++ 2 files changed, 19 insertions(+) (limited to 'jfr_playoff') diff --git a/jfr_playoff/dto.py b/jfr_playoff/dto.py index 58b08c1..b1a3a5c 100644 --- a/jfr_playoff/dto.py +++ b/jfr_playoff/dto.py @@ -9,11 +9,13 @@ def coalesce(*arg): class Team(object): name = None + possible_name = None score = 0.0 known_teams = 0 def __init__(self): self.name = [] + self.possible_name = [] def __unicode__(self): return u'%s (%.1f)' % (coalesce(self.name, ''), self.score) @@ -29,6 +31,8 @@ class Match(object): link = None winner = None loser = None + possible_winner = None + possible_loser = None winner_matches = None loser_matches = None diff --git a/jfr_playoff/matchinfo.py b/jfr_playoff/matchinfo.py index f7a156d..bb13ed9 100644 --- a/jfr_playoff/matchinfo.py +++ b/jfr_playoff/matchinfo.py @@ -159,6 +159,7 @@ class MatchInfo: def __get_config_teams(self, teams): for i in range(0, 2): match_teams = [] + possible_teams = [] if isinstance(self.config['teams'][i], basestring): teams[i].name = [self.config['teams'][i]] elif isinstance(self.config['teams'][i], list): @@ -168,15 +169,22 @@ class MatchInfo: match_teams += [ MatchInfo.matches[winner_match].winner for winner_match in self.config['teams'][i]['winner']] + possible_teams += [ + MatchInfo.matches[winner_match].possible_winner + for winner_match in self.config['teams'][i]['winner']] if 'loser' in self.config['teams'][i]: match_teams += [ MatchInfo.matches[loser_match].loser for loser_match in self.config['teams'][i]['loser']] + possible_teams += [ + MatchInfo.matches[loser_match].possible_loser + for loser_match in self.config['teams'][i]['loser']] if 'place' in self.config['teams'][i]: match_teams += [ self.teams[place-1][0] for place in self.config['teams'][i]['place']] 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]) PlayoffLogger.get('matchinfo').info( 'config scores for match #%d: %s', @@ -347,6 +355,13 @@ class MatchInfo: else: self.info.loser = self.info.teams[0].name[0] self.info.winner = self.info.teams[1].name[0] + elif self.info.running > 0: + if self.info.teams[0].score > self.info.teams[1].score: + self.info.possible_winner = self.info.teams[0].name[0] + self.info.possible_loser = self.info.teams[1].name[0] + elif self.info.teams[0].score < self.info.teams[1].score: + self.info.possible_loser = self.info.teams[0].name[0] + self.info.possible_winner = self.info.teams[1].name[0] def __get_db_running_link(self, prefix, round_no): current_segment = int( -- cgit v1.2.3 From 6119175f65c6bc12771a968cd72e6c8179848f78 Mon Sep 17 00:00:00 2001 From: emkael Date: Tue, 2 Oct 2018 12:43:11 +0200 Subject: Templates and strings for new team label rendering method --- jfr_playoff/generator.py | 6 ++++++ jfr_playoff/i18n.py | 4 +++- jfr_playoff/template.py | 8 ++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) (limited to 'jfr_playoff') diff --git a/jfr_playoff/generator.py b/jfr_playoff/generator.py index f2a2c55..fab6d0e 100644 --- a/jfr_playoff/generator.py +++ b/jfr_playoff/generator.py @@ -51,6 +51,12 @@ class PlayoffGenerator(object): 'PAGE_BODY_FOOTER', datetime.now().strftime('%Y-%m-%d o %H:%M:%S')))) + def __get_team_label(self, team_name, template='MATCH_TEAM_LABEL'): + if not self.page.get('predict_teams', None): + # override template if team predictions are not enabled + template = 'MATCH_TEAM_LABEL' + return self.p_temp.get(template, team_name) + def get_match_table(self, match): rows = '' for team in match.teams: diff --git a/jfr_playoff/i18n.py b/jfr_playoff/i18n.py index c4134a9..63576db 100644 --- a/jfr_playoff/i18n.py +++ b/jfr_playoff/i18n.py @@ -11,7 +11,9 @@ PLAYOFF_I18N_DEFAULTS = { 'STANDINGS_TEAM': 'drużyna', 'STANDINGS_CAPTIONS': 'legenda', 'FOOTER_GENERATED': 'strona wygenerowana', - 'SWISS_DEFAULT_LABEL': 'Turniej o %d. miejsce' + 'SWISS_DEFAULT_LABEL': 'Turniej o %d. miejsce', + 'DETERMINED_TEAMS': 'Drużyny z pewnym miejscem w tej fazie:', + 'POSSIBLE_TEAMS': 'Drużyny z trwających meczów poprzedniej fazy:' } class PlayoffI18N(object): diff --git a/jfr_playoff/template.py b/jfr_playoff/template.py index 70c179b..5845498 100644 --- a/jfr_playoff/template.py +++ b/jfr_playoff/template.py @@ -24,6 +24,14 @@ class PlayoffTemplateStrings(object):  %.1f  ''' + MATCH_TEAM_LABEL = '%s' + + MATCH_PREDICTED_TEAM_LABEL = '%s' + + MATCH_TEAM_LIST_HEADER = '{{DETERMINED_TEAMS}}' + + MATCH_POSSIBLE_TEAM_LIST_HEADER = '{{POSSIBLE_TEAMS}}' + MATCH_TEAM_LINK = ''' %s ''' -- cgit v1.2.3 From 79c281bb47d08f1fd1be04b1d7d58dfd8c672bc5 Mon Sep 17 00:00:00 2001 From: emkael Date: Tue, 2 Oct 2018 13:31:02 +0200 Subject: New team label rendering method, including outcome preditctions --- jfr_playoff/generator.py | 73 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 63 insertions(+), 10 deletions(-) (limited to 'jfr_playoff') diff --git a/jfr_playoff/generator.py b/jfr_playoff/generator.py index fab6d0e..7895a73 100644 --- a/jfr_playoff/generator.py +++ b/jfr_playoff/generator.py @@ -60,15 +60,68 @@ class PlayoffGenerator(object): def get_match_table(self, match): rows = '' for team in match.teams: + # the easy part: team score cell score_html = self.p_temp.get('MATCH_SCORE', team.score) - teams = [coalesce(name, '??') for name in team.name] - team_label = ' / '.join([ - self.data.get_shortname(name) if name is not None else '??' for name in team.name]) \ - if team.known_teams > 0 else '' - team_name = '
'.join(teams) - label_max_length = self.page.get('label_length_limit', 0) - if label_max_length: - team_label = team_label[:label_max_length] + (team_label[label_max_length:] and '(...)') + # the hard part begins here. + team_label = [] # label is what's shown in the table cell + label_separator = ' / ' + team_name = [] # name is what's shown in the tooltip + name_separator = '
' + name_prefix = '  ' # prefix (indent) for team names in the tooltip + if (team.known_teams == 0) and not self.page.get('predict_teams', False): + # we've got no teams eligible for the match and the prediction option is disabled + 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 + 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] + predicted_labels = [self.data.get_shortname(name) if name else None for name in team.possible_name] + for l in range(0, len(labels)): + if labels[l] is None: + if self.page.get('predict_teams', False) and (len(predicted_labels) > l): + # fill team labels with either predictions... + labels[l] = predicted_labels[l] + else: + # ...or empty placeholders + labels[l] = '??' + # count how many teams are eligible (how many non-predicted teams are there) + known_teams = len(is_label_predicted) - sum(is_label_predicted) + # sort labels to move eligible teams in front of predicted teams + # TODO: should this be optional? + labels = [label for i, label in enumerate(labels) if not is_label_predicted[i]] \ + + [label for i, label in enumerate(labels) if is_label_predicted[i]] + if len([label for label in labels if label is not None]): + # we have at least one known/predicted team + for l in range(0, len(labels)): + # fill any remaining empty labels (i.e. these which had empty predictions available) with placeholders + labels[l] = coalesce(labels[l], '??') + # concatenate labels, assigning appropriate classes to predicted teams + team_label.append(self.__get_team_label( + labels[l], + 'MATCH_PREDICTED_TEAM_LABEL' if l >= known_teams 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.page.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 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) + team_name = name_separator.join(team_name) team_html = self.p_temp.get( 'MATCH_TEAM_LINK', match.link, team_name, team_label) \ @@ -79,8 +132,8 @@ class PlayoffGenerator(object): rows += self.p_temp.get( 'MATCH_TEAM_ROW', ' '.join([ - 'winner' if match.winner in teams else '', - 'loser' if match.loser in teams else '' + 'winner' if (match.winner is not None) and (match.winner in team.name) else '', + 'loser' if (match.loser is not None) and (match.loser in team.name) else '' ]).strip(), team_html, self.p_temp.get( -- cgit v1.2.3 From b2a6d843d69edc40c8f7782e47db28ca89baf77e Mon Sep 17 00:00:00 2001 From: emkael Date: Tue, 2 Oct 2018 13:32:08 +0200 Subject: Bringing back label shortening, this time compatible with separate team labels --- jfr_playoff/generator.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'jfr_playoff') diff --git a/jfr_playoff/generator.py b/jfr_playoff/generator.py index 7895a73..beaabd7 100644 --- a/jfr_playoff/generator.py +++ b/jfr_playoff/generator.py @@ -57,6 +57,30 @@ class PlayoffGenerator(object): template = 'MATCH_TEAM_LABEL' return self.p_temp.get(template, team_name) + def __shorten_labels(self, labels, limit, separator, ellipsis): + if limit > 0: + current_length = 0 + shortened = [] + for l in range(0, len(labels)): + if current_length + len(labels[l]) > limit: + # current label won't fit within limit, shorten it and stop + shortened.append(labels[l][0:limit-current_length] + ellipsis) + break + else: + # current label fits, add it to output + shortened.append(labels[l]) + current_length += len(labels[l]) + if l < len(labels) - 1: + # if it's not the last label, separator will be added + # if it was the last label, next condition won't run and ellipsis won't be added + current_length += len(separator) + if current_length > limit: + # if separator puts us over the limit, add ellipsis and stop + shortened.append(ellipsis) + break + labels = shortened + return labels + def get_match_table(self, match): rows = '' for team in match.teams: @@ -97,6 +121,9 @@ class PlayoffGenerator(object): for l in range(0, len(labels)): # fill any remaining empty labels (i.e. these which had empty predictions available) with placeholders labels[l] = coalesce(labels[l], '??') + # shorten concatenated label to specified combined length + labels = self.__shorten_labels(labels, self.page.get('label_length_limit', 0), label_separator, '(...)') + for l in range(0, len(labels)): # concatenate labels, assigning appropriate classes to predicted teams team_label.append(self.__get_team_label( labels[l], -- cgit v1.2.3 From 43d8243888590debd2d2efcdd5be3f415cfa1756 Mon Sep 17 00:00:00 2001 From: emkael Date: Tue, 2 Oct 2018 13:33:12 +0200 Subject: Documentation for team name predictions Fixes #7 --- CONFIG.md | 1 + jfr_playoff/generator.py | 1 + 2 files changed, 2 insertions(+) (limited to 'jfr_playoff') diff --git a/CONFIG.md b/CONFIG.md index 3a26f81..471b190 100644 --- a/CONFIG.md +++ b/CONFIG.md @@ -26,6 +26,7 @@ Konfiguracja składa się, po kolei, z: + `"width"` i `"height"` - wymiary (w pikselach) miejsca rezerwowanego dla każdego meczu w widoku drabinki (`"width"` bezpośrednio wpływa na rozmieszczanie kolumn, wewnątrz każdej z kolumn mecze rozmieszczane są równomiernie, w zależnie od ich liczby) + `"margin"` - odstęp między w/w miejscem (minimalny - jak widać, w przypadku mniejszej liczby meczów w fazie, odstępy się dopasują) + `"label_length_limit"` - maksymalna liczba znaków wyświetlanych jako skrócona nazwa drużyn(y) w schemacie (`0` lub brak wartości oznacza brak limitu) + + `"predict_teams"` - flaga, jeśli włączona (`1`), w kolejnej fazie wypełniane są nazwy drużyn prowadzących/przegrywających w trwających meczach tak, jakby mecz miał się skończyć aktualnym wynikiem (etykiety takich drużyn mają nadaną osobną klasę CSS) - sekcji `"canvas"`: ustawień rysowania linii + `"winner_h_offset"`, `"winner_v_offset"` - marginesy (poziomy i pionowy) rysowania linii zwycięzców (odpowiednio: pionowych i poziomych, względem środka obszaru) + `"loser_h_offset"`, `"loser_v_offset"` - analogiczne marginesy rysowania linii przegranych diff --git a/jfr_playoff/generator.py b/jfr_playoff/generator.py index beaabd7..2028060 100644 --- a/jfr_playoff/generator.py +++ b/jfr_playoff/generator.py @@ -87,6 +87,7 @@ class PlayoffGenerator(object): # the easy part: team score cell score_html = self.p_temp.get('MATCH_SCORE', team.score) # the hard part begins here. + # TODO: should separators and ellipsis indicators be configurable? team_label = [] # label is what's shown in the table cell label_separator = ' / ' team_name = [] # name is what's shown in the tooltip -- cgit v1.2.3 From 0ae3b4c385d293b1ac8553717c30e4f7222a743c Mon Sep 17 00:00:00 2001 From: emkael Date: Wed, 10 Oct 2018 00:00:37 +0200 Subject: Parameterization of team box label settings --- CONFIG.md | 10 ++++++++-- jfr_playoff/generator.py | 24 +++++++++++++----------- 2 files changed, 21 insertions(+), 13 deletions(-) (limited to 'jfr_playoff') diff --git a/CONFIG.md b/CONFIG.md index 471b190..f6d55c5 100644 --- a/CONFIG.md +++ b/CONFIG.md @@ -25,8 +25,14 @@ Konfiguracja składa się, po kolei, z: + `"refresh"` - parametr odświeżania strony drabinki: `0` = wyłączone, liczba naturalna = interwał odświeżania, w sekundach + `"width"` i `"height"` - wymiary (w pikselach) miejsca rezerwowanego dla każdego meczu w widoku drabinki (`"width"` bezpośrednio wpływa na rozmieszczanie kolumn, wewnątrz każdej z kolumn mecze rozmieszczane są równomiernie, w zależnie od ich liczby) + `"margin"` - odstęp między w/w miejscem (minimalny - jak widać, w przypadku mniejszej liczby meczów w fazie, odstępy się dopasują) - + `"label_length_limit"` - maksymalna liczba znaków wyświetlanych jako skrócona nazwa drużyn(y) w schemacie (`0` lub brak wartości oznacza brak limitu) - + `"predict_teams"` - flaga, jeśli włączona (`1`), w kolejnej fazie wypełniane są nazwy drużyn prowadzących/przegrywających w trwających meczach tak, jakby mecz miał się skończyć aktualnym wynikiem (etykiety takich drużyn mają nadaną osobną klasę CSS) + + słownik `"team_boxes"` przechowuje opcjonalne ustawienia wyświetlania nazw teamów: + * `"label_length_limit"` - maksymalna liczba znaków wyświetlanych jako skrócona nazwa drużyn(y) w schemacie (domyślnie `0` = brak limitu) + * `"predict_teams"` - flaga, jeśli włączona (`1`), w kolejnej fazie wypełniane są nazwy drużyn prowadzących/przegrywających w trwających meczach tak, jakby mecz miał się skończyć aktualnym wynikiem (etykiety takich drużyn mają nadaną osobną klasę CSS) + * `"label_separator"` - ciąg rozdzielający skrócone nazwy drużyn wyświetlane na schemacie (domyślnie ` / `) + * `"label_placeholder"` - ciąg wyświetlany w miejsce nieznanej drużyny (domyślnie `??`) + * `"label_ellipsis"` - ciąg wyświetlany na końcu skróconej etykiety teamów, gdy ustawienie `label_length_limit` ją skróciło (domyślnie `(...)`) + * `"name_separator"` - ciąg rozdzielający pełne nazwy teamów w etykiecie po najechaniu na skrócone nazwy w schemacie (domyślnie `
`) + * `"name_prefix"` - ciąg poprzedzający każdą pełną nazwę teamów w etykiecie po najechaniu (domyślnie wcięcie `  `) - sekcji `"canvas"`: ustawień rysowania linii + `"winner_h_offset"`, `"winner_v_offset"` - marginesy (poziomy i pionowy) rysowania linii zwycięzców (odpowiednio: pionowych i poziomych, względem środka obszaru) + `"loser_h_offset"`, `"loser_v_offset"` - analogiczne marginesy rysowania linii przegranych diff --git a/jfr_playoff/generator.py b/jfr_playoff/generator.py index 2028060..48a2eac 100644 --- a/jfr_playoff/generator.py +++ b/jfr_playoff/generator.py @@ -12,6 +12,7 @@ class PlayoffGenerator(object): self.page = settings.get('page') PlayoffLogger.get('generator').info( 'page settings: %s', self.page) + self.team_box_settings = self.page.get('team_boxes', {}) self.canvas = {} if settings.has_section('canvas'): self.canvas = settings.get('canvas') @@ -52,7 +53,7 @@ class PlayoffGenerator(object): datetime.now().strftime('%Y-%m-%d o %H:%M:%S')))) def __get_team_label(self, team_name, template='MATCH_TEAM_LABEL'): - if not self.page.get('predict_teams', None): + if not self.team_box_settings.get('predict_teams', None): # override template if team predictions are not enabled template = 'MATCH_TEAM_LABEL' return self.p_temp.get(template, team_name) @@ -87,13 +88,14 @@ class PlayoffGenerator(object): # the easy part: team score cell score_html = self.p_temp.get('MATCH_SCORE', team.score) # the hard part begins here. - # TODO: should separators and ellipsis indicators be configurable? team_label = [] # label is what's shown in the table cell - label_separator = ' / ' + label_separator = self.team_box_settings.get('label_separator', ' / ') + label_placeholder = self.team_box_settings.get('label_placeholder', '??') + label_ellipsis = self.team_box_settings.get('label_ellipsis', '(...)') team_name = [] # name is what's shown in the tooltip - name_separator = '
' - name_prefix = '  ' # prefix (indent) for team names in the tooltip - if (team.known_teams == 0) and not self.page.get('predict_teams', False): + name_separator = self.team_box_settings.get('name_separator', '
') + name_prefix = self.team_box_settings.get('name_prefix', '  ') # prefix (indent) for team names in the tooltip + if (team.known_teams == 0) and not self.team_box_settings.get('predict_teams', False): # we've got no teams eligible for the match and the prediction option is disabled team_label = '' team_name = '' @@ -105,12 +107,12 @@ class PlayoffGenerator(object): predicted_labels = [self.data.get_shortname(name) if name else None for name in team.possible_name] for l in range(0, len(labels)): if labels[l] is None: - if self.page.get('predict_teams', False) and (len(predicted_labels) > l): + if self.team_box_settings.get('predict_teams', False) and (len(predicted_labels) > l): # fill team labels with either predictions... labels[l] = predicted_labels[l] else: # ...or empty placeholders - labels[l] = '??' + labels[l] = label_placeholder # count how many teams are eligible (how many non-predicted teams are there) known_teams = len(is_label_predicted) - sum(is_label_predicted) # sort labels to move eligible teams in front of predicted teams @@ -121,9 +123,9 @@ class PlayoffGenerator(object): # we have at least one known/predicted team for l in range(0, len(labels)): # fill any remaining empty labels (i.e. these which had empty predictions available) with placeholders - labels[l] = coalesce(labels[l], '??') + labels[l] = coalesce(labels[l], label_placeholder) # shorten concatenated label to specified combined length - labels = self.__shorten_labels(labels, self.page.get('label_length_limit', 0), label_separator, '(...)') + labels = self.__shorten_labels(labels, self.team_box_settings.get('label_length_limit', 0), label_separator, label_ellipsis) for l in range(0, len(labels)): # concatenate labels, assigning appropriate classes to predicted teams team_label.append(self.__get_team_label( @@ -134,7 +136,7 @@ class PlayoffGenerator(object): if name: # every non-empty name gets some indentation team_name.append(name_prefix + name) - if self.page.get('predict_teams', False): + 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: -- cgit v1.2.3 From 13e1272ad6daf785671270b38cccbff3afb91716 Mon Sep 17 00:00:00 2001 From: emkael Date: Wed, 10 Oct 2018 00:57:58 +0200 Subject: Logging messages for team label/name generator --- jfr_playoff/generator.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'jfr_playoff') diff --git a/jfr_playoff/generator.py b/jfr_playoff/generator.py index 48a2eac..64bdeaa 100644 --- a/jfr_playoff/generator.py +++ b/jfr_playoff/generator.py @@ -85,8 +85,12 @@ class PlayoffGenerator(object): def get_match_table(self, match): rows = '' for team in match.teams: + PlayoffLogger.get('generator').info( + 'generating HTML for team object: %s', team) # the easy part: team score cell score_html = self.p_temp.get('MATCH_SCORE', team.score) + PlayoffLogger.get('generator').info( + 'score HTML for team object: %s', score_html.strip()) # the hard part begins here. team_label = [] # label is what's shown in the table cell label_separator = self.team_box_settings.get('label_separator', ' / ') @@ -96,6 +100,7 @@ class PlayoffGenerator(object): name_separator = self.team_box_settings.get('name_separator', '
') name_prefix = self.team_box_settings.get('name_prefix', '  ') # prefix (indent) for team names in the tooltip if (team.known_teams == 0) and not self.team_box_settings.get('predict_teams', False): + PlayoffLogger.get('generator').info('no eligible teams and predictions are disabled') # we've got no teams eligible for the match and the prediction option is disabled team_label = '' team_name = '' @@ -104,7 +109,9 @@ class PlayoffGenerator(object): 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] + PlayoffLogger.get('generator').info('eligible team labels: %s', labels) predicted_labels = [self.data.get_shortname(name) if name else None for name in team.possible_name] + PlayoffLogger.get('generator').info('predicted team labels: %s', predicted_labels) for l in range(0, len(labels)): if labels[l] is None: if self.team_box_settings.get('predict_teams', False) and (len(predicted_labels) > l): @@ -115,10 +122,12 @@ class PlayoffGenerator(object): labels[l] = label_placeholder # 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 teams, predicted mask: %s', known_teams, is_label_predicted) # sort labels to move eligible teams in front of predicted teams # TODO: should this be optional? labels = [label for i, label in enumerate(labels) if not is_label_predicted[i]] \ + [label for i, label in enumerate(labels) if is_label_predicted[i]] + PlayoffLogger.get('generator').info('team labels: %s', labels) if len([label for label in labels if label is not None]): # we have at least one known/predicted team for l in range(0, len(labels)): @@ -126,6 +135,7 @@ class PlayoffGenerator(object): labels[l] = coalesce(labels[l], label_placeholder) # shorten concatenated label to specified combined length labels = self.__shorten_labels(labels, self.team_box_settings.get('label_length_limit', 0), label_separator, label_ellipsis) + PlayoffLogger.get('generator').info('shortened team labels: %s', labels) for l in range(0, len(labels)): # concatenate labels, assigning appropriate classes to predicted teams team_label.append(self.__get_team_label( @@ -151,7 +161,9 @@ class PlayoffGenerator(object): 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) team_name = name_separator.join(team_name) + PlayoffLogger.get('generator').info('output teams name HTML: %s', team_name) team_html = self.p_temp.get( 'MATCH_TEAM_LINK', match.link, team_name, team_label) \ -- cgit v1.2.3 From 8181571f14486be1d81dde08e8c7a088241f9fb7 Mon Sep 17 00:00:00 2001 From: emkael Date: Wed, 10 Oct 2018 01:03:02 +0200 Subject: Sorting eligible teams in front of predicted teams is now optional --- CONFIG.md | 1 + jfr_playoff/generator.py | 21 +++++++++++++-------- 2 files changed, 14 insertions(+), 8 deletions(-) (limited to 'jfr_playoff') diff --git a/CONFIG.md b/CONFIG.md index f6d55c5..eec5ed1 100644 --- a/CONFIG.md +++ b/CONFIG.md @@ -33,6 +33,7 @@ Konfiguracja składa się, po kolei, z: * `"label_ellipsis"` - ciąg wyświetlany na końcu skróconej etykiety teamów, gdy ustawienie `label_length_limit` ją skróciło (domyślnie `(...)`) * `"name_separator"` - ciąg rozdzielający pełne nazwy teamów w etykiecie po najechaniu na skrócone nazwy w schemacie (domyślnie `
`) * `"name_prefix"` - ciąg poprzedzający każdą pełną nazwę teamów w etykiecie po najechaniu (domyślnie wcięcie `  `) + * `"sort_eligible_first"` - flaga włączająca wyświetlanie teamów zakwalifikowanych do danej fazy (tj. z zakończonym meczem bieżącej fazy) przed teamami z trwających meczów (domyślnie włączona) - sekcji `"canvas"`: ustawień rysowania linii + `"winner_h_offset"`, `"winner_v_offset"` - marginesy (poziomy i pionowy) rysowania linii zwycięzców (odpowiednio: pionowych i poziomych, względem środka obszaru) + `"loser_h_offset"`, `"loser_v_offset"` - analogiczne marginesy rysowania linii przegranych diff --git a/jfr_playoff/generator.py b/jfr_playoff/generator.py index 64bdeaa..c78d5cb 100644 --- a/jfr_playoff/generator.py +++ b/jfr_playoff/generator.py @@ -122,11 +122,11 @@ class PlayoffGenerator(object): labels[l] = label_placeholder # 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 teams, predicted mask: %s', known_teams, is_label_predicted) - # sort labels to move eligible teams in front of predicted teams - # TODO: should this be optional? - labels = [label for i, label in enumerate(labels) if not is_label_predicted[i]] \ - + [label for i, label in enumerate(labels) if is_label_predicted[i]] + PlayoffLogger.get('generator').info('detected %d known team(s), predicted mask: %s', known_teams, is_label_predicted) + 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]] \ + + [label for i, label in enumerate(labels) if is_label_predicted[i]] PlayoffLogger.get('generator').info('team labels: %s', labels) if len([label for label in labels if label is not None]): # we have at least one known/predicted team @@ -138,9 +138,14 @@ class PlayoffGenerator(object): PlayoffLogger.get('generator').info('shortened team labels: %s', labels) for l in range(0, len(labels)): # concatenate labels, assigning appropriate classes to predicted teams - team_label.append(self.__get_team_label( - labels[l], - 'MATCH_PREDICTED_TEAM_LABEL' if l >= known_teams else 'MATCH_TEAM_LABEL')) + if self.team_box_settings.get('sort_eligible_first', True): + team_label.append(self.__get_team_label( + labels[l], + 'MATCH_PREDICTED_TEAM_LABEL' if l >= known_teams else 'MATCH_TEAM_LABEL')) + else: + 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: -- cgit v1.2.3 From ef9a1565fba727d05d4ebf91ef4a63f01b83f4bf Mon Sep 17 00:00:00 2001 From: emkael Date: Wed, 10 Oct 2018 01:09:05 +0200 Subject: Backwards compatibility with legacy config structure --- jfr_playoff/generator.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'jfr_playoff') diff --git a/jfr_playoff/generator.py b/jfr_playoff/generator.py index c78d5cb..898e5ed 100644 --- a/jfr_playoff/generator.py +++ b/jfr_playoff/generator.py @@ -95,6 +95,7 @@ class PlayoffGenerator(object): team_label = [] # label is what's shown in the table cell label_separator = self.team_box_settings.get('label_separator', ' / ') label_placeholder = self.team_box_settings.get('label_placeholder', '??') + label_length_limit = self.team_box_settings.get('label_length_limit', self.page.get('label_length_limit', 0)) label_ellipsis = self.team_box_settings.get('label_ellipsis', '(...)') team_name = [] # name is what's shown in the tooltip name_separator = self.team_box_settings.get('name_separator', '
') @@ -134,7 +135,7 @@ class PlayoffGenerator(object): # fill any remaining empty labels (i.e. these which had empty predictions available) with placeholders labels[l] = coalesce(labels[l], label_placeholder) # shorten concatenated label to specified combined length - labels = self.__shorten_labels(labels, self.team_box_settings.get('label_length_limit', 0), label_separator, label_ellipsis) + labels = self.__shorten_labels(labels, label_length_limit, label_separator, label_ellipsis) PlayoffLogger.get('generator').info('shortened team labels: %s', labels) for l in range(0, len(labels)): # concatenate labels, assigning appropriate classes to predicted teams -- cgit v1.2.3