James McCool commited on
Commit
a95448c
·
1 Parent(s): c2ffc4c

Enhance app.py by adding a new tab for Stack Type Statistics, which displays average statistics and counts for team stacks. Update existing tabs to include 'Avg Own' in dataframes and improve user feedback when simulation data is unavailable. Additionally, implement a download button for stack frequency data, enhancing data export functionality.

Browse files
Files changed (1) hide show
  1. app.py +47 -2
app.py CHANGED
@@ -491,7 +491,7 @@ with tab1:
491
  file_name='MLB_consim_export.csv',
492
  mime='text/csv',
493
  )
494
- tab1, tab2 = st.tabs(['Winning Frame Statistics', 'Flex Exposure Statistics'])
495
 
496
  with tab1:
497
  if 'Sim_Winner_Display' in st.session_state:
@@ -538,6 +538,7 @@ with tab1:
538
  st.dataframe(summary_df.style.format({
539
  'Salary': '{:.2f}',
540
  'Proj': '{:.2f}',
 
541
  'Fantasy': '{:.2f}',
542
  'GPP_Proj': '{:.2f}'
543
  }).background_gradient(cmap='RdYlGn', axis=0, subset=['Salary', 'Proj', 'Own', 'Fantasy', 'GPP_Proj']), use_container_width=True)
@@ -569,14 +570,47 @@ with tab1:
569
  st.dataframe(flex_summary.style.format({
570
  'Count': '{:.0f}',
571
  'Avg Proj': '{:.2f}',
 
572
  'Avg Fantasy': '{:.2f}',
573
  'Avg GPP_Proj': '{:.2f}'
574
  }).background_gradient(cmap='RdYlGn', axis=0, subset=['Count', 'Avg Proj', 'Avg Own', 'Avg Fantasy', 'Avg GPP_Proj']), use_container_width=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
575
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
576
  else:
577
  st.write("Simulation data or position mapping not available.")
 
 
578
  with st.container():
579
- tab1, tab2, tab3, tab4, tab5, tab6, tab7 = st.tabs(['Overall Exposures', 'Center Exposures', 'Wing Exposures', 'Defense Exposures', 'Flex Exposures', 'Goalie Exposures', 'Team Exposures'])
580
  with tab1:
581
  if 'player_freq' in st.session_state:
582
 
@@ -653,4 +687,15 @@ with tab1:
653
  file_name='team_freq.csv',
654
  mime='text/csv',
655
  key='team'
 
 
 
 
 
 
 
 
 
 
 
656
  )
 
491
  file_name='MLB_consim_export.csv',
492
  mime='text/csv',
493
  )
494
+ tab1, tab2, tab3 = st.tabs(['Winning Frame Statistics', 'Flex Exposure Statistics', 'Stack Type Statistics'])
495
 
496
  with tab1:
497
  if 'Sim_Winner_Display' in st.session_state:
 
538
  st.dataframe(summary_df.style.format({
539
  'Salary': '{:.2f}',
540
  'Proj': '{:.2f}',
541
+ 'Own': '{:.2f}',
542
  'Fantasy': '{:.2f}',
543
  'GPP_Proj': '{:.2f}'
544
  }).background_gradient(cmap='RdYlGn', axis=0, subset=['Salary', 'Proj', 'Own', 'Fantasy', 'GPP_Proj']), use_container_width=True)
 
570
  st.dataframe(flex_summary.style.format({
571
  'Count': '{:.0f}',
572
  'Avg Proj': '{:.2f}',
573
+ 'Avg Own': '{:.2f}',
574
  'Avg Fantasy': '{:.2f}',
575
  'Avg GPP_Proj': '{:.2f}'
576
  }).background_gradient(cmap='RdYlGn', axis=0, subset=['Count', 'Avg Proj', 'Avg Own', 'Avg Fantasy', 'Avg GPP_Proj']), use_container_width=True)
577
+ else:
578
+ st.write("Simulation data or position mapping not available.")
579
+
580
+ with tab3:
581
+ if 'Sim_Winner_Display' in st.session_state:
582
+ # Apply position mapping to FLEX column
583
+ stack_counts = st.session_state.freq_copy['Team_count'].value_counts()
584
+
585
+ # Calculate average statistics for each stack size
586
+ stack_stats = st.session_state.freq_copy.groupby('Team_count').agg({
587
+ 'proj': 'mean',
588
+ 'Own': 'mean',
589
+ 'Fantasy': 'mean',
590
+ 'GPP_Proj': 'mean'
591
+ })
592
 
593
+ # Combine counts and average statistics
594
+ stack_summary = pd.concat([stack_counts, stack_stats], axis=1)
595
+ stack_summary.columns = ['Count', 'Avg Proj', 'Avg Own', 'Avg Fantasy', 'Avg GPP_Proj']
596
+ stack_summary = stack_summary.reset_index()
597
+ stack_summary.columns = ['Position', 'Count', 'Avg Proj', 'Avg Own', 'Avg Fantasy', 'Avg GPP_Proj']
598
+
599
+ # Display the summary dataframe
600
+ st.subheader("Stack Type Statistics")
601
+ st.dataframe(stack_summary.style.format({
602
+ 'Count': '{:.0f}',
603
+ 'Avg Proj': '{:.2f}',
604
+ 'Avg Own': '{:.2f}',
605
+ 'Avg Fantasy': '{:.2f}',
606
+ 'Avg GPP_Proj': '{:.2f}'
607
+ }).background_gradient(cmap='RdYlGn', axis=0, subset=['Count', 'Avg Proj', 'Avg Own', 'Avg Fantasy', 'Avg GPP_Proj']), use_container_width=True)
608
  else:
609
  st.write("Simulation data or position mapping not available.")
610
+
611
+
612
  with st.container():
613
+ tab1, tab2, tab3, tab4, tab5, tab6, tab7, tab8 = st.tabs(['Overall Exposures', 'Center Exposures', 'Wing Exposures', 'Defense Exposures', 'Flex Exposures', 'Goalie Exposures', 'Team Exposures', 'Stack Exposures'])
614
  with tab1:
615
  if 'player_freq' in st.session_state:
616
 
 
687
  file_name='team_freq.csv',
688
  mime='text/csv',
689
  key='team'
690
+ )
691
+ with tab8:
692
+ if 'stack_freq' in st.session_state:
693
+
694
+ st.dataframe(st.session_state.stack_freq.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(percentages_format, precision=2), use_container_width = True)
695
+ st.download_button(
696
+ label="Export Exposures",
697
+ data=st.session_state.stack_freq.to_csv().encode('utf-8'),
698
+ file_name='stack_freq.csv',
699
+ mime='text/csv',
700
+ key='team'
701
  )