From 528bbb28fafdef9aa107149fa5f2a90dccfa00f9 Mon Sep 17 00:00:00 2001 From: emkael Date: Fri, 28 Sep 2018 14:30:19 +0200 Subject: Comments on the code for single-segment match team/score fetching --- jfr_playoff/matchinfo.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'jfr_playoff/matchinfo.py') diff --git a/jfr_playoff/matchinfo.py b/jfr_playoff/matchinfo.py index 2aeb2c1..b40d6d1 100644 --- a/jfr_playoff/matchinfo.py +++ b/jfr_playoff/matchinfo.py @@ -116,6 +116,7 @@ class MatchInfo: in row.select('td.bdc')[-1].contents if isinstance(text, unicode)] except ValueError: + # single-segment match try: # running single-segment scores = [ @@ -272,11 +273,14 @@ class MatchInfo: segments = [cell for cell in cells if self.__has_segment_link(cell)] towels = [cell for cell in cells if self.__has_towel_image(cell)] if len(segments) == 0: + # in single-segment match, there are no td.bdc cells with segment links + # but maybe it's a multi-segment match with towels if len(towels) > 0: PlayoffLogger.get('matchinfo').info( 'HTML board count for match #%d: all towels', self.info.id) return 1, 1 # entire match is toweled, so mark as finished else: + # not a single-segment match, no need to look for td.bdcg cells break if len(segments) == 0: raise ValueError('segments not found') -- cgit v1.2.3 From b1ce81da1478715b1d3a8dd6883c5655db0a8f68 Mon Sep 17 00:00:00 2001 From: emkael Date: Fri, 28 Sep 2018 14:30:55 +0200 Subject: Fixing score fetch for a single-segment match with a towel --- jfr_playoff/matchinfo.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'jfr_playoff/matchinfo.py') diff --git a/jfr_playoff/matchinfo.py b/jfr_playoff/matchinfo.py index b40d6d1..f726282 100644 --- a/jfr_playoff/matchinfo.py +++ b/jfr_playoff/matchinfo.py @@ -124,11 +124,15 @@ class MatchInfo: in row.select('td.bdcg a')[-1].contents if isinstance(text, unicode)] except IndexError: - # static single-segment - scores = [ - float(text.strip()) for text - in row.select('td.bdc a')[-1].contents - if isinstance(text, unicode)] + try: + # static single-segment + scores = [ + float(text.strip()) for text + in row.select('td.bdc a')[-1].contents + if isinstance(text, unicode)] + except IndexError: + # toweled single-segment + scores = [0.0, 0.0] # carry-over carry_over = [ float(text.strip()) if len(text.strip()) > 0 else 0.0 for text -- cgit v1.2.3 From cb1edf3fb102f347adde2a1c8aec205c24cd36be Mon Sep 17 00:00:00 2001 From: emkael Date: Fri, 28 Sep 2018 14:31:35 +0200 Subject: Fixing carry-over fetch for a single-segment match if there's none --- jfr_playoff/matchinfo.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'jfr_playoff/matchinfo.py') diff --git a/jfr_playoff/matchinfo.py b/jfr_playoff/matchinfo.py index f726282..d968a34 100644 --- a/jfr_playoff/matchinfo.py +++ b/jfr_playoff/matchinfo.py @@ -138,6 +138,9 @@ class MatchInfo: float(text.strip()) if len(text.strip()) > 0 else 0.0 for text in row.select('td.bdc')[0].contents if isinstance(text, unicode)] + if len(carry_over) < 2: + # no carry-over, possibly no carry-over cells or empty + carry_over = [0.0, 0.0] for i in range(0, 2): scores[i] += carry_over[i] team_names = [[text for text in link.contents -- cgit v1.2.3 From e23ef3b9dc245d134e4b0105e2dca7a1833f1ba5 Mon Sep 17 00:00:00 2001 From: emkael Date: Fri, 28 Sep 2018 14:32:23 +0200 Subject: Fixing overall bourd count fetch for a single-segment match --- jfr_playoff/matchinfo.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'jfr_playoff/matchinfo.py') diff --git a/jfr_playoff/matchinfo.py b/jfr_playoff/matchinfo.py index d968a34..900c210 100644 --- a/jfr_playoff/matchinfo.py +++ b/jfr_playoff/matchinfo.py @@ -292,7 +292,6 @@ class MatchInfo: if len(segments) == 0: raise ValueError('segments not found') running_segments = row.select('td.bdca') - # FIXME: running single-segment match board count running_boards = sum([self.__get_html_running_boards(segment) for segment in running_segments]) finished_segments = [] boards_in_segment = None @@ -303,10 +302,14 @@ class MatchInfo: finished_segments.append(segment) if boards_in_segment is None and boards > 0: boards_in_segment = boards - PlayoffLogger.get('matchinfo').info( - 'HTML board count for match #%d, found: %d finished segments, %d towels, %d boards per segment and %d boards in running segment', - self.info.id, len(finished_segments), len(towels), boards_in_segment, running_boards) - total_boards = (len(segments) + len(towels) + len(running_segments)) * boards_in_segment + if 'bdcg' in segments[0]['class']: + # only a single-segment match will yield td.bdcg cells with segment scores + total_boards = boards_in_segment + else: + PlayoffLogger.get('matchinfo').info( + 'HTML board count for match #%d, found: %d finished segments, %d towels, %d boards per segment and %d boards in running segment', + self.info.id, len(finished_segments), len(towels), boards_in_segment, running_boards) + total_boards = (len(segments) + len(towels) + len(running_segments)) * boards_in_segment played_boards = (len(towels) + len(finished_segments)) * boards_in_segment + running_boards PlayoffLogger.get('matchinfo').info( 'HTML board count for match #%d: %d/%d', -- cgit v1.2.3 From 1ab6233374e1c25e3f9f58db98b547125cbef452 Mon Sep 17 00:00:00 2001 From: emkael Date: Fri, 28 Sep 2018 15:46:28 +0200 Subject: Revert running segment link if there are no scores in the segment (possibly "Don't send scores") Part of #7 is implented by this change --- jfr_playoff/matchinfo.py | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) (limited to 'jfr_playoff/matchinfo.py') diff --git a/jfr_playoff/matchinfo.py b/jfr_playoff/matchinfo.py index 900c210..dd2ee30 100644 --- a/jfr_playoff/matchinfo.py +++ b/jfr_playoff/matchinfo.py @@ -245,6 +245,15 @@ class MatchInfo: def __get_html_running_boards(self, cell): return int(cell.contents[-1].strip()) + def __get_html_segment_board_count(self, segment_url): + segment_content = p_remote.fetch(segment_url) + board_rows = [row for row in segment_content.find_all('tr') if len(row.select('td.bdcc a.zb')) > 0] + board_count = len(board_rows) + played_boards = len([ + row for row in board_rows if len( + ''.join([cell.text.strip() for cell in row.select('td.bdc')])) > 0]) + return played_boards, board_count + def __get_finished_info(self, cell): segment_link = cell.select('a[href]') if len(segment_link) > 0: @@ -252,12 +261,7 @@ class MatchInfo: r'\.htm$', '.html', urljoin(self.info.link, segment_link[0]['href'])) try: - segment_content = p_remote.fetch(segment_url) - board_rows = [row for row in segment_content.find_all('tr') if len(row.select('td.bdcc a.zb')) > 0] - board_count = len(board_rows) - played_boards = len([ - row for row in board_rows if len( - ''.join([cell.text.strip() for cell in row.select('td.bdc')])) > 0]) + played_boards, board_count = self.__get_html_segment_board_count(segment_url) PlayoffLogger.get('matchinfo').info( 'HTML played boards count for segment: %d/%d', played_boards, board_count) @@ -373,6 +377,7 @@ class MatchInfo: def __determine_running_link(self): if self.info.link is None: return + match_link = self.info.link link_match = re.match(r'^(.*)runda(\d+)\.html$', self.info.link) if link_match: try: @@ -390,6 +395,21 @@ class MatchInfo: PlayoffLogger.get('matchinfo').warning( 'cannot determine running link from HTML for match #%d: %s(%s)', self.info.id, type(e).__name__, str(e)) + if self.info.link != match_link: + # we've detected a running segment link + # we should check if the segment's uploaded live + try: + boards_played, board_count = self.__get_html_segment_board_count(re.sub('\.htm$', '.html', self.info.link)) + except IOError as e: + PlayoffLogger.get('matchinfo').warning( + 'cannot determine running link (%s) board count for match #%d: %s(%s)', + self.info.link, self.info.id, type(e).__name__, str(e)) + boards_played = 0 + if not boards_played: + PlayoffLogger.get('matchinfo').warning( + 'running link (%s) for match #%d is not live, reverting to match link (%s)', + self.info.link, self.info.id, match_link) + self.info.link = match_link def set_phase_link(self, phase_link): if self.info.link is None: -- cgit v1.2.3