Exemplo n.º 1
0
 def test_sum(self):
     wl1 = WinLoss(7, 3)
     wl2 = WinLoss(6, 4)
     wl3 = WinLoss(0, 0)
     dct = {1: wl1, 2: wl2, 3: wl3}
     s = sum((dct[i] for i in range(1, 4)), WinLoss())
     self.assertEqual(wl1 + wl2 + wl3, s)
Exemplo n.º 2
0
    def test_close_by_right(self):
        qstat1 = QuadServiceStat()
        qstat1.update_with(
            prev_score=sc.Score("5-1"),
            prev_ingame=("30", "40"),
            prev_left_service=False,
            score=sc.Score("5-2"),
            ingame=("0", "0"),
            left_service=True,
        )

        self.assertEqual(WinLoss(1, 0), qstat1.srv_win_loss(co.RIGHT, co.ADV))
        self.assertEqual(WinLoss(0, 0),
                         qstat1.srv_win_loss(co.RIGHT, co.DEUCE))

        self.assertEqual(WinLoss(0, 0), qstat1.srv_win_loss(co.LEFT))
Exemplo n.º 3
0
 def test_close_by_left_then_fresh_left_tiebreak(self):
     qstat1 = QuadServiceStat()
     qstat1.update_with(
         prev_score=sc.Score("6-4 5-6"),
         prev_ingame=("30", "40"),
         prev_left_service=True,
         score=sc.Score("6-4 6-6"),
         ingame=("2", "0"),
         left_service=True,
     )
     # closing: left hold by win 3 points: ADV(2), DEUCE(1)
     # freshing: right opener by loss 1 point: DEUCE(0)
     # freshing: left by win 1 point: ADV(1)
     self.assertEqual(WinLoss(3, 0), qstat1.srv_win_loss(co.LEFT, co.ADV))
     self.assertEqual(WinLoss(1, 0), qstat1.srv_win_loss(co.LEFT, co.DEUCE))
     self.assertEqual(WinLoss(0, 1),
                      qstat1.srv_win_loss(co.RIGHT, co.DEUCE))
     self.assertEqual(WinLoss(0, 0), qstat1.srv_win_loss(co.RIGHT, co.ADV))
Exemplo n.º 4
0
    def test_close_by_left_then_fresh_right(self):
        qstat1 = QuadServiceStat()
        qstat1.update_with(
            prev_score=sc.Score("5-1"),
            prev_ingame=("30", "40"),
            prev_left_service=False,
            score=sc.Score("6-1 0-0"),
            ingame=("0", "40"),
            left_service=True,
        )
        # closing: right broken by 3 points
        self.assertEqual(WinLoss(0, 2), qstat1.srv_win_loss(co.RIGHT, co.ADV))
        self.assertEqual(WinLoss(0, 1),
                         qstat1.srv_win_loss(co.RIGHT, co.DEUCE))

        # freshing: left loss 3 points
        self.assertEqual(WinLoss(0, 2), qstat1.srv_win_loss(co.LEFT, co.ADV))
        self.assertEqual(WinLoss(0, 1), qstat1.srv_win_loss(co.LEFT, co.DEUCE))
Exemplo n.º 5
0
 def test_get_puig_sharapova(self):
     plr1 = Player(ident=10222, name="Monica Puig", cou="PUR")
     plr2 = Player(ident=503, name="Maria Sharapova", cou="RUS")
     mstat = get(
         sex="wta",
         tour_id=9125,
         rnd=Round("Second"),
         first_player_id=plr1.ident,
         second_player_id=plr2.ident,
         year_weeknum=tt.get_year_weeknum(datetime.date(2014, 5, 14)),
     )
     self.assertNotEqual(mstat, None)
     self.assertEqual(mstat.left_side.aces, 3)
     self.assertEqual(mstat.right_side.aces, 5)
     self.assertEqual(mstat.left_side.first_service_in, WinLoss(32, 24))
     self.assertEqual(mstat.right_side.first_service_in, WinLoss(38, 25))
     self.assertEqual(mstat.left_side.bp_win, WinLoss(2, 5))
     self.assertEqual(mstat.right_side.bp_win, WinLoss(4, 3))
     self.assertEqual(mstat.total_points_won(), (51, 68))
Exemplo n.º 6
0
 def test_close_previous(self):
     stat1 = HoldStat()
     stat1.close_previous(sc.Score("1-1"),
                          prev_left_service=True,
                          prev_left_wingame=True)  # 1/1, 0/0
     stat1.close_previous(sc.Score("2-1"),
                          prev_left_service=False,
                          prev_left_wingame=False)  # 1/1, 1/1
     stat1.close_previous(sc.Score("2-2"),
                          prev_left_service=True,
                          prev_left_wingame=False)  # 1/2, 1/1
     stat1.close_previous(sc.Score("2-3"),
                          prev_left_service=False,
                          prev_left_wingame=False)  # 1/2, 2/2
     stat1.close_previous(sc.Score("2-4"),
                          prev_left_service=True,
                          prev_left_wingame=True)  # 2/3, 2/2
     stat1.close_previous(sc.Score("6-6"),
                          prev_left_service=True,
                          prev_left_wingame=False)  # skip tie
     res_pair = stat1.result_pair(setnum=1, as_float=False)
     self.assertEqual(res_pair, (WinLoss(2, 1), WinLoss(2, 0)))
