Ejemplo n.º 1
0
def main():
    """
    fill the player_prediction db table
    """
    parser = argparse.ArgumentParser(description="fill player predictions")
    parser.add_argument("--weeks_ahead",
                        help="how many weeks ahead to fill",
                        type=int)
    parser.add_argument("--gameweek_start",
                        help="first gameweek to look at",
                        type=int)
    parser.add_argument("--gameweek_end",
                        help="last gameweek to look at",
                        type=int)
    parser.add_argument("--ep_filename",
                        help="csv filename for FPL expected points")
    parser.add_argument("--season",
                        help="season, in format e.g. '1819'",
                        default=CURRENT_SEASON)
    parser.add_argument("--num_thread",
                        help="number of threads to parallelise over",
                        type=int)
    args = parser.parse_args()
    if args.weeks_ahead and (args.gameweek_start or args.gameweek_end):
        print(
            "Please specify either gameweek_start and gameweek_end, OR weeks_ahead"
        )
        raise RuntimeError("Inconsistent arguments")
    if args.weeks_ahead and not args.season == CURRENT_SEASON:
        print(
            "For past seasons, please specify gameweek_start and gameweek_end")
        raise RuntimeError("Inconsistent arguments")
    if args.weeks_ahead:
        gw_range = list(range(NEXT_GAMEWEEK, NEXT_GAMEWEEK + args.weeks_ahead))
    elif args.gameweek_start and args.gameweek_end:
        gw_range = list(range(args.gameweek_start, args.gameweek_end))
    elif args.gameweek_start:  # by default go three weeks ahead
        gw_range = list(range(args.gameweek_start, args.gameweek_start + 3))
    else:
        gw_range = list(range(NEXT_GAMEWEEK, NEXT_GAMEWEEK + 3))
    num_thread = args.num_thread if args.num_thread else None
    with session_scope() as session:
        tag = make_predictedscore_table(session,
                                        gw_range=gw_range,
                                        season=args.season,
                                        num_thread=num_thread)

        # print players with top predicted points
        get_top_predicted_points(
            gameweek=gw_range,
            tag=tag,
            season=args.season,
            dbsession=session,
            per_position=True,
            n_players=5,
        )
def main():
    """
    fill the player_prediction db table
    """
    parser = argparse.ArgumentParser(description="fill player predictions")
    parser.add_argument("--weeks_ahead",
                        help="how many weeks ahead to fill",
                        type=int)
    parser.add_argument("--gameweek_start",
                        help="first gameweek to look at",
                        type=int)
    parser.add_argument("--gameweek_end",
                        help="last gameweek to look at",
                        type=int)
    parser.add_argument("--ep_filename",
                        help="csv filename for FPL expected points")
    parser.add_argument("--season",
                        help="season, in format e.g. '1819'",
                        default=CURRENT_SEASON)
    parser.add_argument("--num_thread",
                        help="number of threads to parallelise over",
                        type=int)
    parser.add_argument(
        "--no_bonus",
        help="don't include bonus points",
        action="store_true",
    )
    parser.add_argument(
        "--no_cards",
        help="don't include points lost to yellow and red cards",
        action="store_true",
    )
    parser.add_argument(
        "--no_saves",
        help="don't include save points for goalkeepers",
        action="store_true",
    )
    parser.add_argument(
        "--sampling",
        help="If set use fit the model using sampling with numpyro",
        action="store_true",
    )

    args = parser.parse_args()
    if args.weeks_ahead and (args.gameweek_start or args.gameweek_end):
        print(
            "Please specify either gameweek_start and gameweek_end, OR weeks_ahead"
        )
        raise RuntimeError("Inconsistent arguments")
    if args.weeks_ahead and args.season != CURRENT_SEASON:
        print(
            "For past seasons, please specify gameweek_start and gameweek_end")
        raise RuntimeError("Inconsistent arguments")
    if args.weeks_ahead:
        gw_range = get_gameweeks_array(args.weeks_ahead)
    elif args.gameweek_start and args.gameweek_end:
        gw_range = list(range(args.gameweek_start, args.gameweek_end))
    elif args.gameweek_start:  # by default go three weeks ahead
        gw_range = list(range(args.gameweek_start, args.gameweek_start + 3))
    else:
        gw_range = list(range(NEXT_GAMEWEEK, NEXT_GAMEWEEK + 3))
    num_thread = args.num_thread or None
    include_bonus = not args.no_bonus
    include_cards = not args.no_cards
    include_saves = not args.no_saves
    if args.sampling:
        player_model = NumpyroPlayerModel()
    else:
        player_model = ConjugatePlayerModel()

    set_multiprocessing_start_method(num_thread)

    with session_scope() as session:
        session.expire_on_commit = False

        tag = make_predictedscore_table(
            gw_range=gw_range,
            season=args.season,
            num_thread=num_thread,
            include_bonus=include_bonus,
            include_cards=include_cards,
            include_saves=include_saves,
            player_model=player_model,
            dbsession=session,
        )

        # print players with top predicted points
        get_top_predicted_points(
            gameweek=gw_range,
            tag=tag,
            season=args.season,
            per_position=True,
            n_players=5,
            dbsession=session,
        )