James McCool
commited on
Commit
·
936a186
1
Parent(s):
ab5ff8c
Add large field preset functionality in app.py and implement large_field_preset function for improved lineup targeting. Update small_field_preset function to sort by 'Own' for consistency in portfolio adjustments.
Browse files- app.py +4 -3
- global_func/large_field_preset.py +23 -0
- global_func/small_field_preset.py +2 -2
app.py
CHANGED
@@ -21,6 +21,7 @@ from global_func.find_csv_mismatches import find_csv_mismatches
|
|
21 |
from global_func.trim_portfolio import trim_portfolio
|
22 |
from global_func.get_portfolio_names import get_portfolio_names
|
23 |
from global_func.small_field_preset import small_field_preset
|
|
|
24 |
|
25 |
freq_format = {'Finish_percentile': '{:.2%}', 'Lineup Edge': '{:.2%}', 'Win%': '{:.2%}'}
|
26 |
stacking_sports = ['MLB', 'NHL', 'NFL']
|
@@ -1109,10 +1110,10 @@ with tab2:
|
|
1109 |
lineup_target = st.number_input("Lineups to produce", value=150, min_value=1, step=1)
|
1110 |
submitted = st.form_submit_button("Submit")
|
1111 |
if submitted:
|
1112 |
-
if preset_choice == 'Small Field':
|
1113 |
parsed_frame = small_field_preset(st.session_state['working_frame'], lineup_target)
|
1114 |
-
|
1115 |
-
|
1116 |
# elif preset_choice == 'Volatile':
|
1117 |
# parsed_frame = volatile_preset(st.session_state['working_frame'], lineup_target)
|
1118 |
# elif preset_choice == 'Distributed':
|
|
|
21 |
from global_func.trim_portfolio import trim_portfolio
|
22 |
from global_func.get_portfolio_names import get_portfolio_names
|
23 |
from global_func.small_field_preset import small_field_preset
|
24 |
+
from global_func.large_field_preset import large_field_preset
|
25 |
|
26 |
freq_format = {'Finish_percentile': '{:.2%}', 'Lineup Edge': '{:.2%}', 'Win%': '{:.2%}'}
|
27 |
stacking_sports = ['MLB', 'NHL', 'NFL']
|
|
|
1110 |
lineup_target = st.number_input("Lineups to produce", value=150, min_value=1, step=1)
|
1111 |
submitted = st.form_submit_button("Submit")
|
1112 |
if submitted:
|
1113 |
+
if preset_choice == 'Small Field (Heavy Own)':
|
1114 |
parsed_frame = small_field_preset(st.session_state['working_frame'], lineup_target)
|
1115 |
+
elif preset_choice == 'Large Field (Finish Percentile / Edge)':
|
1116 |
+
parsed_frame = large_field_preset(st.session_state['working_frame'], lineup_target)
|
1117 |
# elif preset_choice == 'Volatile':
|
1118 |
# parsed_frame = volatile_preset(st.session_state['working_frame'], lineup_target)
|
1119 |
# elif preset_choice == 'Distributed':
|
global_func/large_field_preset.py
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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, 10):
|
6 |
+
rows_to_drop = []
|
7 |
+
|
8 |
+
working_portfolio = portfolio.sort_values(by='Finish_percentile', ascending = True).reset_index(drop=True)
|
9 |
+
working_portfolio = working_portfolio[working_portfolio['Lineup Edge'] > 0]
|
10 |
+
working_portfolio = working_portfolio.reset_index(drop=True)
|
11 |
+
curr_own_type_max = working_portfolio.loc[0, 'Own'] + (slack_var / 10 * working_portfolio.loc[0, 'Own'])
|
12 |
+
|
13 |
+
for i in range(1, len(working_portfolio)):
|
14 |
+
if working_portfolio.loc[i, 'Own'] > curr_own_type_max:
|
15 |
+
rows_to_drop.append(i)
|
16 |
+
else:
|
17 |
+
curr_own_type_max = working_portfolio.loc[i, 'Own'] + (slack_var / 10 * working_portfolio.loc[i, 'Own'])
|
18 |
+
|
19 |
+
working_portfolio = working_portfolio.drop(rows_to_drop).reset_index(drop=True)
|
20 |
+
if len(working_portfolio) >= lineup_target:
|
21 |
+
return working_portfolio.sort_values(by='Own', ascending=False).head(lineup_target)
|
22 |
+
|
23 |
+
return working_portfolio.sort_values(by='Own', ascending=False)
|
global_func/small_field_preset.py
CHANGED
@@ -17,6 +17,6 @@ def small_field_preset(portfolio: pd.DataFrame, lineup_target: int):
|
|
17 |
|
18 |
working_portfolio = working_portfolio.drop(rows_to_drop).reset_index(drop=True)
|
19 |
if len(working_portfolio) >= lineup_target:
|
20 |
-
return working_portfolio.sort_values(by='
|
21 |
|
22 |
-
return working_portfolio.sort_values(by='
|
|
|
17 |
|
18 |
working_portfolio = working_portfolio.drop(rows_to_drop).reset_index(drop=True)
|
19 |
if len(working_portfolio) >= lineup_target:
|
20 |
+
return working_portfolio.sort_values(by='Own', ascending=False).head(lineup_target)
|
21 |
|
22 |
+
return working_portfolio.sort_values(by='Own', ascending=False)
|