コード例 #1
0
ファイル: api_utils.py プロジェクト: shashanksub42/AIrsenal
def best_transfer_suggestions(n_transfer, session_id, dbsession=DBSESSION):
    """
    Use our predicted playerscores to suggest the best transfers.
    """
    n_transfer = int(n_transfer)
    if not n_transfer in range(1,3):
        raise RuntimeError("Need to choose 1 or 2 transfers")
    if not validate_session_squad(session_id, dbsession):
        raise RuntimeError("Cannot suggest transfer without complete squad")

    budget = get_session_budget(session_id, dbsession)
    players = [p["id"] for p in get_session_players(session_id, dbsession)]
    t = Team(budget)
    for p in players:
        added_ok = t.add_player(p)
        if not added_ok:
            raise RuntimeError("Cannot add player {}".format(p))
    pred_tag = get_latest_prediction_tag()
    gw=get_next_gameweek(CURRENT_SEASON, dbsession)
    if n_transfer == 1:
        new_team, pid_out, pid_in = make_optimum_transfer(t, pred_tag)
    elif n_transfer == 2:
        new_team, pid_out, pid_in = make_optimum_double_transfer(t, pred_tag)
    return {
        "transfers_out": pid_out,
        "transfers_in": pid_in
    }
コード例 #2
0
def validate_session_squad(session_id, dbsession=DBSESSION):
    """
    get the list of player_ids for this session_id, and see if we can
    make a valid 15-player squad out of it
    """
    budget = get_session_budget(session_id, dbsession)

    players = get_session_players(session_id, dbsession)
    if len(players) != 15:
        return False
    t = Team(budget)
    for p in players:
        added_ok = t.add_player(p["id"])
        if not added_ok:
            return False
    return True