Spaces:
Running
Running
James McCool
commited on
Commit
·
11e981b
1
Parent(s):
026f31b
Refactor simulation data handling in app.py. Updated variable names for clarity, changing 'sim_results' to 'individual_sim_results' and added 'overall_sim_results' for aggregated player statistics. Enhanced data presentation by introducing subheaders for individual game simulations and overall simulations, improving user experience and data readability. This change streamlines the simulation process and enhances the clarity of displayed results.
Browse files
app.py
CHANGED
@@ -346,7 +346,7 @@ def init_team_data(team, opponent, win_loss_settings, kill_predictions, death_pr
|
|
346 |
results_dict[f'game {game + 1}'] = team_data.dropna()
|
347 |
team_data['playername'] = team_data['playername'] + f' game {game + 1}'
|
348 |
|
349 |
-
|
350 |
|
351 |
return overall_team_data.dropna().set_index('playername'), opp_boosts, results_dict
|
352 |
|
@@ -369,10 +369,10 @@ if st.button("Run"):
|
|
369 |
player_summary = player_summary.set_index('playername')
|
370 |
|
371 |
# Create simulated percentiles
|
372 |
-
|
373 |
for idx, row in team_data.iterrows():
|
374 |
percentiles = simulate_stats(row)
|
375 |
-
|
376 |
'Player': idx,
|
377 |
'Position': row['position'],
|
378 |
'Stat': 'Kills',
|
@@ -384,7 +384,7 @@ if st.button("Run"):
|
|
384 |
})
|
385 |
# Repeat for other stats
|
386 |
for stat, name in [('Death_Proj', 'Deaths'), ('Assist_Proj', 'Assists'), ('CS_Proj', 'CS')]:
|
387 |
-
|
388 |
'Player': idx,
|
389 |
'Position': row['position'],
|
390 |
'Stat': name,
|
@@ -395,11 +395,42 @@ if st.button("Run"):
|
|
395 |
'90%': percentiles[stat][4]
|
396 |
})
|
397 |
|
398 |
-
sim_df = pd.DataFrame(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
399 |
|
400 |
tab1, tab2 = st.tabs(["Team Data", "Opponent Data"])
|
401 |
with tab1:
|
|
|
402 |
st.dataframe(player_summary.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(display_formats, precision=2), use_container_width = True)
|
|
|
403 |
st.dataframe(team_data.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(display_formats, precision=2), use_container_width = True)
|
404 |
with tab2:
|
405 |
st.dataframe(opp_boost.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True)
|
@@ -407,6 +438,7 @@ if st.button("Run"):
|
|
407 |
unique_players = sim_df['Player'].unique().tolist()
|
408 |
player_tabs = st.tabs(unique_players)
|
409 |
|
|
|
410 |
for player, tab in zip(unique_players, player_tabs):
|
411 |
with tab:
|
412 |
player_data = sim_df[sim_df['Player'] == player]
|
@@ -415,4 +447,7 @@ if st.button("Run"):
|
|
415 |
player_data[['10%', '25%', '50%', '75%', '90%']]
|
416 |
.style.format(precision=2),
|
417 |
use_container_width=True
|
418 |
-
)
|
|
|
|
|
|
|
|
346 |
results_dict[f'game {game + 1}'] = team_data.dropna()
|
347 |
team_data['playername'] = team_data['playername'] + f' game {game + 1}'
|
348 |
|
349 |
+
overall_team_data = pd.concat([overall_team_data, team_data])
|
350 |
|
351 |
return overall_team_data.dropna().set_index('playername'), opp_boosts, results_dict
|
352 |
|
|
|
369 |
player_summary = player_summary.set_index('playername')
|
370 |
|
371 |
# Create simulated percentiles
|
372 |
+
individual_sim_results = []
|
373 |
for idx, row in team_data.iterrows():
|
374 |
percentiles = simulate_stats(row)
|
375 |
+
individual_sim_results.append({
|
376 |
'Player': idx,
|
377 |
'Position': row['position'],
|
378 |
'Stat': 'Kills',
|
|
|
384 |
})
|
385 |
# Repeat for other stats
|
386 |
for stat, name in [('Death_Proj', 'Deaths'), ('Assist_Proj', 'Assists'), ('CS_Proj', 'CS')]:
|
387 |
+
individual_sim_results.append({
|
388 |
'Player': idx,
|
389 |
'Position': row['position'],
|
390 |
'Stat': name,
|
|
|
395 |
'90%': percentiles[stat][4]
|
396 |
})
|
397 |
|
398 |
+
sim_df = pd.DataFrame(individual_sim_results)
|
399 |
+
|
400 |
+
# Create simulated percentiles
|
401 |
+
overall_sim_results = []
|
402 |
+
for idx, row in player_summary.iterrows():
|
403 |
+
percentiles = simulate_stats(row)
|
404 |
+
overall_sim_results.append({
|
405 |
+
'Player': idx,
|
406 |
+
'Position': row['position'],
|
407 |
+
'Stat': 'Kills',
|
408 |
+
'10%': percentiles['Kill_Proj'][0],
|
409 |
+
'25%': percentiles['Kill_Proj'][1],
|
410 |
+
'50%': percentiles['Kill_Proj'][2],
|
411 |
+
'75%': percentiles['Kill_Proj'][3],
|
412 |
+
'90%': percentiles['Kill_Proj'][4]
|
413 |
+
})
|
414 |
+
# Repeat for other stats
|
415 |
+
for stat, name in [('Death_Proj', 'Deaths'), ('Assist_Proj', 'Assists'), ('CS_Proj', 'CS')]:
|
416 |
+
overall_sim_results.append({
|
417 |
+
'Player': idx,
|
418 |
+
'Position': row['position'],
|
419 |
+
'Stat': name,
|
420 |
+
'10%': percentiles[stat][0],
|
421 |
+
'25%': percentiles[stat][1],
|
422 |
+
'50%': percentiles[stat][2],
|
423 |
+
'75%': percentiles[stat][3],
|
424 |
+
'90%': percentiles[stat][4]
|
425 |
+
})
|
426 |
+
|
427 |
+
overall_sim_df = pd.DataFrame(overall_sim_results)
|
428 |
|
429 |
tab1, tab2 = st.tabs(["Team Data", "Opponent Data"])
|
430 |
with tab1:
|
431 |
+
st.subheader("Full Match Data")
|
432 |
st.dataframe(player_summary.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(display_formats, precision=2), use_container_width = True)
|
433 |
+
st.subheader("Individual Game Data")
|
434 |
st.dataframe(team_data.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(display_formats, precision=2), use_container_width = True)
|
435 |
with tab2:
|
436 |
st.dataframe(opp_boost.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True)
|
|
|
438 |
unique_players = sim_df['Player'].unique().tolist()
|
439 |
player_tabs = st.tabs(unique_players)
|
440 |
|
441 |
+
st.subheader("Individual Game Simulations")
|
442 |
for player, tab in zip(unique_players, player_tabs):
|
443 |
with tab:
|
444 |
player_data = sim_df[sim_df['Player'] == player]
|
|
|
447 |
player_data[['10%', '25%', '50%', '75%', '90%']]
|
448 |
.style.format(precision=2),
|
449 |
use_container_width=True
|
450 |
+
)
|
451 |
+
|
452 |
+
st.subheader("Overall Simulations")
|
453 |
+
st.dataframe(overall_sim_df.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(display_formats, precision=2), use_container_width = True)
|