James McCool commited on
Commit
99b9aa9
·
1 Parent(s): 0512365

Add stratification sample range slider to app.py and update stratification_function to accept threshold parameters for improved player selection control.

Browse files
Files changed (2) hide show
  1. app.py +3 -2
  2. global_func/stratification_function.py +3 -3
app.py CHANGED
@@ -1312,6 +1312,7 @@ with tab2:
1312
  with st.form(key='Stratification'):
1313
  sorting_choice = st.selectbox("Stat Choice", options=['median', 'Own', 'Weighted Own', 'Geomean', 'Lineup Edge', 'Finish_percentile', 'Diversity'], index=0)
1314
  lineup_target = st.number_input("Lineups to produce", value=150, min_value=1, step=1)
 
1315
  submitted_col, export_col = st.columns(2)
1316
  st.info("Portfolio Button applies to your overall Portfolio, Export button applies to your Custom Export")
1317
  with submitted_col:
@@ -1320,12 +1321,12 @@ with tab2:
1320
  exp_submitted = st.form_submit_button("Export")
1321
  if reg_submitted:
1322
  st.session_state['settings_base'] = False
1323
- parsed_frame = stratification_function(st.session_state['working_frame'], lineup_target, excluded_cols, sport_var, sorting_choice)
1324
  st.session_state['working_frame'] = parsed_frame.reset_index(drop=True)
1325
  st.session_state['export_merge'] = st.session_state['working_frame'].copy()
1326
  elif exp_submitted:
1327
  st.session_state['settings_base'] = False
1328
- parsed_frame = stratification_function(st.session_state['export_base'], lineup_target, excluded_cols, sport_var, sorting_choice)
1329
  st.session_state['export_base'] = parsed_frame.reset_index(drop=True)
1330
  st.session_state['export_merge'] = st.session_state['export_base'].copy()
1331
  with st.expander('Exposure Management'):
 
1312
  with st.form(key='Stratification'):
1313
  sorting_choice = st.selectbox("Stat Choice", options=['median', 'Own', 'Weighted Own', 'Geomean', 'Lineup Edge', 'Finish_percentile', 'Diversity'], index=0)
1314
  lineup_target = st.number_input("Lineups to produce", value=150, min_value=1, step=1)
1315
+ strat_sample = st.slider("Sample range", value=0.0, min_value=0.0, max_value=1.0, step=0.05)
1316
  submitted_col, export_col = st.columns(2)
1317
  st.info("Portfolio Button applies to your overall Portfolio, Export button applies to your Custom Export")
1318
  with submitted_col:
 
1321
  exp_submitted = st.form_submit_button("Export")
1322
  if reg_submitted:
1323
  st.session_state['settings_base'] = False
1324
+ parsed_frame = stratification_function(st.session_state['working_frame'], lineup_target, excluded_cols, sport_var, sorting_choice, strat_sample[0], strat_sample[1])
1325
  st.session_state['working_frame'] = parsed_frame.reset_index(drop=True)
1326
  st.session_state['export_merge'] = st.session_state['working_frame'].copy()
1327
  elif exp_submitted:
1328
  st.session_state['settings_base'] = False
1329
+ parsed_frame = stratification_function(st.session_state['export_base'], lineup_target, excluded_cols, sport_var, sorting_choice, strat_sample[0], strat_sample[1])
1330
  st.session_state['export_base'] = parsed_frame.reset_index(drop=True)
1331
  st.session_state['export_merge'] = st.session_state['export_base'].copy()
1332
  with st.expander('Exposure Management'):
global_func/stratification_function.py CHANGED
@@ -1,7 +1,7 @@
1
  import pandas as pd
2
  import numpy as np
3
 
4
- def stratification_function(portfolio: pd.DataFrame, lineup_target: int, exclude_cols: list, sport: str, sorting_choice: str):
5
  excluded_cols = ['salary', 'median', 'Own', 'Finish_percentile', 'Dupes', 'Stack', 'Size', 'Win%', 'Lineup Edge', 'Weighted Own', 'Geomean', 'Diversity']
6
  player_columns = [col for col in portfolio.columns if col not in excluded_cols]
7
 
@@ -12,8 +12,8 @@ def stratification_function(portfolio: pd.DataFrame, lineup_target: int, exclude
12
  concat_portfolio = concat_portfolio.sort_values(by=sorting_choice, ascending=False).reset_index(drop=True)
13
 
14
  # Calculate target similarity scores for linear progression
15
- similarity_floor = concat_portfolio[sorting_choice].min()
16
- similarity_ceiling = concat_portfolio[sorting_choice].max()
17
 
18
  # Create evenly spaced target similarity scores
19
  target_similarities = np.linspace(similarity_floor, similarity_ceiling, lineup_target)
 
1
  import pandas as pd
2
  import numpy as np
3
 
4
+ def stratification_function(portfolio: pd.DataFrame, lineup_target: int, exclude_cols: list, sport: str, sorting_choice: str, low_threshold: float, high_threshold: float):
5
  excluded_cols = ['salary', 'median', 'Own', 'Finish_percentile', 'Dupes', 'Stack', 'Size', 'Win%', 'Lineup Edge', 'Weighted Own', 'Geomean', 'Diversity']
6
  player_columns = [col for col in portfolio.columns if col not in excluded_cols]
7
 
 
12
  concat_portfolio = concat_portfolio.sort_values(by=sorting_choice, ascending=False).reset_index(drop=True)
13
 
14
  # Calculate target similarity scores for linear progression
15
+ similarity_floor = concat_portfolio[sorting_choice].min() + (concat_portfolio[sorting_choice].min() * low_threshold)
16
+ similarity_ceiling = concat_portfolio[sorting_choice].max() - (concat_portfolio[sorting_choice].max() * high_threshold)
17
 
18
  # Create evenly spaced target similarity scores
19
  target_similarities = np.linspace(similarity_floor, similarity_ceiling, lineup_target)