summaryrefslogtreecommitdiff
path: root/jfr_playoff
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2018-09-28 17:37:16 +0200
committeremkael <emkael@tlen.pl>2018-09-28 17:37:16 +0200
commit72e52cf8c572f262d022acaa1eb1aa65bccb099e (patch)
treeae22e9f6cd22bd673da56c8111912e0b37f4209d /jfr_playoff
parentf5ac370c094ae393dc0348bbbf31bef1fe9a7208 (diff)
Refactoring of some config dictionary default value fetches
Diffstat (limited to 'jfr_playoff')
-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
4 files changed, 20 insertions, 34 deletions
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 5dfed13..d358d86 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(
@@ -199,7 +198,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 dd2ee30..ab742d4 100644
--- a/jfr_playoff/matchinfo.py
+++ b/jfr_playoff/matchinfo.py
@@ -191,10 +191,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