Exemple #1
0
def make_mrec_2():
    items = [
        (
            ((0, 0), ),
            DetailedGame("100111",
                         left_wingame=True,
                         left_opener=True,
                         tiebreak=False),
        ),
        (
            ((1, 0), ),
            DetailedGame("011000",
                         left_wingame=True,
                         left_opener=False,
                         tiebreak=False),
        ),
    ]
    ds = DetailedScore(items, retired=False)
    scr = Score.from_pairs(ds.final_score(), retired=False)
    return dbsa.MatchRec(
        date=datetime.date(2020, 6, 26),
        tour_id=101,
        rnd=Round("Final"),
        left_id=555,
        right_id=333,
        detailed_score=ds,
        score=scr,
    )
 def test_save_restore2(self):
     items = [
         (
             ((0, 0), ),
             DetailedGame("1111",
                          left_wingame=True,
                          left_opener=True,
                          tiebreak=False),
         ),
         (
             ((1, 0), ),
             DetailedGame("0000",
                          left_wingame=True,
                          left_opener=False,
                          tiebreak=False),
         ),
     ]
     ds = DetailedScore(items, retired=True)
     ds.error = error_code("SET5_SCORE_PROBLEMS") | error_code(
         "SET4_SCORE_PROBLEMS")
     text = ds.tostring()
     ds2 = DetailedScore.from_str(text)
     self.assertEqual(ds, ds2)
