Multichem commited on
Commit
96889df
·
1 Parent(s): 56ce0fe

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +151 -76
app.py CHANGED
@@ -130,6 +130,23 @@ def seasonlong_build(data_sample):
130
 
131
  return season_long_table
132
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
133
  @st.cache_data(show_spinner=False)
134
  def split_frame(input_df, rows):
135
  df = [input_df.loc[i : i + rows - 1, :] for i in range(0, len(input_df), rows)]
@@ -145,84 +162,142 @@ indv_players = gamelog_table.drop_duplicates(subset='Player')
145
  total_players = indv_players.Player.values.tolist()
146
  total_dates = gamelog_table.Date.values.tolist()
147
 
148
- col1, col2 = st.columns([1, 9])
149
- with col1:
150
- if st.button("Reset Data", key='reset1'):
151
- st.cache_data.clear()
152
- gamelog_table = init_baselines()
153
- indv_teams = gamelog_table.drop_duplicates(subset='Team')
154
- total_teams = indv_teams.Team.values.tolist()
155
- indv_players = gamelog_table.drop_duplicates(subset='Player')
156
- total_players = indv_players.Player.values.tolist()
157
- total_dates = gamelog_table.Date.values.tolist()
158
-
159
- split_var1 = st.radio("What table would you like to view?", ('Season Logs', 'Gamelogs'), key='split_var1')
160
- split_var2 = st.radio("Would you like to view all teams or specific ones?", ('All', 'Specific Teams'), key='split_var2')
161
-
162
- if split_var2 == 'Specific Teams':
163
- team_var1 = st.multiselect('Which teams would you like to include in the tables?', options = total_teams, key='team_var1')
164
- elif split_var2 == 'All':
165
- team_var1 = total_teams
166
 
167
- split_var3 = st.radio("Would you like to view all dates or specific ones?", ('All', 'Specific Dates'), key='split_var3')
168
-
169
- if split_var3 == 'Specific Dates':
170
- low_date = st.date_input('Min Date:', value=None, format="YYYY-MM-DD", key='low_date')
171
- if low_date is not None:
172
- low_date = pd.to_datetime(low_date).date()
173
- high_date = st.date_input('Max Date:', value=None, format="YYYY-MM-DD", key='high_date')
174
- if high_date is not None:
175
- high_date = pd.to_datetime(high_date).date()
176
- elif split_var3 == 'All':
177
- low_date = gamelog_table['Date'].min()
178
- high_date = gamelog_table['Date'].max()
179
-
180
- split_var4 = st.radio("Would you like to view all players or specific ones?", ('All', 'Specific Players'), key='split_var4')
181
-
182
- if split_var4 == 'Specific Players':
183
- player_var1 = st.multiselect('Which players would you like to include in the tables?', options = total_players, key='player_var1')
184
- elif split_var4 == 'All':
185
- player_var1 = total_players
186
-
187
- min_var1 = st.slider("Is there a certain minutes range you want to view?", 0, 60, (0, 60), key='min_var1')
188
-
189
- with col2:
190
- if split_var1 == 'Season Logs':
191
- display = st.container()
192
- gamelog_table = gamelog_table[gamelog_table['Date'] >= low_date]
193
- gamelog_table = gamelog_table[gamelog_table['Date'] <= high_date]
194
- gamelog_table = gamelog_table[gamelog_table['Min'] >= min_var1[0]]
195
- gamelog_table = gamelog_table[gamelog_table['Min'] <= min_var1[1]]
196
- gamelog_table = gamelog_table[gamelog_table['Team'].isin(team_var1)]
197
- gamelog_table = gamelog_table[gamelog_table['Player'].isin(player_var1)]
198
- season_long_table = seasonlong_build(gamelog_table)
199
- season_long_table = season_long_table.set_index('Player')
200
- display.dataframe(season_long_table.style.format(precision=2), use_container_width = True)
201
 
202
- elif split_var1 == 'Gamelogs':
203
- gamelog_table = gamelog_table[gamelog_table['Date'] >= low_date]
204
- gamelog_table = gamelog_table[gamelog_table['Date'] <= high_date]
205
- gamelog_table = gamelog_table[gamelog_table['Min'] >= min_var1[0]]
206
- gamelog_table = gamelog_table[gamelog_table['Min'] <= min_var1[1]]
207
- gamelog_table = gamelog_table[gamelog_table['Team'].isin(team_var1)]
208
- gamelog_table = gamelog_table[gamelog_table['Player'].isin(player_var1)]
209
- gamelog_table = gamelog_table.reset_index(drop=True)
210
- display = st.container()
211
 
212
- bottom_menu = st.columns((4, 1, 1))
213
- with bottom_menu[2]:
214
- batch_size = st.selectbox("Page Size", options=[25, 50, 100])
215
- with bottom_menu[1]:
216
- total_pages = (
217
- int(len(gamelog_table) / batch_size) if int(len(gamelog_table) / batch_size) > 0 else 1
218
- )
219
- current_page = st.number_input(
220
- "Page", min_value=1, max_value=total_pages, step=1
221
- )
222
- with bottom_menu[0]:
223
- st.markdown(f"Page **{current_page}** of **{total_pages}** ")
 
 
 
 
 
 
 
 
 
 
224
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
225
 
