James McCool commited on
Commit
206da8c
·
1 Parent(s): ec67dfb

Enhance preset functions in app.py and related modules to include 'sport' parameter for improved flexibility in lineup management. This update modifies the small_field_preset, large_field_preset, volatility_preset, hedging_preset, and reduce_volatility_preset functions to accommodate sport-specific logic, enhancing user experience and accuracy in lineup strategies.

Browse files
app.py CHANGED
@@ -1118,15 +1118,15 @@ with tab2:
1118
  submitted = st.form_submit_button("Submit")
1119
  if submitted:
1120
  if preset_choice == 'Small Field (Heavy Own)':
1121
- parsed_frame = small_field_preset(st.session_state['working_frame'], lineup_target, excluded_cols)
1122
  elif preset_choice == 'Large Field (Manage Diversity)':
1123
- parsed_frame = large_field_preset(st.session_state['working_frame'], lineup_target, excluded_cols)
1124
  elif preset_choice == 'Volatility (Heavy Lineup Edge)':
1125
- parsed_frame = volatility_preset(st.session_state['working_frame'], lineup_target, excluded_cols)
1126
  elif preset_choice == 'Hedge Chalk (Manage Leverage)':
1127
- parsed_frame = hedging_preset(st.session_state['working_frame'], lineup_target, st.session_state['projections_df'])
1128
  elif preset_choice == 'Reduce Volatility (Manage Own)':
1129
- parsed_frame = reduce_volatility_preset(st.session_state['working_frame'], lineup_target, excluded_cols)
1130
  st.session_state['working_frame'] = parsed_frame.reset_index(drop=True)
1131
  st.session_state['export_merge'] = st.session_state['working_frame'].copy()
1132
 
 
1118
  submitted = st.form_submit_button("Submit")
1119
  if submitted:
1120
  if preset_choice == 'Small Field (Heavy Own)':
1121
+ parsed_frame = small_field_preset(st.session_state['working_frame'], lineup_target, excluded_cols, sport_var)
1122
  elif preset_choice == 'Large Field (Manage Diversity)':
1123
+ parsed_frame = large_field_preset(st.session_state['working_frame'], lineup_target, excluded_cols, sport_var)
1124
  elif preset_choice == 'Volatility (Heavy Lineup Edge)':
1125
+ parsed_frame = volatility_preset(st.session_state['working_frame'], lineup_target, excluded_cols, sport_var)
1126
  elif preset_choice == 'Hedge Chalk (Manage Leverage)':
1127
+ parsed_frame = hedging_preset(st.session_state['working_frame'], lineup_target, st.session_state['projections_df'], sport_var)
1128
  elif preset_choice == 'Reduce Volatility (Manage Own)':
1129
+ parsed_frame = reduce_volatility_preset(st.session_state['working_frame'], lineup_target, excluded_cols, sport_var)
1130
  st.session_state['working_frame'] = parsed_frame.reset_index(drop=True)
1131
  st.session_state['export_merge'] = st.session_state['working_frame'].copy()
1132
 
global_func/hedging_preset.py CHANGED
@@ -3,10 +3,13 @@ import math
3
  from global_func.small_field_preset import small_field_preset
4
  from global_func.large_field_preset import large_field_preset
5
 
6
- def hedging_preset(portfolio: pd.DataFrame, lineup_target: int, projections_file: pd.DataFrame):
7
 
8
  excluded_cols = ['salary', 'median', 'Own', 'Finish_percentile', 'Dupes', 'Stack', 'Size', 'Win%', 'Lineup Edge', 'Weighted Own', 'Geomean', 'Diversity']
9
- list_size = 3
 
 
 
10
 
11
  check_own_df = projections_file.copy()
12
  check_own_df = check_own_df.sort_values(by='ownership', ascending=False)
