コード例 #1
0
def pickup(state):
    """
    Recommends players to pick up to win the match of the week

    :param state: current state of variables
    :return: prints the best pick up for the week
    """

    # Initialize variables
    if state.opponent is None:
        while 1:
            state.opponent = raw_input("Who are you playing this week?: ")
            if state.opponent not in state.teams:
                print "Please enter a valid opponent name\n"
            else:
                break
    taken_players = []
    for users in state.teams:
        state.teams[users] = Helper.lowercase(state.teams[users])
        taken_players += state.teams[users]
    players_on_team = Helper.lowercase(state.teams[state.current_user])
    swap_dictionary = defaultdict(lambda: defaultdict(int))

    # Constructs a list of players from best to worst
    ranked_players = Helper.sort_dictionary(state.cumulative_player_statistics[state.iteration])
    ranked_players = [ranked_players[x][0] for x in range(len(ranked_players))]

    for n in range(len(ranked_players)):

        # Removes players already on the team
        if ranked_players[n] in players_on_team:
            players_on_team.pop(players_on_team.index(ranked_players[n]))

        # Prints other players
        if ranked_players[n] not in taken_players and len(players_on_team) != 0:

            # Determines the best player to drop and add
            for player in players_on_team:
                new_change = sum(Helper.evaluate_player_swap(copy.deepcopy(state.teams),
                                                             player, ranked_players[n],
                                                             state.normalized_player_statistics[state.iteration],
                                                             state, state.opponent)[0].values())
                swap_dictionary[player][ranked_players[n]] = new_change

    return swap_dictionary
コード例 #2
0
def trade(state):
    """
    Suggests players on your team to trade for a given player

    :param state: current state of variables
    :return: prints players to trade and their rankings
    """

    # Initialize variables
    players_on_team = Helper.lowercase(state.teams[state.current_user])
    for x in state.teams:
        state.teams[x] = Helper.lowercase(state.teams[x])

    while state.player_to_obtain is None:
        desired_player = raw_input("Enter the player you are trying to move: ").lower()

        if desired_player in state.cumulative_player_statistics[state.iteration]:
            state.update_player_to_obtain(desired_player)
        else:
            Helper.check_incorrect_input(desired_player, state.normalized_player_statistics[state.iteration].keys())

    return Helper.find_trade_possibilities(state.cumulative_player_statistics[state.iteration],
                                           state.normalized_player_statistics[state.iteration],
                                           state.player_to_obtain, players_on_team, state)
コード例 #3
0
ファイル: State.py プロジェクト: crsabbagh/fantasy-bball
    def __init__(self):
        # Options
        self.current_user = "******"
        self.per_game = False
        self.punt_categories = ['PTS']

        # Initialize variables
        self.opponent = None
        self.player_to_trade = None
        self.player_to_obtain = None
        self.sorted_players = None
        self.teams = Parser.parse_teams("files/teams/teams.txt")
        self.taken_players = self.find_taken_players()
        self.players_on_team = Helper.lowercase(self.teams[self.current_user])
        self.player_dictionary = self.create_player_dictionary()
        self.iteration = 0
        (self.cumulative_player_statistics, self.normalized_player_statistics) = Parser.choose_parse_type(self.per_game)
コード例 #4
0
def swap(state):
    """
    Shows the change in statistics if a player is swapped from your team

    :param state: current state of variables
    :return: prints statistic changes
    """

    # Initialize variables
    for user in state.teams:
        state.teams[user] = Helper.lowercase(state.teams[user])
    state.teams_storage = copy.deepcopy(state.teams)

    if state.player_to_obtain is None and state.player_to_trade is None:
        state.update_player_to_trade(raw_input("Enter the player you want to remove from your team: ").lower())
        state.update_player_to_obtain(raw_input("Enter the player you want to add to your team: ").lower())
        print ""

    # If the input is valid, analyze statistic changes
    if state.player_to_trade in state.cumulative_player_statistics[state.iteration] \
            and state.player_to_trade in state.teams[state.current_user] \
            and state.player_to_obtain in state.cumulative_player_statistics[state.iteration] \
            and state.player_to_obtain not in state.teams[state.current_user]:
        state.teams = copy.deepcopy(state.teams_storage)
        return Helper.evaluate_player_swap(state.teams, state.player_to_trade, state.player_to_obtain,
                                           state.normalized_player_statistics[state.iteration], state)

    # Notifies user if player is not in their team
    elif state.player_to_trade not in state.teams[state.current_user]:
        print state.player_to_trade.title(), "is not on your team"
    elif state.player_to_obtain in state.teams["Chris S"]:
        print state.player_to_obtain.title(), "is already on your team"

    # Suggests player names if input is incorrect
    elif state.player_to_trade not in state.cumulative_player_statistics[state.iteration]:
        Helper.check_incorrect_input(state.player_to_trade, state.normalized_player_statistics[state.iteration].keys())
    else:
        Helper.check_incorrect_input(state.player_to_obtain, state.normalized_player_statistics[state.iteration].keys())
コード例 #5
0
ファイル: State.py プロジェクト: crsabbagh/fantasy-bball
 def find_taken_players(self):
     taken_players = []
     for users in self.teams:
         self.teams[users] = Helper.lowercase(self.teams[users])
         taken_players += self.teams[users]
     return taken_players