summaryrefslogtreecommitdiff
path: root/jfr_playoff
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2019-11-09 21:03:17 +0100
committeremkael <emkael@tlen.pl>2019-11-09 21:03:17 +0100
commitcbb990edded54dd1c3f6d20c5737cbf48a364476 (patch)
tree006babdbe8d9238f746e7426d84f13612e4181b5 /jfr_playoff
parent2933caa662921883884d5bb5fe7c730341873a89 (diff)
Custom order for final leaderboard positions is configurable
Diffstat (limited to 'jfr_playoff')
-rw-r--r--jfr_playoff/data.py24
1 files changed, 23 insertions, 1 deletions
diff --git a/jfr_playoff/data.py b/jfr_playoff/data.py
index 107f012..f4adf6f 100644
--- a/jfr_playoff/data.py
+++ b/jfr_playoff/data.py
@@ -13,6 +13,15 @@ class PlayoffData(object):
if self.database is None:
PlayoffLogger.get('db').warning(PlayoffDB.DATABASE_NOT_CONFIGURED_WARNING)
self.team_settings = settings.get('teams')
+ self.custom_final_order = []
+ if settings.has_section('custom_final_order'):
+ self.custom_final_order = settings.get('custom_final_order')
+ self.custom_final_order = [
+ t for t in [
+ self.teams[i-1] if isinstance(i, int)
+ else self.get_team_data_by_name(i)
+ for i in self.custom_final_order]
+ if t is not None]
self.phases = settings.get('phases')
self.swiss = []
if settings.has_section('swiss'):
@@ -127,6 +136,13 @@ class PlayoffData(object):
leaderboard_teams[loser_key] = []
leaderboard_teams[loser_key].append(
self.match_info[match['id']].loser)
+ final_order = self.custom_final_order + [
+ t for t in self.teams if t not in self.custom_final_order]
+ PlayoffLogger.get('data').info(
+ 'custom order for final positions: %s', self.custom_final_order)
+ PlayoffLogger.get('data').info(
+ 'order of teams to fill leaderboard positions: %s',
+ final_order)
for positions, position_teams in leaderboard_teams.iteritems():
positions = list(positions)
PlayoffLogger.get('data').info(
@@ -134,7 +150,7 @@ class PlayoffData(object):
positions, position_teams)
if len(positions) == len([
team for team in position_teams if team is not None]):
- for table_team in self.teams:
+ for table_team in final_order:
if table_team[0] in position_teams:
position = positions.pop(0)
self.leaderboard[position-1] = table_team[0]
@@ -165,6 +181,12 @@ class PlayoffData(object):
PlayoffLogger.get('data').info('grid dimensions: %s', dimensions)
return dimensions
+ def get_team_data_by_name(self, fullname):
+ for team in self.teams:
+ if team[0] == fullname:
+ return team
+ return None
+
def get_shortname(self, fullname):
for team in self.teams:
if team[0] == fullname: