James McCool
commited on
Commit
·
1b1db4f
1
Parent(s):
5830bfb
Enhance small_field_preset and large_field_preset functions to accept an additional parameter for excluded columns, improving filtering capabilities and lineup accuracy. Update app.py to reflect these changes in preset selections.
Browse files- app.py +2 -2
- global_func/large_field_preset.py +61 -17
- global_func/small_field_preset.py +1 -1
app.py
CHANGED
|
@@ -1112,9 +1112,9 @@ with tab2:
|
|
| 1112 |
submitted = st.form_submit_button("Submit")
|
| 1113 |
if submitted:
|
| 1114 |
if preset_choice == 'Small Field (Heavy Own)':
|
| 1115 |
-
parsed_frame = small_field_preset(st.session_state['working_frame'], lineup_target)
|
| 1116 |
elif preset_choice == 'Large Field (Finish Percentile / Edge)':
|
| 1117 |
-
parsed_frame = large_field_preset(st.session_state['working_frame'], lineup_target)
|
| 1118 |
# elif preset_choice == 'Volatile':
|
| 1119 |
# parsed_frame = volatile_preset(st.session_state['working_frame'], lineup_target)
|
| 1120 |
# elif preset_choice == 'Distributed':
|
|
|
|
| 1112 |
submitted = st.form_submit_button("Submit")
|
| 1113 |
if submitted:
|
| 1114 |
if preset_choice == 'Small Field (Heavy Own)':
|
| 1115 |
+
parsed_frame = small_field_preset(st.session_state['working_frame'], lineup_target, excluded_cols)
|
| 1116 |
elif preset_choice == 'Large Field (Finish Percentile / Edge)':
|
| 1117 |
+
parsed_frame = large_field_preset(st.session_state['working_frame'], lineup_target, excluded_cols)
|
| 1118 |
# elif preset_choice == 'Volatile':
|
| 1119 |
# parsed_frame = volatile_preset(st.session_state['working_frame'], lineup_target)
|
| 1120 |
# elif preset_choice == 'Distributed':
|
global_func/large_field_preset.py
CHANGED
|
@@ -1,26 +1,70 @@
|
|
| 1 |
import pandas as pd
|
| 2 |
|
| 3 |
-
def large_field_preset(portfolio: pd.DataFrame, lineup_target: int):
|
| 4 |
|
| 5 |
for slack_var in range(1, 20):
|
| 6 |
concat_portfolio = pd.DataFrame(columns=portfolio.columns)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
-
|
| 9 |
-
rows_to_drop = []
|
| 10 |
-
working_portfolio = portfolio.copy()
|
| 11 |
-
working_portfolio = working_portfolio[working_portfolio['Stack'] == team].sort_values(by='Finish_percentile', ascending = True)
|
| 12 |
-
working_portfolio = working_portfolio.reset_index(drop=True)
|
| 13 |
-
curr_own_type_max = working_portfolio.loc[0, 'Own'] + (slack_var / 20 * working_portfolio.loc[0, 'Own'])
|
| 14 |
-
|
| 15 |
-
for i in range(1, len(working_portfolio)):
|
| 16 |
-
if working_portfolio.loc[i, 'Own'] > curr_own_type_max:
|
| 17 |
-
rows_to_drop.append(i)
|
| 18 |
-
else:
|
| 19 |
-
curr_own_type_max = working_portfolio.loc[i, 'Own'] + (slack_var / 20 * working_portfolio.loc[i, 'Own'])
|
| 20 |
-
|
| 21 |
-
working_portfolio = working_portfolio.drop(rows_to_drop).reset_index(drop=True)
|
| 22 |
-
concat_portfolio = pd.concat([concat_portfolio, working_portfolio])
|
| 23 |
-
if len(concat_portfolio) >= lineup_target:
|
| 24 |
return concat_portfolio.sort_values(by='Finish_percentile', ascending=True).head(lineup_target)
|
| 25 |
|
| 26 |
return concat_portfolio.sort_values(by='Finish_percentile', ascending=True)
|
|
|
|
| 1 |
import pandas as pd
|
| 2 |
|
| 3 |
+
def large_field_preset(portfolio: pd.DataFrame, lineup_target: int, exclude_cols: list):
|
| 4 |
|
| 5 |
for slack_var in range(1, 20):
|
| 6 |
concat_portfolio = pd.DataFrame(columns=portfolio.columns)
|
| 7 |
+
|
| 8 |
+
player_columns = [col for col in concat_portfolio.columns if col not in concat_portfolio]
|
| 9 |
+
|
| 10 |
+
remove_list = []
|
| 11 |
+
|
| 12 |
+
max_iterations = 5
|
| 13 |
+
for each_iteration in range(max_iterations):
|
| 14 |
+
player_stats = []
|
| 15 |
+
concat_portfolio = pd.DataFrame(columns=portfolio.columns)
|
| 16 |
+
|
| 17 |
+
for team in portfolio['Stack'].unique():
|
| 18 |
+
rows_to_drop = []
|
| 19 |
+
working_portfolio = portfolio.copy()
|
| 20 |
+
if remove_list:
|
| 21 |
+
if len(remove_list) > 0:
|
| 22 |
+
remove_mask = working_portfolio[player_columns].apply(
|
| 23 |
+
lambda row: not any(player in list(row) for player in remove_list), axis=1
|
| 24 |
+
)
|
| 25 |
+
working_portfolio = working_portfolio[remove_mask]
|
| 26 |
+
|
| 27 |
+
working_portfolio = working_portfolio[working_portfolio['Stack'] == team].sort_values(by='Finish_percentile', ascending = True)
|
| 28 |
+
working_portfolio = working_portfolio.reset_index(drop=True)
|
| 29 |
+
|
| 30 |
+
if len(working_portfolio) == 0:
|
| 31 |
+
continue
|
| 32 |
+
|
| 33 |
+
curr_own_type_max = working_portfolio.loc[0, 'Own'] + (slack_var / 20 * working_portfolio.loc[0, 'Own'])
|
| 34 |
+
|
| 35 |
+
for i in range(1, len(working_portfolio)):
|
| 36 |
+
if working_portfolio.loc[i, 'Own'] > curr_own_type_max:
|
| 37 |
+
rows_to_drop.append(i)
|
| 38 |
+
else:
|
| 39 |
+
curr_own_type_max = working_portfolio.loc[i, 'Own'] + (slack_var / 20 * working_portfolio.loc[i, 'Own'])
|
| 40 |
+
|
| 41 |
+
working_portfolio = working_portfolio.drop(rows_to_drop).reset_index(drop=True)
|
| 42 |
+
|
| 43 |
+
concat_portfolio = pd.concat([concat_portfolio, working_portfolio])
|
| 44 |
+
|
| 45 |
+
player_names = set()
|
| 46 |
+
for col in concat_portfolio.columns:
|
| 47 |
+
if col not in exclude_cols:
|
| 48 |
+
player_names.update(concat_portfolio[col].unique())
|
| 49 |
+
for player in player_names:
|
| 50 |
+
player_mask = concat_portfolio[player_columns].apply(
|
| 51 |
+
lambda row: player in list(row), axis=1
|
| 52 |
+
)
|
| 53 |
+
|
| 54 |
+
if player_mask.any():
|
| 55 |
+
player_stats.append({
|
| 56 |
+
'Player': player,
|
| 57 |
+
'Lineup Count': player_mask.sum(),
|
| 58 |
+
'Exposure': player_mask.sum() / len(concat_portfolio),
|
| 59 |
+
})
|
| 60 |
+
player_exposure = pd.DataFrame(player_stats)
|
| 61 |
+
player_exposure = player_exposure[player_exposure['Exposure'] > .50]
|
| 62 |
+
remove_list = player_exposure['Player'].tolist()
|
| 63 |
+
|
| 64 |
+
if len(remove_list) == 0:
|
| 65 |
+
break
|
| 66 |
|
| 67 |
+
if len(concat_portfolio) >= lineup_target and len(remove_list) == 0:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
return concat_portfolio.sort_values(by='Finish_percentile', ascending=True).head(lineup_target)
|
| 69 |
|
| 70 |
return concat_portfolio.sort_values(by='Finish_percentile', ascending=True)
|
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):
|
| 4 |
|
| 5 |
for slack_var in range(1, 20):
|
| 6 |
concat_portfolio = pd.DataFrame(columns=portfolio.columns)
|
|
|
|
| 1 |
import pandas as pd
|
| 2 |
|
| 3 |
+
def small_field_preset(portfolio: pd.DataFrame, lineup_target: int, exclude_cols: list):
|
| 4 |
|
| 5 |
for slack_var in range(1, 20):
|
| 6 |
concat_portfolio = pd.DataFrame(columns=portfolio.columns)
|