Multichem commited on
Commit
1b37964
·
1 Parent(s): d9ad3e8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -20
app.py CHANGED
@@ -69,52 +69,62 @@ def init_baselines():
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
 
 
 
 
 
 
72
  return gamelog_table
73
 
74
  @st.cache_data(show_spinner=False)
75
  def seasonlong_build(data_sample):
76
  season_long_table = data_sample[['PLAYER_NAME', 'TEAM_NAME']]
77
- season_long_table['MIN'] = data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['MIN'].transform('mean').astype(float)
78
- season_long_table['touches'] = data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['touches'].transform('mean').astype(float)
79
  season_long_table['FGM'] = data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['FGM'].transform('mean').astype(float)
80
  season_long_table['FGA'] = data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['FGA'].transform('mean').astype(float)
81
- season_long_table['FG_PCT'] = (data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['FGM'].transform('sum').astype(int) /
82
  data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['FGA'].transform('sum').astype(int))
83
  season_long_table['FG3M'] = data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['FG3M'].transform('mean').astype(float)
84
  season_long_table['FG3A'] = data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['FG3A'].transform('mean').astype(float)
85
- season_long_table['FG3_PCT'] = (data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['FG3M'].transform('sum').astype(int) /
86
  data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['FG3A'].transform('sum').astype(int))
87
  season_long_table['FTM'] = data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['FTM'].transform('mean').astype(float)
88
  season_long_table['FTA'] = data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['FTA'].transform('mean').astype(float)
89
- season_long_table['FT_PCT'] = (data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['FTM'].transform('sum').astype(int) /
90
  data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['FTA'].transform('sum').astype(int))
91
- season_long_table['reboundChancesOffensive'] = data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['reboundChancesOffensive'].transform('mean').astype(float)
92
  season_long_table['OREB'] = data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['OREB'].transform('mean').astype(float)
93
- season_long_table['reboundChancesDefensive'] = data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['reboundChancesDefensive'].transform('mean').astype(float)
94
  season_long_table['DREB'] = data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['DREB'].transform('mean').astype(float)
95
- season_long_table['reboundChancesTotal'] = data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['reboundChancesTotal'].transform('mean').astype(float)
96
  season_long_table['REB'] = data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['REB'].transform('mean').astype(float)
97
- season_long_table['passes'] = data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['passes'].transform('mean').astype(float)
98
- season_long_table['secondaryAssists'] = data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['secondaryAssists'].transform('mean').astype(float)
99
- season_long_table['freeThrowAssists'] = data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['freeThrowAssists'].transform('mean').astype(float)
100
- season_long_table['assists'] = data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['assists'].transform('mean').astype(float)
101
- season_long_table['STL'] = data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['STL'].transform('mean').astype(float)
102
- season_long_table['BLK'] = data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['BLK'].transform('mean').astype(float)
103
- season_long_table['TOV'] = data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['TOV'].transform('mean').astype(float)
104
  season_long_table['PF'] = data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['PF'].transform('mean').astype(float)
105
  season_long_table['DD'] = data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['DD'].transform('mean').astype(float)
106
  season_long_table['TD'] = data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['TD'].transform('mean').astype(float)
107
  season_long_table['Fantasy'] = data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['Fantasy'].transform('mean').astype(float)
108
  season_long_table['FD_Fantasy'] = data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['FD_Fantasy'].transform('mean').astype(float)
109
- season_long_table['rebound%'] = (data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['REB'].transform('sum').astype(int) /
110
  data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['reboundChancesTotal'].transform('sum').astype(int))
111
- season_long_table['assists_per_pass'] = (data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['assists'].transform('sum').astype(int) /
112
  data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['passes'].transform('sum').astype(int))
113
- season_long_table['Fantasy_per_touch'] = (data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['Fantasy'].transform('sum').astype(int) /
114
  data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['touches'].transform('sum').astype(int))
115
- season_long_table['FD_Fantasy_per_touch'] = (data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['FD_Fantasy'].transform('sum').astype(int) /
116
  data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['touches'].transform('sum').astype(int))
117
  season_long_table = season_long_table.drop_duplicates(subset='PLAYER_NAME')
 
 
 
 
 
118
 
119
  return season_long_table
