summaryrefslogtreecommitdiff
path: root/jfr_playoff/data.py
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2018-09-28 17:38:01 +0200
committeremkael <emkael@tlen.pl>2018-09-28 17:38:01 +0200
commit1e17305d838189d9e4e8f861f9c67fa736a0ba11 (patch)
tree3456082e55715df8ea0562de4deae571f6257a19 /jfr_playoff/data.py
parentc2150a64886a2bf6550f873a1c6d57c949d224be (diff)
parent72e52cf8c572f262d022acaa1eb1aa65bccb099e (diff)
Merge branch 'devel' into position-boxes
Diffstat (limited to 'jfr_playoff/data.py')
-rw-r--r--jfr_playoff/data.py37
1 files changed, 13 insertions, 24 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