summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2018-02-17 15:21:29 +0100
committeremkael <emkael@tlen.pl>2018-02-17 15:21:29 +0100
commitab371e10931e1c42877a0758cdcb2144e886850f (patch)
treef11fae9f964c6d1ff19674d13f6b28a1a2c549c6
parentf2fe40754a9a63d1854885e17b0e304dbf4a834f (diff)
If a match is running, link to first unfinished segment
Fixes #6
-rw-r--r--jfr_playoff/matchinfo.py18
-rw-r--r--jfr_playoff/sql.py5
2 files changed, 23 insertions, 0 deletions
diff --git a/jfr_playoff/matchinfo.py b/jfr_playoff/matchinfo.py
index 9366d5f..9f446cc 100644
--- a/jfr_playoff/matchinfo.py
+++ b/jfr_playoff/matchinfo.py
@@ -1,3 +1,4 @@
+import re
from urlparse import urljoin
import mysql
@@ -169,6 +170,21 @@ class MatchInfo:
self.info.loser = self.info.teams[0].name
self.info.winner = self.info.teams[1].name
+ def __get_db_running_link(self, prefix, round_no):
+ current_segment = int(
+ self.database.fetch(
+ self.config['database'], p_sql.CURRENT_SEGMENT, ())[0])
+ return '%s%st%d-%d.html' % (
+ prefix, round_no, self.config['table'], current_segment)
+
+ def __determine_running_link(self):
+ link_match = re.match(r'^(.*)runda(\d+)\.html$', self.info.link)
+ if link_match:
+ try:
+ self.info.link = self.__get_db_running_link(
+ link_match.group(1), link_match.group(2))
+ except (mysql.connector.Error, TypeError, IndexError, KeyError):
+ pass
def set_phase_link(self, phase_link):
if self.info.link is None:
@@ -181,4 +197,6 @@ class MatchInfo:
self.__fetch_teams_with_scores()
self.__fetch_board_count()
self.__determine_outcome()
+ if self.info.running > 0:
+ self.__determine_running_link()
return self.info
diff --git a/jfr_playoff/sql.py b/jfr_playoff/sql.py
index ab6d0be..1eac414 100644
--- a/jfr_playoff/sql.py
+++ b/jfr_playoff/sql.py
@@ -33,6 +33,11 @@ WHERE #db#.segments.tabl = %s AND #db#.segments.rnd = %s
GROUP BY #db#.segments.tabl, #db#.segments.rnd
'''
+CURRENT_SEGMENT = '''
+SELECT LEAST(segmentsperround, segm+1)
+FROM #db#.admin
+'''
+
PREFIX = '''
SELECT shortname FROM #db#.admin
'''