예제 #1
0
def initialize(sex):
    max_date = None  # datetime.date(2010, 1, 1)
    if not dba.initialized():
        dba.open_connect()
    min_date = None  # tt.now_minus_history_days(get_history_days(sex))
    ratings_std.initialize(
        sex=sex,
        min_date=None  # min_date - datetime.timedelta(days=7),
    )

    if sex in ("wta", None):
        _initialize_results_sex(
            "wta",
            max_rating=RANK_STD_BOTH_ABOVE,
            max_rating_dif=RANK_STD_MAX_DIF,
            min_date=min_date,
            max_date=max_date,
        )
    if sex in ("atp", None):
        _initialize_results_sex(
            "atp",
            max_rating=RANK_STD_BOTH_ABOVE,
            max_rating_dif=RANK_STD_MAX_DIF,
            min_date=min_date,
            max_date=max_date,
        )
    ratings_std.clear(sex)
예제 #2
0
def get_presence_results(
    idents: Set[int],
    sex: str,
    min_date: datetime.date,
    max_date: datetime.date,
    with_retired=False,
) -> List[PlayerResult]:
    """[min_date, max_date) is semiclose range
    :return list where date is latest for [min_date,...,max_date)
    """
    present_pids = set()
    present_results = []
    date_now = datetime.date.today()
    if not dba.initialized():
        dba.open_connect()
    sql = """select games.DATE_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, dator="games.DATE_G")
    sql += " order by games.DATE_G desc;"
    with closing(dba.get_connect().cursor()) as cursor:
        for (match_dt, score_txt, fst_id, snd_id) in cursor.execute(sql):
            match_date = match_dt.date() if match_dt else None
            if not score_txt:
                continue  # may be it is scheduled match
            date = match_date
            if date is None:
                log.error(
                    f"empty date in {sex} pid1{fst_id} pid2 {snd_id} score:{score_txt}"
                )
                continue
            if with_retired and not sc.Score(score_txt).retired:
                continue
            if not with_retired and fst_id in idents and fst_id not in present_pids:
                present_pids.add(fst_id)
                present_results.append(
                    PlayerResult(id=fst_id, days_ago=(date_now - date).days))
            if snd_id in idents and snd_id not in present_pids:
                present_pids.add(snd_id)
                present_results.append(
                    PlayerResult(id=snd_id, days_ago=(date_now - date).days))
    return present_results
예제 #3
0
def process(sex: str, min_date, max_date):
    from tournament import tours_generator

    if not dba.initialized():
        dba.open_connect()
    if max_date.isoweekday() == 1:
        # for including qualification matches with match.date < max_date
        max_tour_date = max_date + datetime.timedelta(days=7)
    else:
        max_tour_date = max_date
    for tour in tours_generator(sex, min_date=min_date,
                                max_date=max_tour_date):
        for match, rnd in tour.match_rnd_list():
            if match.date and match.date > max_date:
                continue
            if match.date is None and tour.date >= tt.past_monday_date(
                    max_date):
                continue
            put_match(sex, tour, rnd, match)
def setUpModule():
    if not dba.initialized():
        dba.open_connect()
    oncourt_players.initialize()
        check_impl("Some E.-N.", ["Some"], ["E", "N"])
        check_impl("Some E.N.", ["Some"], ["E", "N"])
        check_impl("Some Any E.", ["Some", "Any"], ["E"])
        check_impl("Some Any", ["Some", "Any"], [])
        check_impl("Some And.", ["Some"], ["And"])
        check_impl("Bar D.", ["Bar"], ["D"])
        check_impl("Some A", ["Some"], ["A"])
        check_impl("Some A. K", ["Some"], ["A", "K"])
        check_impl("Some Any E. V.", ["Some", "Any"], ["E", "V"])
        check_impl("Some Any E.V.", ["Some", "Any"], ["E", "V"])
        check_impl("Some Any E.-V.", ["Some", "Any"], ["E", "V"])
        check_impl("Some Any E.-V", ["Some", "Any"], ["E", "V"])
        check_impl("Some Any R. - S.", ["Some", "Any"], ["R", "S"])
        check_impl("Hsieh Su-Wei", ["Hsieh", "Su Wei"], [])


def setUpModule():
    if not dba.initialized():
        dba.open_connect()
    oncourt_players.initialize()


if __name__ == "__main__":
    log.initialize(co.logname(__file__, test=True),
                   file_level="info",
                   console_level="info")
    if not dba.initialized():
        dba.open_connect()
    unittest.main()
    dba.close_connect()