Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -64,14 +64,15 @@ def init_baselines():
|
|
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', 'POS', 'TEAM_NAME', 'OPP_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', 'Pos', 'Team', 'Opp', 'Season', 'Date', 'Matchup', 'Min', 'Touches', 'Pts', 'FGM', 'FGA', 'FG%', 'FG3M',
|
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 |
|
@@ -117,6 +118,8 @@ def seasonlong_build(data_sample):
|
|
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) /
|
@@ -125,7 +128,7 @@ def seasonlong_build(data_sample):
|
|
125 |
|
126 |
season_long_table = season_long_table.sort_values(by='Fantasy', ascending=False)
|
127 |
|
128 |
-
season_long_table = season_long_table.set_axis(['Player', 'Pos', 'Team', 'Min', 'Touches', 'Pts', 'FGM', 'FGA', 'FG%', 'FG3M', 'FG3A',
|
129 |
'FG3%', 'FTM', 'FTA', 'FT%', 'OREB Chance', 'OREB', 'DREB Chance', 'DREB', 'REB Chance', 'REB',
|
130 |
'Passes', 'Alt Assists', 'FT Assists', 'Assists', 'Stl', 'Blk', 'Tov', 'PF', 'DD', 'TD', 'Fantasy', 'FD_Fantasy',
|
131 |
'Rebound%', 'Assists/Pass', 'Fantasy/Touch', 'FD Fantasy/Touch'], axis=1)
|
@@ -181,7 +184,7 @@ indv_players = gamelog_table.drop_duplicates(subset='Player')
|
|
181 |
total_players = indv_players.Player.values.tolist()
|
182 |
total_dates = gamelog_table.Date.values.tolist()
|
183 |
|
184 |
-
tab1, tab2 = st.tabs(['Gamelogs', 'Correlation Matrix'])
|
185 |
|
186 |
with tab1:
|
187 |
col1, col2 = st.columns([1, 9])
|
@@ -330,3 +333,65 @@ with tab2:
|
|
330 |
elif corr_var == 'Minutes':
|
331 |
corr_display = run_min_corr(gamelog_table)
|
332 |
display.dataframe(corr_display.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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['Touch_per_min'] = gamelog_table['touches'] / gamelog_table['MIN']
|
68 |
gamelog_table['Fantasy_per_touch'] = gamelog_table['Fantasy'] / gamelog_table['touches']
|
69 |
gamelog_table['FD_Fantasy_per_touch'] = gamelog_table['FD_Fantasy'] / gamelog_table['touches']
|
70 |
data_cols = gamelog_table.columns.drop(['PLAYER_NAME', 'POS', 'TEAM_NAME', 'OPP_NAME', 'SEASON_ID', 'GAME_DATE', 'MATCHUP'])
|
71 |
gamelog_table[data_cols] = gamelog_table[data_cols].apply(pd.to_numeric, errors='coerce')
|
72 |
gamelog_table['GAME_DATE'] = pd.to_datetime(gamelog_table['GAME_DATE']).dt.date
|
73 |
|
74 |
+
gamelog_table = gamelog_table.set_axis(['Player', 'Pos', 'Team', 'Opp', 'Season', 'Date', 'Matchup', 'Min', 'Touches', 'Touch/Min', 'Pts', 'FGM', 'FGA', 'FG%', 'FG3M',
|
75 |
+
'FG3A', 'FG3%', 'FTM', 'FTA', 'FT%', 'OREB Chance', 'OREB', 'DREB Chance', 'DREB', 'REB Chance', 'REB',
|
76 |
'Passes', 'Alt Assists', 'FT Assists', 'Assists', 'Stl', 'Blk', 'Tov', 'PF', 'DD', 'TD', 'Fantasy', 'FD_Fantasy',
|
77 |
'Rebound%', 'Assists/Pass', 'Fantasy/Touch', 'FD Fantasy/Touch'], axis=1)
|
78 |
|
|
|
118 |
data_sample.groupby(['Player', 'Season'], sort=False)['REB Chance'].transform('sum').astype(int))
|
119 |
season_long_table['Assists/Pass'] = (data_sample.groupby(['Player', 'Season'], sort=False)['Assists'].transform('sum').astype(int) /
|
120 |
data_sample.groupby(['Player', 'Season'], sort=False)['Passes'].transform('sum').astype(int))
|
121 |
+
season_long_table['Touch/Min'] = (data_sample.groupby(['Player', 'Season'], sort=False)['Touches'].transform('sum').astype(int) /
|
122 |
+
data_sample.groupby(['Player', 'Season'], sort=False)['Min'].transform('sum').astype(int))
|
123 |
season_long_table['Fantasy/Touch'] = (data_sample.groupby(['Player', 'Season'], sort=False)['Fantasy'].transform('sum').astype(int) /
|
124 |
data_sample.groupby(['Player', 'Season'], sort=False)['Touches'].transform('sum').astype(int))
|
125 |
season_long_table['FD Fantasy/Touch'] = (data_sample.groupby(['Player', 'Season'], sort=False)['FD_Fantasy'].transform('sum').astype(int) /
|
|
|
128 |
|
129 |
season_long_table = season_long_table.sort_values(by='Fantasy', ascending=False)
|
130 |
|
131 |
+
season_long_table = season_long_table.set_axis(['Player', 'Pos', 'Team', 'Min', 'Touches', 'Touch/Min', 'Pts', 'FGM', 'FGA', 'FG%', 'FG3M', 'FG3A',
|
132 |
'FG3%', 'FTM', 'FTA', 'FT%', 'OREB Chance', 'OREB', 'DREB Chance', 'DREB', 'REB Chance', 'REB',
|
133 |
'Passes', 'Alt Assists', 'FT Assists', 'Assists', 'Stl', 'Blk', 'Tov', 'PF', 'DD', 'TD', 'Fantasy', 'FD_Fantasy',
|
134 |
'Rebound%', 'Assists/Pass', 'Fantasy/Touch', 'FD Fantasy/Touch'], axis=1)
|
|
|
184 |
total_players = indv_players.Player.values.tolist()
|
185 |
total_dates = gamelog_table.Date.values.tolist()
|
186 |
|
187 |
+
tab1, tab2, tab3 = st.tabs(['Gamelogs', 'Correlation Matrix', 'Position vs. Opp'])
|
188 |
|
189 |
with tab1:
|
190 |
col1, col2 = st.columns([1, 9])
|
|
|
333 |
elif corr_var == 'Minutes':
|
334 |
corr_display = run_min_corr(gamelog_table)
|
335 |
display.dataframe(corr_display.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True)
|
336 |
+
|
337 |
+
with tab3:
|
338 |
+
col1, col2 = st.columns([1, 9])
|
339 |
+
with col1:
|
340 |
+
if st.button("Reset Data", key='reset3'):
|
341 |
+
st.cache_data.clear()
|
342 |
+
gamelog_table = init_baselines()
|
343 |
+
indv_teams = gamelog_table.drop_duplicates(subset='Team')
|
344 |
+
total_teams = indv_teams.Team.values.tolist()
|
345 |
+
indv_players = gamelog_table.drop_duplicates(subset='Player')
|
346 |
+
total_players = indv_players.Player.values.tolist()
|
347 |
+
total_dates = gamelog_table.Date.values.tolist()
|
348 |
+
|
349 |
+
|
350 |
+
team_var3 = st.multiselect('Which opponent would you like to view?', options = total_teams, key='team_var3')
|
351 |
+
pos_var3 = st.selectbox('Which position would you like to view?', options = ['PG', 'SG', 'SF', 'PF', 'C'], key='pos_var3')
|
352 |
+
date_var3 = st.radio("Would you like to view all dates or specific ones?", ('All', 'Specific Dates'), key='split_var3')
|
353 |
+
|
354 |
+
if date_var3 == 'Specific Dates':
|
355 |
+
low_date3 = st.date_input('Min Date:', value=None, format="YYYY-MM-DD", key='low_date3')
|
356 |
+
if low_date3 is not None:
|
357 |
+
low_date3 = pd.to_datetime(low_date3).date()
|
358 |
+
high_date3 = st.date_input('Max Date:', value=None, format="YYYY-MM-DD", key='high_date3')
|
359 |
+
if high_date3 is not None:
|
360 |
+
high_date3 = pd.to_datetime(high_date3).date()
|
361 |
+
elif split_var3 == 'All':
|
362 |
+
low_date3 = gamelog_table['Date'].min()
|
363 |
+
high_date3 = gamelog_table['Date'].max()
|
364 |
+
|
365 |
+
min_var3 = st.slider("Is there a certain minutes range you want to view?", 0, 60, (0, 60), key='min_var3')
|
366 |
+
|
367 |
+
with col2:
|
368 |
+
gamelog_table = gamelog_table[gamelog_table['Date'] >= low_date3]
|
369 |
+
gamelog_table = gamelog_table[gamelog_table['Date'] <= high_date3]
|
370 |
+
season_long_table = seasonlong_build(gamelog_table)
|
371 |
+
|
372 |
+
gamelog_table = gamelog_table[gamelog_table['Date'] >= low_date3]
|
373 |
+
gamelog_table = gamelog_table[gamelog_table['Date'] <= high_date3]
|
374 |
+
gamelog_table = gamelog_table[gamelog_table['Pos'] == pos_var3]
|
375 |
+
gamelog_table = gamelog_table[gamelog_table['Min'] >= min_var3[0]]
|
376 |
+
gamelog_table = gamelog_table[gamelog_table['Min'] <= min_var3[1]]
|
377 |
+
gamelog_table = gamelog_table[gamelog_table['Opp'].isin(team_var3)]
|
378 |
+
gamelog_display = gamelog_table.reset_index(drop=True)
|
379 |
+
display = st.container()
|
380 |
+
|
381 |
+
bottom_menu = st.columns((4, 1, 1))
|
382 |
+
with bottom_menu[2]:
|
383 |
+
batch_size = st.selectbox("Page Size", options=[25, 50, 100])
|
384 |
+
with bottom_menu[1]:
|
385 |
+
total_pages = (
|
386 |
+
int(len(gamelog_display) / batch_size) if int(len(gamelog_display) / batch_size) > 0 else 1
|
387 |
+
)
|
388 |
+
current_page = st.number_input(
|
389 |
+
"Page", min_value=1, max_value=total_pages, step=1
|
390 |
+
)
|
391 |
+
with bottom_menu[0]:
|
392 |
+
st.markdown(f"Page **{current_page}** of **{total_pages}** ")
|
393 |
+
|
394 |
+
|
395 |
+
pages = split_frame(gamelog_display, batch_size)
|
396 |
+
# pages = pages.set_index('Player')
|
397 |
+
display.dataframe(data=pages[current_page - 1].style.format(precision=2), height=500, use_container_width=True)
|