summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ausbutler/butler.py6
-rw-r--r--ausbutler/interface.py44
-rw-r--r--template/segment.html80
3 files changed, 129 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')
+ )
+
diff --git a/template/segment.html b/template/segment.html
new file mode 100644
index 0000000..b1b0a7c
--- /dev/null
+++ b/template/segment.html
@@ -0,0 +1,80 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<html>
+ <head>
+ <meta http-equiv="Pragma" content="no-cache">
+ <meta http-equiv="Cache-Control" content="no-cache">
+ <meta name="robots" content="noarchive">
+ <meta http-equiv="expires" content="0">
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+ <meta name="Generator" content="jfrteamy-aus-butler">
+ <title>{{"PAGE_TITLE"|translate}}</title>
+ <link rel="stylesheet" type="text/css" href="css/kolorki.css">
+ <script type="text/javascript" src="sklady/myAjax.js"></script>
+ </head>
+ <body class="all">
+ <script type="text/javascript" src="sklady/wz_tooltip.js"></script>
+ <table cellspacing="0">
+ <tr>
+ <td colspan="3">
+ {{logoh}}
+ </td>
+ </tr>
+ <tr>
+ <td class="e" colspan="3">&nbsp;</td>
+ </tr>
+ <tr>
+ <td class="bdnt12" colspan="3">{{"BUTLER_ROUND"|translate}}{{round_no}} {{"SEGMENT"|translate}}{{segment_no}}</td>
+ </tr>
+ <tr>
+ <td class="e" colspan="3">&nbsp;</td>
+ </tr>
+ <tr valign="top">
+ <td>
+ <table cellspacing="0">
+ <tr>
+ <td class="bdcc12">{{"HEADER_PLACE"|translate}}</td>
+ <td class="bdcc2">{{"HEADER_TABLE"|translate}}</td>
+ <td class="bdcc2">&nbsp;</td>
+ <td class="bdcc2">{{"HEADER_TEAM"|translate}}</td>
+ <td class="bdcc2">&nbsp;&nbsp;&nbsp;{{"HEADER_IMPS"|translate}}&nbsp;&nbsp;&nbsp;</td>
+ <td class="bdcc2">&nbsp;&nbsp;&nbsp;{{"HEADER_OPPS"|translate}}&nbsp;&nbsp;&nbsp;</td>
+ <td class="bdcc2">&nbsp;{{"HEADER_NORMALIZED"|translate}}&nbsp;</td>
+ </tr>
+ {% for result in results %}
+ <tr>
+ <td class="bdc1">{{result['place']}}</td>
+ <td class="bdc">{{result['position']}}</td>
+ <td class="zno">{{'-'.join(result['players'])}}</td>
+ <td class="zno">{{result['team']}}</td>
+ <td class="bdc">{{ '%0+d' % result['score']}}</td>
+ <td class="bdc">{{ '%+.2f' % result['opp_score']}}</td>
+ <td class="bdc">{{ '%+.2f' % result['norm_score']}}</td>
+ </tr>
+ {% endfor %}
+ </table>
+ </td>
+ <td>&nbsp;&nbsp;&nbsp;</td>
+ <td>
+ <table cellspacing="0">
+ <tr>
+ <td class="bdcc12">{{"HEADER_BOARD_NO"|translate}}</td>
+ </tr>
+ {% for board_no in boards %}
+ <tr>
+ <td class="bdcc1">
+ <a href="{{prefix}}{{round_no}}b-{{board_no}}.html" class="zb" target="popra">&nbsp;&nbsp;&nbsp;{{board_no}}&nbsp;&nbsp;</a>
+ </td>
+ </tr>
+ {% endfor %}
+ </table>
+ </td>
+ </tr>
+ </table>
+ <p class="vs"></p>
+ <p class="f">
+ {{"FOOTER_ANALYSIS"|translate}}, &copy;William Bailey&#39;1999<br />
+ &nbsp;Admin&nbsp;&copy;Jan Romański&#39;2005,&nbsp;jfrteamy-ausbutler&nbsp;&copy;Michał Klichowicz&#39;2017{{"FOOTER_GENERATED"|translate}}
+ {{date}}{{"FOOTER_AT"|translate}}{{time}}{{"FOOTER_OPTIMIZED"|translate}}
+ </p>
+ </body>
+</html>