Spaces:
Sleeping
Sleeping
James McCool
commited on
Commit
·
05f2b9c
1
Parent(s):
01c1482
Add support for LOL in app.py and related functions, updating sport selection and eligibility checks across multiple modules to include League of Legends, enhancing overall functionality and user experience.
Browse files- app.py +10 -10
- global_func/exposure_spread.py +21 -0
- global_func/hedging_preset.py +2 -2
- global_func/predict_dupes.py +1 -1
- global_func/small_field_preset.py +1 -1
- global_func/volatility_preset.py +1 -1
app.py
CHANGED
@@ -28,7 +28,7 @@ from global_func.stratification_function import stratification_function
|
|
28 |
from global_func.exposure_spread import exposure_spread
|
29 |
|
30 |
freq_format = {'Finish_percentile': '{:.2%}', 'Lineup Edge': '{:.2%}', 'Win%': '{:.2%}'}
|
31 |
-
stacking_sports = ['MLB', 'NHL', 'NFL']
|
32 |
player_wrong_names_mlb = ['Enrique Hernandez', 'Joseph Cantillo', 'Mike Soroka', 'Jakob Bauers', 'Temi Fágbénlé']
|
33 |
player_right_names_mlb = ['Kike Hernandez', 'Joey Cantillo', 'Michael Soroka', 'Jake Bauers', 'Temi Fagbenle']
|
34 |
|
@@ -42,7 +42,7 @@ with st.container():
|
|
42 |
site_var = st.selectbox("Select Site", ['Draftkings', 'Fanduel'])
|
43 |
|
44 |
with col3:
|
45 |
-
sport_var = st.selectbox("Select Sport", ['NFL', 'MLB', 'NBA', 'NHL', 'MMA', 'CS2', 'TENNIS', 'NASCAR', 'GOLF', 'WNBA'])
|
46 |
|
47 |
with col4:
|
48 |
type_var = st.selectbox("Select Game Type", ['Classic', 'Showdown'])
|
@@ -296,7 +296,7 @@ with tab1:
|
|
296 |
if 'map_dict' not in st.session_state:
|
297 |
if site_var == 'Draftkings':
|
298 |
if type_var == 'Classic':
|
299 |
-
if sport_var == 'CS2':
|
300 |
st.session_state['map_dict'] = {
|
301 |
'pos_map':dict(zip(st.session_state['projections_df']['player_names'], st.session_state['projections_df']['position'])),
|
302 |
'team_map':dict(zip(st.session_state['projections_df']['player_names'], st.session_state['projections_df']['team'])),
|
@@ -308,7 +308,7 @@ with tab1:
|
|
308 |
'cpt_proj_map':dict(zip(st.session_state['projections_df']['player_names'], st.session_state['projections_df']['median'] * 1.5)),
|
309 |
'cpt_own_map':dict(zip(st.session_state['projections_df']['player_names'], st.session_state['projections_df']['captain ownership']))
|
310 |
}
|
311 |
-
elif sport_var != 'CS2':
|
312 |
st.session_state['map_dict'] = {
|
313 |
'pos_map':dict(zip(st.session_state['projections_df']['player_names'], st.session_state['projections_df']['position'])),
|
314 |
'team_map':dict(zip(st.session_state['projections_df']['player_names'], st.session_state['projections_df']['team'])),
|
@@ -903,7 +903,7 @@ with tab2:
|
|
903 |
st.session_state['working_frame'] = pd.read_parquet(io.BytesIO(st.session_state['origin_portfolio']))
|
904 |
|
905 |
if type_var == 'Classic':
|
906 |
-
if sport_var == 'CS2':
|
907 |
# Calculate salary (CPT uses cpt_salary_map, others use salary_map)
|
908 |
st.session_state['working_frame']['salary'] = st.session_state['working_frame'].apply(
|
909 |
lambda row: st.session_state['map_dict']['cpt_salary_map'].get(row.iloc[0], 0) +
|
@@ -925,7 +925,7 @@ with tab2:
|
|
925 |
axis=1
|
926 |
)
|
927 |
|
928 |
-
elif sport_var != 'CS2':
|
929 |
st.session_state['working_frame']['salary'] = st.session_state['working_frame'].apply(lambda row: sum(st.session_state['map_dict']['salary_map'].get(player, 0) for player in row), axis=1)
|
930 |
st.session_state['working_frame']['median'] = st.session_state['working_frame'].apply(lambda row: sum(st.session_state['map_dict']['proj_map'].get(player, 0) for player in row), axis=1)
|
931 |
st.session_state['working_frame']['Own'] = st.session_state['working_frame'].apply(lambda row: sum(st.session_state['map_dict']['own_map'].get(player, 0) for player in row), axis=1)
|
@@ -989,7 +989,7 @@ with tab2:
|
|
989 |
max_salary = st.number_input("Max acceptable salary?", value=100000, min_value=1000, step=100)
|
990 |
max_finish_percentile = st.number_input("Max acceptable finish percentile?", value=.50, min_value=0.005, step=.001)
|
991 |
min_lineup_edge = st.number_input("Min acceptable Lineup Edge?", value=-.5, min_value=-1.00, step=.001)
|
992 |
-
if sport_var in ['NFL', 'MLB', 'NHL']:
|
993 |
stack_include_toggle = st.selectbox("Include specific stacks?", options=['All Stacks', 'Specific Stacks'], index=0)
|
994 |
stack_selections = st.multiselect("If Specific Stacks, Which to include?", options=sorted(list(set(st.session_state['stack_dict'].values()))), default=[])
|
995 |
|
@@ -1028,7 +1028,7 @@ with tab2:
|
|
1028 |
player_remove = st.multiselect("Remove players?", options=sorted(list(player_names)), default=[])
|
1029 |
team_include = st.multiselect("Include teams?", options=sorted(list(set(st.session_state['projections_df']['team'].unique()))), default=[])
|
1030 |
team_remove = st.multiselect("Remove teams?", options=sorted(list(set(st.session_state['projections_df']['team'].unique()))), default=[])
|
1031 |
-
if sport_var in ['NFL', 'MLB', 'NHL']:
|
1032 |
size_include = st.multiselect("Include sizes?", options=sorted(list(set(st.session_state['working_frame']['Size'].unique()))), default=[])
|
1033 |
else:
|
1034 |
size_include = []
|
@@ -1329,7 +1329,7 @@ with tab2:
|
|
1329 |
'Avg Lineup Edge': display_frame[flex_mask]['Lineup Edge'].mean(),
|
1330 |
})
|
1331 |
else:
|
1332 |
-
if sport_var == 'CS2':
|
1333 |
# Handle Captain positions
|
1334 |
for player in player_names:
|
1335 |
# Create mask for lineups where this player is Captain (first column)
|
@@ -1363,7 +1363,7 @@ with tab2:
|
|
1363 |
'Avg Finish %': display_frame[flex_mask]['Finish_percentile'].mean(),
|
1364 |
'Avg Lineup Edge': display_frame[flex_mask]['Lineup Edge'].mean(),
|
1365 |
})
|
1366 |
-
elif sport_var != 'CS2':
|
1367 |
# Original Classic format processing
|
1368 |
for player in player_names:
|
1369 |
player_mask = display_frame[player_columns].apply(
|
|
|
28 |
from global_func.exposure_spread import exposure_spread
|
29 |
|
30 |
freq_format = {'Finish_percentile': '{:.2%}', 'Lineup Edge': '{:.2%}', 'Win%': '{:.2%}'}
|
31 |
+
stacking_sports = ['MLB', 'NHL', 'NFL', 'LOL']
|
32 |
player_wrong_names_mlb = ['Enrique Hernandez', 'Joseph Cantillo', 'Mike Soroka', 'Jakob Bauers', 'Temi Fágbénlé']
|
33 |
player_right_names_mlb = ['Kike Hernandez', 'Joey Cantillo', 'Michael Soroka', 'Jake Bauers', 'Temi Fagbenle']
|
34 |
|
|
|
42 |
site_var = st.selectbox("Select Site", ['Draftkings', 'Fanduel'])
|
43 |
|
44 |
with col3:
|
45 |
+
sport_var = st.selectbox("Select Sport", ['NFL', 'MLB', 'NBA', 'NHL', 'MMA', 'CS2', 'LOL', 'TENNIS', 'NASCAR', 'GOLF', 'WNBA'])
|
46 |
|
47 |
with col4:
|
48 |
type_var = st.selectbox("Select Game Type", ['Classic', 'Showdown'])
|
|
|
296 |
if 'map_dict' not in st.session_state:
|
297 |
if site_var == 'Draftkings':
|
298 |
if type_var == 'Classic':
|
299 |
+
if sport_var == 'CS2' or sport_var == 'LOL':
|
300 |
st.session_state['map_dict'] = {
|
301 |
'pos_map':dict(zip(st.session_state['projections_df']['player_names'], st.session_state['projections_df']['position'])),
|
302 |
'team_map':dict(zip(st.session_state['projections_df']['player_names'], st.session_state['projections_df']['team'])),
|
|
|
308 |
'cpt_proj_map':dict(zip(st.session_state['projections_df']['player_names'], st.session_state['projections_df']['median'] * 1.5)),
|
309 |
'cpt_own_map':dict(zip(st.session_state['projections_df']['player_names'], st.session_state['projections_df']['captain ownership']))
|
310 |
}
|
311 |
+
elif sport_var != 'CS2' and sport_var != 'LOL':
|
312 |
st.session_state['map_dict'] = {
|
313 |
'pos_map':dict(zip(st.session_state['projections_df']['player_names'], st.session_state['projections_df']['position'])),
|
314 |
'team_map':dict(zip(st.session_state['projections_df']['player_names'], st.session_state['projections_df']['team'])),
|
|
|
903 |
st.session_state['working_frame'] = pd.read_parquet(io.BytesIO(st.session_state['origin_portfolio']))
|
904 |
|
905 |
if type_var == 'Classic':
|
906 |
+
if sport_var == 'CS2' or sport_var == 'LOL':
|
907 |
# Calculate salary (CPT uses cpt_salary_map, others use salary_map)
|
908 |
st.session_state['working_frame']['salary'] = st.session_state['working_frame'].apply(
|
909 |
lambda row: st.session_state['map_dict']['cpt_salary_map'].get(row.iloc[0], 0) +
|
|
|
925 |
axis=1
|
926 |
)
|
927 |
|
928 |
+
elif sport_var != 'CS2' and sport_var != 'LOL':
|
929 |
st.session_state['working_frame']['salary'] = st.session_state['working_frame'].apply(lambda row: sum(st.session_state['map_dict']['salary_map'].get(player, 0) for player in row), axis=1)
|
930 |
st.session_state['working_frame']['median'] = st.session_state['working_frame'].apply(lambda row: sum(st.session_state['map_dict']['proj_map'].get(player, 0) for player in row), axis=1)
|
931 |
st.session_state['working_frame']['Own'] = st.session_state['working_frame'].apply(lambda row: sum(st.session_state['map_dict']['own_map'].get(player, 0) for player in row), axis=1)
|
|
|
989 |
max_salary = st.number_input("Max acceptable salary?", value=100000, min_value=1000, step=100)
|
990 |
max_finish_percentile = st.number_input("Max acceptable finish percentile?", value=.50, min_value=0.005, step=.001)
|
991 |
min_lineup_edge = st.number_input("Min acceptable Lineup Edge?", value=-.5, min_value=-1.00, step=.001)
|
992 |
+
if sport_var in ['NFL', 'MLB', 'NHL', 'LOL']:
|
993 |
stack_include_toggle = st.selectbox("Include specific stacks?", options=['All Stacks', 'Specific Stacks'], index=0)
|
994 |
stack_selections = st.multiselect("If Specific Stacks, Which to include?", options=sorted(list(set(st.session_state['stack_dict'].values()))), default=[])
|
995 |
|
|
|
1028 |
player_remove = st.multiselect("Remove players?", options=sorted(list(player_names)), default=[])
|
1029 |
team_include = st.multiselect("Include teams?", options=sorted(list(set(st.session_state['projections_df']['team'].unique()))), default=[])
|
1030 |
team_remove = st.multiselect("Remove teams?", options=sorted(list(set(st.session_state['projections_df']['team'].unique()))), default=[])
|
1031 |
+
if sport_var in ['NFL', 'MLB', 'NHL', 'LOL']:
|
1032 |
size_include = st.multiselect("Include sizes?", options=sorted(list(set(st.session_state['working_frame']['Size'].unique()))), default=[])
|
1033 |
else:
|
1034 |
size_include = []
|
|
|
1329 |
'Avg Lineup Edge': display_frame[flex_mask]['Lineup Edge'].mean(),
|
1330 |
})
|
1331 |
else:
|
1332 |
+
if sport_var == 'CS2' or sport_var == 'LOL':
|
1333 |
# Handle Captain positions
|
1334 |
for player in player_names:
|
1335 |
# Create mask for lineups where this player is Captain (first column)
|
|
|
1363 |
'Avg Finish %': display_frame[flex_mask]['Finish_percentile'].mean(),
|
1364 |
'Avg Lineup Edge': display_frame[flex_mask]['Lineup Edge'].mean(),
|
1365 |
})
|
1366 |
+
elif sport_var != 'CS2' and sport_var != 'LOL':
|
1367 |
# Original Classic format processing
|
1368 |
for player in player_names:
|
1369 |
player_mask = display_frame[player_columns].apply(
|
global_func/exposure_spread.py
CHANGED
@@ -32,6 +32,25 @@ def check_nba_position_eligibility(column_name, player_positions):
|
|
32 |
return True # UTIL can be any position
|
33 |
return False
|
34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
def check_mlb_position_eligibility(column_name, player_positions):
|
36 |
"""
|
37 |
Check if a player is eligible for a specific MLB column position.
|
@@ -184,6 +203,8 @@ def check_position_eligibility(sport, column_name, player_positions):
|
|
184 |
return check_golf_position_eligibility(column_name, player_positions)
|
185 |
elif sport == 'Tennis':
|
186 |
return check_tennis_position_eligibility(column_name, player_positions)
|
|
|
|
|
187 |
else:
|
188 |
# Default fallback - assume exact position match
|
189 |
return column_name in player_positions
|
|
|
32 |
return True # UTIL can be any position
|
33 |
return False
|
34 |
|
35 |
+
def check_lol_position_eligibility(column_name, player_positions):
|
36 |
+
"""
|
37 |
+
Check if a player is eligible for a specific LOL column position.
|
38 |
+
|
39 |
+
Args:
|
40 |
+
column_name (str): The column name (TOP, JNG, MID, ADC, SUP, UTIL)
|
41 |
+
player_positions (list): List of positions the player is eligible for
|
42 |
+
|
43 |
+
Returns:
|
44 |
+
bool: True if player is eligible for the column
|
45 |
+
"""
|
46 |
+
if any(pos in column_name for pos in ['TOP', 'JNG', 'MID', 'ADC', 'SUP', 'Team']):
|
47 |
+
# Extract the base position from the column name
|
48 |
+
base_position = next(pos for pos in ['TOP', 'JNG', 'MID', 'ADC', 'SUP', 'Team'] if pos in column_name)
|
49 |
+
return base_position in player_positions
|
50 |
+
elif 'CPT' in column_name:
|
51 |
+
return any(pos in ['TOP', 'JNG', 'MID', 'ADC', 'SUP'] for pos in player_positions)
|
52 |
+
return False
|
53 |
+
|
54 |
def check_mlb_position_eligibility(column_name, player_positions):
|
55 |
"""
|
56 |
Check if a player is eligible for a specific MLB column position.
|
|
|
203 |
return check_golf_position_eligibility(column_name, player_positions)
|
204 |
elif sport == 'Tennis':
|
205 |
return check_tennis_position_eligibility(column_name, player_positions)
|
206 |
+
elif sport == 'LOL':
|
207 |
+
return check_lol_position_eligibility(column_name, player_positions)
|
208 |
else:
|
209 |
# Default fallback - assume exact position match
|
210 |
return column_name in player_positions
|
global_func/hedging_preset.py
CHANGED
@@ -35,7 +35,7 @@ def hedging_preset(portfolio: pd.DataFrame, lineup_target: int, projections_file
|
|
35 |
|
36 |
return team_ownership
|
37 |
|
38 |
-
if sport == 'MLB':
|
39 |
team_ownership = get_team_hitter_ownership(projections_file)
|
40 |
top_owned_teams = team_ownership.head(list_size).index.tolist()
|
41 |
|
@@ -72,7 +72,7 @@ def hedging_preset(portfolio: pd.DataFrame, lineup_target: int, projections_file
|
|
72 |
print(f"No lineups found containing {player}")
|
73 |
concat_portfolio = pd.concat([concat_portfolio, removed_lineups])
|
74 |
|
75 |
-
if sport == 'MLB':
|
76 |
for team in top_owned_teams:
|
77 |
working_df = portfolio.copy()
|
78 |
removed_df = working_df[working_df['Stack'] != team]
|
|
|
35 |
|
36 |
return team_ownership
|
37 |
|
38 |
+
if sport == 'MLB' or sport == 'LOL' or sport == 'NHL':
|
39 |
team_ownership = get_team_hitter_ownership(projections_file)
|
40 |
top_owned_teams = team_ownership.head(list_size).index.tolist()
|
41 |
|
|
|
72 |
print(f"No lineups found containing {player}")
|
73 |
concat_portfolio = pd.concat([concat_portfolio, removed_lineups])
|
74 |
|
75 |
+
if sport == 'MLB' or sport == 'LOL' or sport == 'NHL':
|
76 |
for team in top_owned_teams:
|
77 |
working_df = portfolio.copy()
|
78 |
removed_df = working_df[working_df['Stack'] != team]
|
global_func/predict_dupes.py
CHANGED
@@ -208,7 +208,7 @@ def predict_dupes_vectorized(portfolio, maps_dict, site_var, type_var, Contest_S
|
|
208 |
percentile_cut_scalar = portfolio_values[:, portfolio.columns.get_loc('median')].max()
|
209 |
|
210 |
if type_var == 'Classic':
|
211 |
-
own_ratio_nerf = 2 if sport_var == 'CS2' else 1.5
|
212 |
elif type_var == 'Showdown':
|
213 |
own_ratio_nerf = 1.5
|
214 |
|
|
|
208 |
percentile_cut_scalar = portfolio_values[:, portfolio.columns.get_loc('median')].max()
|
209 |
|
210 |
if type_var == 'Classic':
|
211 |
+
own_ratio_nerf = 2 if sport_var == 'CS2' or sport_var == 'LOL' else 1.5
|
212 |
elif type_var == 'Showdown':
|
213 |
own_ratio_nerf = 1.5
|
214 |
|
global_func/small_field_preset.py
CHANGED
@@ -6,7 +6,7 @@ def small_field_preset(portfolio: pd.DataFrame, lineup_target: int, exclude_cols
|
|
6 |
|
7 |
for slack_var in range(1, 20):
|
8 |
concat_portfolio = pd.DataFrame(columns=portfolio.columns)
|
9 |
-
if sport == 'MLB':
|
10 |
for team in portfolio['Stack'].unique():
|
11 |
rows_to_drop = []
|
12 |
working_portfolio = portfolio.copy()
|
|
|
6 |
|
7 |
for slack_var in range(1, 20):
|
8 |
concat_portfolio = pd.DataFrame(columns=portfolio.columns)
|
9 |
+
if sport == 'MLB' or sport == 'LOL' or sport == 'NHL':
|
10 |
for team in portfolio['Stack'].unique():
|
11 |
rows_to_drop = []
|
12 |
working_portfolio = portfolio.copy()
|
global_func/volatility_preset.py
CHANGED
@@ -6,7 +6,7 @@ def volatility_preset(portfolio: pd.DataFrame, lineup_target: int, exclude_cols:
|
|
6 |
|
7 |
for slack_var in range(1, 20):
|
8 |
concat_portfolio = pd.DataFrame(columns=portfolio.columns)
|
9 |
-
if sport == 'MLB':
|
10 |
for team in portfolio['Stack'].unique():
|
11 |
rows_to_drop = []
|
12 |
working_portfolio = portfolio.copy()
|
|
|
6 |
|
7 |
for slack_var in range(1, 20):
|
8 |
concat_portfolio = pd.DataFrame(columns=portfolio.columns)
|
9 |
+
if sport == 'MLB' or sport == 'LOL' or sport == 'NHL':
|
10 |
for team in portfolio['Stack'].unique():
|
11 |
rows_to_drop = []
|
12 |
working_portfolio = portfolio.copy()
|