summaryrefslogtreecommitdiff
path: root/ausbutler
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2017-01-06 00:29:12 +0100
committeremkael <emkael@tlen.pl>2017-01-06 00:29:12 +0100
commit89591b0893bf3ec2ca5124c19ea1c660978d1b40 (patch)
tree8fab348161e89ef44875a8b733e1e1534e5b08b3 /ausbutler
parent3698d02c9a57e13070bae5d4b51e40d9879522bb (diff)
Generating segment pages
Diffstat (limited to 'ausbutler')
-rw-r--r--ausbutler/butler.py6
-rw-r--r--ausbutler/interface.py44
2 files changed, 49 insertions, 1 deletions
diff --git a/ausbutler/butler.py b/ausbutler/butler.py
index 2766069..a88776e 100644
--- a/ausbutler/butler.py
+++ b/ausbutler/butler.py
@@ -25,6 +25,12 @@ def get_room(butler, player):
if player in [table.closeE, table.closeW, table.closeN, table.closeS]:
return 'closed'
+def get_line(butler, player):
+ table = butler.table
+ room = get_room(butler, player).upper()
+ direction = 'NS' if player in [table.openN, table.openS, table.closeN, table.closeS] else 'EW'
+ return '%s_%s' % (room, direction)
+
def normalize(butler, opp_factor=0.5):
if butler.board_count == 0:
return 0.0
diff --git a/ausbutler/interface.py b/ausbutler/interface.py
index 30c2f70..8f10ffa 100644
--- a/ausbutler/interface.py
+++ b/ausbutler/interface.py
@@ -1,8 +1,9 @@
import re
+from datetime import datetime
from os import path
from jinja2 import Environment, FileSystemLoader
-from .butler import cutoff, get_opponents, get_room, normalize
+from .butler import cutoff, get_opponents, get_room, normalize, get_line
from .db import get_session
from .model import AusButler, Butler
from .tour_config import Translations, Constants
@@ -94,3 +95,44 @@ class Interface(object):
})
)
+ def generate_segments(self):
+ template = self.template.get_template('segment.html')
+ for round_no in range(1, Constants.rnd + 1):
+ for segment_no in range(1, Constants.segmentsperround + 1):
+ first_board = 1 + (segment_no - 1) * Constants.boardspersegment
+ filename = '%snormbutler%d-%d.html' % (
+ Constants.shortname,
+ round_no, segment_no
+ )
+ results = {}
+ for butler in self.session.query(AusButler).filter(AusButler.match == round_no, AusButler.segment == segment_no):
+ line = 'TABLE_%s' % (get_line(butler, butler.id))
+ position = '%d%s' % (butler.table.tabl, self.translation.get_translation(line))
+ if position not in results:
+ results[position] = {'players': []}
+ results[position]['players'].append(str(butler.player).decode('utf8'))
+ results[position]['position'] = position
+ results[position]['team'] = str(butler.player.team_).decode('utf8')
+ results[position]['score'] = butler.score
+ results[position]['opp_score'] = butler.opp_score
+ results[position]['norm_score'] = butler.corrected_score
+ results = sorted(results.values(), key=lambda r: r['norm_score'], reverse=True)
+ place = 1
+ previous = None
+ for r in range(0, len(results)):
+ results[r]['place'] = place if results[r]['norm_score'] != previous else ''
+ previous = results[r]['norm_score']
+ place += 1
+ file(path.join(Constants.path, filename), 'w').write(
+ template.render({
+ 'prefix': Constants.shortname,
+ 'logoh': Constants.logoh,
+ 'round_no': round_no,
+ 'segment_no': segment_no,
+ 'results': results,
+ 'boards': range(first_board, first_board + Constants.boardspersegment),
+ 'date': datetime.now().strftime('%Y-%m-%d'),
+ 'time': datetime.now().strftime('%H:%M')
+ }).encode('utf8')
+ )
+