summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--jfr_playoff/dto.py1
-rw-r--r--jfr_playoff/generator.py11
-rw-r--r--jfr_playoff/matchinfo.py18
3 files changed, 16 insertions, 14 deletions
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 = '<br />'.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 = '<br />'.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]