summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2017-01-06 00:30:34 +0100
committeremkael <emkael@tlen.pl>2017-01-06 00:30:34 +0100
commit187fcccf7d41508d10bde62ce47079b2d3f859a4 (patch)
tree7d34618e11c5d45af5a95a520689d817e515e68c
parent89591b0893bf3ec2ca5124c19ea1c660978d1b40 (diff)
Generating compiled table page
-rw-r--r--ausbutler/interface.py57
-rw-r--r--config/butler.json3
-rw-r--r--template/table.html152
3 files changed, 211 insertions, 1 deletions
diff --git a/ausbutler/interface.py b/ausbutler/interface.py
index 8f10ffa..27ad703 100644
--- a/ausbutler/interface.py
+++ b/ausbutler/interface.py
@@ -1,6 +1,7 @@
import re
from datetime import datetime
from os import path
+from copy import copy
from jinja2 import Environment, FileSystemLoader
from .butler import cutoff, get_opponents, get_room, normalize, get_line
@@ -136,3 +137,59 @@ class Interface(object):
}).encode('utf8')
)
+ def generate_table(self):
+ template = self.template.get_template('table.html')
+ filename = '%snormbutler.html' % (Constants.shortname)
+ segments = []
+ result_template = []
+ for rnd in range(1, Constants.rnd + 1):
+ for segment in range(1, Constants.segmentsperround + 1):
+ segments.append({'round': rnd, 'segment': segment})
+ result_template.append('')
+ players = {}
+ for butler in self.session.query(AusButler).all():
+ if butler.id not in players:
+ players[butler.id] = {
+ 'name': str(butler.player).decode('utf8'),
+ 'team': str(butler.player.team_).decode('utf8'),
+ 'sum': 0,
+ 'count': 0,
+ 'results': copy(result_template)
+ }
+ players[butler.id]['sum'] += butler.corrected_score
+ players[butler.id]['count'] += butler.board_count
+ players[butler.id]['results'][(butler.match - 1) * Constants.segmentsperround + butler.segment - 1] = butler.corrected_score
+ for player in players.values():
+ if player['count'] > 0:
+ player['sum'] /= player['count']
+ players = sorted(players.values(), key=lambda p: p['sum'], reverse=True)
+ board_threshold = Constants.boardspersegment * Constants.segmentsperround * \
+ (Constants.rnd + (Constants.roundcnt * (Constants.minbutler / 100.0 - 1)))
+ above_threshold = []
+ below_threshold = []
+ for player in players:
+ if player['count'] >= board_threshold:
+ above_threshold.append(player)
+ else:
+ below_threshold.append(player)
+ for p_list in [above_threshold, below_threshold]:
+ place = 1
+ prev = None
+ for player in p_list:
+ if player['sum'] != prev:
+ player['place'] = place
+ prev = player['sum']
+ place += 1
+ file(path.join(Constants.path, filename), 'w').write(
+ template.render({
+ 'prefix': Constants.shortname,
+ 'logoh': Constants.logoh,
+ 'percent_threshold': Constants.minbutler,
+ 'segments': segments,
+ 'segment_limit': self.config['segments_in_table_limit'],
+ 'above_threshold': above_threshold,
+ 'below_threshold': below_threshold,
+ 'date': datetime.now().strftime('%Y-%m-%d'),
+ 'time': datetime.now().strftime('%H:%M')
+ }).encode('utf8')
+ )
diff --git a/config/butler.json b/config/butler.json
index ab19a17..e238779 100644
--- a/config/butler.json
+++ b/config/butler.json
@@ -1,5 +1,6 @@
{
"cutoff_point": 32,
"cutoff_rate": 0.1,
- "opponent_factor": 0.5
+ "opponent_factor": 0.5,
+ "segments_in_table_limit": 10
}
diff --git a/template/table.html b/template/table.html
new file mode 100644
index 0000000..51559c2
--- /dev/null
+++ b/template/table.html
@@ -0,0 +1,152 @@
+<!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}}: {{"BUTLER"|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="{{segment_limit+5}}">
+ {{logoh}}
+ </td>
+ </tr>
+ <tr>
+ <td class="e" colspan="{{segment_limit+5}}">&nbsp;</td>
+ </tr>
+ <tr>
+ <td class="bdnt12" colspan="{{segment_limit+5}}">
+ {{"NORMALIZED_CLASSIFICATION"|translate}}
+ {% if percent_threshold > 0 %}
+ <small><br />{{"PLAYERS_WITHOUT_CHANCES"|translate}}{{percent_threshold}}{{"PERCENT_NOT_LISTED"|translate}}</small>
+ {% endif %}
+ </td>
+ </tr>
+ <tr>
+ <td class="e" colspan="{{segment_limit+5}}">&nbsp;</td>
+ </tr>
+ {% if segments|length > segment_limit %}
+ <tr>
+ <td class="bdnl12" colspan="{{segment_limit+5}}">
+ {{"HEADER_PREV_ROUNDS"|translate}}
+ {% for segment in segments[0:-segment_limit] %}
+ |<a href="{{prefix}}normbutler{{segment['round']}}-{{segment['segment']}}.htm">
+ {{segment['round']}}-{{segment['segment']}}
+ </a>
+ {% endfor %}
+ |
+ </td>
+ </tr>
+ <tr>
+ <td class="e" colspan="{{segment_limit+5}}">&nbsp;</td>
+ </tr>
+ {% endif %}
+ <tr>
+ <td class="bdcc12">{{"HEADER_PLACE"|translate}}</td>
+ <td class="bdcc2">&nbsp;</td>
+ <td class="bdcc2">{{"HEADER_TEAM"|translate}}</td>
+ <td class="bdcc2">{{"HEADER_IMPBRD"|translate}}</td>
+ <td class="bdcc2">{{"HEADER_BOARDS"|translate}}</td>
+ {% for segment in segments[-segment_limit:] %}
+ <td class="bdcc2">
+ <a href="{{prefix}}normbutler{{segment['round']}}-{{segment['segment']}}.htm">
+ {{segment['round']}}-{{segment['segment']}}
+ </a>
+ </td>
+ {% endfor %}
+ </tr>
+ {% for player in above_threshold %}
+ <tr>
+ <td class="bdc1">{{player['place']}}</td>
+ <td class="bd">{{player['name']}}</td>
+ <td class="bd">{{player['team']}}</td>
+ <td class="bdc">{{'%.2f' % player['sum']}}</td>
+ <td class="bdc">{{player['count']}}</td>
+ {% for result in player['results'][-segment_limit:] %}
+ {% if result != '' %}
+ <td class="bdc">{{'%+.2f' % result}}</td>
+ {% else %}
+ <td class="bdc">&nbsp;</td>
+ {% endif %}
+ {% endfor %}
+ </tr>
+ {% endfor %}
+ {% if below_threshold|length > 0 %}
+ <tr>
+ <td class="e" colspan="{{segment_limit+5}}">&nbsp;</td>
+ </tr>
+ <tr>
+ <td class="bdnt12" colspan="{{segment_limit+5}}">
+ {{"NORMALIZED_CLASSIFICATION"|translate}}
+ {% if percent_threshold > 0 %}
+ <small><br />{{"PLAYERS_WITHOUT_CHANCES"|translate}}{{percent_threshold}}%</small>
+ {% endif %}
+ </td>
+ </tr>
+ <tr>
+ <td class="e" colspan="{{segment_limit+5}}">&nbsp;</td>
+ </tr>
+ {% if segments|length > segment_limit %}
+ <tr>
+ <td class="bdnl12" colspan="{{segment_limit+5}}">
+ {{"HEADER_PREV_ROUNDS"|translate}}
+ {% for segment in segments[0:-segment_limit] %}
+ |<a href="{{prefix}}normbutler{{segment['round']}}-{{segment['segment']}}.htm">
+ {{segment['round']}}-{{segment['segment']}}
+ </a>
+ {% endfor %}
+ |
+ </td>
+ </tr>
+ <tr>
+ <td class="e" colspan="{{segment_limit+5}}">&nbsp;</td>
+ </tr>
+ {% endif %}
+ <tr>
+ <td class="bdcc12">{{"HEADER_PLACE"|translate}}</td>
+ <td class="bdcc2">&nbsp;</td>
+ <td class="bdcc2">{{"HEADER_TEAM"|translate}}</td>
+ <td class="bdcc2">{{"HEADER_IMPBRD"|translate}}</td>
+ <td class="bdcc2">{{"HEADER_BOARDS"|translate}}</td>
+ {% for segment in segments[-segment_limit:] %}
+ <td class="bdcc2">
+ <a href="{{prefix}}normbutler{{segment['round']}}-{{segment['segment']}}.htm">
+ {{segment['round']}}-{{segment['segment']}}
+ </a>
+ </td>
+ {% endfor %}
+ </tr>
+ {% for player in below_threshold %}
+ <tr>
+ <td class="bdc1">{{player['place']}}</td>
+ <td class="bd">{{player['name']}}</td>
+ <td class="bd">{{player['team']}}</td>
+ <td class="bdc">{{'%.2f' % player['sum']}}</td>
+ <td class="bdc">{{player['count']}}</td>
+ {% for result in player['results'][-segment_limit:] %}
+ {% if result != '' %}
+ <td class="bdc">{{'%+.2f' % result}}</td>
+ {% else %}
+ <td class="bdc">&nbsp;</td>
+ {% endif %}
+ {% endfor %}
+ </tr>
+ {% endfor %}
+ {% endif %}
+ </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>