def league_menu():
    global curr_league
    global curr_team
    global matchday_option
    global team_option
    league_update()
    curr_league = League(leagues[league.get()])
    Label(root, text=curr_league.print_standings(), width=60, height=23, justify=LEFT, font="Consolas 12").place(x=50,
                                                                                                                 y=100)
    Button(root, text='Get scorers', command=print_scorers).place(x=25, y=550)
    matchday_option = Button(root, text='Get matchday', command=matchday)
    matchday_option.place(x=25, y=585)
    team_option = Button(root, text='Choose team', command=team_menu)
    team_option.place(x=225, y=550)
예제 #2
0
def match_predict(home_identifier, away_identifier, league_name):
    """
    Predict goals scored in match using Poisson distribution based on historical data for current season

    :param home_identifier: home team
    :param away_identifier: away team
    :param league_name: league containing home and away team
    :return: predicted goals in match
    """
    print()
    engine = connect_to_db(str(league_name))

    league = League(league_name, engine)
    home_team = " ".join(home_identifier.split(" ")[:-1])
    away_team = " ".join(away_identifier.split(" ")[:-1])

    home = Team(home_team, engine, league, 'HOME')
    away = Team(away_team, engine, league, 'AWAY')

    home.plot_gf()
    home.plot_ga()
    print(home.get_stats())
    away.plot_gf()
    away.plot_ga()
    print(away.get_stats())
예제 #3
0
 def choose_league(self):
     """
     Initializes the league
     :return: None
     """
     print(
         "\nEnter the league:\nPremier League(ENG)\nLa Liga(ESP)\nBundesliga(GER)\nSerie A(ITA)\nLigue 1(FRA)"
     )
     leagues = {
         "Premier League": "PL",
         "La Liga": "PD",
         "Bundesliga": "BL1",
         "Serie A": "SA",
         "Ligue 1": "FL1"
     }
     league = input("enter league name:")
     try:
         league_id = leagues[league]
         self._league = League(league_id)
         print("You have successfully chosen the league")
     except KeyError:
         print("Enter a valid league name!")
         self.choose_league()
예제 #4
0
def prob_predictions(lid, tid, tid_venue, oid, oid_venue):
    if tid_venue == oid_venue:
        raise ValueError("Team venue and opponent venue cannot be the same!")
    engine = connect_to_db(lid)
    if engine:
        league = League(lid, engine)
        team = Team(tid, engine, league, tid_venue)
        opponent = Team(oid, engine, league, oid_venue)
        team.set_opposition(opponent)
        opponent.set_opposition(team)
        # team.plot_xgf()
        # opponent.plot_xgf()
        results_dict = get_result_prob(team, opponent)
        return results_dict
예제 #5
0
def main(league):
    """
    Populates home and away league tables. Uses classes League() and Team().

    :param league: league with home and away tables to be populated
    """
    engine = connect_to_db(league)
    if engine:
        league = League(league, engine)
        for team in league.teams:
            print()
            for venue in ['HOME', 'AWAY']:
                print(team, venue)
                team_instance = Team(team, engine, league, venue)
                stats = team_instance.get_stats()
                cols = [
                    'team', 'mp', 'w', 'd', 'l', 'gf', 'ga', 'gd', 'points'
                ]
                df = pd.DataFrame([[
                    team,
                    stats.Games.values.sum(),
                    stats.W.values.sum(),
                    stats.D.values.sum(),
                    stats.L.values.sum(),
                    stats.GF.values.sum(),
                    stats.GA.values.sum(),
                    (stats.GF.values.sum() - stats.GA.values.sum()),
                    (3 * stats.W.values.sum() + stats.D.values.sum())
                ]],
                                  columns=cols)
                print(df)
                table_name = venue.lower() + "_league_table"
                connection = engine.connect()
                df.to_sql(con=connection,
                          name=table_name,
                          if_exists='append',
                          index=False)
                connection.close()
예제 #6
0
파일: info.py 프로젝트: erwinmintiens/FPL
        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())