120
 
@@ -127,17 +137,26 @@ def convert_df_to_csv(df):
127
  return df.to_csv().encode('utf-8')
128
 
129
  gamelog_table = init_baselines()
 
130
 
131
  col1, col2 = st.columns([1, 9])
132
  with col1:
133
  if st.button("Reset Data", key='reset1'):
134
  st.cache_data.clear()
135
  gamelog_table = init_baselines()
 
136
  split_var1 = st.radio("What table would you like to view?", ('Season Logs', 'Gamelogs'), key='split_var1')
 
 
 
 
 
 
137
 
138
  with col2:
139
  if split_var1 == 'Season Logs':
140
  display = st.container()
 
141
  season_long_table = seasonlong_build(gamelog_table)
142
  display.dataframe(season_long_table.style.format(precision=2), use_container_width = True)
143
 
@@ -156,6 +175,6 @@ with col2:
156
  )
157
  with bottom_menu[0]:
158
  st.markdown(f"Page **{current_page}** of **{total_pages}** ")
159
-
160
  pages = split_frame(gamelog_table, batch_size)
161
  display.dataframe(data=pages[current_page - 1].style.format(precision=2), use_container_width=True)
 
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
 
72
+ gamelog_table = gamelog_table.set_axis(['Player', 'Team', 'Season', 'Date', 'Matchup', 'Min', 'Touches', 'Pts', 'FGM', 'FGA', 'FG%', 'FG3M', 'FG3A',
73
+ 'FG3%', 'FTM', 'FTA', 'FT%', 'OREB Chance', 'OREB', 'DREB Chance', 'DREB', 'REB Chance', 'REB',
74
+ 'Passes', 'Alt Assists', 'FT Assists', 'Assists', 'Stl', 'Blk', 'Tov', 'PF', 'DD', 'TD', 'Fantasy', 'FD_Fantasy',
75
+ 'Rebound%', 'Assists/Pass', 'Fantasy/Touch', 'FD Fantasy/Touch'], axis=1)
76
+
77
  return gamelog_table
78
 
79
  @st.cache_data(show_spinner=False)
80
  def seasonlong_build(data_sample):
81
  season_long_table = data_sample[['PLAYER_NAME', 'TEAM_NAME']]
82
+ season_long_table['Min'] = data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['Min'].transform('mean').astype(float)
83
+ season_long_table['Touches'] = data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['Touches'].transform('mean').astype(float)
84
  season_long_table['FGM'] = data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['FGM'].transform('mean').astype(float)
85
  season_long_table['FGA'] = data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['FGA'].transform('mean').astype(float)
86
+ season_long_table['FG%'] = (data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['FGM'].transform('sum').astype(int) /
87
  data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['FGA'].transform('sum').astype(int))
88
  season_long_table['FG3M'] = data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['FG3M'].transform('mean').astype(float)
89
  season_long_table['FG3A'] = data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['FG3A'].transform('mean').astype(float)
90
+ season_long_table['FG3%'] = (data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['FG3M'].transform('sum').astype(int) /
91
  data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['FG3A'].transform('sum').astype(int))
92
  season_long_table['FTM'] = data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['FTM'].transform('mean').astype(float)
93
  season_long_table['FTA'] = data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['FTA'].transform('mean').astype(float)
94
+ season_long_table['FT%'] = (data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['FTM'].transform('sum').astype(int) /
95
  data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['FTA'].transform('sum').astype(int))
96
+ season_long_table['OREB Chance'] = data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['OREB Chance'].transform('mean').astype(float)
97
  season_long_table['OREB'] = data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['OREB'].transform('mean').astype(float)
98
+ season_long_table['DREB Chance'] = data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['DREB Chance'].transform('mean').astype(float)
99
  season_long_table['DREB'] = data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['DREB'].transform('mean').astype(float)
100
+ season_long_table['REB Chance'] = data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['REB Chance'].transform('mean').astype(float)
101
  season_long_table['REB'] = data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['REB'].transform('mean').astype(float)
