diff options
author | emkael <emkael@tlen.pl> | 2018-09-28 17:37:16 +0200 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2018-09-28 17:37:16 +0200 |
commit | 72e52cf8c572f262d022acaa1eb1aa65bccb099e (patch) | |
tree | ae22e9f6cd22bd673da56c8111912e0b37f4209d /jfr_playoff/data.py | |
parent | f5ac370c094ae393dc0348bbbf31bef1fe9a7208 (diff) |
Refactoring of some config dictionary default value fetches
Diffstat (limited to 'jfr_playoff/data.py')
-rw-r--r-- | jfr_playoff/data.py | 37 |
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 |