예제 #7
0
class Menu():
    """Class for navigating the program"""
    def __init__(self):
        self.menu_map = {
            "choose another league": self.choose_league,
            "get standings": self.get_standings,
            "get scorers": self.get_scorers,
            "get matchday": self.get_matchday,
            "choose a team": self.choose_team,
            "quit": self.quit
        }
        self._league = None

    def choose_league(self):
        """
        Initializes the league
        :return: None
        """
        print(
            "\nEnter the league:\nPremier League(ENG)\nLa Liga(ESP)\nBundesliga(GER)\nSerie A(ITA)\nLigue 1(FRA)"
        )
        leagues = {
            "Premier League": "PL",
            "La Liga": "PD",
            "Bundesliga": "BL1",
            "Serie A": "SA",
            "Ligue 1": "FL1"
        }
        league = input("enter league name:")
        try:
            league_id = leagues[league]
            self._league = League(league_id)
            print("You have successfully chosen the league")
        except KeyError:
            print("Enter a valid league name!")
            self.choose_league()

    def get_standings(self):
        """
        Prints the standings of current league
        :return: None
        """
        self._league.print_standings()

    def get_scorers(self):
        """
        Prints top 10 scorers of current league
        :return: None
        """
        self._league.print_scorers()

    def get_matchday(self):
        """
        Prints matches of entered matchday
        :return: None
        """
        valid = False
        while not valid:
            num = int(input("Enter the matchday number:"))
            if self._league.code == "BL1":
                if num >= 1 and num <= 34:
                    valid = True
                else:
                    print("Enter a valid matchday number!")
            else:
                if num >= 1 and num <= 38:
                    valid = True
                else:
                    print("Enter a valid matchday number!")
        self._league.print_matchday(num)

    def choose_team(self):
        """
        Initializes a team from current league
        :return: None
        """
        self._league.print_standings()
        valid = False
        while not valid:
            answer = input("Enter the team name:")
            if answer in self._league.teams:
                team = self._league.teams[answer]
                valid = True
            else:
                print("Enter valid team name!")
        self.team_menu(team)

    def team_menu(self, team):
        """
        A team menu that gives list of available commands to the user and runs chosen commands
        :param team: team name
        :return: None
        """
        team_menu_map = {
            "get stats": self.get_stats,
            "compare": self.compare,
            "back": self.menu
        }
        while True:
            print("""
Please enter a command:

\tget stats---Get detailed team statistics
\tcompare---Compare two teams head to head
\tback---Go back to previous page
""")
            answer = input("Enter a command:")
            try:
                func = team_menu_map[answer]
            except KeyError:
                print("{} is not a valid command".format(answer))
            else:
                if answer != "back":
                    func(team)
                else:
                    func()

    def get_stats(self, team):
        """
        Prints the team statistics
        :param team: team name
        :return: None
        """
        team.print_info()

    def compare(self, team):
        """
        Prints a comparison of two teams
        :param team: other team name
        :return: None
        """
        valid = False
        while not valid:
            answer = input("Enter the name of team you want compare with:")
            if answer in self._league.teams:
                another_team = self._league.teams[answer]
                valid = True
            else:
                print("Enter valid team name!")
        team.print_head_to_head(another_team)

    def quit(self):
        """
        Quits the program
        :return: None
        """
        print("Thank you for using our program!")
        raise SystemExit

    def menu(self):
        """
        Menu that gives list of available commands to the user and runs chosen commands
        :return: None
        """
        if not self._league:
            print("Welcome to the Football Data Analysis app")
            print("Please choose a league:")
            self.choose_league()

        while True:
            print("\n")
            print("""
Please enter a command:

\tget standings ---Get league standings
\tget scorers---Get list of league top scorers
\tget matchday---Get all matches of the chosen matchday
\tchoose a team---Choose a team and get it stats
\tchoose another league---Choose another league
\tquit---Quit the program
""")
            answer = input("Enter a command: ").lower()
            try:
                func = self.menu_map[answer]
            except KeyError:
                print("{} is not a valid command".format(answer))
            else:
                func()