James McCool
commited on
Commit
·
28cb5be
1
Parent(s):
57ecfc8
Refactor portfolio loading logic in app.py: ensure portfolio is only loaded if not already in session state, and add minimum lineup edge input for filtering.
Browse files
app.py
CHANGED
@@ -76,33 +76,33 @@ with tab1:
|
|
76 |
del st.session_state['portfolio']
|
77 |
if 'export_portfolio' in st.session_state:
|
78 |
del st.session_state['export_portfolio']
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
|
107 |
with col3:
|
108 |
st.subheader("Projections File")
|
@@ -693,13 +693,12 @@ with tab3:
|
|
693 |
|
694 |
with col2:
|
695 |
sport_var = st.selectbox("Select Sport", ['NFL', 'MLB', 'NBA', 'NHL', 'MMA'])
|
696 |
-
st.info("It currently does not matter what sport you select, it may matter in the future.")
|
697 |
type_var = st.selectbox("Select Game Type", ['Classic', 'Showdown'])
|
698 |
|
699 |
with col3:
|
700 |
Contest_Size = st.number_input("Enter Contest Size", value=25000, min_value=1, step=1)
|
701 |
strength_var = st.selectbox("Select field strength", ['Average', 'Sharp', 'Weak'])
|
702 |
-
|
703 |
if site_var == 'Draftkings':
|
704 |
if type_var == 'Classic':
|
705 |
map_dict = {
|
@@ -779,13 +778,14 @@ with tab3:
|
|
779 |
axis=1
|
780 |
)
|
781 |
|
782 |
-
col1, col2 = st.columns([
|
783 |
-
with
|
784 |
with st.form(key='filter_form'):
|
785 |
max_dupes = st.number_input("Max acceptable dupes?", value=1000, min_value=1, step=1)
|
786 |
min_salary = st.number_input("Min acceptable salary?", value=1000, min_value=1000, step=100)
|
787 |
max_salary = st.number_input("Max acceptable salary?", value=60000, min_value=1000, step=100)
|
788 |
max_finish_percentile = st.number_input("Max acceptable finish percentile?", value=.50, min_value=0.005, step=.001)
|
|
|
789 |
player_names = set()
|
790 |
for col in st.session_state['portfolio'].columns:
|
791 |
if col not in excluded_cols:
|
@@ -799,12 +799,13 @@ with tab3:
|
|
799 |
|
800 |
submitted = st.form_submit_button("Submit")
|
801 |
|
802 |
-
with
|
803 |
st.session_state['portfolio'] = predict_dupes(st.session_state['portfolio'], map_dict, site_var, type_var, Contest_Size, strength_var)
|
804 |
st.session_state['portfolio'] = st.session_state['portfolio'][st.session_state['portfolio']['Dupes'] <= max_dupes]
|
805 |
st.session_state['portfolio'] = st.session_state['portfolio'][st.session_state['portfolio']['salary'] >= min_salary]
|
806 |
st.session_state['portfolio'] = st.session_state['portfolio'][st.session_state['portfolio']['salary'] <= max_salary]
|
807 |
st.session_state['portfolio'] = st.session_state['portfolio'][st.session_state['portfolio']['Finish_percentile'] <= max_finish_percentile]
|
|
|
808 |
if stack_dict is not None:
|
809 |
if stack_toggle == 'All Stacks':
|
810 |
st.session_state['portfolio'] = st.session_state['portfolio']
|
|
|
76 |
del st.session_state['portfolio']
|
77 |
if 'export_portfolio' in st.session_state:
|
78 |
del st.session_state['export_portfolio']
|
79 |
+
if 'portfolio' not in st.session_state:
|
80 |
+
if portfolio_file:
|
81 |
+
if saber_toggle == 'Yes':
|
82 |
+
st.session_state['export_portfolio'], st.session_state['portfolio'] = load_ss_file(portfolio_file, st.session_state['csv_file'])
|
83 |
+
st.session_state['export_portfolio'] = st.session_state['export_portfolio'].dropna(how='all')
|
84 |
+
st.session_state['export_portfolio'] = st.session_state['export_portfolio'].reset_index(drop=True)
|
85 |
+
st.session_state['portfolio'] = st.session_state['portfolio'].dropna(how='all')
|
86 |
+
st.session_state['portfolio'] = st.session_state['portfolio'].reset_index(drop=True)
|
87 |
+
else:
|
88 |
+
st.session_state['export_portfolio'], st.session_state['portfolio'] = load_file(portfolio_file)
|
89 |
+
st.session_state['export_portfolio'] = st.session_state['export_portfolio'].dropna(how='all')
|
90 |
+
st.session_state['export_portfolio'] = st.session_state['export_portfolio'].reset_index(drop=True)
|
91 |
+
st.session_state['portfolio'] = st.session_state['portfolio'].dropna(how='all')
|
92 |
+
st.session_state['portfolio'] = st.session_state['portfolio'].reset_index(drop=True)
|
93 |
+
# Check if Stack column exists in the portfolio
|
94 |
+
if 'Stack' in st.session_state['portfolio'].columns:
|
95 |
+
# Create dictionary mapping index to Stack values
|
96 |
+
stack_dict = dict(zip(st.session_state['portfolio'].index, st.session_state['portfolio']['Stack']))
|
97 |
+
st.write(f"Found {len(stack_dict)} stack assignments")
|
98 |
+
st.session_state['portfolio'] = st.session_state['portfolio'].drop(columns=['Stack'])
|
99 |
+
else:
|
100 |
+
stack_dict = None
|
101 |
+
st.info("No Stack column found in portfolio")
|
102 |
+
if st.session_state['portfolio'] is not None:
|
103 |
+
st.success('Portfolio file loaded successfully!')
|
104 |
+
st.session_state['portfolio'] = st.session_state['portfolio'].apply(lambda x: x.replace(player_wrong_names_mlb, player_right_names_mlb))
|
105 |
+
st.dataframe(st.session_state['portfolio'].head(10))
|
106 |
|
107 |
with col3:
|
108 |
st.subheader("Projections File")
|
|
|
693 |
|
694 |
with col2:
|
695 |
sport_var = st.selectbox("Select Sport", ['NFL', 'MLB', 'NBA', 'NHL', 'MMA'])
|
|
|
696 |
type_var = st.selectbox("Select Game Type", ['Classic', 'Showdown'])
|
697 |
|
698 |
with col3:
|
699 |
Contest_Size = st.number_input("Enter Contest Size", value=25000, min_value=1, step=1)
|
700 |
strength_var = st.selectbox("Select field strength", ['Average', 'Sharp', 'Weak'])
|
701 |
+
|
702 |
if site_var == 'Draftkings':
|
703 |
if type_var == 'Classic':
|
704 |
map_dict = {
|
|
|
778 |
axis=1
|
779 |
)
|
780 |
|
781 |
+
col1, col2 = st.columns([1, 10])
|
782 |
+
with col1:
|
783 |
with st.form(key='filter_form'):
|
784 |
max_dupes = st.number_input("Max acceptable dupes?", value=1000, min_value=1, step=1)
|
785 |
min_salary = st.number_input("Min acceptable salary?", value=1000, min_value=1000, step=100)
|
786 |
max_salary = st.number_input("Max acceptable salary?", value=60000, min_value=1000, step=100)
|
787 |
max_finish_percentile = st.number_input("Max acceptable finish percentile?", value=.50, min_value=0.005, step=.001)
|
788 |
+
min_lineup_edge = st.number_input("Min acceptable Lineup Edge?", value=-.5, min_value=-1, step=.001)
|
789 |
player_names = set()
|
790 |
for col in st.session_state['portfolio'].columns:
|
791 |
if col not in excluded_cols:
|
|
|
799 |
|
800 |
submitted = st.form_submit_button("Submit")
|
801 |
|
802 |
+
with col2:
|
803 |
st.session_state['portfolio'] = predict_dupes(st.session_state['portfolio'], map_dict, site_var, type_var, Contest_Size, strength_var)
|
804 |
st.session_state['portfolio'] = st.session_state['portfolio'][st.session_state['portfolio']['Dupes'] <= max_dupes]
|
805 |
st.session_state['portfolio'] = st.session_state['portfolio'][st.session_state['portfolio']['salary'] >= min_salary]
|
806 |
st.session_state['portfolio'] = st.session_state['portfolio'][st.session_state['portfolio']['salary'] <= max_salary]
|
807 |
st.session_state['portfolio'] = st.session_state['portfolio'][st.session_state['portfolio']['Finish_percentile'] <= max_finish_percentile]
|
808 |
+
st.session_state['portfolio'] = st.session_state['portfolio'][st.session_state['portfolio']['Lineup Edge'] >= min_lineup_edge]
|
809 |
if stack_dict is not None:
|
810 |
if stack_toggle == 'All Stacks':
|
811 |
st.session_state['portfolio'] = st.session_state['portfolio']
|