summaryrefslogtreecommitdiff
path: root/jfr_playoff
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2018-01-22 14:43:02 +0100
committeremkael <emkael@tlen.pl>2018-01-22 14:43:02 +0100
commitb2a504ceec511d601a0be10af08c5e98fbbfc481 (patch)
tree7e07daa0ba29a596c76d0479aa16a6a779b7b05a /jfr_playoff
parent2947c609534ac652380d020df5d9a3023f222b60 (diff)
Swiss results retrieval factored out
Diffstat (limited to 'jfr_playoff')
-rw-r--r--jfr_playoff/data.py36
-rw-r--r--jfr_playoff/sql.py4
2 files changed, 25 insertions, 15 deletions
diff --git a/jfr_playoff/data.py b/jfr_playoff/data.py
index 435b4b6..2c35191 100644
--- a/jfr_playoff/data.py
+++ b/jfr_playoff/data.py
@@ -183,13 +183,6 @@ class PlayoffData(object):
swiss_finished = self.database.fetch(
event['database'], p_sql.SWISS_ENDED, {})
if swiss_finished[0] > 0:
- swiss_teams = self.database.fetch_all(
- event['database'], p_sql.SWISS_RESULTS, {})
- swiss_results = [(teams.index(team[0]), team[1], team[2]) for
- team in swiss_teams]
- swiss_results = sorted(swiss_results, key=lambda t: t[0])
- swiss_results = sorted(
- swiss_results, key=lambda t: t[1], reverse=True)
swiss_position = (
event['swiss_position']
if 'swiss_position' in event
@@ -200,22 +193,37 @@ class PlayoffData(object):
if 'position_to' in event
else 9999
)
- prev_result = None
place = 1
- for team in sorted(
- swiss_results, key=lambda team: team[2]):
- if prev_result == team[1]:
- print SWISS_TIE_WARNING % (event['database'])
- prev_result = team[1]
+ swiss_results = self.get_swiss_results(
+ event['database'], teams)
+ for team in swiss_results:
if place >= swiss_position:
target_position = event['position'] \
+ place - swiss_position
if target_position <= min(
position_limit, len(self.leaderboard)):
self.leaderboard[
- target_position - 1] = teams[team[0]]
+ target_position - 1] = team[0]
place += 1
+ def get_swiss_results(self, swiss, ties=None):
+ if ties is None:
+ ties = []
+ swiss_teams = self.database.fetch_all(
+ swiss, p_sql.SWISS_RESULTS, {})
+ swiss_results = sorted(
+ swiss_teams,
+ key=lambda t: ties.index(t[0]) if t[0] in ties else -1)
+ swiss_results = sorted(
+ swiss_results, key=lambda t: t[1], reverse=True)
+ swiss_results = sorted(swiss_results, key=lambda team: team[2])
+ prev_result = None
+ for team in swiss_results:
+ if prev_result == team[1]:
+ print SWISS_TIE_WARNING % (swiss)
+ prev_result = team[1]
+ return [[team[0], team[3], team[4]] for team in swiss_results]
+
def fill_leaderboard(self):
self.prefill_leaderboard(self.teams)
leaderboard_teams = {}
diff --git a/jfr_playoff/sql.py b/jfr_playoff/sql.py
index afbfbfb..52d8248 100644
--- a/jfr_playoff/sql.py
+++ b/jfr_playoff/sql.py
@@ -43,7 +43,9 @@ SWISS_RESULTS = '''
SELECT #db#.teams.fullname,
SUM(IF(#db#.matches.homet = #db#.teams.id, vph+corrh, vpv+corrv))
+ #db#.teams.score,
- #db#.teams.grupa
+ #db#.teams.grupa,
+ #db#.teams.shortname,
+ #db#.teams.gif
FROM #db#.teams
LEFT JOIN #db#.matches
ON (#db#.teams.id = #db#.matches.homet OR #db#.teams.id = #db#.matches.visit)