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, 'pandas.read_csv', 'pd.read_csv', (['"""games_details.csv"""'], {}), True, 'import pandas as pd\n'), (22, 'streamlit.checkbox', 'st.checkbox', (['"""Show dataframe"""'], {}), True, 'import streamlit as st\n'), (28, 'streamlit.write', 'st.write', (['"""Top 20 Players in the NBA"""'], {}), True, 'import streamlit as st\n'), (30, 'matplotlib.pyplot.figure', 'plt.figure', ([], {'figsize': '(15, 10)'}), True, 'import matplotlib.pyplot as plt\n'), (31, 'matplotlib.pyplot.xlabel', 'plt.xlabel', (['"""POINTS"""'], {'fontsize': '(15)'}), True, 'import matplotlib.pyplot as plt\n'), (32, 'matplotlib.pyplot.ylabel', 'plt.ylabel', (['"""PLAYER_NAME"""'], {'fontsize': '(15)'}), True, 'import matplotlib.pyplot as plt\n'), (33, 'matplotlib.pyplot.title', 'plt.title', (['"""Top 20 Players in the NBA League"""'], {'fontsize': '(20)'}), True, 'import matplotlib.pyplot as plt\n'), (34, 'seaborn.barplot', 'sns.barplot', ([], {'x': "top_activities['PTS']", 'y': "top_activities['PLAYER_NAME']"}), True, 'import seaborn as sns\n'), (38, 'streamlit.pyplot', 'st.pyplot', (['plt'], {}), True, 'import streamlit as st\n'), (40, 'streamlit.multiselect', 'st.multiselect', (['"""Choose Player"""', "df['PLAYER_NAME']"], {}), True, 'import streamlit as st\n'), (44, 'streamlit.write', 'st.write', (['"""\n# My first app\nHello *world!*\n"""'], {}), True, 'import streamlit as st\n'), (49, 'streamlit.slider', 'st.slider', (['"""Select a number"""'], {}), True, 'import streamlit as st\n'), (50, 'streamlit.write', 'st.write', (['"""You selected:"""', 'x'], {}), True, 'import streamlit as st\n'), (23, 'streamlit.write', 'st.write', (['"""Players Game Details"""'], {}), True, 'import streamlit as st\n')]