import streamlit as st
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt

# --------------------------------------------------------------
# Import and clean data
game_details = pd.read_csv('games_details.csv')
# print(game_details.head(5))
game_details.drop(['GAME_ID', 'TEAM_ID', 'PLAYER_ID', 'START_POSITION',
                   'COMMENT', 'TEAM_ABBREVIATION'], axis=1, inplace=True)
game_details['FTL'] = game_details['FTA'] - game_details['FTM']
game_details = game_details.dropna()
# game_details.shape
# game_details.info()


game_details['MIN'] = game_details['MIN'].str.strip(':').str[0:2]
df = game_details.copy()

if st.checkbox('Show dataframe'):
    st.write("Players Game Details")
    st.dataframe(df.head(10))

# --------------------------------------------------------------

st.write("Top 20 Players in the NBA")
top_activities = df.groupby(by='PLAYER_NAME')['PTS'].sum().sort_values(ascending=False).head(20).reset_index()
plt.figure(figsize=(15, 10))
plt.xlabel('POINTS', fontsize=15)
plt.ylabel('PLAYER_NAME', fontsize=15)
plt.title('Top 20 Players in the NBA League', fontsize=20)
ax = sns.barplot(x=top_activities['PTS'], y=top_activities['PLAYER_NAME'])
for i, (value, name) in enumerate(zip(top_activities['PTS'], top_activities['PLAYER_NAME'])):
    ax.text(value, i - .05, f'{value:,.0f}', size=10, ha='left', va='center')
ax.set(xlabel='POINTS', ylabel='PLAYER_NAME')
st.pyplot(plt)

player = st.multiselect(
    "Choose Player", df['PLAYER_NAME']
)

st.write("""
# My first app
Hello *world!*
""")

x = st.slider("Select a number")
st.write("You selected:", x)

[((221, 253), 'pandas.read_csv', 'pd.read_csv', (['"""games_details.csv"""'], {}), "('games_details.csv')\n", (232, 253), True, 'import pandas as pd\n'), ((671, 700), 'streamlit.checkbox', 'st.checkbox', (['"""Show dataframe"""'], {}), "('Show dataframe')\n", (682, 700), True, 'import streamlit as st\n'), ((836, 873), 'streamlit.write', 'st.write', (['"""Top 20 Players in the NBA"""'], {}), "('Top 20 Players in the NBA')\n", (844, 873), True, 'import streamlit as st\n'), ((985, 1013), 'matplotlib.pyplot.figure', 'plt.figure', ([], {'figsize': '(15, 10)'}), '(figsize=(15, 10))\n', (995, 1013), True, 'import matplotlib.pyplot as plt\n'), ((1014, 1047), 'matplotlib.pyplot.xlabel', 'plt.xlabel', (['"""POINTS"""'], {'fontsize': '(15)'}), "('POINTS', fontsize=15)\n", (1024, 1047), True, 'import matplotlib.pyplot as plt\n'), ((1048, 1086), 'matplotlib.pyplot.ylabel', 'plt.ylabel', (['"""PLAYER_NAME"""'], {'fontsize': '(15)'}), "('PLAYER_NAME', fontsize=15)\n", (1058, 1086), True, 'import matplotlib.pyplot as plt\n'), ((1087, 1145), 'matplotlib.pyplot.title', 'plt.title', (['"""Top 20 Players in the NBA League"""'], {'fontsize': '(20)'}), "('Top 20 Players in the NBA League', fontsize=20)\n", (1096, 1145), True, 'import matplotlib.pyplot as plt\n'), ((1151, 1220), 'seaborn.barplot', 'sns.barplot', ([], {'x': "top_activities['PTS']", 'y': "top_activities['PLAYER_NAME']"}), "(x=top_activities['PTS'], y=top_activities['PLAYER_NAME'])\n", (1162, 1220), True, 'import seaborn as sns\n'), ((1439, 1453), 'streamlit.pyplot', 'st.pyplot', (['plt'], {}), '(plt)\n', (1448, 1453), True, 'import streamlit as st\n'), ((1464, 1514), 'streamlit.multiselect', 'st.multiselect', (['"""Choose Player"""', "df['PLAYER_NAME']"], {}), "('Choose Player', df['PLAYER_NAME'])\n", (1478, 1514), True, 'import streamlit as st\n'), ((1522, 1569), 'streamlit.write', 'st.write', (['"""\n# My first app\nHello *world!*\n"""'], {}), '("""\n# My first app\nHello *world!*\n""")\n', (1530, 1569), True, 'import streamlit as st\n'), ((1575, 1603), 'streamlit.slider', 'st.slider', (['"""Select a number"""'], {}), "('Select a number')\n", (1584, 1603), True, 'import streamlit as st\n'), ((1604, 1632), 'streamlit.write', 'st.write', (['"""You selected:"""', 'x'], {}), "('You selected:', x)\n", (1612, 1632), True, 'import streamlit as st\n'), ((706, 738), 'streamlit.write', 'st.write', (['"""Players Game Details"""'], {}), "('Players Game Details')\n", (714, 738), True, 'import streamlit as st\n')]