summaryrefslogtreecommitdiff
path: root/jfr_playoff
diff options
context:
space:
mode:
Diffstat (limited to 'jfr_playoff')
-rw-r--r--jfr_playoff/__init__.py0
-rw-r--r--jfr_playoff/db.py19
-rw-r--r--jfr_playoff/settings.py31
-rw-r--r--jfr_playoff/sql.py34
-rw-r--r--jfr_playoff/template.py128
5 files changed, 212 insertions, 0 deletions
diff --git a/jfr_playoff/__init__.py b/jfr_playoff/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/jfr_playoff/__init__.py
diff --git a/jfr_playoff/db.py b/jfr_playoff/db.py
new file mode 100644
index 0000000..aa0c2e2
--- /dev/null
+++ b/jfr_playoff/db.py
@@ -0,0 +1,19 @@
+import mysql.connector
+
+class PlayoffDB(object):
+
+ db_cursor = None
+
+ def __init__(self, settings):
+ self.database = mysql.connector.connect(
+ user=settings['user'],
+ password=settings['pass'],
+ host=settings['host'],
+ port=settings['port']
+ )
+ self.db_cursor = self.database.cursor(buffered=True)
+
+ def fetch(self, db, sql, params):
+ self.db_cursor.execute(sql.replace('#db#', db), params)
+ row = self.db_cursor.fetchone()
+ return row
diff --git a/jfr_playoff/settings.py b/jfr_playoff/settings.py
new file mode 100644
index 0000000..dd7399d
--- /dev/null
+++ b/jfr_playoff/settings.py
@@ -0,0 +1,31 @@
+import glob, json, os, readline, sys
+
+def complete_filename(text, state):
+ return (glob.glob(text+'*')+[None])[state]
+
+class PlayoffSettings:
+
+ def __init__(self):
+ self.interactive = False
+ if len(sys.argv) > 1:
+ settings_file = sys.argv[1]
+ else:
+ self.interactive = True
+ readline.set_completer_delims(' \t\n;')
+ readline.parse_and_bind("tab: complete")
+ readline.set_completer(complete_filename)
+ settings_file = raw_input('JSON settings file: ')
+
+ if not os.path.exists(settings_file):
+ raise IOError('Settings file %s not found' % settings_file)
+
+ self.settings = json.load(open(settings_file))
+
+ def has_section(self, key):
+ return key in self.settings
+
+ def get(self, *keys):
+ section = self.settings
+ for key in keys:
+ section = section[key]
+ return section
diff --git a/jfr_playoff/sql.py b/jfr_playoff/sql.py
new file mode 100644
index 0000000..76ea728
--- /dev/null
+++ b/jfr_playoff/sql.py
@@ -0,0 +1,34 @@
+MATCH_RESULTS = '''
+SELECT t1.fullname, t2.fullname, matches.carry, matches.vph, matches.vpv, matches.corrh, matches.corrv
+FROM #db#.matches matches
+JOIN #db#.teams t1
+ ON t1.id = #db#.matches.homet
+JOIN #db#.teams t2
+ ON t2.id = #db#.matches.visit
+WHERE matches.tabl = %s AND matches.rnd = %s
+'''
+
+BOARD_COUNT = '''
+SELECT segmentsperround*boardspersegment, SUM(sc1.contract IS NOT NULL AND sc2.contract IS NOT NULL)
+FROM #db#.scores sc1
+JOIN #db#.scores sc2
+ ON sc1.rnd = sc2.rnd
+ AND sc1.segment = sc2.segment
+ AND sc1.tabl = sc2.tabl
+ AND sc1.board = sc2.board
+ AND sc1.room = 1
+ AND sc2.room = 2
+JOIN #db#.admin
+WHERE sc1.tabl = %s AND sc1.rnd = %s
+'''
+
+TOWEL_COUNT = '''
+SELECT #db#.admin.boardspersegment * SUM(#db#.segments.towel > 0)
+FROM #db#.segments
+JOIN #db#.admin
+WHERE #db#.segments.tabl = %s AND #db#.segments.rnd = %s
+'''
+
+PREFIX = '''
+SELECT shortname FROM #db#.admin
+'''
diff --git a/jfr_playoff/template.py b/jfr_playoff/template.py
new file mode 100644
index 0000000..8713ab9
--- /dev/null
+++ b/jfr_playoff/template.py
@@ -0,0 +1,128 @@
+#encoding=utf-8
+
+MATCH_TABLE = '''
+<table border="0" cellspacing="0">
+<tr>
+<td class="s12" width="%d">&nbsp;</td>
+<td class="bdcc2" width="%d">&nbsp;wynik&nbsp;</td>
+</tr>
+%s
+</table>
+'''
+
+MATCH_TEAM_ROW = '''
+<tr class="%s">
+<td class="bd1">&nbsp;<a href="%s" onmouseover="Tip('%s')" onmouseout="UnTip()">%s</a>&nbsp;</td>
+<td class="bdc">
+<a href="%s" target="_top">
+&nbsp;%.1f&nbsp;
+</a>
+</td>
+</tr>
+'''
+
+MATCH_RUNNING = '''
+<a href="%s" target="_top">
+<img src="images/A.gif" />
+%d
+<img src="images/A.gif" />
+</a>
+'''
+
+MATCH_GRID = '''
+<div style="position: relative; width: %dpx; height: %dpx; margin: 10px">
+<canvas width="%d" height="%d" id="playoff_canvas" %s></canvas>
+%s
+<script src="sklady/playoff.js" type="text/javascript"></script>
+</div>
+'''
+
+MATCH_GRID_PHASE = '''
+<a href="%s" target="_top" style="display: inline-block; width: %dpx; text-align: center; position: absolute; top: 0; left: %dpx">
+<font size="4">%s</font>
+</a>
+'''
+
+MATCH_GRID_PHASE_RUNNING = '''
+<a href="%s" target="_top" style="display: inline-block; width: %dpx; text-align: center; position: absolute; top: 0; left: %dpx">
+<img src="images/A.gif" />
+<font size="4">%s</font>
+<img src="images/A.gif" />
+</a>
+'''
+
+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">
+%s
+</div>
+'''
+
+LEADERBOARD = '''
+<table border="0" cellspacing="0">
+<tr>
+<td class="bdnl12" colspan="2" align="center"><b>&nbsp;KLASYFIKACJA KOŃCOWA&nbsp;</b></td>
+</tr>
+<tr>
+<td class="e" colspan="2">&nbsp;</td>
+</tr>
+<tr>
+<td class="bdcc12">&nbsp;miejsce&nbsp;</td>
+<td class="bdcc2">&nbsp;drużyna&nbsp;</td>
+</tr>
+%s
+</table>
+'''
+
+LEADERBOARD_ROW = '''
+<tr>
+<td class="bdc1">%d</td>
+<td class="bd">
+&nbsp;%s&nbsp;&nbsp;%s&nbsp;
+</td>
+</tr>
+'''
+
+LEADERBOARD_ROW_FLAG = '''
+<img class="fl" src="images/%s" />
+'''
+
+PAGE_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="PlayOff" />
+%s
+<title>%s</title>
+<link rel="stylesheet" type="text/css" href="css/kolorki.css" />
+<script type="text/javascript" src="sklady/myAjax.js"></script>
+'''
+
+PAGE_HEAD_REFRESH = '''
+<meta http-equiv="Refresh" content="%d" />
+'''
+
+PAGE_BODY = '''
+<script type="text/javascript" src="sklady/wz_tooltip.js"></script>
+%s
+%s
+%s
+%s
+'''
+
+PAGE_BODY_FOOTER = '''
+<p class="f">&nbsp;Admin&nbsp;&copy;Jan Romański&#39;2005, PlayOff&nbsp;&copyMichał Klichowicz&#39;2017, strona wygenerowana %s</p>
+'''
+
+PAGE = '''
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<html>
+<head>
+%s
+</head>
+<body class="all">
+%s
+</body>
+</html>
+'''