Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -34,101 +34,113 @@ def init_conn():
|
|
34 |
|
35 |
gcservice_account = init_conn()
|
36 |
|
37 |
-
|
38 |
|
39 |
@st.cache_resource(ttl = 600)
|
40 |
def init_baselines():
|
41 |
-
sh = gcservice_account.open_by_url(
|
42 |
|
43 |
worksheet = sh.worksheet('Gamelog')
|
44 |
raw_display = pd.DataFrame(worksheet.get_values())
|
45 |
raw_display.columns = raw_display.iloc[0]
|
46 |
raw_display = raw_display[1:]
|
47 |
raw_display = raw_display.reset_index(drop=True)
|
48 |
-
gamelog_table = raw_display[raw_display['
|
49 |
-
gamelog_table = gamelog_table[['
|
50 |
-
'
|
51 |
-
'
|
52 |
-
|
53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
gamelog_table[data_cols] = gamelog_table[data_cols].apply(pd.to_numeric, errors='coerce')
|
55 |
-
gamelog_table['
|
56 |
-
# gamelog_table['Shots'].replace("", 0, inplace=True)
|
57 |
-
# gamelog_table['Shots Blocked'].replace("", 0, inplace=True)
|
58 |
-
# gamelog_table['Goals'].replace("", 0, inplace=True)
|
59 |
-
# gamelog_table['Total Points'].replace("", 0, inplace=True)
|
60 |
-
# gamelog_table['Shots'] = gamelog_table['Shots'].astype(int)
|
61 |
-
# gamelog_table['Shots Blocked'] = gamelog_table['Shots Blocked'].astype(int)
|
62 |
-
# gamelog_table['Goals'] = gamelog_table['Goals'].astype(int)
|
63 |
-
# gamelog_table['Total Points'] = gamelog_table['Total Points'].astype(int)
|
64 |
-
gamelog_table['dk_shots_bonus'] = np.where((gamelog_table['Shots'] >= 5), 1, 0)
|
65 |
-
gamelog_table['dk_blocks_bonus'] = np.where((gamelog_table['Shots Blocked'] >= 3), 1, 0)
|
66 |
-
gamelog_table['dk_goals_bonus'] = np.where((gamelog_table['Goals'] >= 3), 1, 0)
|
67 |
-
gamelog_table['dk_points_bonus'] = np.where((gamelog_table['Total Points'] >= 3), 1, 0)
|
68 |
-
gamelog_table['dk_fantasy'] = sum([(gamelog_table['Goals'] * 8.5), (gamelog_table['Total Assists'] * 5), (gamelog_table['Shots'] * 1.5),
|
69 |
-
(gamelog_table['Shots Blocked'] * 1.3), (gamelog_table['dk_shots_bonus'] * 3), (gamelog_table['dk_blocks_bonus'] * 3),
|
70 |
-
(gamelog_table['dk_goals_bonus'] * 3), (gamelog_table['dk_points_bonus'] * 3)]).astype(float).round(2)
|
71 |
-
gamelog_table['fd_fantasy'] = sum([(gamelog_table['Goals'] * 12), (gamelog_table['Total Assists'] * 8), (gamelog_table['Shots'] * 1.6),
|
72 |
-
(gamelog_table['Shots Blocked'] * 1.6)]).astype(float).round(2)
|
73 |
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
'
|
78 |
-
'Major', 'Penalties Drawn', 'Giveaways', 'Takeaways', 'Hits', 'Hits Taken', 'Shots Blocked', 'Faceoffs Won',
|
79 |
-
'Faceoffs Lost', 'Faceoffs%'], axis=1)
|
80 |
|
81 |
return gamelog_table
|
82 |
|
83 |
@st.cache_data(show_spinner=False)
|
84 |
def seasonlong_build(data_sample):
|
85 |
season_long_table = data_sample[['Player', 'Team']]
|
86 |
-
season_long_table['
|
87 |
-
season_long_table['
|
88 |
-
season_long_table['
|
89 |
-
season_long_table['
|
90 |
-
season_long_table['
|
91 |
-
season_long_table['
|
92 |
-
|
93 |
-
season_long_table['
|
94 |
-
season_long_table['
|
95 |
-
season_long_table['
|
96 |
-
|
97 |
-
season_long_table['
|
98 |
-
season_long_table['
|
99 |
-
season_long_table['
|
100 |
-
|
101 |
-
season_long_table['
|
102 |
-
season_long_table['
|
103 |
-
season_long_table['
|
104 |
-
season_long_table['
|
105 |
-
season_long_table['
|
106 |
-
season_long_table['
|
107 |
-
season_long_table['
|
108 |
-
season_long_table['
|
109 |
-
season_long_table['
|
110 |
-
season_long_table['
|
111 |
-
season_long_table['
|
112 |
-
season_long_table['
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
113 |
season_long_table = season_long_table.drop_duplicates(subset='Player')
|
114 |
|
115 |
-
season_long_table = season_long_table.set_axis(['Player', 'Team', '
|
116 |
-
'
|
117 |
-
'
|
118 |
-
'
|
119 |
|
120 |
return season_long_table
|
121 |
|
122 |
@st.cache_data(show_spinner=False)
|
123 |
def run_fantasy_corr(data_sample):
|
124 |
cor_testing = data_sample
|
|
|
125 |
date_list = cor_testing['Date'].unique().tolist()
|
126 |
player_list = cor_testing['Player'].unique().tolist()
|
127 |
corr_frame = pd.DataFrame()
|
128 |
corr_frame['DATE'] = date_list
|
129 |
for player in player_list:
|
130 |
player_testing = cor_testing[cor_testing['Player'] == player]
|
131 |
-
fantasy_map = dict(zip(player_testing['Date'], player_testing['
|
132 |
corr_frame[player] = corr_frame['DATE'].map(fantasy_map)
|
133 |
players_fantasy = corr_frame.drop('DATE', axis=1)
|
134 |
corrM = players_fantasy.corr()
|
@@ -138,13 +150,14 @@ def run_fantasy_corr(data_sample):
|
|
138 |
@st.cache_data(show_spinner=False)
|
139 |
def run_min_corr(data_sample):
|
140 |
cor_testing = data_sample
|
|
|
141 |
date_list = cor_testing['Date'].unique().tolist()
|
142 |
player_list = cor_testing['Player'].unique().tolist()
|
143 |
corr_frame = pd.DataFrame()
|
144 |
corr_frame['DATE'] = date_list
|
145 |
for player in player_list:
|
146 |
player_testing = cor_testing[cor_testing['Player'] == player]
|
147 |
-
fantasy_map = dict(zip(player_testing['Date'], player_testing['
|
148 |
corr_frame[player] = corr_frame['DATE'].map(fantasy_map)
|
149 |
players_fantasy = corr_frame.drop('DATE', axis=1)
|
150 |
corrM = players_fantasy.corr()
|
@@ -191,10 +204,10 @@ with tab1:
|
|
191 |
split_var3 = st.radio("Would you like to view all dates or specific ones?", ('All', 'Specific Dates'), key='split_var3')
|
192 |
|
193 |
if split_var3 == 'Specific Dates':
|
194 |
-
low_date = st.date_input('Min Date:', value=None, format="MM
|
195 |
if low_date is not None:
|
196 |
low_date = pd.to_datetime(low_date).date()
|
197 |
-
high_date = st.date_input('Max Date:', value=None, format="MM
|
198 |
if high_date is not None:
|
199 |
high_date = pd.to_datetime(high_date).date()
|
200 |
elif split_var3 == 'All':
|
@@ -208,15 +221,15 @@ with tab1:
|
|
208 |
elif split_var4 == 'All':
|
209 |
player_var1 = total_players
|
210 |
|
211 |
-
min_var1 = st.slider("Is there a certain
|
212 |
|
213 |
with col2:
|
214 |
if split_var1 == 'Season Logs':
|
215 |
display = st.container()
|
216 |
gamelog_table = gamelog_table[gamelog_table['Date'] >= low_date]
|
217 |
gamelog_table = gamelog_table[gamelog_table['Date'] <= high_date]
|
218 |
-
gamelog_table = gamelog_table[gamelog_table['
|
219 |
-
gamelog_table = gamelog_table[gamelog_table['
|
220 |
gamelog_table = gamelog_table[gamelog_table['Team'].isin(team_var1)]
|
221 |
gamelog_table = gamelog_table[gamelog_table['Player'].isin(player_var1)]
|
222 |
season_long_table = seasonlong_build(gamelog_table)
|
@@ -226,8 +239,8 @@ with tab1:
|
|
226 |
elif split_var1 == 'Gamelogs':
|
227 |
gamelog_table = gamelog_table[gamelog_table['Date'] >= low_date]
|
228 |
gamelog_table = gamelog_table[gamelog_table['Date'] <= high_date]
|
229 |
-
gamelog_table = gamelog_table[gamelog_table['
|
230 |
-
gamelog_table = gamelog_table[gamelog_table['
|
231 |
gamelog_table = gamelog_table[gamelog_table['Team'].isin(team_var1)]
|
232 |
gamelog_table = gamelog_table[gamelog_table['Player'].isin(player_var1)]
|
233 |
gamelog_table = gamelog_table.reset_index(drop=True)
|
@@ -263,7 +276,7 @@ with tab2:
|
|
263 |
total_players = indv_players.Player.values.tolist()
|
264 |
total_dates = gamelog_table.Date.values.tolist()
|
265 |
|
266 |
-
corr_var = st.radio("Are you correlating fantasy or
|
267 |
|
268 |
split_var1_t2 = st.radio("Would you like to view specific teams or specific players?", ('Specific Teams', 'Specific Players'), key='split_var1_t2')
|
269 |
|
@@ -275,17 +288,17 @@ with tab2:
|
|
275 |
split_var2_t2 = st.radio("Would you like to view all dates or specific ones?", ('All', 'Specific Dates'), key='split_var3_t2')
|
276 |
|
277 |
if split_var2_t2 == 'Specific Dates':
|
278 |
-
low_date_t2 = st.date_input('Min Date:', value=None, format="MM
|
279 |
if low_date_t2 is not None:
|
280 |
low_date_t2 = pd.to_datetime(low_date_t2).date()
|
281 |
-
high_date_t2 = st.date_input('Max Date:', value=None, format="MM
|
282 |
if high_date_t2 is not None:
|
283 |
high_date_t2 = pd.to_datetime(high_date_t2).date()
|
284 |
elif split_var2_t2 == 'All':
|
285 |
low_date_t2 = gamelog_table['Date'].min()
|
286 |
high_date_t2 = gamelog_table['Date'].max()
|
287 |
|
288 |
-
min_var1_t2 = st.slider("Is there a certain minutes range you want to view?", 0,
|
289 |
|
290 |
with col2:
|
291 |
if split_var1_t2 == 'Specific Teams':
|
@@ -293,12 +306,12 @@ with tab2:
|
|
293 |
gamelog_table = gamelog_table.sort_values(by='Fantasy', ascending=False)
|
294 |
gamelog_table = gamelog_table[gamelog_table['Date'] >= low_date_t2]
|
295 |
gamelog_table = gamelog_table[gamelog_table['Date'] <= high_date_t2]
|
296 |
-
gamelog_table = gamelog_table[gamelog_table['
|
297 |
-
gamelog_table = gamelog_table[gamelog_table['
|
298 |
gamelog_table = gamelog_table[gamelog_table['Team'].isin(corr_var1_t2)]
|
299 |
if corr_var == 'Fantasy':
|
300 |
corr_display = run_fantasy_corr(gamelog_table)
|
301 |
-
elif corr_var == '
|
302 |
corr_display = run_min_corr(gamelog_table)
|
303 |
display.dataframe(corr_display.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), height=1000, use_container_width = True)
|
304 |
|
@@ -307,11 +320,11 @@ with tab2:
|
|
307 |
gamelog_table = gamelog_table.sort_values(by='Fantasy', ascending=False)
|
308 |
gamelog_table = gamelog_table[gamelog_table['Date'] >= low_date_t2]
|
309 |
gamelog_table = gamelog_table[gamelog_table['Date'] <= high_date_t2]
|
310 |
-
gamelog_table = gamelog_table[gamelog_table['
|
311 |
-
gamelog_table = gamelog_table[gamelog_table['
|
312 |
gamelog_table = gamelog_table[gamelog_table['Player'].isin(corr_var1_t2)]
|
313 |
if corr_var == 'Fantasy':
|
314 |
corr_display = run_fantasy_corr(gamelog_table)
|
315 |
-
elif corr_var == '
|
316 |
corr_display = run_min_corr(gamelog_table)
|
317 |
display.dataframe(corr_display.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True)
|
|
|
34 |
|
35 |
gcservice_account = init_conn()
|
36 |
|
37 |
+
NBA_Data = 'https://docs.google.com/spreadsheets/d/1Yq0vGriWK-bS79e-bD6_u9pqrYE6Yrlbb_wEkmH-ot0/edit#gid=1808117109'
|
38 |
|
39 |
@st.cache_resource(ttl = 600)
|
40 |
def init_baselines():
|
41 |
+
sh = gcservice_account.open_by_url(NBA_Data)
|
42 |
|
43 |
worksheet = sh.worksheet('Gamelog')
|
44 |
raw_display = pd.DataFrame(worksheet.get_values())
|
45 |
raw_display.columns = raw_display.iloc[0]
|
46 |
raw_display = raw_display[1:]
|
47 |
raw_display = raw_display.reset_index(drop=True)
|
48 |
+
gamelog_table = raw_display[raw_display['PLAYER_NAME'] != ""]
|
49 |
+
gamelog_table = gamelog_table[['PLAYER_NAME', 'TEAM_NAME', 'SEASON_ID', 'GAME_DATE', 'MATCHUP', 'MIN', 'touches', 'PTS', 'FGM', 'FGA', 'FG_PCT', 'FG3M', 'FG3A',
|
50 |
+
'FG3_PCT', 'FTM', 'FTA', 'FT_PCT', 'reboundChancesOffensive', 'OREB', 'reboundChancesDefensive', 'DREB', 'reboundChancesTotal', 'REB',
|
51 |
+
'passes', 'secondaryAssists', 'freeThrowAssists', 'assists', 'STL', 'BLK', 'TOV', 'PF', 'DD', 'TD', 'Fantasy', 'FD_Fantasy']]
|
52 |
+
gamelog_table['assists'].replace("", 0, inplace=True)
|
53 |
+
gamelog_table['reboundChancesTotal'].replace("", 0, inplace=True)
|
54 |
+
gamelog_table['passes'].replace("", 0, inplace=True)
|
55 |
+
gamelog_table['touches'].replace("", 0, inplace=True)
|
56 |
+
gamelog_table['Fantasy'].replace("", 0, inplace=True)
|
57 |
+
gamelog_table['FD_Fantasy'].replace("", 0, inplace=True)
|
58 |
+
gamelog_table['REB'] = gamelog_table['REB'].astype(int)
|
59 |
+
gamelog_table['assists'] = gamelog_table['assists'].astype(int)
|
60 |
+
gamelog_table['reboundChancesTotal'] = gamelog_table['reboundChancesTotal'].astype(int)
|
61 |
+
gamelog_table['passes'] = gamelog_table['passes'].astype(int)
|
62 |
+
gamelog_table['touches'] = gamelog_table['touches'].astype(int)
|
63 |
+
gamelog_table['Fantasy'] = gamelog_table['Fantasy'].astype(float)
|
64 |
+
gamelog_table['FD_Fantasy'] = gamelog_table['FD_Fantasy'].astype(float)
|
65 |
+
gamelog_table['rebound%'] = gamelog_table['REB'] / gamelog_table['reboundChancesTotal']
|
66 |
+
gamelog_table['assists_per_pass'] = gamelog_table['assists'] / gamelog_table['passes']
|
67 |
+
gamelog_table['Fantasy_per_touch'] = gamelog_table['Fantasy'] / gamelog_table['touches']
|
68 |
+
gamelog_table['FD_Fantasy_per_touch'] = gamelog_table['FD_Fantasy'] / gamelog_table['touches']
|
69 |
+
data_cols = gamelog_table.columns.drop(['PLAYER_NAME', 'TEAM_NAME', 'SEASON_ID', 'GAME_DATE', 'MATCHUP'])
|
70 |
gamelog_table[data_cols] = gamelog_table[data_cols].apply(pd.to_numeric, errors='coerce')
|
71 |
+
gamelog_table['GAME_DATE'] = pd.to_datetime(gamelog_table['GAME_DATE']).dt.date
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
|
73 |
+
gamelog_table = gamelog_table.set_axis(['Player', 'Team', 'Season', 'Date', 'Matchup', 'Min', 'Touches', 'Pts', 'FGM', 'FGA', 'FG%', 'FG3M', 'FG3A',
|
74 |
+
'FG3%', 'FTM', 'FTA', 'FT%', 'OREB Chance', 'OREB', 'DREB Chance', 'DREB', 'REB Chance', 'REB',
|
75 |
+
'Passes', 'Alt Assists', 'FT Assists', 'Assists', 'Stl', 'Blk', 'Tov', 'PF', 'DD', 'TD', 'Fantasy', 'FD_Fantasy',
|
76 |
+
'Rebound%', 'Assists/Pass', 'Fantasy/Touch', 'FD Fantasy/Touch'], axis=1)
|
|
|
|
|
77 |
|
78 |
return gamelog_table
|
79 |
|
80 |
@st.cache_data(show_spinner=False)
|
81 |
def seasonlong_build(data_sample):
|
82 |
season_long_table = data_sample[['Player', 'Team']]
|
83 |
+
season_long_table['Min'] = data_sample.groupby(['Player', 'Season'], sort=False)['Min'].transform('mean').astype(float)
|
84 |
+
season_long_table['Touches'] = data_sample.groupby(['Player', 'Season'], sort=False)['Touches'].transform('mean').astype(float)
|
85 |
+
season_long_table['Pts'] = data_sample.groupby(['Player', 'Season'], sort=False)['Pts'].transform('mean').astype(float)
|
86 |
+
season_long_table['FGM'] = data_sample.groupby(['Player', 'Season'], sort=False)['FGM'].transform('mean').astype(float)
|
87 |
+
season_long_table['FGA'] = data_sample.groupby(['Player', 'Season'], sort=False)['FGA'].transform('mean').astype(float)
|
88 |
+
season_long_table['FG%'] = (data_sample.groupby(['Player', 'Season'], sort=False)['FGM'].transform('sum').astype(int) /
|
89 |
+
data_sample.groupby(['Player', 'Season'], sort=False)['FGA'].transform('sum').astype(int))
|
90 |
+
season_long_table['FG3M'] = data_sample.groupby(['Player', 'Season'], sort=False)['FG3M'].transform('mean').astype(float)
|
91 |
+
season_long_table['FG3A'] = data_sample.groupby(['Player', 'Season'], sort=False)['FG3A'].transform('mean').astype(float)
|
92 |
+
season_long_table['FG3%'] = (data_sample.groupby(['Player', 'Season'], sort=False)['FG3M'].transform('sum').astype(int) /
|
93 |
+
data_sample.groupby(['Player', 'Season'], sort=False)['FG3A'].transform('sum').astype(int))
|
94 |
+
season_long_table['FTM'] = data_sample.groupby(['Player', 'Season'], sort=False)['FTM'].transform('mean').astype(float)
|
95 |
+
season_long_table['FTA'] = data_sample.groupby(['Player', 'Season'], sort=False)['FTA'].transform('mean').astype(float)
|
96 |
+
season_long_table['FT%'] = (data_sample.groupby(['Player', 'Season'], sort=False)['FTM'].transform('sum').astype(int) /
|
97 |
+
data_sample.groupby(['Player', 'Season'], sort=False)['FTA'].transform('sum').astype(int))
|
98 |
+
season_long_table['OREB Chance'] = data_sample.groupby(['Player', 'Season'], sort=False)['OREB Chance'].transform('mean').astype(float)
|
99 |
+
season_long_table['OREB'] = data_sample.groupby(['Player', 'Season'], sort=False)['OREB'].transform('mean').astype(float)
|
100 |
+
season_long_table['DREB Chance'] = data_sample.groupby(['Player', 'Season'], sort=False)['DREB Chance'].transform('mean').astype(float)
|
101 |
+
season_long_table['DREB'] = data_sample.groupby(['Player', 'Season'], sort=False)['DREB'].transform('mean').astype(float)
|
102 |
+
season_long_table['REB Chance'] = data_sample.groupby(['Player', 'Season'], sort=False)['REB Chance'].transform('mean').astype(float)
|
103 |
+
season_long_table['REB'] = data_sample.groupby(['Player', 'Season'], sort=False)['REB'].transform('mean').astype(float)
|
104 |
+
season_long_table['Passes'] = data_sample.groupby(['Player', 'Season'], sort=False)['Passes'].transform('mean').astype(float)
|
105 |
+
season_long_table['Alt Assists'] = data_sample.groupby(['Player', 'Season'], sort=False)['Alt Assists'].transform('mean').astype(float)
|
106 |
+
season_long_table['FT Assists'] = data_sample.groupby(['Player', 'Season'], sort=False)['FT Assists'].transform('mean').astype(float)
|
107 |
+
season_long_table['Assists'] = data_sample.groupby(['Player', 'Season'], sort=False)['Assists'].transform('mean').astype(float)
|
108 |
+
season_long_table['Stl'] = data_sample.groupby(['Player', 'Season'], sort=False)['Stl'].transform('mean').astype(float)
|
109 |
+
season_long_table['Blk'] = data_sample.groupby(['Player', 'Season'], sort=False)['Blk'].transform('mean').astype(float)
|
110 |
+
season_long_table['Tov'] = data_sample.groupby(['Player', 'Season'], sort=False)['Tov'].transform('mean').astype(float)
|
111 |
+
season_long_table['PF'] = data_sample.groupby(['Player', 'Season'], sort=False)['PF'].transform('mean').astype(float)
|
112 |
+
season_long_table['DD'] = data_sample.groupby(['Player', 'Season'], sort=False)['DD'].transform('mean').astype(float)
|
113 |
+
season_long_table['TD'] = data_sample.groupby(['Player', 'Season'], sort=False)['TD'].transform('mean').astype(float)
|
114 |
+
season_long_table['Fantasy'] = data_sample.groupby(['Player', 'Season'], sort=False)['Fantasy'].transform('mean').astype(float)
|
115 |
+
season_long_table['FD_Fantasy'] = data_sample.groupby(['Player', 'Season'], sort=False)['FD_Fantasy'].transform('mean').astype(float)
|
116 |
+
season_long_table['Rebound%'] = (data_sample.groupby(['Player', 'Season'], sort=False)['REB'].transform('sum').astype(int) /
|
117 |
+
data_sample.groupby(['Player', 'Season'], sort=False)['REB Chance'].transform('sum').astype(int))
|
118 |
+
season_long_table['Assists/Pass'] = (data_sample.groupby(['Player', 'Season'], sort=False)['Assists'].transform('sum').astype(int) /
|
119 |
+
data_sample.groupby(['Player', 'Season'], sort=False)['Passes'].transform('sum').astype(int))
|
120 |
+
season_long_table['Fantasy/Touch'] = (data_sample.groupby(['Player', 'Season'], sort=False)['Fantasy'].transform('sum').astype(int) /
|
121 |
+
data_sample.groupby(['Player', 'Season'], sort=False)['Touches'].transform('sum').astype(int))
|
122 |
+
season_long_table['FD Fantasy/Touch'] = (data_sample.groupby(['Player', 'Season'], sort=False)['FD_Fantasy'].transform('sum').astype(int) /
|
123 |
+
data_sample.groupby(['Player', 'Season'], sort=False)['Touches'].transform('sum').astype(int))
|
124 |
season_long_table = season_long_table.drop_duplicates(subset='Player')
|
125 |
|
126 |
+
season_long_table = season_long_table.set_axis(['Player', 'Team', 'Min', 'Touches', 'Pts', 'FGM', 'FGA', 'FG%', 'FG3M', 'FG3A',
|
127 |
+
'FG3%', 'FTM', 'FTA', 'FT%', 'OREB Chance', 'OREB', 'DREB Chance', 'DREB', 'REB Chance', 'REB',
|
128 |
+
'Passes', 'Alt Assists', 'FT Assists', 'Assists', 'Stl', 'Blk', 'Tov', 'PF', 'DD', 'TD', 'Fantasy', 'FD_Fantasy',
|
129 |
+
'Rebound%', 'Assists/Pass', 'Fantasy/Touch', 'FD Fantasy/Touch'], axis=1)
|
130 |
|
131 |
return season_long_table
|
132 |
|
133 |
@st.cache_data(show_spinner=False)
|
134 |
def run_fantasy_corr(data_sample):
|
135 |
cor_testing = data_sample
|
136 |
+
cor_testing = cor_testing[cor_testing['Season'] == '22023']
|
137 |
date_list = cor_testing['Date'].unique().tolist()
|
138 |
player_list = cor_testing['Player'].unique().tolist()
|
139 |
corr_frame = pd.DataFrame()
|
140 |
corr_frame['DATE'] = date_list
|
141 |
for player in player_list:
|
142 |
player_testing = cor_testing[cor_testing['Player'] == player]
|
143 |
+
fantasy_map = dict(zip(player_testing['Date'], player_testing['Fantasy']))
|
144 |
corr_frame[player] = corr_frame['DATE'].map(fantasy_map)
|
145 |
players_fantasy = corr_frame.drop('DATE', axis=1)
|
146 |
corrM = players_fantasy.corr()
|
|
|
150 |
@st.cache_data(show_spinner=False)
|
151 |
def run_min_corr(data_sample):
|
152 |
cor_testing = data_sample
|
153 |
+
cor_testing = cor_testing[cor_testing['Season'] == '22023']
|
154 |
date_list = cor_testing['Date'].unique().tolist()
|
155 |
player_list = cor_testing['Player'].unique().tolist()
|
156 |
corr_frame = pd.DataFrame()
|
157 |
corr_frame['DATE'] = date_list
|
158 |
for player in player_list:
|
159 |
player_testing = cor_testing[cor_testing['Player'] == player]
|
160 |
+
fantasy_map = dict(zip(player_testing['Date'], player_testing['Min']))
|
161 |
corr_frame[player] = corr_frame['DATE'].map(fantasy_map)
|
162 |
players_fantasy = corr_frame.drop('DATE', axis=1)
|
163 |
corrM = players_fantasy.corr()
|
|
|
204 |
split_var3 = st.radio("Would you like to view all dates or specific ones?", ('All', 'Specific Dates'), key='split_var3')
|
205 |
|
206 |
if split_var3 == 'Specific Dates':
|
207 |
+
low_date = st.date_input('Min Date:', value=None, format="YYYY-MM-DD", key='low_date')
|
208 |
if low_date is not None:
|
209 |
low_date = pd.to_datetime(low_date).date()
|
210 |
+
high_date = st.date_input('Max Date:', value=None, format="YYYY-MM-DD", key='high_date')
|
211 |
if high_date is not None:
|
212 |
high_date = pd.to_datetime(high_date).date()
|
213 |
elif split_var3 == 'All':
|
|
|
221 |
elif split_var4 == 'All':
|
222 |
player_var1 = total_players
|
223 |
|
224 |
+
min_var1 = st.slider("Is there a certain minutes range you want to view?", 0, 60, (0, 60), key='min_var1')
|
225 |
|
226 |
with col2:
|
227 |
if split_var1 == 'Season Logs':
|
228 |
display = st.container()
|
229 |
gamelog_table = gamelog_table[gamelog_table['Date'] >= low_date]
|
230 |
gamelog_table = gamelog_table[gamelog_table['Date'] <= high_date]
|
231 |
+
gamelog_table = gamelog_table[gamelog_table['Min'] >= min_var1[0]]
|
232 |
+
gamelog_table = gamelog_table[gamelog_table['Min'] <= min_var1[1]]
|
233 |
gamelog_table = gamelog_table[gamelog_table['Team'].isin(team_var1)]
|
234 |
gamelog_table = gamelog_table[gamelog_table['Player'].isin(player_var1)]
|
235 |
season_long_table = seasonlong_build(gamelog_table)
|
|
|
239 |
elif split_var1 == 'Gamelogs':
|
240 |
gamelog_table = gamelog_table[gamelog_table['Date'] >= low_date]
|
241 |
gamelog_table = gamelog_table[gamelog_table['Date'] <= high_date]
|
242 |
+
gamelog_table = gamelog_table[gamelog_table['Min'] >= min_var1[0]]
|
243 |
+
gamelog_table = gamelog_table[gamelog_table['Min'] <= min_var1[1]]
|
244 |
gamelog_table = gamelog_table[gamelog_table['Team'].isin(team_var1)]
|
245 |
gamelog_table = gamelog_table[gamelog_table['Player'].isin(player_var1)]
|
246 |
gamelog_table = gamelog_table.reset_index(drop=True)
|
|
|
276 |
total_players = indv_players.Player.values.tolist()
|
277 |
total_dates = gamelog_table.Date.values.tolist()
|
278 |
|
279 |
+
corr_var = st.radio("Are you correlating fantasy or minutes?", ('Fantasy', 'Minutes'), key='corr_var')
|
280 |
|
281 |
split_var1_t2 = st.radio("Would you like to view specific teams or specific players?", ('Specific Teams', 'Specific Players'), key='split_var1_t2')
|
282 |
|
|
|
288 |
split_var2_t2 = st.radio("Would you like to view all dates or specific ones?", ('All', 'Specific Dates'), key='split_var3_t2')
|
289 |
|
290 |
if split_var2_t2 == 'Specific Dates':
|
291 |
+
low_date_t2 = st.date_input('Min Date:', value=None, format="YYYY-MM-DD", key='low_date_t2')
|
292 |
if low_date_t2 is not None:
|
293 |
low_date_t2 = pd.to_datetime(low_date_t2).date()
|
294 |
+
high_date_t2 = st.date_input('Max Date:', value=None, format="YYYY-MM-DD", key='high_date_t2')
|
295 |
if high_date_t2 is not None:
|
296 |
high_date_t2 = pd.to_datetime(high_date_t2).date()
|
297 |
elif split_var2_t2 == 'All':
|
298 |
low_date_t2 = gamelog_table['Date'].min()
|
299 |
high_date_t2 = gamelog_table['Date'].max()
|
300 |
|
301 |
+
min_var1_t2 = st.slider("Is there a certain minutes range you want to view?", 0, 60, (0, 60), key='min_var1_t2')
|
302 |
|
303 |
with col2:
|
304 |
if split_var1_t2 == 'Specific Teams':
|
|
|
306 |
gamelog_table = gamelog_table.sort_values(by='Fantasy', ascending=False)
|
307 |
gamelog_table = gamelog_table[gamelog_table['Date'] >= low_date_t2]
|
308 |
gamelog_table = gamelog_table[gamelog_table['Date'] <= high_date_t2]
|
309 |
+
gamelog_table = gamelog_table[gamelog_table['Min'] >= min_var1_t2[0]]
|
310 |
+
gamelog_table = gamelog_table[gamelog_table['Min'] <= min_var1_t2[1]]
|
311 |
gamelog_table = gamelog_table[gamelog_table['Team'].isin(corr_var1_t2)]
|
312 |
if corr_var == 'Fantasy':
|
313 |
corr_display = run_fantasy_corr(gamelog_table)
|
314 |
+
elif corr_var == 'Minutes':
|
315 |
corr_display = run_min_corr(gamelog_table)
|
316 |
display.dataframe(corr_display.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), height=1000, use_container_width = True)
|
317 |
|
|
|
320 |
gamelog_table = gamelog_table.sort_values(by='Fantasy', ascending=False)
|
321 |
gamelog_table = gamelog_table[gamelog_table['Date'] >= low_date_t2]
|
322 |
gamelog_table = gamelog_table[gamelog_table['Date'] <= high_date_t2]
|
323 |
+
gamelog_table = gamelog_table[gamelog_table['Min'] >= min_var1_t2[0]]
|
324 |
+
gamelog_table = gamelog_table[gamelog_table['Min'] <= min_var1_t2[1]]
|
325 |
gamelog_table = gamelog_table[gamelog_table['Player'].isin(corr_var1_t2)]
|
326 |
if corr_var == 'Fantasy':
|
327 |
corr_display = run_fantasy_corr(gamelog_table)
|
328 |
+
elif corr_var == 'Minutes':
|
329 |
corr_display = run_min_corr(gamelog_table)
|
330 |
display.dataframe(corr_display.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True)
|