James McCool commited on
Commit
adf0662
·
1 Parent(s): 8ade7a1

Implement macro statistics calculations and enhance table display options in Team Macro Tables

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +18 -2
src/streamlit_app.py CHANGED
@@ -19,6 +19,8 @@ percentages_format = {'Pts% Boost': '{:.2%}', 'Reb% Boost': '{:.2%}', 'Ast% Boos
19
 
20
  team_macro_format = {'FGM%': '{:.2%}', 'FG3M%': '{:.2%}', 'FTM%': '{:.2%}'}
21
 
 
 
22
  st.markdown("""
23
  <style>
24
  /* Tab styling */
@@ -128,13 +130,20 @@ def init_macro_tables():
128
  team_macro_frame = pd.DataFrame(team_macro_json)
129
  team_macro_frame = team_macro_frame.reset_index(drop=True)
130
  team_macro_frame = team_macro_frame[team_macro_frame['Team'] != ""]
 
 
 
 
 
131
 
132
  team_off_frame = team_macro_frame[team_macro_frame['Data'] == 'Off']
133
  team_off_frame = team_off_frame.reset_index(drop=True)
 
134
  team_off_frame = team_off_frame.apply(pd.to_numeric, errors='coerce').fillna(team_off_frame)
135
 
136
  team_def_frame = team_macro_frame[team_macro_frame['Data'] == 'Def']
137
  team_def_frame = team_def_frame.reset_index(drop=True)
 
138
  team_def_frame = team_def_frame.apply(pd.to_numeric, errors='coerce').fillna(team_def_frame)
139
 
140
  team_combo_json = requests.get(NBA_DATA + '?sheet=Team%20Combo%20Data').json()
@@ -227,11 +236,18 @@ if selected_tab == 'Team Macro Tables':
227
  st.cache_data.clear()
228
  team_off_frame, team_def_frame, team_combo_frame, team_matchup_frame = init_macro_tables()
229
  table_var2 = st.selectbox("Select Table", options=['Team Offense', 'Team Defense', 'Team Combo', 'Team Matchups'], key='table_var2')
 
230
  with col2:
231
  if table_var2 == 'Team Offense':
232
- team_macro_display = team_off_frame
 
 
 
233
  elif table_var2 == 'Team Defense':
234
- team_macro_display = team_def_frame
 
 
 
235
  elif table_var2 == 'Team Combo':
236
  team_macro_display = team_combo_frame
237
  elif table_var2 == 'Team Matchups':
 
19
 
20
  team_macro_format = {'FGM%': '{:.2%}', 'FG3M%': '{:.2%}', 'FTM%': '{:.2%}'}
21
 
22
+ macro_minutes_cols = ['Team', 'Games', 'MIN', 'FGA/m', 'FG3A/m', 'FTA/m', 'PTS/m', 'REB/m', 'AST/m', 'STL/m', 'BLK/m', 'Fantasy/m', 'FD_Fantasy/m']
23
+
24
  st.markdown("""
25
  <style>
26
  /* Tab styling */
 
130
  team_macro_frame = pd.DataFrame(team_macro_json)
131
  team_macro_frame = team_macro_frame.reset_index(drop=True)
132
  team_macro_frame = team_macro_frame[team_macro_frame['Team'] != ""]
133
+ team_macro_frame['PTS/m'] = team_macro_frame['PTS'] / team_macro_frame['MIN']
134
+ team_macro_frame['REB/m'] = team_macro_frame['REB'] / team_macro_frame['MIN']
135
+ team_macro_frame['AST/m'] = team_macro_frame['AST'] / team_macro_frame['MIN']
136
+ team_macro_frame['STL/m'] = team_macro_frame['STL'] / team_macro_frame['MIN']
137
+ team_macro_frame['BLK/m'] = team_macro_frame['BLK'] / team_macro_frame['MIN']
138
 
139
  team_off_frame = team_macro_frame[team_macro_frame['Data'] == 'Off']
140
  team_off_frame = team_off_frame.reset_index(drop=True)
141
+ team_off_frame = team_off_frame.drop(columns=['PLUS_MINUS', 'PF', 'Data'], axis=1)
142
  team_off_frame = team_off_frame.apply(pd.to_numeric, errors='coerce').fillna(team_off_frame)
143
 
144
  team_def_frame = team_macro_frame[team_macro_frame['Data'] == 'Def']
145
  team_def_frame = team_def_frame.reset_index(drop=True)
146
+ team_off_frame = team_off_frame.drop(columns=['PLUS_MINUS', 'PF', 'Data'], axis=1)
147
  team_def_frame = team_def_frame.apply(pd.to_numeric, errors='coerce').fillna(team_def_frame)
148
 
149
  team_combo_json = requests.get(NBA_DATA + '?sheet=Team%20Combo%20Data').json()
 
236
  st.cache_data.clear()
237
  team_off_frame, team_def_frame, team_combo_frame, team_matchup_frame = init_macro_tables()
238
  table_var2 = st.selectbox("Select Table", options=['Team Offense', 'Team Defense', 'Team Combo', 'Team Matchups'], key='table_var2')
239
+ display_type2 = st.selectbox("Select Display Type", options=['Minutes', 'Total'], key='display_type2')
240
  with col2:
241
  if table_var2 == 'Team Offense':
242
+ if display_type2 == 'Minutes':
243
+ team_macro_display = team_off_frame.loc[:, team_off_frame.columns.isin(macro_minutes_cols)]
244
+ elif display_type2 == 'Total':
245
+ team_macro_display = team_off_frame.loc[:, ~team_off_frame.columns.isin(macro_minutes_cols)]
246
  elif table_var2 == 'Team Defense':
247
+ if display_type2 == 'Minutes':
248
+ team_macro_display = team_def_frame.loc[:, team_def_frame.columns.isin(macro_minutes_cols)]
249
+ elif display_type2 == 'Total':
250
+ team_macro_display = team_def_frame.loc[:, ~team_def_frame.columns.isin(macro_minutes_cols)]
251
  elif table_var2 == 'Team Combo':
252
  team_macro_display = team_combo_frame
253
  elif table_var2 == 'Team Matchups':