summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--BRANCHES.txt2
-rw-r--r--jfr_playoff/data.py37
-rw-r--r--jfr_playoff/generator.py5
-rw-r--r--jfr_playoff/matchinfo.py5
-rw-r--r--jfr_playoff/tournamentinfo.py7
5 files changed, 21 insertions, 35 deletions
diff --git a/BRANCHES.txt b/BRANCHES.txt
index 5eb0252..ee53fe4 100644
--- a/BRANCHES.txt
+++ b/BRANCHES.txt
@@ -15,7 +15,7 @@ Względem ostatniego sezonu
- [bugfixes]
- obszerne komunikaty diagnostyczne
- poprawki z Sopotu:
- + skracanie wyświetlania długich nazw teamów (> 30 znaków, TODO: parametryzacja długości)
+ + skracanie wyświetlania długich nazw teamów
+ obsługa meczów jednosegmentowych
- nielinkowanie do segmentów, które nie wysyłają wyników na żywo
diff --git a/jfr_playoff/data.py b/jfr_playoff/data.py
index 9f9a0c2..6adf00c 100644
--- a/jfr_playoff/data.py
+++ b/jfr_playoff/data.py
@@ -36,18 +36,16 @@ class PlayoffData(object):
def generate_phases(self):
self.grid = []
for phase in self.phases:
- phase_count = len(phase['matches'])
- if 'dummies' in phase:
- phase_count += len(phase['dummies'])
+ dummies = phase.get('dummies', [])
+ phase_count = len(phase['matches']) + len(dummies)
phase_object = Phase()
phase_object.title = phase['title']
- phase_object.link = phase['link'] if 'link' in phase else None
+ phase_object.link = phase.get('link', None)
phase_object.matches = [None] * phase_count
phase_pos = 0
for match in phase['matches']:
- if 'dummies' in phase:
- while phase_pos in phase['dummies']:
- phase_pos += 1
+ while phase_pos in dummies:
+ phase_pos += 1
phase_object.matches[phase_pos] = match['id']
phase_pos += 1
PlayoffLogger.get('data').info('phase object: %s', phase_object)
@@ -73,8 +71,7 @@ class PlayoffData(object):
def get_swiss_link(self, event):
event_info = TournamentInfo(event, self.database)
swiss_link = event_info.get_results_link()
- if ('relative_path' in event) and (
- event['relative_path'] is not None):
+ if event.get('relative_path', None):
swiss_link = '%s/%s' % (event['relative_path'], swiss_link)
PlayoffLogger.get('data').info('swiss link: %s', swiss_link)
return swiss_link
@@ -94,16 +91,8 @@ class PlayoffData(object):
event['ties'] = teams
event_info = TournamentInfo(event, self.database)
if event_info.is_finished():
- swiss_position = (
- event['swiss_position']
- if 'swiss_position' in event
- else 1
- )
- position_limit = (
- event['position_to']
- if 'position_to' in event
- else 9999
- )
+ swiss_position = event.get('swiss_position', 1)
+ position_limit = event.get('position_to', 9999)
place = 1
swiss_results = event_info.get_tournament_results()
for team in swiss_results:
@@ -156,7 +145,7 @@ class PlayoffData(object):
swiss_info = [{
'link': self.get_swiss_link(event),
'position': event['position'],
- 'label': event['label'] if 'label' in event else None,
+ 'label': event.get('label', None),
'finished': TournamentInfo(event, self.database).is_finished()
} for event in self.swiss]
PlayoffLogger.get('data').info('swiss info: %s', swiss_info)
@@ -166,10 +155,10 @@ class PlayoffData(object):
dimensions = (
len(self.phases),
max([
- len(phase['matches']) + len(phase['dummies'])
- if 'dummies' in phase
- else len(phase['matches'])
- for phase in self.phases]))
+ len(phase['matches']) + len(phase.get('dummies', []))
+ for phase in self.phases
+ ])
+ )
PlayoffLogger.get('data').info('grid dimensions: %s', dimensions)
return dimensions
diff --git a/jfr_playoff/generator.py b/jfr_playoff/generator.py
index 679fb13..19b8c1d 100644
--- a/jfr_playoff/generator.py
+++ b/jfr_playoff/generator.py
@@ -57,8 +57,7 @@ class PlayoffGenerator(object):
team_label = ' / '.join([
self.data.get_shortname(name) for name in
team.name.split('<br />')])
- label_max_length = self.page['label_length_limit'] \
- if 'label_length_limit' in self.page else 0
+ 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(
@@ -286,7 +285,7 @@ class PlayoffGenerator(object):
info = []
for event in self.data.get_swiss_info():
event_label = self.p_temp.get('SWISS_DEFAULT_LABEL', event['position'])
- if 'label' in event and event['label'] is not None:
+ if event.get('label', None):
event_label = event['label']
info.append((self.p_temp.get('SWISS_LINK',
event['link'], event_label) \
diff --git a/jfr_playoff/matchinfo.py b/jfr_playoff/matchinfo.py
index 1357ba3..4089a76 100644
--- a/jfr_playoff/matchinfo.py
+++ b/jfr_playoff/matchinfo.py
@@ -193,10 +193,7 @@ class MatchInfo:
if scores_fetched:
PlayoffLogger.get('matchinfo').info(
'pre-defined scores for match #%d fetched', self.info.id)
- if 'running' in self.config:
- self.info.running = int(self.config['running'])
- else:
- self.info.running = -1
+ self.info.running = int(self.config.get('running', -1))
if not teams_fetched:
try:
try:
diff --git a/jfr_playoff/tournamentinfo.py b/jfr_playoff/tournamentinfo.py
index a646d4e..45a7752 100644
--- a/jfr_playoff/tournamentinfo.py
+++ b/jfr_playoff/tournamentinfo.py
@@ -169,11 +169,12 @@ class TournamentInfo:
PlayoffLogger.get('tournamentinfo').warning(
'cannot determine tournament results from HTML: %s(%s)',
type(e).__name__, str(e))
- if self.is_finished() and 'final_positions' in self.settings:
+ if self.is_finished():
+ final_positions = self.settings.get('final_positions', [])
PlayoffLogger.get('tournamentinfo').info(
'setting final positions from tournament results: %s',
- self.settings['final_positions'])
- for position in self.settings['final_positions']:
+ final_positions)
+ for position in final_positions:
if len(teams) >= position:
teams[position-1].append(position)
return teams