Пример #1
0
 def __init_data(self, sex, player_id, weeks_ago):
     result = []
     monday_date = tt.past_monday_date(datetime.date.today())
     start_ywn = tt.get_year_weeknum(monday_date)
     for ywn in tt.year_weeknum_reversed(start_ywn, weeks_ago):
         result.append(self.__week_results(player_id, weeked_tours.tours(sex, ywn)))
     return result
Пример #2
0
def decided_winloss_by_set2_winner(sex, soft_level, date, set1_score,
                                   set2_score):
    set1, set2 = _make_set2winner_orient(set1_score, set2_score)
    in_ywn = tt.get_year_weeknum(date)
    wl_res = st.WinLoss()
    dct = data_dict[(sex, soft_level)]
    for ywn, scr_dct in dct.items():
        if ywn >= in_ywn:
            break
        wl_res += scr_dct[(set1, set2)]
    return wl_res
Пример #3
0
def _default_inited_dict(min_date, max_date):
    """return OrderedDict where values are inited with []"""
    dct = OrderedDict()
    first_monday = tt.past_monday_date(min_date)
    if max_date is None:
        max_date = tt.past_monday_date(
            datetime.date.today()) + datetime.timedelta(days=7)
    last_monday = tt.past_monday_date(max_date)
    monday = first_monday
    while monday <= last_monday:
        year_weeknum = tt.get_year_weeknum(monday)
        dct[year_weeknum] = []
        monday = monday + datetime.timedelta(days=7)
    return dct
Пример #4
0
def back_year_weeknums(max_weeknum_dist):
    if (
        back_year_weeknums.lst is not None
        and back_year_weeknums.max_dist == max_weeknum_dist
    ):
        return back_year_weeknums.lst
    back_year_weeknums.lst = list(
        tt.year_weeknum_reversed(
            tt.get_year_weeknum(datetime.date.today()),
            max_weeknum_dist=max_weeknum_dist,
        )
    )
    back_year_weeknums.max_dist = max_weeknum_dist
    return back_year_weeknums.lst
Пример #5
0
def initialize(prev_week=False):
    """must be called AFTER weeked_tours::initialize.
    init wta_chal_tour_surf, and add to sex_tourname_surf_map"""
    wta_chal_tour_surf.clear()
    monday = tt.past_monday_date(datetime.date.today())
    if prev_week:
        monday = monday - datetime.timedelta(days=7)
    year_weeknum = tt.get_year_weeknum(monday)
    for tour in weeked_tours.tours("wta", year_weeknum):
        if tour.level == "teamworld":
            sex_tourname_surf_map[("wta", tour.name, None)] = tour.surface
        if tour.level == "chal":
            wta_chal_tour_surf.add((tour.name, tour.surface))
            log.info("FS::init prev_week {} wta_chal {} {}".format(
                prev_week, tour.name, tour.surface))
    def test_year_weeknum(self):
        self.assertEqual(
            get_year_weeknum(datetime.date(year=1997, month=1, day=1)),
            (1997, 1))
        self.assertEqual(
            get_year_weeknum(datetime.date(year=1997, month=12, day=30)),
            (1998, 1))

        # thuesday
        self.assertEqual(
            get_year_weeknum(datetime.date(year=2013, month=1, day=1)),
            (2013, 1))

        # such years was with Adelaide started at wednesday
        self.assertEqual(
            get_year_weeknum(datetime.date(year=1992, month=1, day=1)),
            (1992, 1))
        self.assertEqual(
            get_year_weeknum(datetime.date(year=1997, month=1, day=1)),
            (1997, 1))

        # monday
        self.assertEqual(
            get_year_weeknum(datetime.date(year=2008, month=12, day=29)),
            (2009, 1))
        self.assertEqual(
            get_year_weeknum(datetime.date(year=2012, month=12, day=31)),
            (2013, 1))

        # monday. At this date first atp tours started from weeknum=2
        # (before this there are no real atp events).
        self.assertEqual(
            get_year_weeknum(datetime.date(year=1998, month=1, day=5)),
            (1998, 2))

        # monday. ISO gives: 1998, 53. There are no real tours started at this date.
        self.assertEqual(
            get_year_weeknum(datetime.date(year=1998, month=12, day=28)),
            (1998, 53))
