diff options
author | emkael <emkael@tlen.pl> | 2019-12-31 13:19:48 +0100 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2019-12-31 13:19:48 +0100 |
commit | 7d3a08128bcadd562e7eaa48644c830ed166c98c (patch) | |
tree | f9f3a33c67a3cf0fd85175d346c36883e02fe0bf /jfr_playoff/data/match/jfrdb.py | |
parent | 009c26df9ccc65e3c58f62154a63498debd8e5b3 (diff) |
Migrating JFR match results to result info client model
Diffstat (limited to 'jfr_playoff/data/match/jfrdb.py')
-rw-r--r-- | jfr_playoff/data/match/jfrdb.py | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/jfr_playoff/data/match/jfrdb.py b/jfr_playoff/data/match/jfrdb.py index 7d9e067..8dc57ab 100644 --- a/jfr_playoff/data/match/jfrdb.py +++ b/jfr_playoff/data/match/jfrdb.py @@ -1,3 +1,6 @@ +import re + +import jfr_playoff.sql as p_sql from jfr_playoff.data import TournamentInfo from jfr_playoff.data.match import MatchInfoClient from jfr_playoff.logger import PlayoffLogger @@ -26,3 +29,75 @@ class JFRDbMatchInfo(MatchInfoClient): PlayoffLogger.get('match.jfrdb').info( 'match #%d link fetched: %s', self.settings['id'], link) return link + + def fetch_teams(self, teams): + row = self.database.fetch( + self.settings['database'], p_sql.MATCH_RESULTS, + (self.settings['table'], self.settings['round'])) + for i in range(0, 2): + teams[i].name = [row[i]] + teams[i].known_teams = 1 + teams[0].score = row[3] + row[5] + teams[1].score = row[4] + row[6] + if row[2] > 0: + teams[0].score += row[2] + else: + teams[1].score -= row[2] + PlayoffLogger.get('match.jfrdb').info( + 'scores fetched: %s', teams) + return teams + + def board_count(self): + towels = self.database.fetch( + self.settings['database'], p_sql.TOWEL_COUNT, + (self.settings['table'], self.settings['round'])) + row = [0 if r is None + else r for r in + self.database.fetch( + self.settings['database'], p_sql.BOARD_COUNT, + (self.settings['table'], self.settings['round']))] + boards_to_play = int(row[0]) + boards_played = max(int(row[1]), 0) + if boards_to_play > 0: + boards_played += int(towels[0]) + PlayoffLogger.get('match.jfrdb').info( + 'board count: %d/%d', boards_played, boards_to_play) + return boards_played, boards_to_play + + def running_link(self): + match_link = self.settings['link'] + link_match = re.match(r'^(.*)runda(\d+)\.html$', match_link) + if link_match: + current_segment = int( + self.database.fetch( + self.settings['database'], p_sql.CURRENT_SEGMENT, + (self.settings['round'],))[0]) + PlayoffLogger.get('match.jfrdb').info( + 'fetched running segment: %d', current_segment) + match_link = '%s%st%d-%d.html' % ( + link_match.group(1), link_match.group(2), + self.settings['table'], current_segment) + if match_link != self.settings['link']: + PlayoffLogger.get('match.jfrdb').info( + 'checking if running link %s is live', match_link) + from jfr_playoff.data.match.jfrhtml import JFRHtmlMatchInfo + client = JFRHtmlMatchInfo(self.settings) + try: + boards_played, board_count = client.segment_board_count( + re.sub('\.htm$', '.html', match_link)) + except Exception as e: + PlayoffLogger.get('match.jfrdb').info( + 'unable to determine confirm link: %s(%s)', + type(e).__name__, str(e)) + boards_played = 0 + if not boards_played: + PlayoffLogger.get('match.jfrdb').info( + 'running link is not live - reverting to match link (%s)', + self.settings['link']) + match_link = self.settings['link'] + elif boards_played == board_count: + PlayoffLogger.get('match.jfrdb').info( + 'running link is finished - reverting to match link (%s)', + self.settings['link']) + match_link = self.settings['link'] + return match_link |