Multichem commited on
Commit
0300805
·
verified ·
1 Parent(s): 6fc782b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -1
app.py CHANGED
@@ -512,7 +512,9 @@ with tab1:
512
  file_name='MLB_consim_export.csv',
513
  mime='text/csv',
514
  )
515
- with st.container():
 
 
516
  if 'Sim_Winner_Display' in st.session_state:
517
  # Create a new dataframe with summary statistics
518
  summary_df = pd.DataFrame({
@@ -555,6 +557,42 @@ with tab1:
555
  'Fantasy': '{:.2f}',
556
  'GPP_Proj': '{:.2f}'
557
  }).background_gradient(cmap='RdYlGn', axis=0, subset=['Salary', 'Proj', 'Own', 'Fantasy', 'GPP_Proj']), use_container_width=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
558
  with st.container():
559
  tab1, tab2, tab3, tab4, tab5, tab6, tab7, tab8, tab9 = st.tabs(['Overall Exposures', 'QB Exposures', 'RB-WR-TE Exposures', 'RB Exposures', 'WR Exposures', 'TE Exposures', 'FLEX Exposures', 'DST Exposures', 'Team Exposures'])
560
  with tab1:
 
512
  file_name='MLB_consim_export.csv',
513
  mime='text/csv',
514
  )
515
+ tab1, tab2 = st.tabs(['Winning Frame Statistics', 'Flex Exposure Statistics'])
516
+
517
+ with tab1:
518
  if 'Sim_Winner_Display' in st.session_state:
519
  # Create a new dataframe with summary statistics
520
  summary_df = pd.DataFrame({
 
557
  'Fantasy': '{:.2f}',
558
  'GPP_Proj': '{:.2f}'
559
  }).background_gradient(cmap='RdYlGn', axis=0, subset=['Salary', 'Proj', 'Own', 'Fantasy', 'GPP_Proj']), use_container_width=True)
560
+ with tab2:
561
+ if 'Sim_Winner_Display' in st.session_state and 'maps_dict' in st.session_state:
562
+ # Apply position mapping to FLEX column
563
+ flex_positions = st.session_state.Sim_Winner_Display['FLEX'].map(st.session_state.maps_dict['Pos_map'])
564
+
565
+ # Count occurrences of each position in FLEX
566
+ flex_counts = flex_positions.value_counts()
567
+
568
+ # Calculate average statistics for each FLEX position
569
+ flex_stats = st.session_state.Sim_Winner_Display.groupby(flex_positions).agg({
570
+ 'Proj': 'mean',
571
+ 'Own': 'mean',
572
+ 'Fantasy': 'mean',
573
+ 'GPP_Proj': 'mean'
574
+ })
575
+
576
+ # Combine counts and average statistics
577
+ flex_summary = pd.concat([flex_counts, flex_stats], axis=1)
578
+ flex_summary.columns = ['Count', 'Avg Proj', 'Avg Own', 'Avg Fantasy', 'Avg GPP_Proj']
579
+ flex_summary = flex_summary.reset_index()
580
+ flex_summary.columns = ['Position', 'Count', 'Avg Proj', 'Avg Own', 'Avg Fantasy', 'Avg GPP_Proj']
581
+
582
+ # Display the summary dataframe
583
+ st.subheader("FLEX Position Statistics")
584
+ st.dataframe(flex_summary.style.format({
585
+ 'Count': '{:.0f}',
586
+ 'Avg Proj': '{:.2f}',
587
+ 'Avg Fantasy': '{:.2f}',
588
+ 'Avg GPP_Proj': '{:.2f}'
589
+ }).background_gradient(cmap='RdYlGn', axis=0, subset=['Count', 'Avg Proj', 'Avg Own', 'Avg Fantasy', 'Avg GPP_Proj']), use_container_width=True)
590
+
591
+ # Create a bar chart for FLEX position distribution
592
+ fig = px.bar(flex_summary, x='Position', y='Count', title='FLEX Position Distribution')
593
+ st.plotly_chart(fig, use_container_width=True)
594
+ else:
595
+ st.write("Simulation data or position mapping not available.")
596
  with st.container():
597
  tab1, tab2, tab3, tab4, tab5, tab6, tab7, tab8, tab9 = st.tabs(['Overall Exposures', 'QB Exposures', 'RB-WR-TE Exposures', 'RB Exposures', 'WR Exposures', 'TE Exposures', 'FLEX Exposures', 'DST Exposures', 'Team Exposures'])
598
  with tab1: