def visit_stat_match(mch, coef, stat_name, fst_sum, snd_sum):
     if (
         mch.stat is None
         or mch.paired()
         or mch.score.sets_count(full=True) < 2
         or not mch.stat.is_total_points_won()
     ):
         return
     if match.first_player.ident in (
         mch.first_player.ident,
         mch.second_player.ident,
     ):
         side = co.side(match.first_player.ident == mch.first_player.ident)
         fst_obj = player_stat(mch.stat, stat_name, side)
         if (
             fst_obj
             and fst_obj.value < 1.01
             and fst_sum.size < self.stop_stat_size
         ):
             fst_sum += fst_obj.value * coef
     if match.second_player.ident in (
         mch.first_player.ident,
         mch.second_player.ident,
     ):
         side = co.side(match.second_player.ident == mch.first_player.ident)
         snd_obj = player_stat(mch.stat, stat_name, side)
         if (
             snd_obj
             and snd_obj.value < 1.01
             and snd_sum.size < self.stop_stat_size
         ):
             snd_sum += snd_obj.value * coef
Example #2
0
 def put(self, setnum, scr, is_left_service):
     """True if puted value is majority consilienced, False - not consilienced,
     None if not proof evidence"""
     if scr in ((6, 6), (12, 12)) or is_left_service is None:
         return
     if sum(scr) % 2 == 0:
         self.setnum_dict[setnum].put(is_left_service)
         opener_side = self.setnum_dict[setnum].get_opener_side()
         if opener_side is not None:
             return opener_side == co.side(is_left_service)
     else:
         self.setnum_dict[setnum].put(not is_left_service)
         opener_side = self.setnum_dict[setnum].get_opener_side()
         if opener_side is not None:
             return opener_side == co.side(not is_left_service)
Example #3
0
    def __close_previous(self, prev_left_wingame, prev_score, prev_ingame,
                         prev_left_service):
        def get_num_ingame_to(num_ingame_from, points_to_win):
            if prev_left_wingame:
                return num_ingame_from[0] + points_to_win[0], num_ingame_from[
                    1]
            else:
                return num_ingame_from[
                    0], num_ingame_from[1] + points_to_win[1]

        if prev_score is None or prev_ingame is None or prev_left_service is None:
            return

        sn = len(prev_score)
        self.lastinrow.close_game(sn, prev_left_wingame)
        if self.is_tiebreak(prev_score, prev_ingame):
            num_ingame_from = sc.ingame_to_num(prev_ingame, tiebreak=True)
            points_to_win = sc.num_ingame_to_win(num_ingame_from,
                                                 tiebreak=True)
            num_ingame_to = get_num_ingame_to(num_ingame_from, points_to_win)
            self.__fill_tie(sn, num_ingame_from, num_ingame_to,
                            co.side(prev_left_service))
        else:
            num_ingame_from = sc.ingame_to_num(prev_ingame, tiebreak=False)
            points_to_win = sc.num_ingame_to_win(num_ingame_from,
                                                 tiebreak=False)
            num_ingame_to = get_num_ingame_to(num_ingame_from, points_to_win)
            self.__fill(sn, num_ingame_from, num_ingame_to, prev_left_service)
            self.allow_bp_stat.close_previous(prev_left_wingame, prev_score,
                                              prev_ingame, prev_left_service)
            self.breakup_tracker.close_previous(prev_score, prev_left_service,
                                                prev_left_wingame)
Example #4
0
 def get_opener_side(self):
     all_count = self.left_side_count + self.right_side_count
     if all_count >= self.min_vs_zero_count and (
             self.left_side_count == 0 or self.right_side_count == 0):
         return co.side(self.left_side_count >= self.right_side_count)
     if all_count > self.min_vs_one_count and (self.left_side_count == 1 or
                                               self.right_side_count == 1):
         return co.side(self.left_side_count >= self.right_side_count)
     if all_count >= self.min_dominate_all_count:
         if self.left_side_count >= self.right_side_count:
             ratio = float(self.left_side_count) / float(all_count)
             if ratio >= self.min_dominate_ratio:
                 return co.LEFT
         else:
             ratio = float(self.right_side_count) / float(all_count)
             if ratio >= self.min_dominate_ratio:
                 return co.RIGHT
