Ejemplo n.º 1
0
def update_league(league):
    # Getting data
    # soccer_data = SoccerDataAPI()
    print(f'League Selected by user {league}')
    soccer_data = SoccerDataAPI()
    data = pd.DataFrame()
    # Checking for each type of league dfata call
    if league == "Premier League":
        data = soccer_data.english_premier()
        # df = pd.DataFrame(data)

    elif league == "La Liga":
        data = soccer_data.la_liga()
        # df = pd.DataFrame(data)

    elif league == "Serie A":
        data = soccer_data.serie_a()
        # df = pd.DataFrame(data)

    elif league == "Ligue 1":
        data = soccer_data.ligue_1()
        # df = pd.DataFrame(data)

    elif league == "Bundesliga":
        data = soccer_data.bundesliga()
        # df = pd.DataFrame(data)

    # Setting up and converting df
    df = pd.DataFrame(data)

    # Reformatting data in table to be plotly friendly
    cols2int = [
        'pos',
        'wins',
        'losses',
        'draws',
        'losses',
        'goals_for',
        'goals_against',
        'goal_diff',
    ]
    for col in cols2int:
        df[col] = df[col].astype(int)

    # Adding top scorer goals
    get_goals = lambda x: int(x['top_scorer'].split(' - ')[1])
    df['top_scorer_goals'] = df.apply(get_goals, axis=1)

    print(f'{league} data:\n', df)

    # Seeting up scatter
    f = px.scatter(df,
                   x="goal_diff",
                   y="points",
                   text='team',
                   title=league,
                   hover_data=['team', 'top_scorer'],
                   labels={
                       'goal_diff': 'Goal Differential',
                       'points': 'Points'
                   })
    f.update_traces(textposition='middle right')
    f.update_yaxes(autorange="reversed")

    # Attack bar graph
    a_bar = px.bar(df,
                   x='team',
                   y='goals_for',
                   title=f'{league} Attack',
                   labels={
                       'team': '',
                       'goals_for': 'Goals For'
                   })

    # Defense Bar graph
    d_bar = px.bar(df,
                   x='team',
                   y='goals_against',
                   title=f'{league} Defense',
                   labels={
                       'team': '',
                       'goals_against': 'Goals Against'
                   })

    # Goal differential bar graph
    diff_bar = px.bar(df,
                      x='team',
                      y='goal_diff',
                      title=f'{league} Goal Differential',
                      labels={
                          'team': '',
                          'goal_diff': 'Goal Differential'
                      })

    s_bar = px.bar(df,
                   x='top_scorer',
                   y='top_scorer_goals',
                   title=f'{league} Top Scorers',
                   hover_data=['team', 'top_scorer'],
                   labels={
                       'top_scorer': 'Player',
                       'top_scorer_goals': 'Goals'
                   })

    # Goal Diff Bar Graph
    return f, a_bar, d_bar, diff_bar, s_bar
Ejemplo n.º 2
0
#!J:/WinPython/WPy64-3740/python-3.7.4.amd64/python
'''
    The first line of the Python file indicates where Python is in the PC.
    If Python application file is in the folder J:/WinPython/WPy64-3740/python-3.7.4.amd64 , 
    the first line of Python script should be #!J:/WinPython/WPy64-3740/python-3.7.4.amd64/python
    
    As this web project uses both PHP and Python, and running of Python file is initiated from a PHP file, 
    this is important.
    
'''

from soccer_data_api import SoccerDataAPI
import os

soccer_data = SoccerDataAPI()

if os.path.exists("txt_ligueone.txt"):
    os.remove("txt_ligueone.txt")
f = open("txt_ligueone.txt", "a")
ligueone = soccer_data.ligue_1()
for et in ligueone:
    str1 = et['team'] + "," + et['pos'] + "," + et['points'] + "," + et[
        'matches_played'] + "," + et['wins'] + "," + et['losses'] + "," + et[
            'goals_for'] + "," + et['goal_diff'] + "\n"
    f.write(str1)
f.close()
Ejemplo n.º 3
0
    data = pd.DataFrame()
    # Checking for each type of league dfata call
    if league == "Premier League":
        data = soccer_data.english_premier()
        # df = pd.DataFrame(data)

    elif league == "La Liga":
        data = soccer_data.la_liga()
        # df = pd.DataFrame(data)

    elif league == "Serie A":
        data = soccer_data.serie_a()
        # df = pd.DataFrame(data)

    elif league == "Ligue 1":
        data = soccer_data.ligue_1()
        # df = pd.DataFrame(data)

    elif league == "Bundesliga":
        data = soccer_data.bundesliga()
        # df = pd.DataFrame(data)
    
    # Setting up and converting df
    df = pd.DataFrame(data)

    cols2int = ['pos','wins', 'losses',  'draws', 'losses',
       'goals_for', 'goals_against', 'goal_diff',]
    for col in cols2int:
        df[col] = df[col].astype(int)
        print(df[col])