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)

[((9, 15, 9, 47), 'pandas.read_csv', 'pd.read_csv', ({(9, 27, 9, 46): '"""games_details.csv"""'}, {}), "('games_details.csv')", True, 'import pandas as pd\n'), ((22, 3, 22, 32), 'streamlit.checkbox', 'st.checkbox', ({(22, 15, 22, 31): '"""Show dataframe"""'}, {}), "('Show dataframe')", True, 'import streamlit as st\n'), ((28, 0, 28, 37), 'streamlit.write', 'st.write', ({(28, 9, 28, 36): '"""Top 20 Players in the NBA"""'}, {}), "('Top 20 Players in the NBA')", True, 'import streamlit as st\n'), ((30, 0, 30, 28), 'matplotlib.pyplot.figure', 'plt.figure', (), '', True, 'import matplotlib.pyplot as plt\n'), ((31, 0, 31, 33), 'matplotlib.pyplot.xlabel', 'plt.xlabel', (), '', True, 'import matplotlib.pyplot as plt\n'), ((32, 0, 32, 38), 'matplotlib.pyplot.ylabel', 'plt.ylabel', (), '', True, 'import matplotlib.pyplot as plt\n'), ((33, 0, 33, 58), 'matplotlib.pyplot.title', 'plt.title', (), '', True, 'import matplotlib.pyplot as plt\n'), ((34, 5, 34, 74), 'seaborn.barplot', 'sns.barplot', (), '', True, 'import seaborn as sns\n'), ((38, 0, 38, 14), 'streamlit.pyplot', 'st.pyplot', ({(38, 10, 38, 13): 'plt'}, {}), '(plt)', True, 'import streamlit as st\n'), ((40, 9, 42, 1), 'streamlit.multiselect', 'st.multiselect', ({(41, 4, 41, 19): '"""Choose Player"""', (41, 21, 41, 38): "df['PLAYER_NAME']"}, {}), "('Choose Player', df['PLAYER_NAME'])", True, 'import streamlit as st\n'), ((44, 0, 47, 4), 'streamlit.write', 'st.write', ({(44, 9, 47, 3): '"""\n# My first app\nHello *world!*\n"""'}, {}), '("""\n# My first app\nHello *world!*\n""")', True, 'import streamlit as st\n'), ((49, 4, 49, 32), 'streamlit.slider', 'st.slider', ({(49, 14, 49, 31): '"""Select a number"""'}, {}), "('Select a number')", True, 'import streamlit as st\n'), ((50, 0, 50, 28), 'streamlit.write', 'st.write', ({(50, 9, 50, 24): '"""You selected:"""', (50, 26, 50, 27): 'x'}, {}), "('You selected:', x)", True, 'import streamlit as st\n'), ((23, 4, 23, 36), 'streamlit.write', 'st.write', ({(23, 13, 23, 35): '"""Players Game Details"""'}, {}), "('Players Game Details')", True, 'import streamlit as st\n')]