Example #5
0
 def __open_fresh(self, score, ingame, left_service):
     if ingame in (None, ("0", "0")):
         return
     sn = len(score)
     if self.is_tiebreak(score, ingame):
         num_ingame_to = sc.ingame_to_num(ingame, tiebreak=True)
         tie_open_side = sc.tie_opener_side(num_ingame_to,
                                            co.side(left_service))
         self.__fill_tie(sn, (0, 0), num_ingame_to, tie_open_side)
     else:
         num_ingame_to = sc.ingame_to_num(ingame, tiebreak=False)
         self.__fill(sn, (0, 0), num_ingame_to, left_service)
Example #6
0
 def close_previous(self, prev_score, prev_left_service, prev_left_wingame):
     miss_side = co.RIGHT if prev_left_wingame else co.LEFT
     miss_side_left = miss_side.is_left()
     srv_side = co.side(prev_left_service)
     srv = miss_side == srv_side
     m_val = self.get_tmp_count(co.MATCH, srv, miss_side_left)
     if m_val > 0:
         setnum = len(prev_score)
         self._inc_count(co.MATCH, srv, setnum, miss_side_left, m_val)
     else:
         s_val = self.get_tmp_count(co.SET, srv, miss_side_left)
         if s_val > 0:
             setnum = len(prev_score)
             self._inc_count(co.SET, srv, setnum, miss_side_left, s_val)
     self.clear_tmp()
Example #7
0
 def __continue_current(self, prev_score, prev_ingame, prev_left_service,
                        ingame):
     if prev_ingame == ingame:
         return
     sn = len(prev_score)
     if self.is_tiebreak(prev_score, prev_ingame):
         num_ingame_from = sc.ingame_to_num(prev_ingame, tiebreak=True)
         num_ingame_to = sc.ingame_to_num(ingame, tiebreak=True)
         self.__fill_tie(sn, num_ingame_from, num_ingame_to,
                         co.side(prev_left_service))
     else:
         prev_inset_scr = prev_score[-1]
         num_ingame_from = sc.ingame_to_num(prev_ingame, tiebreak=False)
         num_ingame_to = sc.ingame_to_num(ingame, tiebreak=False)
         self.__fill(sn, num_ingame_from, num_ingame_to, prev_left_service)
         self.allow_bp_stat.continue_current(prev_score, prev_ingame,
                                             prev_left_service, ingame)
def detailed_game_values(sex, level, surface, qualification, det_game, misspoints):
    """выдает пару рез-тов для левого и правого игроков,
    отражающих их игру на важных очках. Оценки м.б. не симметричны.
    большее зн-ние не всегда у выигравшего гейм"""
    if (
        not det_game.valid
        or point_score_error(det_game.error)
        or det_game.extra_points_error()
    ):
        return None
    left_sum, right_sum = 0.0, 0.0
    for point in det_game:
        if det_game.tiebreak:
            imp = tpimportance.point_importance(
                sex,
                level,
                surface,
                qualification,
                point.num_score(),
                co.side(point.serve()),
            )
        else:
            imp = pimportance.point_importance(
                sex, level, surface, qualification, point.text_score()
            )
        if point.win(left=True):
            left_sum += imp
        else:
            right_sum += imp

    min_sum = min(left_sum, right_sum)
    left_val = left_sum - min_sum
    right_val = right_sum - min_sum
    max_value = MAX_TIEBREAK_VALUE if det_game.tiebreak else MAX_GAME_VALUE
    if left_val > max_value:
        left_val = max_value
    if right_val > max_value:
        right_val = max_value

    left_miss_penalty, right_miss_penalty = miss_points.get_penalty(
        sex, misspoints, scope_predicate=lambda s: s != co.GAME
    )
    return left_val - left_miss_penalty, right_val - right_miss_penalty
 def side(self):
     return co.side(self.left_side)
Example #10
0
 def winer_side(self):
     if not self.retired:
         sets_scr = self.sets_score(full=False)
         if sets_scr[0] != sets_scr[1]:
             return co.side(sets_scr[0] > sets_scr[1])