def _get_match_data(sex, date, fst_id, snd_id, scr, max_rating, max_rating_dif,
                    with_bo5):
    def admit_rtg_dif(match_data, recovery_mode):
        match_winer_strong_fav = snd_rtg > (fst_rtg + max_rating_dif)
        if not match_winer_strong_fav:
            return True
        if recovery_mode and match_data.set2_win and match_data.player_id == snd_id:
            return True  # match loser ok recovered in set2
        if (not recovery_mode and not match_data.set2_win
                and match_data.player_id == fst_id):
            return True  # match winner failed keep in set2
        return False

    fst_rtg = ratings_std.get_rank(sex, fst_id, date)
    if fst_rtg is None or fst_rtg > max_rating:
        return None, None
    snd_rtg = ratings_std.get_rank(sex, snd_id, date)
    if snd_rtg is None or snd_rtg > max_rating:
        return None, None
    if sex == "atp" and not with_bo5 and scr.best_of_five():
        return None, None
    set1, set2 = scr[0], scr[1]
    if set1[0] < set1[1]:
        recov = MatchData(fst_id, set2[0] > set2[1])
        keep = MatchData(snd_id, set2[0] <= set2[1])
    else:
        recov = MatchData(snd_id, set2[0] <= set2[1])
        keep = MatchData(fst_id, set2[0] > set2[1])

    if not admit_rtg_dif(recov, recovery_mode=True):
        recov = None
    if not admit_rtg_dif(keep, recovery_mode=False):
        keep = None
    return recov, keep
Exemple #2
0
def _get_match_data(sex, date, fst_id, snd_id, scr, max_rating,
                    max_rating_dif):
    def admit_rtg_dif():
        win_rtg, loss_rtg = fst_rtg, snd_rtg
        if loss_rtg > (win_rtg + max_rating_dif):
            return False  # strong underdog fail or strong favorite prevail
        return True

    fst_rtg = ratings_std.get_rank(sex, fst_id, date)
    if fst_rtg is None or fst_rtg > max_rating:
        return None
    snd_rtg = ratings_std.get_rank(sex, snd_id, date)
    if snd_rtg is None or snd_rtg > max_rating:
        return None
    if not admit_rtg_dif():
        return None
    set1, set2 = scr[0], scr[1]
    if set1[0] < set1[1] and set2[0] > set2[1]:
        # ok score orientation as set2 winner
        return MatchData(set1_score=set1, set2_score=set2, decided_win=True)
    elif set1[0] > set1[1] and set2[0] < set2[1]:
        # make reverse score orientation (opponent is set2 winner)
        return MatchData(
            set1_score=(set1[1], set1[0]),
            set2_score=(set2[1], set2[0]),
            decided_win=False,
        )
Exemple #3
0
    def test_get_rank_atp(self):
        date = datetime.date(2014, 7, 21)

        plr = Player(ident=21812, name="Rodrigo Arus", cou="URU")
        pos = get_rank("atp", plr.ident, date)
        self.assertEqual(pos, None)

        plr = Player(ident=13962, name="Valentin Florez", cou="ARG")
        pos = get_rank("atp", plr.ident, date)
        self.assertEqual(pos, 689)
 def read(self, sex, player_id, surfaces=("all", ), date=None):
     for rtg_name in self.rtg_names:
         for surface in surfaces:
             key = self._make_key(rtg_name, surface)
             if rtg_name == "elo":
                 pts = ratings_elo.get_pts(sex,
                                           player_id,
                                           surface=surface,
                                           isalt=False)
                 rank = ratings_elo.get_rank(sex,
                                             player_id,
                                             surface=surface,
                                             isalt=False)
                 self[key] = (pts, rank)
             elif rtg_name == "elo_alt":
                 pts = ratings_elo.get_pts(sex,
                                           player_id,
                                           surface=surface,
                                           isalt=True)
                 rank = ratings_elo.get_rank(sex,
                                             player_id,
                                             surface=surface,
                                             isalt=True)
                 self[key] = (pts, rank)
             elif rtg_name == "std":
                 pts = ratings_std.get_pts(sex, player_id, date)
                 rank = ratings_std.get_rank(sex, player_id, date)
                 self[key] = (pts, rank)
Exemple #5
0
    def test_get_rank_wta(self):
        plr = Player(ident=14364, name="Angeliki Kairi", cou="GRE")
        pos = get_rank("wta", plr.ident, datetime.date(2014, 7, 21))
        self.assertEqual(pos, None)

        plr = Player(ident=14010, name="Beatrice Cedermark", cou="SWE")
        pos = get_rank("wta", plr.ident, datetime.date(2014, 7, 21))
        self.assertEqual(pos, 723)

        plr = Player(ident=431, name="Vera Zvonareva", cou="RUS")
        pos = get_rank("wta", plr.ident, datetime.date(2012, 5, 28))
        self.assertEqual(pos, 11)
        pts = get_pts("wta", plr.ident, datetime.date(2012, 5, 28))
        self.assertEqual(pts, 344000)

        pos = get_rank("wta", plr.ident, datetime.date(2003, 1, 13))
        self.assertEqual(pos, 43)

        plr = Player(ident=7574, name="Petra Martic", cou="CRO")
        pos = get_rank("wta", plr.ident, datetime.date(2020, 8, 3))
        self.assertEqual(pos, 15)