Пример #7
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))
Пример #8
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))
Пример #9
0
def tours_generator(
    sex,
    todaymode=False,
    min_date=None,
    max_date=None,
    time_reverse=False,
    with_paired=False,
    with_mix=False,
    rnd_detailing=False,
    with_bets=False,
    with_stat=False,
    with_ratings=False,
    with_pers_det=False,
):
    from matchstat import get

    assert not (not with_paired and with_mix), "inconsistent with_paired with_mix"
    sql_builder = SqlBuilder(
        sex,
        todaymode,
        min_date=min_date,
        max_date=max_date,
        time_reverse=time_reverse,
        with_paired=with_paired,
        with_mix=with_mix,
    )
    cur_tour = None
    for row in sql_builder.rows():
        tour = Tournament(
            row.tour_id,
            row.tour_name,
            sex=sex,
            surface=tennis.Surface(row.surf_txt),
            rank=row.tour_rank,
            date=row.tour_dt.date() if row.tour_dt else None,
            money=row.tour_money,
            cou=row.tour_cou,
        )
        rnd = tennis.Round(row.rnd_txt)
        scr = sc.Score(row.score_txt) if row.score_txt else None
        fst_player = tennis.Player(
            ident=row.fst_plr_id,
            name=row.fst_plr_name,
            cou=row.fst_plr_cou,
            birth_date=row.fst_plr_dt.date() if row.fst_plr_dt else None,
        )
        snd_player = tennis.Player(
            ident=row.snd_plr_id,
            name=row.snd_plr_name,
            cou=row.snd_plr_cou,
            birth_date=row.snd_plr_dt.date() if row.snd_plr_dt else None,
        )
        m = tennis.Match(
            fst_player,
            snd_player,
            scr,
            rnd,
            row.match_dt.date() if row.match_dt else None,
        )
        if not m.paired():
            if with_pers_det:
                m.read_pers_det(sex)
            if with_ratings:
                m.read_ratings(sex, tour.date)
            if with_bets:
                m.fill_offer(sex, tour.ident, tour.date, alter_bettor=False)
            if with_stat:
                m.stat = get(
                    sex,
                    tour.ident,
                    rnd,
                    fst_player.ident,
                    snd_player.ident,
                    tt.get_year_weeknum(tour.date),
                )

        if cur_tour is not None and cur_tour.ident != tour.ident:
            if rnd_detailing:
                cur_tour.rounds_detailing()
            yield cur_tour
            cur_tour = tour
        elif cur_tour is None:
            cur_tour = tour
        cur_tour.matches_from_rnd[rnd].append(m)

    if cur_tour is not None:
        if rnd_detailing:
            cur_tour.rounds_detailing()
        yield cur_tour
Пример #10
0
 def year_weeknum(self):
     return tt.get_year_weeknum(self.date)
Пример #11
0
def _initialize_results_sex(sex,
                            max_rating,
                            max_rating_dif,
                            min_date=None,
                            max_date=None):
    sql = """select tours.DATE_T, tours.NAME_T, tours.RANK_T, tours.PRIZE_T, 
                   games.ID_R_G, games.RESULT_G, games.ID1_G, games.ID2_G
             from Tours_{0} AS tours, games_{0} AS games, Players_{0} AS fst_plr
             where games.ID_T_G = tours.ID_T 
               and games.ID1_G = fst_plr.ID_P
               and (tours.NAME_T Not Like '%juniors%')
               and (fst_plr.NAME_P Not Like '%/%') """.format(sex)
    sql += dba.sql_dates_condition(min_date, max_date)
    sql += " order by tours.DATE_T;"
    with closing(dba.get_connect().cursor()) as cursor:
        for (
                tour_dt,
                tour_name,
                db_rank,
                db_money,
                rnd_id,
                score_txt,
                fst_id,
                snd_id,
        ) in cursor.execute(sql):
            date = tour_dt.date() if tour_dt else None
            if date is None:
                raise co.TennisScoreError("none date {}".format(tour_name))
            if not score_txt:
                continue
            scr = sc.Score(score_txt)
            if scr.retired:
                continue
            sets_count = scr.sets_count(full=True)
            if sets_count != 3 or scr.best_of_five():
                continue
            set3_score = scr[2]
            if set3_score[0] < set3_score[1]:
                raise co.TennisScoreError(
                    "right winner unexpected {}".format(scr))
            money = oncourt_db.get_money(db_money)
            rank = None if db_rank is None else int(db_rank)
            if rank is None:
                log.error("none rank date: {} scr: {} name: {}".format(
                    date, scr, tour_name))
            if not isinstance(rank, int):
                raise co.TennisError(
                    "not int rank '{}' date: {} scr: {} name: {}".format(
                        rank, date, scr, tour_name))
            rawname, level = oncourt_db.get_name_level(sex, tour_name.strip(),
                                                       rank, money, date)
            if level in DISABLE_LEVELS:
                continue
            if level is None:
                raise co.TennisError(
                    "none level date: {} scr: {} name: {}".format(
                        date, scr, tour_name))
            rnd = tennis.Round.from_oncourt_id(rnd_id)
            soft_level = tennis.soft_level(level, rnd)
            if soft_level is None:
                raise co.TennisError(
                    "none soft_level date: {} scr: {} name: {}".format(
                        date, scr, tour_name))
            mdata = _get_match_data(sex, date, fst_id, snd_id, scr, max_rating,
                                    max_rating_dif)
            if mdata is not None:
                past_monday = tt.past_monday_date(date)
                ywn = tt.get_year_weeknum(past_monday)
                data_dict[(sex, soft_level)][ywn][(mdata.set1_score,
                                                   mdata.set2_score)].hit(
                                                       mdata.decided_win)