Exemplo n.º 7
0
 def test_get_baroni_williams(self):
     """baroni win 6-4 6-3"""
     plr1 = Player(ident=180, name="Mirjana Lucic-Baroni", cou="CRO")
     plr2 = Player(ident=151, name="Venus Williams", cou="USA")
     mstat = get(
         sex="wta",
         tour_id=9148,
         rnd=Round("Final"),
         first_player_id=plr1.ident,
         second_player_id=plr2.ident,
         year_weeknum=tt.get_year_weeknum(datetime.date(2014, 9, 14)),
     )
     self.assertNotEqual(mstat, None)
     self.assertEqual(mstat.left_side.aces, 6)
     self.assertEqual(mstat.right_side.aces, 5)
     self.assertEqual(mstat.left_side.bp_win, WinLoss(4, 7))
     self.assertEqual(mstat.right_side.bp_win, WinLoss(2, 2))
     self.assertEqual(mstat.left_side.first_service_win, WinLoss(31, 9))
     self.assertEqual(mstat.right_side.first_service_win, WinLoss(23, 14))
     self.assertEqual(mstat.left_side.second_service_win, WinLoss(10, 13))
     self.assertEqual(mstat.right_side.second_service_win, WinLoss(11, 21))
     self.assertEqual(mstat.left_side.double_faults, 4)
     self.assertEqual(mstat.right_side.double_faults, 2)
     self.assertEqual(mstat.total_points_won(), (76, 56))
Exemplo n.º 8
0
def run_stat():
    from bet import FlatLimitedProfiter
    assert predicts_db_hnd is not None, 'not opened db'

    def get_rnd(rnd_db):
        return rnd_db.split(';')[0]

    def get_prof_coef_result():
        nonlocal set2_loss_mched_cnt
        if rec.case_name == 'decided_00':
            return rec.bf_live_coef_matched, bool(rec.predict_result)
        elif rec.case_name == 'secondset_00':
            coef = 1 + (rec.bf_live_coef_matched - 1) * 0.4
            iswin = bool(rec.predict_result)
            if not iswin:
                set2_loss_mched_cnt += 1
                win_one_of = 4
                if (set2_loss_mched_cnt % win_one_of) == 0:
                    # assume win 1 of win_one_of by hedging, our plr looks ok
                    iswin = True
            return coef, iswin
        return None, None

    def do_profiter():
        if rec.bf_live_coef_matched is not None:
            prof_coef, prof_res = get_prof_coef_result()
            if prof_coef is not None:
                profiter.calculate_bet(coef=prof_coef, iswin=prof_res)

    set2_loss_mched_cnt = 0
    wl = WinLoss()
    surf_wl_dct = defaultdict(WinLoss)
    rnd_wl_dct = defaultdict(WinLoss)
    bystartbook_wl = WinLoss()
    book_start_chances = []
    profiter = FlatLimitedProfiter(start_money=9)
    predicts_db_hnd.query_predicts()
    for rec in predicts_db_hnd.records:
        if (rec.predict_result in (0, 1)
                and (not args.sex or (args.sex == rec.sex))
                and (not args.casename or (rec.case_name == args.casename))
                and (args.rejected is None or
                     (args.rejected == 1 and rec.rejected == args.rejected) or
                     (args.rejected == 0 and rec.rejected in (-1, 0)))
                and (not args.minproba or (rec.predict_proba >= args.minproba))
                and (not args.maxproba or (rec.predict_proba <= args.maxproba))
                and (args.opener is None or (args.opener and
                                             ('OPENER' in rec.comments)) or
                     (not args.opener and ('CLOSER' in rec.comments)))):
            predict_ok = bool(rec.predict_result)
            if args.stat_use_matchwinner_only:
                predict_ok = bool(rec.back_win_match)
            # print(f"{rec.back_name} {rec.oppo_name} -> {predict_ok}")
            wl.hit(iswin=predict_ok)
            surf_wl_dct[rec.surface].hit(iswin=predict_ok)
            rnd_wl_dct[get_rnd(rec.rnd)].hit(iswin=predict_ok)
            book_start_chances.append(rec.book_start_chance)
            do_profiter()
            if (rec.back_win_match in (0, 1)
                    and abs(rec.book_start_chance - 0.5) > 0.001):
                bystartbook_win = (bool(rec.back_win_match) is
                                   (rec.book_start_chance > 0.5))
                bystartbook_wl.hit(bystartbook_win)

    print(f"stat: {wl} nw: {wl.win_count} nl: {wl.loss_count}")
    pprint([(s, str(w).strip()) for s, w in surf_wl_dct.items()])
    pprint([(r, str(w).strip()) for r, w in rnd_wl_dct.items()])
    if book_start_chances:
        avg_book_start_chance = round(
            sum(book_start_chances) / len(book_start_chances), 3)
    else:
        avg_book_start_chance = None
    print(f"avg book_start_chance: {avg_book_start_chance}")
    print(f"profit by matched coefs: {profiter}")
    print(f"bystartbook wl : {bystartbook_wl}")
Exemplo n.º 9
0
 def __init__(self):
     self.fst_wl = WinLoss()
     self.snd_wl = WinLoss()