James McCool commited on
Commit
05170c5
·
1 Parent(s): 796d14d

Refactor sim_contest function in app.py to implement stack multipliers for projection calculations, enhancing accuracy based on team participation. Removed unused stack frequency tab from UI, streamlining the user interface and improving overall performance.

Browse files
Files changed (1) hide show
  1. app.py +10 -18
app.py CHANGED
@@ -102,15 +102,18 @@ def sim_contest(Sim_size, seed_frame, maps_dict, Contest_Size, teams_playing_cou
102
  while SimVar <= Sim_size:
103
  fp_random = fp_array[np.random.choice(fp_array.shape[0], Contest_Size)]
104
 
105
- # Calculate base projections
 
 
 
 
 
106
  base_projections = np.sum(np.random.normal(
107
- loc=vec_projection_map(fp_random[:, :-7]),
108
- scale=vec_stdev_map(fp_random[:, :-7])),
109
  axis=1)
110
 
111
- # Apply 10% bonus for stacks of 5 or more based on the number of teams playing
112
- stack_bonus = np.where(fp_random[:, 12] >= 5, base_projections * (0.05 * (teams_playing_count - 12)), 0)
113
- final_projections = base_projections + stack_bonus
114
 
115
  sample_arrays = np.c_[fp_random, final_projections]
116
 
@@ -610,7 +613,7 @@ with tab1:
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,15 +690,4 @@ with tab1:
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
  )
 
102
  while SimVar <= Sim_size:
103
  fp_random = fp_array[np.random.choice(fp_array.shape[0], Contest_Size)]
104
 
105
+ # Calculate stack multipliers first
106
+ stack_multiplier = np.ones(fp_random.shape[0]) # Start with no bonus
107
+ stack_multiplier += np.where(fp_random[:, 12] == 4, 0.05 * (teams_playing_count - 8), 0)
108
+ stack_multiplier += np.where(fp_random[:, 12] >= 5, 0.05 * (teams_playing_count - 12), 0)
109
+
110
+ # Apply multipliers to both loc and scale in the normal distribution
111
  base_projections = np.sum(np.random.normal(
112
+ loc=vec_projection_map(fp_random[:, :-7]) * stack_multiplier[:, np.newaxis],
113
+ scale=vec_stdev_map(fp_random[:, :-7]) * stack_multiplier[:, np.newaxis]),
114
  axis=1)
115
 
116
+ final_projections = base_projections
 
 
117
 
118
  sample_arrays = np.c_[fp_random, final_projections]
119
 
 
613
 
614
 
615
  with st.container():
616
+ tab1, tab2, tab3, tab4, tab5, tab6, tab7 = st.tabs(['Overall Exposures', 'Center Exposures', 'Wing Exposures', 'Defense Exposures', 'Flex Exposures', 'Goalie Exposures', 'Team Exposures'])
617
  with tab1:
618
  if 'player_freq' in st.session_state:
619
 
 
690
  file_name='team_freq.csv',
691
  mime='text/csv',
692
  key='team'
 
 
 
 
 
 
 
 
 
 
 
693
  )