def parse_match_detailed_score(match, fsdriver, verbose: bool = False):
    """return True if ok, False if logged error. type(match) == LiveMatch"""
    if not match.href or match.score is None or match.score.retired:
        return
    sets_count = match.score.sets_count()
    best_of_five = match.best_of_five
    det_score = DetailedScore()
    try:
        for setnum in range(1, sets_count + 1):
            det_set_el = build_root(
                match.pointbypoint_href(setnum), fsdriver, verbose=verbose
            )
            fsdriver.implicitly_wait(random.randint(4, 7))
            entry_elem = co.find_first_xpath(
                det_set_el, "descendant::div[contains(@class,'matchHistoryWrapper')]"
            )
            if entry_elem is None:
                if verbose:
                    print(f"not found matchHistoryWrapper in set={setnum} {match}")
                return False

            set_scr = match.score[setnum - 1]
            is_decided_set = setnum == (5 if best_of_five else 3)
            tie_inf = get_tie_info(match, is_decided_set)
            is_tie = tie_inf.beg_scr is not None and set_scr in (
                (tie_inf.beg_scr[0] + 1, tie_inf.beg_scr[1]),
                (tie_inf.beg_scr[0], tie_inf.beg_scr[1] + 1),
            )
            mhistos = list(
                entry_elem.xpath("child::div[contains(@class, 'matchHistory')]")
            )
            fifteens = list(entry_elem.xpath("child::div[contains(@class, 'fifteen')]"))
            n_usial_games = sum(set_scr) - 1 if is_tie else sum(set_scr)
            for game_idx in range(min(n_usial_games, len(fifteens))):
                mhisto = mhistos[game_idx]
                fifteen = fifteens[game_idx]
                dg_res = _parse_out_result(mhisto)
                game_winside = dg_res.winner()
                if game_winside.is_left():
                    src_score = (dg_res.x - 1, dg_res.y)
                else:
                    src_score = (dg_res.x, dg_res.y - 1)
                point_scores_txt = _parse_point_scores(fifteen)
                nkey = _make_next_key(det_score, setnum, src_score)
                det_game = make_detailed_game(
                    dg_res.srv_side,
                    game_winside,
                    make_num_pairs(point_scores_txt),
                    tiebreak=False,
                    is_super_tie=False,
                )
                det_score[nkey] = copy.copy(det_game)

            if is_tie:
                mhisto = mhistos[n_usial_games]
                x_sup, y_sup = _parse_detgame_tiesup_score(mhisto)
                at_xy = (n_usial_games // 2, n_usial_games // 2)
                nkey = _make_next_key(det_score, setnum, (min(at_xy), min(at_xy)))
                det_game = _parse_tie_scores(
                    mhistos[n_usial_games + 1 :],
                    setnum,
                    (x_sup, y_sup),
                    tie_inf.is_super,
                )
                det_score[nkey] = copy.copy(det_game)
    except co.TennisScoreError as err:
        if verbose:
            print("{} in {}".format(err, match))
        return False
    if len(det_score) >= 12:
        match.detailed_score = det_score
        return True
 def make_2set_det_score_badend():
     items = [
         (
             ((0, 0), ),
             DetailedGame("1111",
                          left_wingame=True,
                          left_opener=True,
                          tiebreak=False),
         ),
         (
             ((1, 0), ),
             DetailedGame("0000",
                          left_wingame=True,
                          left_opener=False,
                          tiebreak=False),
         ),
         (
             ((2, 0), ),
             DetailedGame("1111",
                          left_wingame=True,
                          left_opener=True,
                          tiebreak=False),
         ),
         (
             ((3, 0), ),
             DetailedGame("0000",
                          left_wingame=True,
                          left_opener=False,
                          tiebreak=False),
         ),
         (
             ((4, 0), ),
             DetailedGame("0000",
                          left_wingame=False,
                          left_opener=True,
                          tiebreak=False),
         ),
         (
             ((4, 1), ),
             DetailedGame("1111",
                          left_wingame=False,
                          left_opener=False,
                          tiebreak=False),
         ),
         (
             ((4, 2), ),
             DetailedGame("0000",
                          left_wingame=False,
                          left_opener=True,
                          tiebreak=False),
         ),
         (
             ((4, 3), ),
             DetailedGame("1111",
                          left_wingame=False,
                          left_opener=False,
                          tiebreak=False),
         ),
         (
             ((4, 4), ),
             DetailedGame("0000",
                          left_wingame=False,
                          left_opener=True,
                          tiebreak=False),
         ),
         (
             ((4, 5), ),
             DetailedGame("0000",
                          left_wingame=True,
                          left_opener=False,
                          tiebreak=False),
         ),
         (
             ((5, 5), ),
             DetailedGame("0000",
                          left_wingame=False,
                          left_opener=True,
                          tiebreak=False),
         ),
         (
             ((5, 6), ),
             DetailedGame("0000",
                          left_wingame=True,
                          left_opener=False,
                          tiebreak=False),
         ),
         (
             ((6, 6), ),
             DetailedGame("0000000",
                          left_wingame=False,
                          left_opener=True,
                          tiebreak=True),
         ),
         (
             (
                 (6, 7),
                 (0, 0),
             ),
             DetailedGame("1111",
                          left_wingame=False,
                          left_opener=False,
                          tiebreak=False),
         ),
         (
             (
                 (6, 7),
                 (0, 1),
             ),
             DetailedGame("0000",
                          left_wingame=False,
                          left_opener=True,
                          tiebreak=False),
         ),
         (
             (
                 (6, 7),
                 (0, 2),
             ),
             DetailedGame("1111",
                          left_wingame=False,
                          left_opener=False,
                          tiebreak=False),
         ),
         (
             (
                 (6, 7),
                 (0, 3),
             ),
             DetailedGame("0000",
                          left_wingame=False,
                          left_opener=True,
                          tiebreak=False),
         ),
         (
             (
                 (6, 7),
                 (0, 4),
             ),
             DetailedGame("1111",
                          left_wingame=False,
                          left_opener=False,
                          tiebreak=False),
         ),
     ]
     return DetailedScore(items)
 def make_2set_det_score():
     """:return DetailedScore for 6-7(0) 0-6 where match left_opener"""
     items = [
         (
             ((0, 0), ),
             DetailedGame("1111",
                          left_wingame=True,
                          left_opener=True,
                          tiebreak=False),
         ),
         (
             ((1, 0), ),
             DetailedGame("0000",
                          left_wingame=True,
                          left_opener=False,
                          tiebreak=False),
         ),
         (
             ((2, 0), ),
             DetailedGame("1111",
                          left_wingame=True,
                          left_opener=True,
                          tiebreak=False),
         ),
         (
             ((3, 0), ),
             DetailedGame("0000",
                          left_wingame=True,
                          left_opener=False,
                          tiebreak=False),
         ),
         (
             ((4, 0), ),
             DetailedGame("0000",
                          left_wingame=False,
                          left_opener=True,
                          tiebreak=False),
         ),
         (
             ((4, 1), ),
             DetailedGame("1111",
                          left_wingame=False,
                          left_opener=False,
                          tiebreak=False),
         ),
         (
             ((4, 2), ),
             DetailedGame("0000",
                          left_wingame=False,
                          left_opener=True,
                          tiebreak=False),
         ),
         (
             ((4, 3), ),
             DetailedGame("1111",
                          left_wingame=False,
                          left_opener=False,
                          tiebreak=False),
         ),
         (
             ((4, 4), ),
             DetailedGame("0000",
                          left_wingame=False,
                          left_opener=True,
                          tiebreak=False),
         ),
         (
             ((4, 5), ),
             DetailedGame("0000",
                          left_wingame=True,
                          left_opener=False,
                          tiebreak=False),
         ),
         (
             ((5, 5), ),
             DetailedGame("0000",
                          left_wingame=False,
                          left_opener=True,
                          tiebreak=False),
         ),
         (
             ((5, 6), ),
             DetailedGame("0000",
                          left_wingame=True,
                          left_opener=False,
                          tiebreak=False),
         ),
         (
             ((6, 6), ),
             DetailedGame("0000000",
                          left_wingame=False,
                          left_opener=True,
                          tiebreak=True),
         ),
         (
             (
                 (6, 7),
                 (0, 0),
             ),
             DetailedGame("1111",
                          left_wingame=False,
                          left_opener=False,
                          tiebreak=False),
         ),
         (
             (
                 (6, 7),
                 (0, 1),
             ),
             DetailedGame("0000",
                          left_wingame=False,
                          left_opener=True,
                          tiebreak=False),
         ),
         (
             (
                 (6, 7),
                 (0, 2),
             ),
             DetailedGame("1111",
                          left_wingame=False,
                          left_opener=False,
                          tiebreak=False),
         ),
         (
             (
                 (6, 7),
                 (0, 3),
             ),
             DetailedGame("0000",
                          left_wingame=False,
                          left_opener=True,
                          tiebreak=False),
         ),
         (
             (
                 (6, 7),
                 (0, 4),
             ),
             DetailedGame("1111",
                          left_wingame=False,
                          left_opener=False,
                          tiebreak=False),
         ),
         (
             (
                 (6, 7),
                 (0, 5),
             ),
             DetailedGame("01000",
                          left_wingame=False,
                          left_opener=True,
                          tiebreak=False),
         ),
     ]
     return DetailedScore(items)
 def make_3set_det_score_decsupertie():
     """return DetailedScore variant for Score("7-6 0-6 10-3", decsupertie=True)"""
     items = [
         (
             ((0, 0), ),
             DetailedGame("1111",
                          left_wingame=True,
                          left_opener=True,
                          tiebreak=False),
         ),
         (
             ((1, 0), ),
             DetailedGame("0000",
                          left_wingame=True,
                          left_opener=False,
                          tiebreak=False),
         ),
         (
             ((2, 0), ),
             DetailedGame("1111",
                          left_wingame=True,
                          left_opener=True,
                          tiebreak=False),
         ),
         (
             ((3, 0), ),
             DetailedGame("0000",
                          left_wingame=True,
                          left_opener=False,
                          tiebreak=False),
         ),
         (
             ((4, 0), ),
             DetailedGame("0000",
                          left_wingame=False,
                          left_opener=True,
                          tiebreak=False),
         ),
         (
             ((4, 1), ),
             DetailedGame("1111",
                          left_wingame=False,
                          left_opener=False,
                          tiebreak=False),
         ),
         (
             ((4, 2), ),
             DetailedGame("0000",
                          left_wingame=False,
                          left_opener=True,
                          tiebreak=False),
         ),
         (
             ((4, 3), ),
             DetailedGame("1111",
                          left_wingame=False,
                          left_opener=False,
                          tiebreak=False),
         ),
         (
             ((4, 4), ),
             DetailedGame("0000",
                          left_wingame=False,
                          left_opener=True,
                          tiebreak=False),
         ),
         (
             ((4, 5), ),
             DetailedGame("0000",
                          left_wingame=True,
                          left_opener=False,
                          tiebreak=False),
         ),
         (
             ((5, 5), ),
             DetailedGame("0000",
                          left_wingame=False,
                          left_opener=True,
                          tiebreak=False),
         ),
         (
             ((5, 6), ),
             DetailedGame("0000",
                          left_wingame=True,
                          left_opener=False,
                          tiebreak=False),
         ),
         (
             ((6, 6), ),
             DetailedGame("1111111",
                          left_wingame=True,
                          left_opener=True,
                          tiebreak=True),
         ),
         (
             (
                 (7, 6),
                 (0, 0),
             ),
             DetailedGame("1111",
                          left_wingame=False,
                          left_opener=False,
                          tiebreak=False),
         ),
         (
             (
                 (7, 6),
                 (0, 1),
             ),
             DetailedGame("0000",
                          left_wingame=False,
                          left_opener=True,
                          tiebreak=False),
         ),
         (
             (
                 (7, 6),
                 (0, 2),
             ),
             DetailedGame("1111",
                          left_wingame=False,
                          left_opener=False,
                          tiebreak=False),
         ),
         (
             (
                 (7, 6),
                 (0, 3),
             ),
             DetailedGame("0000",
                          left_wingame=False,
                          left_opener=True,
                          tiebreak=False),
         ),
         (
             (
                 (7, 6),
                 (0, 4),
             ),
             DetailedGame("1111",
                          left_wingame=False,
                          left_opener=False,
                          tiebreak=False),
         ),
         (
             (
                 (7, 6),
                 (0, 5),
             ),
             DetailedGame("01000",
                          left_wingame=False,
                          left_opener=True,
                          tiebreak=False),
         ),
         (
             (
                 (7, 6),
                 (0, 6),
                 (0, 0),
             ),
             DetailedGame(
                 "1110000000000",
                 left_wingame=True,
                 left_opener=False,
                 tiebreak=True,
                 supertiebreak=True,
             ),
         ),
     ]
     return DetailedScore(items)
 def test_save_restore(self):
     ds = DetailedScoreTest.make_2set_det_score()
     text = ds.tostring()
     ds2 = DetailedScore.from_str(text)
     self.assertEqual(ds, ds2)
 def test_empty(self):
     ds = DetailedScore()
     self.assertEqual(bool(ds), False)
Exemple #9
0
 def detailed_score(self):
     if self.detailed_score_txt:
         return DetailedScore.from_str(self.detailed_score_txt)
Exemple #10
0
 def oneset_dscore_mdict():
     ds = DetailedScore()
     mdict = OrderedDict()
     ds[((4, 4),)] = DetailedGame(
         "1111", left_wingame=True, left_opener=True, tiebreak=False
     )
     ds[((5, 4),)] = DetailedGame(
         "10001111", left_wingame=False, left_opener=False, tiebreak=False
     )
     mdict[((5, 4),)] = [
         MissPoint(
             GamePointEvent(
                 left_side=True, left_serve=False, tiebreak=False, multier=2
             ),
             revenged=co.SET,
             scope=co.SET,
         ),
         MissPoint(
             GamePointEvent(
                 left_side=True, left_serve=False, tiebreak=False, multier=1
             ),
             revenged=co.SET,
             scope=co.SET,
         ),
     ]
     ds[((5, 5),)] = DetailedGame(
         "11101", left_wingame=True, left_opener=True, tiebreak=False
     )
     mdict[((5, 5),)] = [
         MissPoint(
             GamePointEvent(
                 left_side=True, left_serve=True, tiebreak=False, multier=3
             ),
             revenged=co.GAME,
         )
     ]
     ds[((6, 5),)] = DetailedGame(
         "00011111", left_wingame=False, left_opener=False, tiebreak=False
     )
     mdict[((6, 5),)] = [
         MissPoint(
             GamePointEvent(
                 left_side=True, left_serve=False, tiebreak=False, multier=3
             ),
             revenged=co.SET,
             scope=co.SET,
         ),
         MissPoint(
             GamePointEvent(
                 left_side=True, left_serve=False, tiebreak=False, multier=2
             ),
             revenged=co.SET,
             scope=co.SET,
         ),
         MissPoint(
             GamePointEvent(
                 left_side=True, left_serve=False, tiebreak=False, multier=1
             ),
             revenged=co.SET,
             scope=co.SET,
         ),
     ]
     ds[((6, 6),)] = DetailedGame(
         "1111111", left_wingame=True, left_opener=True, tiebreak=True
     )
     return ds, mdict