def get_person_captain_for_gameweek( manager: FantasyPremierLeagueManager, gameweek: Union[int, str]) -> Union[None, list]: captain_played = False vice_captain_played = False is_triple_captain = False person_picks = manager.get_picks_for_gw(gameweek) if not person_picks: return for player in person_picks["picks"]: if player["is_captain"] and player["multiplier"] not in [0, 1]: if player["multiplier"] == 3: is_triple_captain = True captain_played = True return [ PremierLeaguePlayer(player["element"]), captain_played, vice_captain_played, is_triple_captain ] if player["is_vice_captain"] and player["multiplier"] not in [0, 1]: if player["multiplier"] == 3: is_triple_captain = True vice_captain_played = True return [ PremierLeaguePlayer(player["element"]), captain_played, vice_captain_played, is_triple_captain ] return [None, captain_played, vice_captain_played, is_triple_captain]
def replace_all_player_ids_with_players_in_stats(stat: dict): if not stat["a"] and not stat["h"]: return for element in stat["a"]: if "element" in element: element["element"] = PremierLeaguePlayer(element["element"]) for element in stat["h"]: if "element" in element: element["element"] = PremierLeaguePlayer(element["element"]) return stat
def get_player_stats_in_gw(player: PremierLeaguePlayer, gameweek: Union[int, str]) -> Union[None, list]: if not player.stats: player.stats = player.get_summary() if not player.stats: return stats = list() for element in player.stats["history"]: if element["round"] == int(gameweek): stats.append(element) return stats
def replace_player_id_with_player_object(text): if text: if type(text) == dict: if "element" in text: text["element"] = PremierLeaguePlayer(text["element"]) elif type(text) == list: for dictionary in text: if "element" in dictionary: dictionary["element"] = PremierLeaguePlayer( dictionary["element"]) else: raise TypeError( f"Parameter with type {type(text)} is not supported for this function" ) return text
def get_all_used_players_per_manager(): result = dict() for manager in config['managers']: player_list = list() players = get_all_used_players( FantasyPremierLeagueManager(config['managers'][manager]), 1, 38) for player in players: player_list.append(PremierLeaguePlayer(player).web_name) result[manager] = {'players': player_list, 'total': len(player_list)} return result
def get_points_for_player(player: PremierLeaguePlayer, gameweek: Union[int, str]) -> Union[None, int]: player_summary = player.get_summary() if not player_summary: return total = 0 for gw in player_summary: if gw["round"] == gameweek: total += gw["total_points"] return total
def get_player_stat_per_90_minutes(player: PremierLeaguePlayer, stat: str) -> Union[None, float]: global player_stats if stat not in player_stats: raise ValueError(f"Stat {stat} not one of {player_stats}") if not player.stats: player.stats = player.get_summary() if not player.stats: return stat_total = 0 minutes = 0 if stat in ["influence", "creativity", "threat", "ict_index"]: for game in player.stats["history"]: stat_total += float(game[stat]) minutes += game["minutes"] else: for game in player.stats["history"]: stat_total += game[stat] minutes += game["minutes"] return stat_total / minutes * 90
players = get_all_used_players( FantasyPremierLeagueManager(config['managers'][manager]), 1, 38) for player in players: player_list.append(PremierLeaguePlayer(player).web_name) result[manager] = {'players': player_list, 'total': len(player_list)} return result def update_all_files(): data.fetch_all_latest_info() if __name__ == '__main__': # update_all_files() erwin = FantasyPremierLeagueManager(config["managers"]["erwin"]) niels = FantasyPremierLeagueManager(config['managers']['niels']) bale = PremierLeaguePlayer(543) team1 = Team(14) team2 = Team(20) schuppebekske = League(435851) een_fixture = Fixture(200) manchester_united = Team(team_short_name="MUN") mun_mci = get_fixture(manchester_united, Team(team_short_name="MCI")) # print(mun_mci.away_team) # print(een_fixture.yellow_cards) # print(get_captaincy_points_per_manager(36, 36)) # print(get_extra_captaincy_points_between_gws(niels, 1, 36)) print(get_all_used_players_per_manager())