Ejemplo n.º 1
0
def do_stat():
    log.initialize(
        co.logname(__file__, instance=str(args.sex)),
        file_level="debug",
        console_level="info",
    )
    try:
        log.info(__file__ + " started sex: " + str(args.sex))
        start_datetime = datetime.datetime.now()
        dba.open_connect()
        ratings_std.initialize(sex=args.sex)
        qual_seeds.initialize()
        oncourt_players.initialize(yearsnum=18)

        matchstat_process(sex=args.sex)

        process(
            (
                WinFavoriteProcessor(args.sex),
                TourAverageSetProcessor(args.sex),
            ),
            args.sex
        )

        dba.close_connect()
        log.info(
            "{} finished within {}".format(
                __file__, str(datetime.datetime.now() - start_datetime)
            )
        )
        return 0
    except Exception as err:
        log.error("{0} [{1}]".format(err, err.__class__.__name__), exc_info=True)
        return 1
Ejemplo n.º 2
0
def main():
    try:
        args = parse_command_line_args()
        log.initialize(
            co.logname(__file__, instance=args.instance),
            file_level="debug",
            console_level="info",
        )
        log.info(
            "\n--------------------------------------------------------\nstarted"
        )
        dba.open_connect()
        oncourt_players.initialize()
        ratings.initialize("wta", rtg_names=("elo", ))
        ratings.initialize("atp", rtg_names=("elo", ))
        ratings.Rating.register_rtg_name("elo_alt")
        app = Application(
            wta_players=oncourt_players.players("wta"),
            atp_players=oncourt_players.players("atp"),
        )
        app.master.title("Live")
        app.mainloop()
        log.info("sex: " + app.sex())
        log.info("left_player: " + app.left_player_name())
        log.info("right_player: " + app.right_player_name())
        log.info("score: {}".format(app.score()))
        log.info("level: {}".format(app.level()))
        log.info("surface: {}".format(app.surface()))
        dba.close_connect()
        return 0
    except Exception as err:
        log.error("{0} [{1}]".format(err, err.__class__.__name__),
                  exc_info=True)
        return 1
Ejemplo n.º 3
0
def get_dba():
    """Connect to db before tests, disconnect after."""
    # Setup : start db
    dba.open_connect()

    yield dba.get_connect()  # this is where the testing happens

    # Teardown : stop db
    dba.close_connect()
Ejemplo n.º 4
0
def do_stat(sex=None):
    try:
        dba.open_connect()
        oncourt_players.initialize()

        log.info(__file__ + " begining for stat with sex: " + str(sex))
        start_datetime = datetime.datetime.now()

        if sex is None:
            process_sex("wta")
            process_sex("atp")
        else:
            process_sex(sex)

        dba.close_connect()
        log.info("{} finished within {}".format(
            __file__, str(datetime.datetime.now() - start_datetime)))
        return 0
    except Exception as err:
        log.error("{0} [{1}]".format(err, err.__class__.__name__),
                  exc_info=True)
        return 1
Ejemplo n.º 5
0
def do_stat():
    log.initialize(
        co.logname(__file__, instance=str(args.sex)),
        file_level="debug",
        console_level="info",
    )
    try:
        msg = "sex: {} max_rtg: {}  max_rtg_dif: {}".format(
            args.sex, args.max_rating, args.max_rating_dif)
        log.info(__file__ + " started {}".format(msg))
        initialize(args.sex)
        maker = StatMaker(args.sex)
        maker.process_all()
        log.info(__file__ + " done {}".format(ASPECT))

        dba.close_connect()
        log.info(__file__ + " finished sex: {}".format(args.sex))
        return 0
    except Exception as err:
        log.error("{0} [{1}]".format(err, err.__class__.__name__),
                  exc_info=True)
        return 1
def do_stat():
    log.initialize(
        co.logname(__file__, instance=str(args.sex)),
        file_level="debug",
        console_level="info",
    )
    try:
        msg = "sex: {} min_size: {} max_size: {} max_rtg: {}  max_rtg_dif: {}".format(
            args.sex, args.min_size, args.max_size, args.max_rating,
            args.max_rating_dif)
        log.info(__file__ + " started {}".format(msg))
        dba.open_connect()
        oncourt_players.initialize(yearsnum=8)
        min_date = tt.now_minus_history_days(history_days_personal(args.sex))
        ratings_std.initialize(sex=args.sex,
                               min_date=min_date - datetime.timedelta(days=7))
        initialize_results(
            args.sex,
            max_rating=args.max_rating,
            max_rating_dif=args.max_rating_dif,
            min_date=min_date,
        )

        maker = StatMaker(args.sex,
                          min_size=args.min_size,
                          max_size=args.max_size)
        maker.process_all(aspect=RECOVERY_ASPECT)
        log.info(__file__ + " done {}".format(RECOVERY_ASPECT))
        maker.process_all(aspect=KEEP_ASPECT)
        log.info(__file__ + " done {}".format(KEEP_ASPECT))

        dba.close_connect()
        log.info(__file__ + " finished sex: {}".format(args.sex))
        return 0
    except Exception as err:
        log.error("{0} [{1}]".format(err, err.__class__.__name__),
                  exc_info=True)
        return 1
Ejemplo n.º 7
0
            sex="wta",
            tour_id=11805,
            fst_plr_id=8531,
            snd_plr_id=10633,
            bettor_id=MARATHON_ID,
        )
        self.assertTrue(db_offer is not None)
        self.assertTrue(db_offer.win_coefs)

    @staticmethod
    def find_dboffer(sex, tour_id, fst_plr_id, snd_plr_id, bettor_id):
        dboffers = db_offers(sex, bettor_id=bettor_id)
        predicate = lambda o: o.tour_id == tour_id and (
            (o.first_player_id == fst_plr_id and o.second_player_id == snd_plr_id)
            or (o.first_player_id == snd_plr_id and o.second_player_id == fst_plr_id)
        )
        db_offer = co.find_first(dboffers, predicate)
        if db_offer is not None:
            if db_offer.win_coefs:
                if (
                    db_offer.first_player_id == snd_plr_id
                    and db_offer.second_player_id == fst_plr_id
                ):
                    db_offer.flip()
            return db_offer


if __name__ == '__main__':
    unittest.main()
    dba.close_connect()
def fetch_finalize(fsdrv):
    fsdrv.stop()
    dba.close_connect()
Ejemplo n.º 9
0
def write_actual_players(sex, yearsnum=1.8):
    dba.open_connect()
    initialize(sex, yearsnum=yearsnum)
    with open(_actual_players_filename(sex), "w") as fh:
        fh.write(",".join([str(p.ident) for p in players(sex)]))
    dba.close_connect()