102
+ season_long_table['Passes'] = data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['Passes'].transform('mean').astype(float)
103
+ season_long_table['Alt Assists'] = data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['Alt Assists'].transform('mean').astype(float)
104
+ season_long_table['FT Assists'] = data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['FT Assists'].transform('mean').astype(float)
105
+ season_long_table['Assists'] = data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['Assists'].transform('mean').astype(float)
106
+ season_long_table['Stl'] = data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['Stl'].transform('mean').astype(float)
107
+ season_long_table['Blk'] = data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['Blk'].transform('mean').astype(float)
108
+ season_long_table['Tov'] = data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['Tov'].transform('mean').astype(float)
109
  season_long_table['PF'] = data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['PF'].transform('mean').astype(float)
110
  season_long_table['DD'] = data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['DD'].transform('mean').astype(float)
111
  season_long_table['TD'] = data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['TD'].transform('mean').astype(float)
112
  season_long_table['Fantasy'] = data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['Fantasy'].transform('mean').astype(float)
113
  season_long_table['FD_Fantasy'] = data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['FD_Fantasy'].transform('mean').astype(float)
114
+ season_long_table['Rebound%'] = (data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['REB'].transform('sum').astype(int) /
115
  data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['reboundChancesTotal'].transform('sum').astype(int))
116
+ season_long_table['Assists/Pass'] = (data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['assists'].transform('sum').astype(int) /
117
  data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['passes'].transform('sum').astype(int))
118
+ season_long_table['Fantasy/Touch'] = (data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['Fantasy'].transform('sum').astype(int) /
119
  data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['touches'].transform('sum').astype(int))
120
+ season_long_table['FD Fantasy/Touch'] = (data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['FD_Fantasy'].transform('sum').astype(int) /
121
  data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['touches'].transform('sum').astype(int))
122
  season_long_table = season_long_table.drop_duplicates(subset='PLAYER_NAME')
123
+
124
+ season_long_table = season_long_table.set_axis(['Player', 'Team', 'Season', 'Date', 'Matchup', 'Min', 'Touches', 'Pts', 'FGM', 'FGA', 'FG%', 'FG3M', 'FG3A',
125
+ 'FG3%', 'FTM', 'FTA', 'FT%', 'OREB Chance', 'OREB', 'DREB Chance', 'DREB', 'REB Chance', 'REB',
126
+ 'Passes', 'Alt Assists', 'FT Assists', 'Assists', 'Stl', 'Blk', 'Tov', 'PF', 'DD', 'TD', 'Fantasy', 'FD_Fantasy',
127
+ 'Rebound%', 'Assists/Pass', 'Fantasy/Touch', 'FD Fantasy/Touch'], axis=1)
128
 
129
  return season_long_table
130
 
 
137
  return df.to_csv().encode('utf-8')
138
 
139
  gamelog_table = init_baselines()
140
+ total_teams = gamelog_table.Team.values.tolist()
141
 
142
  col1, col2 = st.columns([1, 9])
143
  with col1:
144
  if st.button("Reset Data", key='reset1'):
145
  st.cache_data.clear()
146
  gamelog_table = init_baselines()
147
+
148
  split_var1 = st.radio("What table would you like to view?", ('Season Logs', 'Gamelogs'), key='split_var1')
149
+ split_var2 = st.radio("Would you like to view all teams or specific ones?", ('All', 'Specific Teams'), key='split_var2')
150
+
151
+ if split_var2 == 'Specific Teams':
152
+ team_var1 = st.multiselect('Which teams would you like to include in the tables?', options = total_teams, key='team_var1')
153
+ elif split_var2 == 'All':
154
+ team_var1 = total_teams
155
 
156
  with col2:
157
  if split_var1 == 'Season Logs':
158
  display = st.container()
159
+ gamelog_table = gamelog_table[gamelog_table['Team'].isin(team_var1)]
160
  season_long_table = seasonlong_build(gamelog_table)
161
  display.dataframe(season_long_table.style.format(precision=2), use_container_width = True)
162
 
 
175
  )
176
  with bottom_menu[0]:
177
  st.markdown(f"Page **{current_page}** of **{total_pages}** ")
178
+ gamelog_table = gamelog_table[gamelog_table['Team'].isin(team_var1)]
179
  pages = split_frame(gamelog_table, batch_size)
180
  display.dataframe(data=pages[current_page - 1].style.format(precision=2), use_container_width=True)