Example #1
0
def breaks_advantage(insetscore, srv_side: Side):
    """breaks advantage for left: 0 - no adv. n>0 left leads n breaks. n<0 left trails.

    >>> breaks_advantage((1, 1), srv_side=co.LEFT)
    0
    >>> breaks_advantage((0, 1), srv_side=co.LEFT)
    0
    >>> breaks_advantage((2, 0), srv_side=co.LEFT)
    1
    >>> breaks_advantage((1, 2), srv_side=co.RIGHT)
    -1
    >>> breaks_advantage((3, 0), srv_side=co.LEFT)
    2
    >>> breaks_advantage((1, 4), srv_side=co.RIGHT)
    -2
    >>> breaks_advantage((0, 6), srv_side=co.LEFT)
    -3
    """
    diff = insetscore[0] - insetscore[1]
    if diff == 0:
        return 0
    if diff < 0:
        return -breaks_advantage(co.reversed_tuple(insetscore), srv_side.fliped())
    # only left may have advantage
    if srv_side.is_left():
        return (diff + 1) // 2
    else:
        return diff // 2
Example #2
0
 def side_prefer(self, side: Side, dif: Union[float,
                                              int]) -> Optional[bool]:
     if self.left_prefer is None:
         return None  # ни у кого нет преимущества
     if side.is_left() != self.left_prefer:
         return False
     if self.dif is None:
         return True
     return self.dif >= dif
 def opener_s2choke_adv():
     s2loser = Side(match.score[1][0] < match.score[1][1])
     if s2loser.is_left():
         was_breakup = match.quad_stat.breakup_tracker.is_fst_breakup(
             setnum=2)
     else:
         was_breakup = match.quad_stat.breakup_tracker.is_snd_breakup(
             setnum=2)
     if not was_breakup:
         return 0
     return -1 if decset_open_side == s2loser else 1
Example #4
0
 def test_simple(self):
     left = Side("LEFT")
     left2 = Side("LEFT")
     right = Side("RIGHT")
     self.assertEqual(left, "LEFT")
     self.assertTrue(left.is_left())
     self.assertFalse(left.is_right())
     self.assertTrue(left.is_oppose(right))
     self.assertTrue(left.is_oppose(left.fliped()))
     self.assertFalse(left.is_oppose(left2))
     self.assertTrue(left != right)
     self.assertTrue(left == left2)
     self.assertFalse(left2.fliped().is_left())
 def srv_side_at_begin(self, setnum: int):
     if (
         self.setnum is not None
         and self.inset is not None
         and self.is_left_srv is not None
     ):
         if self.setnum == setnum:
             return (
                 Side(self.is_left_srv)
                 if co.is_even(sum(self.inset))
                 else Side(not self.is_left_srv)
             )
         if (self.setnum + 1) == setnum and max(self.inset) >= 5:
             prob_set_winner = Side(self.inset[0] > self.inset[1])
             if self.is_left_srv is prob_set_winner.is_left():
                 return prob_set_winner.fliped()
             return prob_set_winner
Example #6
0
def write_bf_live_coef(date: datetime.date, sex: str, fst_id: int, snd_id: int,
                       case_name: str, back_side: Side, bf_live_coef: float):
    if predicts_db_hnd is None:
        return
    if back_side.is_left():
        back_id, oppo_id = fst_id, snd_id
    else:
        back_id, oppo_id = snd_id, fst_id
    rec = predicts_dbsa.find_predict_rec_by(predicts_db_hnd.session,
                                            sex,
                                            date,
                                            case_name,
                                            back_id=back_id,
                                            oppo_id=oppo_id)
    if isinstance(rec, predicts_dbsa.PredictRec):
        rec.bf_live_coef = bf_live_coef
        _commit(bytime=False)
Example #7
0
def write_rejected(match, case_name: str, back_side: Side, reason: str = ""):
    if predicts_db_hnd is None:
        return
    if back_side.is_left():
        back_id, oppo_id = match.first_player.ident, match.second_player.ident
    else:
        back_id, oppo_id = match.second_player.ident, match.first_player.ident
    rec = predicts_dbsa.find_predict_rec_by(predicts_db_hnd.session,
                                            match.sex,
                                            match.date,
                                            case_name,
                                            back_id=back_id,
                                            oppo_id=oppo_id)
    if isinstance(rec, predicts_dbsa.PredictRec):
        rec.rejected = 1
        if reason:
            rec.comments = cut_comments(rec.comments + " " + reason)
        _commit(bytime=False)
Example #8
0
def write_predict(match,
                  case_name: str,
                  back_side: Side,
                  proba: float,
                  comments: str = '',
                  rejected: int = -1):
    if predicts_db_hnd is None:
        return
    if back_side.is_left():
        back_id, oppo_id = match.first_player.ident, match.second_player.ident
        back_name = match.first_player.name
        oppo_name = match.second_player.name
        book_start_chance = match.first_player_bet_chance()
    else:
        back_id, oppo_id = match.second_player.ident, match.first_player.ident
        back_name = match.second_player.name
        oppo_name = match.first_player.name
        book_start_chance = 1 - match.first_player_bet_chance()
    rec = predicts_dbsa.PredictRec(
        date=match.date,
        sex=match.sex,
        case_name=case_name,
        tour_name=str(match.tour_name),
        level=match.level,
        surface=match.surface,
        rnd=match.rnd,
        back_id=back_id,
        oppo_id=oppo_id,
        predict_proba=proba,
        predict_result=-1,
        comments=cut_comments(comments),
        back_name=back_name,
        oppo_name=oppo_name,
        book_start_chance=book_start_chance,
        rejected=rejected,
    )
    predicts_db_hnd.insert_obj(rec)
    _commit(bytime=False)