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
def waiver(state): """ Recommends players to pick up off the waiver :param state: current state of variables :return: """ # Initialize variables swap_dictionary = defaultdict(lambda: defaultdict(int)) players = state.cumulative_player_statistics[state.iteration].keys() team_stat = Helper.evaluate_teams(copy.deepcopy(state.teams), state.normalized_player_statistics[state.iteration], state) print team_stat """ for player in players: # Only iterates through players on waiver wire # TODO: Replace with SQL query if player not in state.taken_players and player not in state.players_on_team: # Loops over all players on team for other_player in state.players_on_team: change_stat = copy.deepcopy(team_stat) """ # """ for player in players: # Prints other players if player not in state.taken_players and player not in state.players_on_team: # Determines the best player to drop and add for other_player in state.players_on_team: new_change = sum(Helper.evaluate_player_swap(copy.deepcopy(state.teams), other_player, player, state.normalized_player_statistics[state.iteration], state)[0].values()) swap_dictionary[other_player][player] = new_change # """ return swap_dictionary
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())