Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
st.set_page_config(layout="wide")
|
3 |
+
|
4 |
+
for name in dir():
|
5 |
+
if not name.startswith('_'):
|
6 |
+
del globals()[name]
|
7 |
+
|
8 |
+
import numpy as np
|
9 |
+
import pandas as pd
|
10 |
+
import streamlit as st
|
11 |
+
import gspread
|
12 |
+
import plotly.express as px
|
13 |
+
import random
|
14 |
+
import gc
|
15 |
+
|
16 |
+
@st.cache_resource
|
17 |
+
def init_conn():
|
18 |
+
scope = ['https://spreadsheets.google.com/feeds', 'https://www.googleapis.com/auth/drive']
|
19 |
+
|
20 |
+
credentials = {
|
21 |
+
"type": "service_account",
|
22 |
+
"project_id": "dfsnew",
|
23 |
+
"private_key_id": "2432f6c3771f70a410c5c878d1359869fc9dddc8",
|
24 |
+
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDBNBDU2aJuEr6n\ne0o7pDY8gjg1+g1e3oHlpyY/CHMByZuEwfXewsZYP/TApfr8zxXDNG9X31CloWXH\n6ef8H0h6TjhRppE/2YCUZlbgtvpwlDg+1aKTKY5Lc/L937I6V512mgMDhDmTwX+p\noV0vhPuJnyFy+Fuo+xu8D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RzWnR/HYmFYgQKBgFOy\nbSX/pAgVCkedvc0c5lBymvZMkJ+VJrxPS+Ckpn43jKea6M/uUl7Cb8jZKSoKdgS6\n3FpJvc+Y2eOgKw4AfHuSG5Xn8roaEj23XK/KacoQl130DUZ0wV2+xvuvBz7h+ni8\nQQphFxoEhcBRq7ys1h6ebt+86mQW1ne4aRjWbKxBAoGARA+rBNIC9Z1vyRzMAXfj\nnQ9/wShd/NGpVRNrm7sdUastfoyK8Ip3HkJac3xE1ARpQTvxAz742mdeDxPWI8wZ\nHDsjIrRqGLKMN7tSIoM720y6PY/Tsg89SdY4y0h6M75rrEi4Lv5b7s4EmqAZdfKT\nbEyuT7sCPCLeOX/RLy/lCpA=\n-----END PRIVATE KEY-----\n",
|
25 |
+
"client_email": "[email protected]",
|
26 |
+
"client_id": "105107448378741046480",
|
27 |
+
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
|
28 |
+
"token_uri": "https://oauth2.googleapis.com/token",
|
29 |
+
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
|
30 |
+
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/dfsapps%40dfsnew.iam.gserviceaccount.com",
|
31 |
+
"universe_domain": "googleapis.com"
|
32 |
+
}
|
33 |
+
|
34 |
+
header= {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) '
|
35 |
+
'AppleWebKit/537.11 (KHTML, like Gecko) '
|
36 |
+
'Chrome/23.0.1271.64 Safari/537.11',
|
37 |
+
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
|
38 |
+
'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3',
|
39 |
+
'Accept-Encoding': 'none',
|
40 |
+
'Accept-Language': 'en-US,en;q=0.8',
|
41 |
+
'Connection': 'keep-alive'}
|
42 |
+
|
43 |
+
gc_con = service_account_from_dict(creds, scope)
|
44 |
+
|
45 |
+
return gc_con
|
46 |
+
|
47 |
+
gcservice_account = init_conn()
|
48 |
+
|
49 |
+
master_hold = 'https://docs.google.com/spreadsheets/d/1Yq0vGriWK-bS79e-bD6_u9pqrYE6Yrlbb_wEkmH-ot0/edit#gid=853878325'
|
50 |
+
|
51 |
+
@st.cache_resource(ttl = 300)
|
52 |
+
def init_baselines():
|
53 |
+
sh = gcservice_account.open_by_url(master_hold)
|
54 |
+
|
55 |
+
worksheet = sh.worksheet('Arturo Props')
|
56 |
+
raw_display = pd.DataFrame(worksheet.get_all_records())
|
57 |
+
raw_display.replace('', np.nan, inplace=True)
|
58 |
+
raw_display = raw_display[['Player', 'Pos', 'Team', 'Opponent', 'Min', 'mpgL3', 'Diff', 'Status', 'Pts', 'Rbs', 'Asst', 'TOs', '3PM',
|
59 |
+
'Steals', 'Blk', 'FD', 'DK']]
|
60 |
+
player_stats = raw_display[raw_display['Min'] > 0]
|
61 |
+
|
62 |
+
return player_stats
|
63 |
+
|
64 |
+
def convert_df_to_csv(df):
|
65 |
+
return df.to_csv().encode('utf-8')
|
66 |
+
|
67 |
+
player_stats = init_baselines()
|
68 |
+
|
69 |
+
if st.button("Reset Data", key='reset1'):
|
70 |
+
st.cache_data.clear()
|
71 |
+
player_stats = init_baselines()
|
72 |
+
split_var1 = st.radio("Would you like to view all teams or specific ones?", ('All', 'Specific Teams'), key='split_var1')
|
73 |
+
if split_var1 == 'Specific Teams':
|
74 |
+
team_var1 = st.multiselect('Which teams would you like to include in the tables?', options = player_stats['Team'].unique(), key='team_var1')
|
75 |
+
elif split_var1 == 'All':
|
76 |
+
team_var1 = player_stats.Team.values.tolist()
|
77 |
+
player_stats = player_stats[player_stats['Team'].isin(team_var1)]
|
78 |
+
player_stats_disp = player_stats.set_index('Player')
|
79 |
+
player_stats_disp = player_stats_disp.sort_values(by=['Team', 'Min'], ascending=False)
|
80 |
+
st.dataframe(player_stats_disp.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True)
|
81 |
+
st.download_button(
|
82 |
+
label="Export Prop Model",
|
83 |
+
data=convert_df_to_csv(player_stats),
|
84 |
+
file_name='AmericanNumbers_stats_export.csv',
|
85 |
+
mime='text/csv',
|
86 |
+
)
|