summaryrefslogtreecommitdiff
path: root/jfr_playoff
diff options
context:
space:
mode:
Diffstat (limited to 'jfr_playoff')
-rw-r--r--jfr_playoff/dto.py4
-rw-r--r--jfr_playoff/generator.py63
-rw-r--r--jfr_playoff/matchinfo.py4
-rw-r--r--jfr_playoff/template.py16
4 files changed, 76 insertions, 11 deletions
diff --git a/jfr_playoff/dto.py b/jfr_playoff/dto.py
index a88cd2b..fa22265 100644
--- a/jfr_playoff/dto.py
+++ b/jfr_playoff/dto.py
@@ -10,6 +10,10 @@ def coalesce(*arg):
class Team(object):
name = ''
score = 0.0
+ place = None
+
+ def __init__(self):
+ self.place = []
def __unicode__(self):
return u'%s (%.1f)' % (coalesce(self.name, '<None>'), self.score)
diff --git a/jfr_playoff/generator.py b/jfr_playoff/generator.py
index 2206520..6a184fb 100644
--- a/jfr_playoff/generator.py
+++ b/jfr_playoff/generator.py
@@ -106,33 +106,70 @@ class PlayoffGenerator(object):
def get_match_box(self, match, position):
if match is not None:
+ winner_link = [
+ str(m) for m in match.winner_matches
+ ] if match.winner_matches is not None else []
+ loser_link = [
+ str(m) for m in match.loser_matches
+ ] if match.loser_matches is not None else []
+ place_loser_link = []
+ place_winner_link = []
+ if 'starting_position_indicators' in self.page \
+ and self.page['starting_position_indicators']:
+ for team in match.teams:
+ if len(team.place) > 0:
+ place_link = ['place-' + str(pl) for pl in team.place]
+ if len(team.place) > 1:
+ place_loser_link += place_link
+ else:
+ place_winner_link += place_link
return self.p_temp.get(
'MATCH_BOX',
position[0], position[1],
match.id,
- ' '.join([
- str(m) for m in match.winner_matches
- ]) if match.winner_matches is not None else '',
- ' '.join([
- str(m) for m in match.loser_matches
- ]) if match.loser_matches is not None else '',
+ ' '.join(winner_link),
+ ' '.join(loser_link),
+ ' '.join(place_winner_link),
+ ' '.join(place_loser_link),
self.get_match_table(match))
return ''
+ def get_starting_position_box(self, positions, dimensions):
+ if 'starting_position_indicators' not in self.page \
+ or not self.page['starting_position_indicators']:
+ return ''
+ boxes = ''
+ order = 0
+ for place in sorted(positions):
+ boxes += self.p_temp.get(
+ 'STARTING_POSITION_BOX',
+ 0,
+ int(float(order) / float(len(positions)) * dimensions[1]),
+ place, place)
+ order += 1
+ return boxes
+
+
def get_match_grid(self, dimensions, grid, matches):
- canvas_size = (
+ canvas_size = [
dimensions[0] * (
self.page['width'] + self.page['margin']
- ) - self.page['margin'],
+ ),
dimensions[1] * (
self.page['height'] + self.page['margin']
- ) - self.page['margin'])
+ ) - self.page['margin']]
+ if 'starting_position_indicators' not in self.page \
+ or not self.page['starting_position_indicators']:
+ canvas_size[0] -= self.page['margin']
PlayoffLogger.get('generator').info(
'canvas size: %s', canvas_size)
grid_boxes = ''
col_no = 0
+ starting_positions = set()
for phase in grid:
- grid_x = col_no * (self.page['width'] + self.page['margin'])
+ grid_x = col_no * self.page['width'] + (col_no + 1) * self.page['margin'] \
+ if self.page['starting_position_indicators'] \
+ else col_no * (self.page['width'] + self.page['margin'])
grid_boxes += self.get_phase_header(phase, grid_x)
match_height = canvas_size[1] / len(phase.matches)
row_no = 0
@@ -146,8 +183,13 @@ class PlayoffGenerator(object):
grid_boxes += self.get_match_box(
matches[match] if match is not None else None,
(grid_x, grid_y))
+ if match is not None:
+ for team in matches[match].teams:
+ starting_positions.update(team.place)
row_no += 1
col_no += 1
+ starting_positions_boxes = self.get_starting_position_box(
+ starting_positions, canvas_size)
return self.p_temp.get(
'MATCH_GRID',
canvas_size[0], canvas_size[1],
@@ -155,6 +197,7 @@ class PlayoffGenerator(object):
' '.join(['data-%s="%s"' % (
setting.replace('_', '-'), str(value)
) for setting, value in self.canvas.iteritems()]),
+ starting_positions_boxes,
grid_boxes
)
diff --git a/jfr_playoff/matchinfo.py b/jfr_playoff/matchinfo.py
index 93b997a..5a31577 100644
--- a/jfr_playoff/matchinfo.py
+++ b/jfr_playoff/matchinfo.py
@@ -187,6 +187,10 @@ class MatchInfo:
'fetching HTML scores for match #%d failed: %s(%s)',
self.info.id, type(e).__name__, str(e))
self.info.teams = self.__get_config_teams(self.info.teams)
+ for team in range(0, len(self.info.teams)):
+ if 'place' in self.config['teams'][team]:
+ self.info.teams[team].place = self.config['teams'][team]['place']
+
def __get_db_board_count(self):
towels = self.database.fetch(
diff --git a/jfr_playoff/template.py b/jfr_playoff/template.py
index 70c179b..7b91b3b 100644
--- a/jfr_playoff/template.py
+++ b/jfr_playoff/template.py
@@ -51,6 +51,7 @@ class PlayoffTemplateStrings(object):
<div style="position: relative; width: %dpx; height: %dpx; margin: 10px">
<canvas width="%d" height="%d" id="playoff_canvas" %s></canvas>
%s
+ %s
<script src="sklady/playoff.js" type="text/javascript"></script>
</div>
'''
@@ -77,8 +78,21 @@ class PlayoffTemplateStrings(object):
<img src="images/A.gif" />
'''
+ STARTING_POSITION_BOX = '''
+ <div style="position: absolute; left: %dpx; top: %dpx" class="playoff_matchbox" data-id="place-%d">
+ <table border="0" cellspacing="0">
+ <tr>
+ <td class="bdcc1" style="opacity: 0">&nbsp;</td>
+ </tr>
+ <tr>
+ <td class="bdc12" width="20">%d</td>
+ </tr>
+ </table>
+ </div>
+ '''
+
MATCH_BOX = '''
- <div style="text-align: center; position: absolute; left: %dpx; top: %dpx" data-id="%d" data-winner="%s" data-loser="%s" class="playoff_matchbox">
+ <div style="text-align: center; position: absolute; left: %dpx; top: %dpx" data-id="%d" data-winner="%s" data-loser="%s" data-place-winner="%s" data-place-loser="%s" class="playoff_matchbox">
%s
</div>
'''