Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -768,49 +768,53 @@ with tab2:
|
|
768 |
Strength_var = .01
|
769 |
scaling_var = 15
|
770 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
771 |
with col2:
|
772 |
if st.button("Simulate Contest"):
|
773 |
with st.container():
|
774 |
st.write('Contest Simulation Starting')
|
775 |
-
seed_depth1 = 10
|
776 |
-
Total_Runs = 1000000
|
777 |
-
if Contest_Size <= 1000:
|
778 |
-
strength_grow = .01
|
779 |
-
elif Contest_Size > 1000 and Contest_Size <= 2500:
|
780 |
-
strength_grow = .025
|
781 |
-
elif Contest_Size > 2500 and Contest_Size <= 5000:
|
782 |
-
strength_grow = .05
|
783 |
-
elif Contest_Size > 5000 and Contest_Size <= 20000:
|
784 |
-
strength_grow = .075
|
785 |
-
elif Contest_Size > 20000:
|
786 |
-
strength_grow = .1
|
787 |
-
|
788 |
-
field_growth = 100 * strength_grow
|
789 |
|
790 |
-
|
791 |
-
|
792 |
-
|
793 |
-
elif Sort_function == 'Own':
|
794 |
-
Sim_function = 'Own'
|
795 |
-
|
796 |
if slate_var1 == 'User':
|
797 |
-
|
798 |
-
|
799 |
-
|
800 |
-
|
801 |
-
|
802 |
-
|
803 |
-
|
804 |
-
|
805 |
-
|
806 |
-
|
807 |
-
|
808 |
-
|
809 |
-
|
810 |
-
|
811 |
-
|
812 |
-
|
813 |
-
|
|
|
|
|
|
|
|
|
|
|
814 |
|
815 |
if insert_port == 1:
|
816 |
UserPortfolio = portfolio_dataframe[['QB', 'RB1', 'RB2', 'WR1', 'WR2', 'WR3', 'FLEX', 'S_FLEX']]
|
@@ -1078,66 +1082,66 @@ with tab2:
|
|
1078 |
for checkVar in range(len(team_list)):
|
1079 |
st.session_state.dst_freq['Team'] = st.session_state.dst_freq['Team'].replace(item_list, team_list)
|
1080 |
|
1081 |
-
|
1082 |
-
|
1083 |
-
|
1084 |
-
|
1085 |
-
|
1086 |
-
|
1087 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1088 |
|
1089 |
-
|
1090 |
-
|
1091 |
-
|
1092 |
-
|
1093 |
-
|
1094 |
-
st.dataframe(st.session_state.Sim_Winner_Display.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').background_gradient(cmap='RdYlGn_r', subset=['Own']).format(precision=2), use_container_width = True)
|
1095 |
-
if 'Sim_Winner_Export' in st.session_state:
|
1096 |
st.download_button(
|
1097 |
-
label="Export
|
1098 |
-
data=
|
1099 |
-
file_name='
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1100 |
mime='text/csv',
|
1101 |
)
|
1102 |
-
|
1103 |
-
with st.container():
|
1104 |
-
tab1, tab2, tab3, tab4 = st.tabs(['Overall Exposures', 'QB Exposures', 'RB Exposures', 'WR Exposures'])
|
1105 |
-
with tab1:
|
1106 |
-
if 'player_freq' in st.session_state:
|
1107 |
-
st.dataframe(st.session_state.player_freq.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(freq_format, precision=2), use_container_width = True)
|
1108 |
-
st.download_button(
|
1109 |
-
label="Export Exposures",
|
1110 |
-
data=st.session_state.player_freq.to_csv().encode('utf-8'),
|
1111 |
-
file_name='player_freq_export.csv',
|
1112 |
-
mime='text/csv',
|
1113 |
-
)
|
1114 |
-
with tab2:
|
1115 |
-
if 'qb_freq' in st.session_state:
|
1116 |
-
st.dataframe(st.session_state.qb_freq.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(freq_format, precision=2), use_container_width = True)
|
1117 |
-
st.download_button(
|
1118 |
-
label="Export Exposures",
|
1119 |
-
data=st.session_state.qb_freq.to_csv().encode('utf-8'),
|
1120 |
-
file_name='qb_freq_export.csv',
|
1121 |
-
mime='text/csv',
|
1122 |
-
)
|
1123 |
-
with tab3:
|
1124 |
-
if 'rb_freq' in st.session_state:
|
1125 |
-
st.dataframe(st.session_state.rb_freq.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(freq_format, precision=2), use_container_width = True)
|
1126 |
-
st.download_button(
|
1127 |
-
label="Export Exposures",
|
1128 |
-
data=st.session_state.rb_freq.to_csv().encode('utf-8'),
|
1129 |
-
file_name='rb_freq_export.csv',
|
1130 |
-
mime='text/csv',
|
1131 |
-
)
|
1132 |
-
with tab4:
|
1133 |
-
if 'wr_freq' in st.session_state:
|
1134 |
-
st.dataframe(st.session_state.wr_freq.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(freq_format, precision=2), use_container_width = True)
|
1135 |
-
st.download_button(
|
1136 |
-
label="Export Exposures",
|
1137 |
-
data=st.session_state.wr_freq.to_csv().encode('utf-8'),
|
1138 |
-
file_name='wr_freq_export.csv',
|
1139 |
-
mime='text/csv',
|
1140 |
-
)
|
1141 |
|
1142 |
|
1143 |
gc.collect()
|
|
|
768 |
Strength_var = .01
|
769 |
scaling_var = 15
|
770 |
|
771 |
+
Sort_function = 'Median'
|
772 |
+
Sim_function = 'Projection'
|
773 |
+
|
774 |
+
if Contest_Size <= 1000:
|
775 |
+
strength_grow = .01
|
776 |
+
elif Contest_Size > 1000 and Contest_Size <= 2500:
|
777 |
+
strength_grow = .025
|
778 |
+
elif Contest_Size > 2500 and Contest_Size <= 5000:
|
779 |
+
strength_grow = .05
|
780 |
+
elif Contest_Size > 5000 and Contest_Size <= 20000:
|
781 |
+
strength_grow = .075
|
782 |
+
elif Contest_Size > 20000:
|
783 |
+
strength_grow = .1
|
784 |
+
|
785 |
+
field_growth = 100 * strength_grow
|
786 |
+
|
787 |
with col2:
|
788 |
if st.button("Simulate Contest"):
|
789 |
with st.container():
|
790 |
st.write('Contest Simulation Starting')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
791 |
|
792 |
+
for key in st.session_state.keys():
|
793 |
+
del st.session_state[key]
|
794 |
+
|
|
|
|
|
|
|
795 |
if slate_var1 == 'User':
|
796 |
+
initial_proj = proj_dataframe[['Player', 'Team', 'Position', 'Median', 'Own', 'Salary']]
|
797 |
+
|
798 |
+
# Define the calculation to be applied
|
799 |
+
def calculate_own(position, own, mean_own, factor, max_own=75):
|
800 |
+
return np.where((position == 'QB') & (own - mean_own >= 0),
|
801 |
+
own * (factor * (own - mean_own) / 100) + mean_own,
|
802 |
+
own)
|
803 |
+
|
804 |
+
# Set the factors based on the contest_var1
|
805 |
+
factor_qb, factor_other = {
|
806 |
+
'Small': (10, 5),
|
807 |
+
'Medium': (6, 3),
|
808 |
+
'Large': (3, 1.5),
|
809 |
+
}[contest_var1]
|
810 |
+
|
811 |
+
# Apply the calculation to the DataFrame
|
812 |
+
initial_proj['Own%'] = initial_proj.apply(lambda row: calculate_own(row['Position'], row['Own'], initial_proj.loc[initial_proj['Position'] == row['Position'], 'Own'].mean(), factor_qb if row['Position'] == 'QB' else factor_other), axis=1)
|
813 |
+
initial_proj['Own%'] = initial_proj['Own%'].clip(upper=75)
|
814 |
+
initial_proj['Own'] = initial_proj['Own%'] * (900 / initial_proj['Own%'].sum())
|
815 |
+
|
816 |
+
# Drop unnecessary columns and create the final DataFrame
|
817 |
+
Overall_Proj = initial_proj[['Player', 'Team', 'Position', 'Median', 'Own', 'Salary']]
|
818 |
|
819 |
if insert_port == 1:
|
820 |
UserPortfolio = portfolio_dataframe[['QB', 'RB1', 'RB2', 'WR1', 'WR2', 'WR3', 'FLEX', 'S_FLEX']]
|
|
|
1082 |
for checkVar in range(len(team_list)):
|
1083 |
st.session_state.dst_freq['Team'] = st.session_state.dst_freq['Team'].replace(item_list, team_list)
|
1084 |
|
1085 |
+
with st.container():
|
1086 |
+
if 'player_freq' in st.session_state:
|
1087 |
+
player_split_var2 = st.radio("Are you wanting to isolate any lineups with specific players?", ('Full Players', 'Specific Players'), key='player_split_var2')
|
1088 |
+
if player_split_var2 == 'Specific Players':
|
1089 |
+
find_var2 = st.multiselect('Which players must be included in the lineups?', options = st.session_state.player_freq['Player'].unique())
|
1090 |
+
elif player_split_var2 == 'Full Players':
|
1091 |
+
find_var2 = st.session_state.player_freq.Player.values.tolist()
|
1092 |
+
|
1093 |
+
if player_split_var2 == 'Specific Players':
|
1094 |
+
st.session_state.Sim_Winner_Display = st.session_state.Sim_Winner_Frame[np.equal.outer(st.session_state.Sim_Winner_Frame.to_numpy(), find_var2).any(axis=1).all(axis=1)]
|
1095 |
+
if player_split_var2 == 'Full Players':
|
1096 |
+
st.session_state.Sim_Winner_Display = st.session_state.Sim_Winner_Frame
|
1097 |
+
if 'Sim_Winner_Display' in st.session_state:
|
1098 |
+
st.dataframe(st.session_state.Sim_Winner_Display.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').background_gradient(cmap='RdYlGn_r', subset=['Own']).format(precision=2), use_container_width = True)
|
1099 |
+
if 'Sim_Winner_Export' in st.session_state:
|
1100 |
+
st.download_button(
|
1101 |
+
label="Export Tables",
|
1102 |
+
data=convert_df_to_csv(st.session_state.Sim_Winner_Export),
|
1103 |
+
file_name='NFL_consim_export.csv',
|
1104 |
+
mime='text/csv',
|
1105 |
+
)
|
1106 |
|
1107 |
+
with st.container():
|
1108 |
+
tab1, tab2, tab3, tab4 = st.tabs(['Overall Exposures', 'QB Exposures', 'RB Exposures', 'WR Exposures'])
|
1109 |
+
with tab1:
|
1110 |
+
if 'player_freq' in st.session_state:
|
1111 |
+
st.dataframe(st.session_state.player_freq.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(freq_format, precision=2), use_container_width = True)
|
|
|
|
|
1112 |
st.download_button(
|
1113 |
+
label="Export Exposures",
|
1114 |
+
data=st.session_state.player_freq.to_csv().encode('utf-8'),
|
1115 |
+
file_name='player_freq_export.csv',
|
1116 |
+
mime='text/csv',
|
1117 |
+
)
|
1118 |
+
with tab2:
|
1119 |
+
if 'qb_freq' in st.session_state:
|
1120 |
+
st.dataframe(st.session_state.qb_freq.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(freq_format, precision=2), use_container_width = True)
|
1121 |
+
st.download_button(
|
1122 |
+
label="Export Exposures",
|
1123 |
+
data=st.session_state.qb_freq.to_csv().encode('utf-8'),
|
1124 |
+
file_name='qb_freq_export.csv',
|
1125 |
+
mime='text/csv',
|
1126 |
+
)
|
1127 |
+
with tab3:
|
1128 |
+
if 'rb_freq' in st.session_state:
|
1129 |
+
st.dataframe(st.session_state.rb_freq.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(freq_format, precision=2), use_container_width = True)
|
1130 |
+
st.download_button(
|
1131 |
+
label="Export Exposures",
|
1132 |
+
data=st.session_state.rb_freq.to_csv().encode('utf-8'),
|
1133 |
+
file_name='rb_freq_export.csv',
|
1134 |
+
mime='text/csv',
|
1135 |
+
)
|
1136 |
+
with tab4:
|
1137 |
+
if 'wr_freq' in st.session_state:
|
1138 |
+
st.dataframe(st.session_state.wr_freq.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(freq_format, precision=2), use_container_width = True)
|
1139 |
+
st.download_button(
|
1140 |
+
label="Export Exposures",
|
1141 |
+
data=st.session_state.wr_freq.to_csv().encode('utf-8'),
|
1142 |
+
file_name='wr_freq_export.csv',
|
1143 |
mime='text/csv',
|
1144 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1145 |
|
1146 |
|
1147 |
gc.collect()
|