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_cmp(self): self.assertTrue(Round("Rubber 3") < "Rubber 5") self.assertTrue(Round("Rubber 3") > "Rubber 2") self.assertTrue("Rubber 3" < Round("Rubber 5")) self.assertTrue("Rubber 3" > Round("Rubber 2")) self.assertTrue("Rubber 3" == Round("Rubber 3")) self.assertTrue(Round("Rubber 3") == "Rubber 3") self.assertFalse(Round("Rubber 2").qualification()) self.assertTrue(Round("First", details="vs qual") == "First")
def test_recent_winner(self): plr1 = Player(ident=6590, name="Cagla Buyukakcay", cou="TUR") plr2 = Player(ident=8951, name="Veronica Cepede Royg", cou="PAR") match = Match(first_player=plr1, second_player=plr2, score=None, rnd=Round('Second'), date=datetime.date(2019, 10, 18)) h2h = HeadToHead(sex='wta', match=match, completed_only=True) recent_winner_id = h2h.recently_won_player_id() self.assertEqual(recent_winner_id, plr1.ident)
def make_fake_match(): return FakeMatch( date=datetime.date(2021, 3, 13), sex="atp", tour_name=TourName("Dubai"), level=Level("main"), rnd=Round("q-Second"), fst_name="Dmitry Popko", snd_name="Blaz Rola", std_score=Score("3-6 6-4 6-7 (12)"), href="https://www.flashscore.com/match/6XLRjIHk", )
def make_fake_match(): return FakeMatch( date=datetime.date(2021, 3, 18), sex="wta", tour_name=TourName("St. Petersburg"), level=Level("main"), rnd=Round("Second"), fst_name="Anastasia Gasanova", snd_name="Anastasia Pavlyuchenkova", std_score=Score("1-6 7-6(8) 7-6 (4)"), href="https://www.flashscore.com/match/6NvqT9V8", )
def test_ito_kukushkin(self): plr1 = Player(ident=8313, name="Tatsuma Ito", cou="JPN") plr2 = Player(ident=9043, name="Mikhail Kukushkin", cou="KAZ") match = Match( first_player=plr1, second_player=plr2, score=sc.Score("4-6 7-6(3) 7-6(6)"), rnd=Round("Second"), date=datetime.date(2017, 2, 1), ) h2hdir = HeadToHead(sex="atp", match=match, completed_only=True).direct() self.assertEqual(h2hdir, None)
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))
def __init__(self, _game, _name, _parent, _json_data): self.name = _name self.game = _game self.parent = _parent self.json_data = _json_data self.rounds = {} self.difficulty = _json_data['_difficulty'] self.prize_money = _json_data['prize_money'] self.complete = False # Read in Round Data for round_number in _json_data["rounds"]: round_data = _json_data["rounds"][round_number] # Load our Round in (if it is new) if (round_number not in self.rounds): # Create our Tournament Object self.rounds.update({ round_number: Round.Round(self.game, round_number, self, round_data) }) if (_game.debug): print("[TOURNAMENT]: Tournament '{}' made!".format(_name))
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))
def test_round_compare(self): self._strict_lt_compare(Round("q-Second"), Round("First")) self._strict_lt_compare(Round("q-Second"), "First") self._strict_lt_compare(Round("Pre-q"), Round("q-First")) self.assertFalse(Round("Final") != Round("Final")) self.assertEqual(Round("q-Second"), Round("q-Second")) self.assertEqual(Round("q-Second"), "q-Second") self.assertEqual("q-Second", Round("q-Second")) lst = [Round("First"), Round("Pre-q"), Round("q-First")] lst_asc = [Round("Pre-q"), Round("q-First"), Round("First")] lst_desc = [Round("First"), Round("q-First"), Round("Pre-q")] self.assertEqual(sorted(lst, reverse=False), lst_asc) self.assertEqual(sorted(lst, reverse=True), lst_desc)
def get_decided_tiebreak_info_ext( tour, rnd: Round, score: Score ) -> Tuple[Score, TieInfo]: """:return Tuple[may be edited Score, dec TieInfo] can raise TennisScoreSuperTieError. if in score no exist dec set, than return Tuple[in score, default TieInfo]""" n_sets = score.sets_count() best_of_five = False if tour.sex == "wta" else score.best_of_five() dec_set_num = 5 if best_of_five else 3 dec_set = score[dec_set_num - 1] if n_sets == dec_set_num else None if dec_set is None: return score, default_tie_info is_dec_supertie_scr_uniq = None if is_dec_supertie_scr(dec_set, score.retired, unique_mode=True): is_dec_supertie_scr_uniq = True is_dec_supertie_scr_lowrank = None if ( tour.sex == "wta" and ( tour.level in ("future", "chal") or "All Lower level tournaments" in tour.name ) and is_dec_supertie_scr(dec_set, score.retired) ): is_dec_supertie_scr_lowrank = True dec_tie_fmt = get_decided_tiebreak_info( tour.sex, tour.date.year, tour.name, rnd.qualification(), level=tour.level, best_of_five=best_of_five, money=tour.money, ) if is_dec_supertie_scr_uniq: res_dectieinfo = TieInfo(beg_scr=(0, 0), is_super=True) elif ( not dec_tie_fmt.is_tiebreak() or dec_tie_fmt.is_fmt66_over(dec_set) or dec_tie_fmt.is_fmt1212_over(dec_set) ): res_dectieinfo = TieInfo(None, False) elif is_dec_supertie_scr_lowrank: res_dectieinfo = TieInfo(beg_scr=(0, 0), is_super=True) else: res_dectieinfo = dec_tie_fmt res_score = score if res_dectieinfo.beg_scr == (0, 0): if not score.retired and max(dec_set) < 10: return score, default_tie_info # dec super tie impossible scr_txt = str(score) try: res_score = Score(scr_txt, decsupertie=True) except co.TennisScoreSuperTieError as err: raise co.TennisScoreSuperTieError( f"{err} sex:{tour.sex} {tour.date} tour:{tour.name} " f"rnd:{rnd} lev:{tour.level} ${tour.money}" ) return res_score, res_dectieinfo