Multichem commited on
Commit
57edccb
·
1 Parent(s): 6c48772

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +56 -6
app.py CHANGED
@@ -36,6 +36,8 @@ 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)
@@ -78,7 +80,17 @@ def init_baselines():
78
  'Passes', 'Alt Assists', 'FT Assists', 'Assists', 'Stl', 'Blk', 'Tov', 'PF', 'DD', 'TD', 'Fantasy', 'FD_Fantasy',
79
  'Rebound%', 'Assists/Pass', 'Touch_per_min', 'Fantasy/Touch', 'FD Fantasy/Touch'], axis=1)
80
 
81
- return gamelog_table
 
 
 
 
 
 
 
 
 
 
82
 
83
  @st.cache_data(show_spinner=False)
84
  def seasonlong_build(data_sample):
@@ -179,7 +191,7 @@ def split_frame(input_df, rows):
179
  def convert_df_to_csv(df):
180
  return df.to_csv().encode('utf-8')
181
 
182
- gamelog_table = init_baselines()
183
  basic_cols = ['Player', 'Pos', 'Team', 'Opp', 'Season', 'Date', 'Matchup', 'Min']
184
  basic_season_cols = ['Pos', 'Team', 'Min']
185
  data_cols = ['Touches', 'Pts', 'FGM', 'FGA', 'FG%', 'FG3M',
@@ -196,14 +208,14 @@ indv_players = gamelog_table.drop_duplicates(subset='Player')
196
  total_players = indv_players.Player.values.tolist()
197
  total_dates = gamelog_table.Date.values.tolist()
198
 
199
- tab1, tab2, tab3 = st.tabs(['Gamelogs', 'Correlation Matrix', 'Position vs. Opp'])
200
 
201
  with tab1:
202
  col1, col2 = st.columns([1, 9])
203
  with col1:
204
  if st.button("Reset Data", key='reset1'):
205
  st.cache_data.clear()
206
- gamelog_table = init_baselines()
207
  basic_cols = ['Player', 'Pos', 'Team', 'Opp', 'Season', 'Date', 'Matchup', 'Min']
208
  basic_season_cols = ['Pos', 'Team', 'Min']
209
  data_cols = ['Touches', 'Pts', 'FGM', 'FGA', 'FG%', 'FG3M',
@@ -319,7 +331,7 @@ with tab2:
319
  with col1:
320
  if st.button("Reset Data", key='reset2'):
321
  st.cache_data.clear()
322
- gamelog_table = init_baselines()
323
  basic_cols = ['Player', 'Pos', 'Team', 'Opp', 'Season', 'Date', 'Matchup', 'Min']
324
  basic_season_cols = ['Pos', 'Team', 'Min']
325
  data_cols = ['Touches', 'Pts', 'FGM', 'FGA', 'FG%', 'FG3M',
@@ -401,7 +413,7 @@ with tab3:
401
  with col1:
402
  if st.button("Reset Data", key='reset3'):
403
  st.cache_data.clear()
404
- gamelog_table = init_baselines()
405
  basic_cols = ['Player', 'Pos', 'Team', 'Opp', 'Season', 'Date', 'Matchup', 'Min']
406
  basic_season_cols = ['Pos', 'Team', 'Min']
407
  data_cols = ['Touches', 'Pts', 'FGM', 'FGA', 'FG%', 'FG3M',
@@ -470,4 +482,42 @@ with tab3:
470
  data=convert_df_to_csv(gamelog_display),
471
  file_name='Matchups_NBA_View.csv',
472
  mime='text/csv',
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
473
  )
 
36
 
37
  NBA_Data = 'https://docs.google.com/spreadsheets/d/1Yq0vGriWK-bS79e-bD6_u9pqrYE6Yrlbb_wEkmH-ot0/edit#gid=1808117109'
38
 
39
+ percentages_format = {'PG': '{:.2%}', 'SG': '{:.2%}', 'SF': '{:.2%}', 'PF': '{:.2%}', 'C': '{:.2%}'}
40
+
41
  @st.cache_resource(ttl = 600)
42
  def init_baselines():
43
  sh = gcservice_account.open_by_url(NBA_Data)
 
80
  'Passes', 'Alt Assists', 'FT Assists', 'Assists', 'Stl', 'Blk', 'Tov', 'PF', 'DD', 'TD', 'Fantasy', 'FD_Fantasy',
81
  'Rebound%', 'Assists/Pass', 'Touch_per_min', 'Fantasy/Touch', 'FD Fantasy/Touch'], axis=1)
82
 
83
+ worksheet = sh.worksheet('Rotations')
84
+ raw_display = pd.DataFrame(worksheet.get_values())
85
+ raw_display.columns = raw_display.iloc[0]
86
+ raw_display = raw_display[1:]
87
+ raw_display = raw_display.reset_index(drop=True)
88
+ rot_table = raw_display[raw_display['Player'] != ""]
89
+ rot_table = rot_table[['Player', 'Team', 'PG', 'SG', 'SF', 'PF', 'C', 'Given Pos']]
90
+ data_cols = ['PG', 'SG', 'SF', 'PF', 'C']
91
+ rot_table[data_cols] = rot_table[data_cols].apply(pd.to_numeric, errors='coerce')
92
+
93
+ return gamelog_table, rot_table
94
 
95
  @st.cache_data(show_spinner=False)
96
  def seasonlong_build(data_sample):
 
191
  def convert_df_to_csv(df):
192
  return df.to_csv().encode('utf-8')
193
 
194
+ gamelog_table, rot_table = init_baselines()
195
  basic_cols = ['Player', 'Pos', 'Team', 'Opp', 'Season', 'Date', 'Matchup', 'Min']
196
  basic_season_cols = ['Pos', 'Team', 'Min']
197
  data_cols = ['Touches', 'Pts', 'FGM', 'FGA', 'FG%', 'FG3M',
 
208
  total_players = indv_players.Player.values.tolist()
209
  total_dates = gamelog_table.Date.values.tolist()
210
 
211
+ tab1, tab2, tab3, tab4 = st.tabs(['Gamelogs', 'Correlation Matrix', 'Position vs. Opp', 'Rotations'])
212
 
213
  with tab1:
214
  col1, col2 = st.columns([1, 9])
215
  with col1:
216
  if st.button("Reset Data", key='reset1'):
217
  st.cache_data.clear()
218
+ gamelog_table, rot_table = init_baselines()
219
  basic_cols = ['Player', 'Pos', 'Team', 'Opp', 'Season', 'Date', 'Matchup', 'Min']
220
  basic_season_cols = ['Pos', 'Team', 'Min']
221
  data_cols = ['Touches', 'Pts', 'FGM', 'FGA', 'FG%', 'FG3M',
 
331
  with col1:
332
  if st.button("Reset Data", key='reset2'):
333
  st.cache_data.clear()
334
+ gamelog_table, rot_table = init_baselines()
335
  basic_cols = ['Player', 'Pos', 'Team', 'Opp', 'Season', 'Date', 'Matchup', 'Min']
336
  basic_season_cols = ['Pos', 'Team', 'Min']
337
  data_cols = ['Touches', 'Pts', 'FGM', 'FGA', 'FG%', 'FG3M',
 
413
  with col1:
414
  if st.button("Reset Data", key='reset3'):
415
  st.cache_data.clear()
416
+ gamelog_table, rot_table = init_baselines()
417
  basic_cols = ['Player', 'Pos', 'Team', 'Opp', 'Season', 'Date', 'Matchup', 'Min']
418
  basic_season_cols = ['Pos', 'Team', 'Min']
419
  data_cols = ['Touches', 'Pts', 'FGM', 'FGA', 'FG%', 'FG3M',
 
482
  data=convert_df_to_csv(gamelog_display),
483
  file_name='Matchups_NBA_View.csv',
484
  mime='text/csv',
485
+ )
486
+
487
+ with tab4:
488
+ col1, col2 = st.columns([1, 9])
489
+ with col1:
490
+ if st.button("Reset Data", key='reset3'):
491
+ st.cache_data.clear()
492
+ gamelog_table, rot_table = init_baselines()
493
+ basic_cols = ['Player', 'Pos', 'Team', 'Opp', 'Season', 'Date', 'Matchup', 'Min']
494
+ basic_season_cols = ['Pos', 'Team', 'Min']
495
+ data_cols = ['Touches', 'Pts', 'FGM', 'FGA', 'FG%', 'FG3M',
496
+ 'FG3A', 'FG3%', 'FTM', 'FTA', 'FT%', 'OREB Chance', 'OREB', 'DREB Chance', 'DREB', 'REB Chance', 'REB',
497
+ 'Passes', 'Alt Assists', 'FT Assists', 'Assists', 'Stl', 'Blk', 'Tov', 'PF', 'DD', 'TD', 'Fantasy', 'FD_Fantasy',
498
+ 'Rebound%', 'Assists/Pass', 'Touch_per_min', 'Fantasy/Touch', 'FD Fantasy/Touch']
499
+ season_data_cols = ['Touches', 'Touch/Min', 'Pts', 'FGM', 'FGA', 'FG%', 'FG3M', 'FG3A',
500
+ 'FG3%', 'FTM', 'FTA', 'FT%', 'OREB Chance', 'OREB', 'DREB Chance', 'DREB', 'REB Chance', 'REB',
501
+ 'Passes', 'Alt Assists', 'FT Assists', 'Assists', 'Stl', 'Blk', 'Tov', 'PF', 'DD', 'TD', 'Fantasy', 'FD_Fantasy',
502
+ 'Rebound%', 'Assists/Pass', 'Fantasy/Touch', 'FD Fantasy/Touch']
503
+ indv_teams = gamelog_table.drop_duplicates(subset='Team')
504
+ total_teams = indv_teams.Team.values.tolist()
505
+ indv_players = gamelog_table.drop_duplicates(subset='Player')
506
+ total_players = indv_players.Player.values.tolist()
507
+ total_dates = gamelog_table.Date.values.tolist()
508
+
509
+ team_var4 = st.selectbox('Which team would you like to view?', options = total_teams, key='team_var4')
510
+
511
+ with col2:
512
+ working_data = rot_table
513
+ rot_display = working_data[working_data['Team'] == team_var4]
514
+ display = st.container()
515
+
516
+ rot_display = rot_display.set_index('Player')
517
+ display.dataframe(rot_display.style.format(percentages_format, precision=2), height=500, use_container_width=True)
518
+ st.download_button(
519
+ label="Export Rotations Model",
520
+ data=convert_df_to_csv(rot_display),
521
+ file_name='Rotations_NBA_View.csv',
522
+ mime='text/csv',
523
  )