Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -180,6 +180,16 @@ def convert_df_to_csv(df):
|
|
180 |
return df.to_csv().encode('utf-8')
|
181 |
|
182 |
gamelog_table = init_baselines()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
183 |
indv_teams = gamelog_table.drop_duplicates(subset='Team')
|
184 |
total_teams = indv_teams.Team.values.tolist()
|
185 |
indv_players = gamelog_table.drop_duplicates(subset='Player')
|
@@ -194,6 +204,16 @@ with tab1:
|
|
194 |
if st.button("Reset Data", key='reset1'):
|
195 |
st.cache_data.clear()
|
196 |
gamelog_table = init_baselines()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
197 |
indv_teams = gamelog_table.drop_duplicates(subset='Team')
|
198 |
total_teams = indv_teams.Team.values.tolist()
|
199 |
indv_players = gamelog_table.drop_duplicates(subset='Player')
|
@@ -233,6 +253,10 @@ with tab1:
|
|
233 |
with col2:
|
234 |
working_data = gamelog_table
|
235 |
if split_var1 == 'Season Logs':
|
|
|
|
|
|
|
|
|
236 |
display = st.container()
|
237 |
working_data = working_data[working_data['Date'] >= low_date]
|
238 |
working_data = working_data[working_data['Date'] <= high_date]
|
@@ -242,7 +266,8 @@ with tab1:
|
|
242 |
working_data = working_data[working_data['Player'].isin(player_var1)]
|
243 |
season_long_table = seasonlong_build(working_data)
|
244 |
season_long_table = season_long_table.set_index('Player')
|
245 |
-
|
|
|
246 |
st.download_button(
|
247 |
label="Export seasonlogs Model",
|
248 |
data=convert_df_to_csv(season_long_table),
|
@@ -251,6 +276,10 @@ with tab1:
|
|
251 |
)
|
252 |
|
253 |
elif split_var1 == 'Gamelogs':
|
|
|
|
|
|
|
|
|
254 |
working_data = working_data[working_data['Date'] >= low_date]
|
255 |
working_data = working_data[working_data['Date'] <= high_date]
|
256 |
working_data = working_data[working_data['Min'] >= min_var1[0]]
|
@@ -258,6 +287,7 @@ with tab1:
|
|
258 |
working_data = working_data[working_data['Team'].isin(team_var1)]
|
259 |
working_data = working_data[working_data['Player'].isin(player_var1)]
|
260 |
working_data = working_data.reset_index(drop=True)
|
|
|
261 |
display = st.container()
|
262 |
|
263 |
bottom_menu = st.columns((4, 1, 1))
|
@@ -265,7 +295,7 @@ with tab1:
|
|
265 |
batch_size = st.selectbox("Page Size", options=[25, 50, 100])
|
266 |
with bottom_menu[1]:
|
267 |
total_pages = (
|
268 |
-
int(len(
|
269 |
)
|
270 |
current_page = st.number_input(
|
271 |
"Page", min_value=1, max_value=total_pages, step=1
|
@@ -274,12 +304,12 @@ with tab1:
|
|
274 |
st.markdown(f"Page **{current_page}** of **{total_pages}** ")
|
275 |
|
276 |
|
277 |
-
pages = split_frame(
|
278 |
# pages = pages.set_index('Player')
|
279 |
display.dataframe(data=pages[current_page - 1].style.format(precision=2), height=500, use_container_width=True)
|
280 |
st.download_button(
|
281 |
label="Export gamelogs Model",
|
282 |
-
data=convert_df_to_csv(
|
283 |
file_name='Gamelogs_NBA_View.csv',
|
284 |
mime='text/csv',
|
285 |
)
|
|
|
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 = ['Player', 'Pos', 'Team', 'Min']
|
185 |
+
data_cols = ['Touches', 'Pts', 'FGM', 'FGA', 'FG%', 'FG3M',
|
186 |
+
'FG3A', 'FG3%', 'FTM', 'FTA', 'FT%', 'OREB Chance', 'OREB', 'DREB Chance', 'DREB', 'REB Chance', 'REB',
|
187 |
+
'Passes', 'Alt Assists', 'FT Assists', 'Assists', 'Stl', 'Blk', 'Tov', 'PF', 'DD', 'TD', 'Fantasy', 'FD_Fantasy',
|
188 |
+
'Rebound%', 'Assists/Pass', 'Touch_per_min', 'Fantasy/Touch', 'FD Fantasy/Touch']
|
189 |
+
season_data_cols = ['Touches', 'Touch/Min', 'Pts', 'FGM', 'FGA', 'FG%', 'FG3M', 'FG3A',
|
190 |
+
'FG3%', 'FTM', 'FTA', 'FT%', 'OREB Chance', 'OREB', 'DREB Chance', 'DREB', 'REB Chance', 'REB',
|
191 |
+
'Passes', 'Alt Assists', 'FT Assists', 'Assists', 'Stl', 'Blk', 'Tov', 'PF', 'DD', 'TD', 'Fantasy', 'FD_Fantasy',
|
192 |
+
'Rebound%', 'Assists/Pass', 'Fantasy/Touch', 'FD Fantasy/Touch']
|
193 |
indv_teams = gamelog_table.drop_duplicates(subset='Team')
|
194 |
total_teams = indv_teams.Team.values.tolist()
|
195 |
indv_players = gamelog_table.drop_duplicates(subset='Player')
|
|
|
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 = ['Player', 'Pos', 'Team', 'Min']
|
209 |
+
data_cols = ['Touches', 'Pts', 'FGM', 'FGA', 'FG%', 'FG3M',
|
210 |
+
'FG3A', 'FG3%', 'FTM', 'FTA', 'FT%', 'OREB Chance', 'OREB', 'DREB Chance', 'DREB', 'REB Chance', 'REB',
|
211 |
+
'Passes', 'Alt Assists', 'FT Assists', 'Assists', 'Stl', 'Blk', 'Tov', 'PF', 'DD', 'TD', 'Fantasy', 'FD_Fantasy',
|
212 |
+
'Rebound%', 'Assists/Pass', 'Touch_per_min', 'Fantasy/Touch', 'FD Fantasy/Touch']
|
213 |
+
season_data_cols = ['Touches', 'Touch/Min', 'Pts', 'FGM', 'FGA', 'FG%', 'FG3M', 'FG3A',
|
214 |
+
'FG3%', 'FTM', 'FTA', 'FT%', 'OREB Chance', 'OREB', 'DREB Chance', 'DREB', 'REB Chance', 'REB',
|
215 |
+
'Passes', 'Alt Assists', 'FT Assists', 'Assists', 'Stl', 'Blk', 'Tov', 'PF', 'DD', 'TD', 'Fantasy', 'FD_Fantasy',
|
216 |
+
'Rebound%', 'Assists/Pass', 'Fantasy/Touch', 'FD Fantasy/Touch']
|
217 |
indv_teams = gamelog_table.drop_duplicates(subset='Team')
|
218 |
total_teams = indv_teams.Team.values.tolist()
|
219 |
indv_players = gamelog_table.drop_duplicates(subset='Player')
|
|
|
253 |
with col2:
|
254 |
working_data = gamelog_table
|
255 |
if split_var1 == 'Season Logs':
|
256 |
+
choose_cols = st.container()
|
257 |
+
with choose_cols:
|
258 |
+
choose_disp = st.multiselect('Which stats would you like to view?', options = season_data_cols, default = season_data_cols, key='col_display')
|
259 |
+
disp_stats = basic_season_cols + choose_disp
|
260 |
display = st.container()
|
261 |
working_data = working_data[working_data['Date'] >= low_date]
|
262 |
working_data = working_data[working_data['Date'] <= high_date]
|
|
|
266 |
working_data = working_data[working_data['Player'].isin(player_var1)]
|
267 |
season_long_table = seasonlong_build(working_data)
|
268 |
season_long_table = season_long_table.set_index('Player')
|
269 |
+
season_long_table_disp = season_long_table.reindex(disp_stats,axis="columns")
|
270 |
+
display.dataframe(season_long_table_disp.style.format(precision=2), height=750, use_container_width = True)
|
271 |
st.download_button(
|
272 |
label="Export seasonlogs Model",
|
273 |
data=convert_df_to_csv(season_long_table),
|
|
|
276 |
)
|
277 |
|
278 |
elif split_var1 == 'Gamelogs':
|
279 |
+
choose_cols = st.container()
|
280 |
+
with choose_cols:
|
281 |
+
choose_disp = st.multiselect('Which stats would you like to view?', options = data_cols, default = data_cols, key='col_display')
|
282 |
+
disp_stats = basic_cols + choose_disp
|
283 |
working_data = working_data[working_data['Date'] >= low_date]
|
284 |
working_data = working_data[working_data['Date'] <= high_date]
|
285 |
working_data = working_data[working_data['Min'] >= min_var1[0]]
|
|
|
287 |
working_data = working_data[working_data['Team'].isin(team_var1)]
|
288 |
working_data = working_data[working_data['Player'].isin(player_var1)]
|
289 |
working_data = working_data.reset_index(drop=True)
|
290 |
+
gamelog_data = working_data.reindex(disp_stats,axis="columns")
|
291 |
display = st.container()
|
292 |
|
293 |
bottom_menu = st.columns((4, 1, 1))
|
|
|
295 |
batch_size = st.selectbox("Page Size", options=[25, 50, 100])
|
296 |
with bottom_menu[1]:
|
297 |
total_pages = (
|
298 |
+
int(len(gamelog_data) / batch_size) if int(len(gamelog_data) / batch_size) > 0 else 1
|
299 |
)
|
300 |
current_page = st.number_input(
|
301 |
"Page", min_value=1, max_value=total_pages, step=1
|
|
|
304 |
st.markdown(f"Page **{current_page}** of **{total_pages}** ")
|
305 |
|
306 |
|
307 |
+
pages = split_frame(gamelog_data, batch_size)
|
308 |
# pages = pages.set_index('Player')
|
309 |
display.dataframe(data=pages[current_page - 1].style.format(precision=2), height=500, use_container_width=True)
|
310 |
st.download_button(
|
311 |
label="Export gamelogs Model",
|
312 |
+
data=convert_df_to_csv(gamelog_data),
|
313 |
file_name='Gamelogs_NBA_View.csv',
|
314 |
mime='text/csv',
|
315 |
)
|