@@ -31,8 +34,10 @@ def hedging_preset(portfolio: pd.DataFrame, lineup_target: int, projections_file
31
 
32
  return team_ownership
33
 
34
- team_ownership = get_team_hitter_ownership(projections_file)
35
- top_owned_teams = team_ownership.head(list_size).index.tolist()
 
 
36
  init_counter = 6
37
 
38
  for runs in range(1, 5):
@@ -66,20 +71,21 @@ def hedging_preset(portfolio: pd.DataFrame, lineup_target: int, projections_file
66
  print(f"No lineups found containing {player}")
67
  concat_portfolio = pd.concat([concat_portfolio, removed_lineups])
68
 
69
- for team in top_owned_teams:
70
- working_df = portfolio.copy()
71
- removed_df = working_df[working_df['Stack'] != team]
72
- teams_df = working_df[working_df['Stack'] == team]
 
73
 
74
- removed_lineups = small_field_preset(removed_df, math.ceil(lineup_target / (list_size * init_counter)), excluded_cols)
75
- # Check if teams_df is empty before calling large_field_preset
76
- if not teams_df.empty:
77
- team_lineups = large_field_preset(teams_df, math.ceil(lineup_target / (list_size * init_counter)), excluded_cols)
78
- concat_portfolio = pd.concat([concat_portfolio, removed_lineups, team_lineups])
79
- else:
80
- # If no lineups have this team stacked, just add the removed lineups
81
- print(f"No lineups found with {team} stacked")
82
- concat_portfolio = pd.concat([concat_portfolio, removed_lineups])
83
 
84
  concat_portfolio = concat_portfolio.drop_duplicates(subset=['median', 'Own', 'Lineup Edge', 'Diversity'])
85
 
 
3
  from global_func.small_field_preset import small_field_preset
4
  from global_func.large_field_preset import large_field_preset
5
 
6
+ def hedging_preset(portfolio: pd.DataFrame, lineup_target: int, projections_file: pd.DataFrame, sport: str):
7
 
8
  excluded_cols = ['salary', 'median', 'Own', 'Finish_percentile', 'Dupes', 'Stack', 'Size', 'Win%', 'Lineup Edge', 'Weighted Own', 'Geomean', 'Diversity']
9
+ if sport == 'MLB':
10
+ list_size = 3
11
+ else:
12
+ list_size = 5
13
 
14
  check_own_df = projections_file.copy()
15
  check_own_df = check_own_df.sort_values(by='ownership', ascending=False)
 
34
 
35
  return team_ownership
36
 
37
+ if sport == 'MLB':
38
+ team_ownership = get_team_hitter_ownership(projections_file)
39
+ top_owned_teams = team_ownership.head(list_size).index.tolist()
40
+
41
  init_counter = 6
42
 
43
  for runs in range(1, 5):
 
71
  print(f"No lineups found containing {player}")
72
  concat_portfolio = pd.concat([concat_portfolio, removed_lineups])
73
 
74
+ if sport == 'MLB':
75
+ for team in top_owned_teams:
76
+ working_df = portfolio.copy()
77
+ removed_df = working_df[working_df['Stack'] != team]
78
+ teams_df = working_df[working_df['Stack'] == team]
79
 
80
+ removed_lineups = small_field_preset(removed_df, math.ceil(lineup_target / (list_size * init_counter)), excluded_cols)
81
+ # Check if teams_df is empty before calling large_field_preset
82
+ if not teams_df.empty:
83
+ team_lineups = large_field_preset(teams_df, math.ceil(lineup_target / (list_size * init_counter)), excluded_cols)
84
+ concat_portfolio = pd.concat([concat_portfolio, removed_lineups, team_lineups])
85
+ else:
86
+ # If no lineups have this team stacked, just add the removed lineups
87
+ print(f"No lineups found with {team} stacked")
88
+ concat_portfolio = pd.concat([concat_portfolio, removed_lineups])
89
 
90
  concat_portfolio = concat_portfolio.drop_duplicates(subset=['median', 'Own', 'Lineup Edge', 'Diversity'])
91
 
global_func/large_field_preset.py CHANGED
@@ -1,7 +1,7 @@
1
  import pandas as pd
2
  import numpy as np
3
 
4
- def large_field_preset(portfolio: pd.DataFrame, lineup_target: int, exclude_cols: list):
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
 
 
1
  import pandas as pd
2
  import numpy as np
3
 
4
+ def large_field_preset(portfolio: pd.DataFrame, lineup_target: int, exclude_cols: list, sport: 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
 
global_func/reduce_volatility_preset.py CHANGED
@@ -1,7 +1,7 @@
1
  import pandas as pd
2
  import numpy as np
3
 
4
- def reduce_volatility_preset(portfolio: pd.DataFrame, lineup_target: int, exclude_cols: list):
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
 
 
1
  import pandas as pd
2
  import numpy as np
3
 
4
+ def reduce_volatility_preset(portfolio: pd.DataFrame, lineup_target: int, exclude_cols: list, sport: 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
 
global_func/small_field_preset.py CHANGED
@@ -1,6 +1,6 @@
1
  import pandas as pd
2
 
3
- def small_field_preset(portfolio: pd.DataFrame, lineup_target: int, exclude_cols: list):
4
  excluded_cols = ['salary', 'median', 'Own', 'Finish_percentile', 'Dupes', 'Stack', 'Size', 'Win%', 'Lineup Edge', 'Weighted Own', 'Geomean', 'Diversity']
5
  player_columns = [col for col in portfolio.columns if col not in excluded_cols]
6
 
 
1
  import pandas as pd
2
 
3
+ def small_field_preset(portfolio: pd.DataFrame, lineup_target: int, exclude_cols: list, sport: str):
4
  excluded_cols = ['salary', 'median', 'Own', 'Finish_percentile', 'Dupes', 'Stack', 'Size', 'Win%', 'Lineup Edge', 'Weighted Own', 'Geomean', 'Diversity']
5
  player_columns = [col for col in portfolio.columns if col not in excluded_cols]
6
 
global_func/volatility_preset.py CHANGED
@@ -1,7 +1,7 @@
1
  import pandas as pd
2
  import numpy as np
3
 
4
- def volatility_preset(portfolio: pd.DataFrame, lineup_target: int, exclude_cols: list):
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
 
 
1
  import pandas as pd
2
  import numpy as np
3
 
4
+ def volatility_preset(portfolio: pd.DataFrame, lineup_target: int, exclude_cols: list, sport: 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