226
- pages = split_frame(gamelog_table, batch_size)
227
- # pages = pages.set_index('Player')
228
- display.dataframe(data=pages[current_page - 1].style.format(precision=2), use_container_width=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
130
 
131
  return season_long_table
132
 
133
+ @st.cache_data(show_spinner=False)
134
+ def run_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()
147
+
148
+ return corrM
149
+
150
  @st.cache_data(show_spinner=False)
151
  def split_frame(input_df, rows):
152
  df = [input_df.loc[i : i + rows - 1, :] for i in range(0, len(input_df), rows)]
 
162
  total_players = indv_players.Player.values.tolist()
163
  total_dates = gamelog_table.Date.values.tolist()
164
 
165
+ tab1, tab2 = st.tabs(['Gamelogs', 'Correlation Matrix'])
166
+
167
+ with tab1:
168
+ col1, col2 = st.columns([1, 9])
169
+ with col1:
170
+ if st.button("Reset Data", key='reset1'):
171
+ st.cache_data.clear()
172
+ gamelog_table = init_baselines()
173
+ indv_teams = gamelog_table.drop_duplicates(subset='Team')
174
+ total_teams = indv_teams.Team.values.tolist()
175
+ indv_players = gamelog_table.drop_duplicates(subset='Player')
176
+ total_players = indv_players.Player.values.tolist()
177
+ total_dates = gamelog_table.Date.values.tolist()
 
 
 
 
 
178
 
179
+ split_var1 = st.radio("What table would you like to view?", ('Season Logs', 'Gamelogs'), key='split_var1')
180
+ split_var2 = st.radio("Would you like to view all teams or specific ones?", ('All', 'Specific Teams'), key='split_var2')
181
+
182
+ if split_var2 == 'Specific Teams':
183
+ team_var1 = st.multiselect('Which teams would you like to include in the tables?', options = total_teams, key='team_var1')
184
+ elif split_var2 == 'All':
185
+ team_var1 = total_teams
186
+
187
+ split_var3 = st.radio("Would you like to view all dates or specific ones?", ('All', 'Specific Dates'), key='split_var3')
188
+
189
+ if split_var3 == 'Specific Dates':
190
+ low_date = st.date_input('Min Date:', value=None, format="YYYY-MM-DD", key='low_date')
191
+ if low_date is not None:
192
+ low_date = pd.to_datetime(low_date).date()
193
+ high_date = st.date_input('Max Date:', value=None, format="YYYY-MM-DD", key='high_date')
194
+ if high_date is not None:
195
+ high_date = pd.to_datetime(high_date).date()
196
+ elif split_var3 == 'All':
197
+ low_date = gamelog_table['Date'].min()
198
+ high_date = gamelog_table['Date'].max()
199
+
200
+ split_var4 = st.radio("Would you like to view all players or specific ones?", ('All', 'Specific Players'), key='split_var4')
201
+
202
+ if split_var4 == 'Specific Players':
203
+ player_var1 = st.multiselect('Which players would you like to include in the tables?', options = total_players, key='player_var1')
204
+ elif split_var4 == 'All':
205
+ player_var1 = total_players
 
 
 
 
 
 
 
206
 
207
+ min_var1 = st.slider("Is there a certain minutes range you want to view?", 0, 60, (0, 60), key='min_var1')
 
 
 
 
 
 
 
 
208
 
209
+ with col2:
210
+ if split_var1 == 'Season Logs':
211
+ display = st.container()
212
+ gamelog_table = gamelog_table[gamelog_table['Date'] >= low_date]
213
+ gamelog_table = gamelog_table[gamelog_table['Date'] <= high_date]
214
+ gamelog_table = gamelog_table[gamelog_table['Min'] >= min_var1[0]]
215
+ gamelog_table = gamelog_table[gamelog_table['Min'] <= min_var1[1]]
216
+ gamelog_table = gamelog_table[gamelog_table['Team'].isin(team_var1)]
217
+ gamelog_table = gamelog_table[gamelog_table['Player'].isin(player_var1)]
218
+ season_long_table = seasonlong_build(gamelog_table)
219
+ season_long_table = season_long_table.set_index('Player')
220
+ display.dataframe(season_long_table.style.format(precision=2), use_container_width = True)
221
+
222
+ elif split_var1 == 'Gamelogs':
223
+ gamelog_table = gamelog_table[gamelog_table['Date'] >= low_date]
224
+ gamelog_table = gamelog_table[gamelog_table['Date'] <= high_date]
225
+ gamelog_table = gamelog_table[gamelog_table['Min'] >= min_var1[0]]
226
+ gamelog_table = gamelog_table[gamelog_table['Min'] <= min_var1[1]]
227
+ gamelog_table = gamelog_table[gamelog_table['Team'].isin(team_var1)]
228
+ gamelog_table = gamelog_table[gamelog_table['Player'].isin(player_var1)]
229
+ gamelog_table = gamelog_table.reset_index(drop=True)
230
+ display = st.container()
231
 
232
+ bottom_menu = st.columns((4, 1, 1))
233
+ with bottom_menu[2]:
234
+ batch_size = st.selectbox("Page Size", options=[25, 50, 100])
235
+ with bottom_menu[1]:
236
+ total_pages = (
237
+ int(len(gamelog_table) / batch_size) if int(len(gamelog_table) / batch_size) > 0 else 1
238
+ )
239
+ current_page = st.number_input(
240
+ "Page", min_value=1, max_value=total_pages, step=1
241
+ )
242
+ with bottom_menu[0]:
243
+ st.markdown(f"Page **{current_page}** of **{total_pages}** ")
244
+
245
+
246
+ pages = split_frame(gamelog_table, batch_size)
247
+ # pages = pages.set_index('Player')
248
+ display.dataframe(data=pages[current_page - 1].style.format(precision=2), use_container_width=True)
249
+
250
+ with tab2:
251
+ col1, col2 = st.columns([1, 9])
252
+ with col1:
253
+ if st.button("Reset Data", key='reset2'):
254
+ st.cache_data.clear()
255
+ gamelog_table = init_baselines()
256
+ indv_teams = gamelog_table.drop_duplicates(subset='Team')
257
+ total_teams = indv_teams.Team.values.tolist()
258
+ indv_players = gamelog_table.drop_duplicates(subset='Player')
259
+ total_players = indv_players.Player.values.tolist()
260
+ total_dates = gamelog_table.Date.values.tolist()
261
 
262
+ split_var1_t2 = st.radio("Would you like to view specific teams or specific players?", ('Specific Teams', 'Specific Players'), key='split_var1_t2')
263
+
264
+ if split_var1_t2 == 'Specific Teams':
265
+ corr_var1_t2 = st.multiselect('Which teams would you like to include in the correlation?', options = total_teams, key='corr_var1_t2')
266
+ elif split_var1_t2 == 'Specific Players':
267
+ corr_var1_t2 = st.multiselect('Which players would you like to include in the correlation?', options = total_players, key='corr_var1_t2')
268
+
269
+ split_var2_t2 = st.radio("Would you like to view all dates or specific ones?", ('All', 'Specific Dates'), key='split_var3_t2')
270
+
271
+ if split_var2_t2 == 'Specific Dates':
272
+ low_date_t2 = st.date_input('Min Date:', value=None, format="YYYY-MM-DD", key='low_date_t2')
273
+ if low_date_t2 is not None:
274
+ low_date_t2 = pd.to_datetime(low_date_t2).date()
275
+ high_date_t2 = st.date_input('Max Date:', value=None, format="YYYY-MM-DD", key='high_date_t2')
276
+ if high_date_t2 is not None:
277
+ high_date_t2 = pd.to_datetime(high_date_t2).date()
278
+ elif split_var2_t2 == 'All':
279
+ low_date_t2 = gamelog_table['Date'].min()
280
+ high_date_t2 = gamelog_table['Date'].max()
281
+
282
+ min_var1_t2 = st.slider("Is there a certain minutes range you want to view?", 0, 60, (0, 60), key='min_var1_t2')
283
+
284
+ with col2:
285
+ if split_var1_t2 == 'Specific Teams':
286
+ display = st.container()
287
+ gamelog_table = gamelog_table[gamelog_table['Date'] >= low_date_t2]
288
+ gamelog_table = gamelog_table[gamelog_table['Date'] <= high_date_t2]
289
+ gamelog_table = gamelog_table[gamelog_table['Min'] >= min_var1_t2[0]]
290
+ gamelog_table = gamelog_table[gamelog_table['Min'] <= min_var1_t2[1]]
291
+ gamelog_table = gamelog_table[gamelog_table['Team'].isin(corr_var1_t2)]
292
+ corr_display = run_corr(gamelog_table)
293
+ display.dataframe(corr_display.style.format(precision=2), use_container_width = True)
294
+
295
+ elif split_var1_t2 == 'Specific Players':
296
+ display = st.container()
297
+ gamelog_table = gamelog_table[gamelog_table['Date'] >= low_date_t2]
298
+ gamelog_table = gamelog_table[gamelog_table['Date'] <= high_date_t2]
299
+ gamelog_table = gamelog_table[gamelog_table['Min'] >= min_var1_t2[0]]
300
+ gamelog_table = gamelog_table[gamelog_table['Min'] <= min_var1_t2[1]]
301
+ gamelog_table = gamelog_table[gamelog_table['Player'].isin(corr_var1_t2)]
302
+ corr_display = run_corr(gamelog_table)
303
+ display.dataframe(corr_display.style.format(precision=2), use_container_width = True)