Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -92,17 +92,16 @@ def run_seed_frame(seed_depth1, Strength_var, strength_grow, Teams_used, Total_R
|
|
92 |
while RunsVar <= seed_depth_def:
|
93 |
if RunsVar <= 3:
|
94 |
FieldStrength = Strength_var_def
|
95 |
-
|
96 |
-
|
97 |
-
FinalPortfolio2, maps_dict2 = get_uncorrelated_portfolio_for_sim(Total_Runs_def * .1)
|
98 |
FinalPortfolio = pd.concat([FinalPortfolio, FinalPortfolio2], axis=0)
|
99 |
maps_dict.update(maps_dict2)
|
100 |
del FinalPortfolio2
|
101 |
del maps_dict2
|
102 |
elif RunsVar > 3 and RunsVar <= 4:
|
103 |
FieldStrength += (strength_grow_def + ((30 - len(Teams_used_def)) * .001))
|
104 |
-
FinalPortfolio3, maps_dict3 = get_correlated_portfolio_for_sim(Total_Runs_def * .1)
|
105 |
-
FinalPortfolio4, maps_dict4 = get_uncorrelated_portfolio_for_sim(Total_Runs_def * .1)
|
106 |
FinalPortfolio = pd.concat([FinalPortfolio, FinalPortfolio3], axis=0)
|
107 |
FinalPortfolio = pd.concat([FinalPortfolio, FinalPortfolio4], axis=0)
|
108 |
FinalPortfolio = FinalPortfolio.drop_duplicates(subset = ['Projection', 'Own'],keep = 'last').reset_index(drop = True)
|
@@ -114,8 +113,8 @@ def run_seed_frame(seed_depth1, Strength_var, strength_grow, Teams_used, Total_R
|
|
114 |
del maps_dict4
|
115 |
elif RunsVar > 4:
|
116 |
FieldStrength = 1
|
117 |
-
FinalPortfolio3, maps_dict3 = get_correlated_portfolio_for_sim(Total_Runs_def * .1)
|
118 |
-
FinalPortfolio4, maps_dict4 = get_uncorrelated_portfolio_for_sim(Total_Runs_def * .1)
|
119 |
FinalPortfolio = pd.concat([FinalPortfolio, FinalPortfolio3], axis=0)
|
120 |
FinalPortfolio = pd.concat([FinalPortfolio, FinalPortfolio4], axis=0)
|
121 |
FinalPortfolio = FinalPortfolio.drop_duplicates(subset = ['Projection', 'Own'],keep = 'last').reset_index(drop = True)
|
@@ -225,13 +224,14 @@ def create_random_portfolio(Total_Sample_Size, raw_baselines):
|
|
225 |
RandomPortfolio = pd.DataFrame(np.hstack(all_choices), columns=['QB', 'RB1', 'RB2', 'WR1', 'WR2', 'WR3', 'TE', 'FLEX', 'DST'])
|
226 |
RandomPortfolio['User/Field'] = 0
|
227 |
|
|
|
228 |
del total_elements
|
229 |
del all_choices
|
230 |
del O_merge
|
231 |
|
232 |
return RandomPortfolio, maps_dict, ranges_dict, full_pos_player_dict
|
233 |
|
234 |
-
def get_correlated_portfolio_for_sim(Total_Sample_Size):
|
235 |
|
236 |
sizesplit = round(Total_Sample_Size * sharp_split)
|
237 |
|
@@ -345,11 +345,13 @@ def get_correlated_portfolio_for_sim(Total_Sample_Size):
|
|
345 |
|
346 |
RandomPortfolio = RandomPortfolioDF.sort_values(by=Sim_function, ascending=False)
|
347 |
|
|
|
|
|
348 |
RandomPortfolio = RandomPortfolio[['QB', 'RB1', 'RB2', 'WR1', 'WR2', 'WR3', 'TE', 'FLEX', 'DST', 'User/Field', 'Salary', 'Projection', 'Own']]
|
349 |
|
350 |
return RandomPortfolio, maps_dict
|
351 |
|
352 |
-
def get_uncorrelated_portfolio_for_sim(Total_Sample_Size):
|
353 |
|
354 |
sizesplit = round(Total_Sample_Size * (1-sharp_split))
|
355 |
|
@@ -462,6 +464,8 @@ def get_uncorrelated_portfolio_for_sim(Total_Sample_Size):
|
|
462 |
|
463 |
RandomPortfolio = RandomPortfolio[['QB', 'RB1', 'RB2', 'WR1', 'WR2', 'WR3', 'TE', 'FLEX', 'DST', 'User/Field', 'Salary', 'Projection', 'Own']]
|
464 |
|
|
|
|
|
465 |
return RandomPortfolio, maps_dict
|
466 |
|
467 |
|
@@ -847,18 +851,6 @@ with tab2:
|
|
847 |
with col2:
|
848 |
with st.container():
|
849 |
if st.button("Simulate Contest"):
|
850 |
-
try:
|
851 |
-
del dst_freq
|
852 |
-
del flex_freq
|
853 |
-
del te_freq
|
854 |
-
del wr_freq
|
855 |
-
del rb_freq
|
856 |
-
del qb_freq
|
857 |
-
del player_freq
|
858 |
-
del Sim_Winner_Export
|
859 |
-
del Sim_Winner_Frame
|
860 |
-
except:
|
861 |
-
pass
|
862 |
with st.container():
|
863 |
st.write('Contest Simulation Starting')
|
864 |
for key in st.session_state.keys():
|
@@ -885,7 +877,7 @@ with tab2:
|
|
885 |
Sim_function = 'Own'
|
886 |
|
887 |
if slate_var1 == 'User':
|
888 |
-
OwnFrame = proj_dataframe
|
889 |
if contest_var1 == 'Small':
|
890 |
OwnFrame['Own%'] = np.where((OwnFrame['Position'] == 'QB') & (OwnFrame['Own'] - OwnFrame.loc[OwnFrame['Position'] == 'QB', 'Own'].mean() >= 0), OwnFrame['Own'] * (10 * (OwnFrame['Own'] - OwnFrame.loc[OwnFrame['Position'] == 'QB', 'Own'].mean())/100) + OwnFrame.loc[OwnFrame['Position'] == 'QB', 'Own'].mean(), OwnFrame['Own'])
|
891 |
OwnFrame['Own%'] = np.where((OwnFrame['Position'] != 'QB') & (OwnFrame['Own'] - OwnFrame.loc[OwnFrame['Position'] != 'QB', 'Own'].mean() >= 0), OwnFrame['Own'] * (5 * (OwnFrame['Own'] - OwnFrame.loc[OwnFrame['Position'] != 'QB', 'Own'].mean())/100) + OwnFrame.loc[OwnFrame['Position'] != 'QB', 'Own'].mean(), OwnFrame['Own%'])
|
@@ -953,7 +945,7 @@ with tab2:
|
|
953 |
Teams_used['team_item'] = Teams_used['index'] + 1
|
954 |
Teams_used = Teams_used.drop(columns=['index'])
|
955 |
Teams_used_dictraw = Teams_used.drop(columns=['team_item'])
|
956 |
-
Teams_used_dict = Teams_used_dictraw.to_dict()
|
957 |
|
958 |
del Teams_used_dictraw
|
959 |
|
@@ -1033,6 +1025,8 @@ with tab2:
|
|
1033 |
CleanPortfolio['User/Field'] = CleanPortfolio['index'] + 1
|
1034 |
CleanPortfolio.drop(columns=['index'], inplace=True)
|
1035 |
|
|
|
|
|
1036 |
CleanPortfolio.replace('', np.nan, inplace=True)
|
1037 |
CleanPortfolio.dropna(subset=['QB'], inplace=True)
|
1038 |
|
@@ -1161,8 +1155,12 @@ with tab2:
|
|
1161 |
best_lineup = final_array[final_array[:, -1].argsort(kind='stable')[::-1][:1]]
|
1162 |
Sim_Winners.append(best_lineup)
|
1163 |
SimVar += 1
|
1164 |
-
|
1165 |
-
|
|
|
|
|
|
|
|
|
1166 |
del vec_projection_map
|
1167 |
del vec_stdev_map
|
1168 |
del sample_arrays
|
@@ -1201,8 +1199,7 @@ with tab2:
|
|
1201 |
|
1202 |
for col in columns_to_replace:
|
1203 |
st.session_state.Sim_Winner_Export[col].replace(replace_dict, inplace=True)
|
1204 |
-
|
1205 |
-
|
1206 |
player_freq = pd.DataFrame(np.column_stack(np.unique(st.session_state.Sim_Winner_Frame.iloc[:,0:9].values, return_counts=True)),
|
1207 |
columns=['Player','Freq']).sort_values('Freq', ascending=False).reset_index(drop=True)
|
1208 |
player_freq['Freq'] = player_freq['Freq'].astype(int)
|
@@ -1307,8 +1304,12 @@ with tab2:
|
|
1307 |
|
1308 |
st.session_state.dst_freq = dst_freq[['Player', 'Team', 'Position', 'Salary', 'Proj Own', 'Exposure', 'Edge']]
|
1309 |
del dst_freq
|
|
|
|
|
1310 |
del maps_dict
|
1311 |
-
|
|
|
|
|
1312 |
with st.container():
|
1313 |
simulate_container = st.empty()
|
1314 |
if 'player_freq' in st.session_state:
|
|
|
92 |
while RunsVar <= seed_depth_def:
|
93 |
if RunsVar <= 3:
|
94 |
FieldStrength = Strength_var_def
|
95 |
+
FinalPortfolio, maps_dict = get_correlated_portfolio_for_sim(Total_Runs_def * .1, sharp_split)
|
96 |
+
FinalPortfolio2, maps_dict2 = get_uncorrelated_portfolio_for_sim(Total_Runs_def * .1, sharp_split)
|
|
|
97 |
FinalPortfolio = pd.concat([FinalPortfolio, FinalPortfolio2], axis=0)
|
98 |
maps_dict.update(maps_dict2)
|
99 |
del FinalPortfolio2
|
100 |
del maps_dict2
|
101 |
elif RunsVar > 3 and RunsVar <= 4:
|
102 |
FieldStrength += (strength_grow_def + ((30 - len(Teams_used_def)) * .001))
|
103 |
+
FinalPortfolio3, maps_dict3 = get_correlated_portfolio_for_sim(Total_Runs_def * .1, sharp_split)
|
104 |
+
FinalPortfolio4, maps_dict4 = get_uncorrelated_portfolio_for_sim(Total_Runs_def * .1, sharp_split)
|
105 |
FinalPortfolio = pd.concat([FinalPortfolio, FinalPortfolio3], axis=0)
|
106 |
FinalPortfolio = pd.concat([FinalPortfolio, FinalPortfolio4], axis=0)
|
107 |
FinalPortfolio = FinalPortfolio.drop_duplicates(subset = ['Projection', 'Own'],keep = 'last').reset_index(drop = True)
|
|
|
113 |
del maps_dict4
|
114 |
elif RunsVar > 4:
|
115 |
FieldStrength = 1
|
116 |
+
FinalPortfolio3, maps_dict3 = get_correlated_portfolio_for_sim(Total_Runs_def * .1, sharp_split)
|
117 |
+
FinalPortfolio4, maps_dict4 = get_uncorrelated_portfolio_for_sim(Total_Runs_def * .1, sharp_split)
|
118 |
FinalPortfolio = pd.concat([FinalPortfolio, FinalPortfolio3], axis=0)
|
119 |
FinalPortfolio = pd.concat([FinalPortfolio, FinalPortfolio4], axis=0)
|
120 |
FinalPortfolio = FinalPortfolio.drop_duplicates(subset = ['Projection', 'Own'],keep = 'last').reset_index(drop = True)
|
|
|
224 |
RandomPortfolio = pd.DataFrame(np.hstack(all_choices), columns=['QB', 'RB1', 'RB2', 'WR1', 'WR2', 'WR3', 'TE', 'FLEX', 'DST'])
|
225 |
RandomPortfolio['User/Field'] = 0
|
226 |
|
227 |
+
del rng
|
228 |
del total_elements
|
229 |
del all_choices
|
230 |
del O_merge
|
231 |
|
232 |
return RandomPortfolio, maps_dict, ranges_dict, full_pos_player_dict
|
233 |
|
234 |
+
def get_correlated_portfolio_for_sim(Total_Sample_Size, sharp_split):
|
235 |
|
236 |
sizesplit = round(Total_Sample_Size * sharp_split)
|
237 |
|
|
|
345 |
|
346 |
RandomPortfolio = RandomPortfolioDF.sort_values(by=Sim_function, ascending=False)
|
347 |
|
348 |
+
del RandomPortfolioDF
|
349 |
+
|
350 |
RandomPortfolio = RandomPortfolio[['QB', 'RB1', 'RB2', 'WR1', 'WR2', 'WR3', 'TE', 'FLEX', 'DST', 'User/Field', 'Salary', 'Projection', 'Own']]
|
351 |
|
352 |
return RandomPortfolio, maps_dict
|
353 |
|
354 |
+
def get_uncorrelated_portfolio_for_sim(Total_Sample_Size, sharp_split):
|
355 |
|
356 |
sizesplit = round(Total_Sample_Size * (1-sharp_split))
|
357 |
|
|
|
464 |
|
465 |
RandomPortfolio = RandomPortfolio[['QB', 'RB1', 'RB2', 'WR1', 'WR2', 'WR3', 'TE', 'FLEX', 'DST', 'User/Field', 'Salary', 'Projection', 'Own']]
|
466 |
|
467 |
+
del RandomPortfolioDF
|
468 |
+
|
469 |
return RandomPortfolio, maps_dict
|
470 |
|
471 |
|
|
|
851 |
with col2:
|
852 |
with st.container():
|
853 |
if st.button("Simulate Contest"):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
854 |
with st.container():
|
855 |
st.write('Contest Simulation Starting')
|
856 |
for key in st.session_state.keys():
|
|
|
877 |
Sim_function = 'Own'
|
878 |
|
879 |
if slate_var1 == 'User':
|
880 |
+
OwnFrame = proj_dataframe.copy()
|
881 |
if contest_var1 == 'Small':
|
882 |
OwnFrame['Own%'] = np.where((OwnFrame['Position'] == 'QB') & (OwnFrame['Own'] - OwnFrame.loc[OwnFrame['Position'] == 'QB', 'Own'].mean() >= 0), OwnFrame['Own'] * (10 * (OwnFrame['Own'] - OwnFrame.loc[OwnFrame['Position'] == 'QB', 'Own'].mean())/100) + OwnFrame.loc[OwnFrame['Position'] == 'QB', 'Own'].mean(), OwnFrame['Own'])
|
883 |
OwnFrame['Own%'] = np.where((OwnFrame['Position'] != 'QB') & (OwnFrame['Own'] - OwnFrame.loc[OwnFrame['Position'] != 'QB', 'Own'].mean() >= 0), OwnFrame['Own'] * (5 * (OwnFrame['Own'] - OwnFrame.loc[OwnFrame['Position'] != 'QB', 'Own'].mean())/100) + OwnFrame.loc[OwnFrame['Position'] != 'QB', 'Own'].mean(), OwnFrame['Own%'])
|
|
|
945 |
Teams_used['team_item'] = Teams_used['index'] + 1
|
946 |
Teams_used = Teams_used.drop(columns=['index'])
|
947 |
Teams_used_dictraw = Teams_used.drop(columns=['team_item'])
|
948 |
+
# Teams_used_dict = Teams_used_dictraw.to_dict()
|
949 |
|
950 |
del Teams_used_dictraw
|
951 |
|
|
|
1025 |
CleanPortfolio['User/Field'] = CleanPortfolio['index'] + 1
|
1026 |
CleanPortfolio.drop(columns=['index'], inplace=True)
|
1027 |
|
1028 |
+
del positions
|
1029 |
+
|
1030 |
CleanPortfolio.replace('', np.nan, inplace=True)
|
1031 |
CleanPortfolio.dropna(subset=['QB'], inplace=True)
|
1032 |
|
|
|
1155 |
best_lineup = final_array[final_array[:, -1].argsort(kind='stable')[::-1][:1]]
|
1156 |
Sim_Winners.append(best_lineup)
|
1157 |
SimVar += 1
|
1158 |
+
|
1159 |
+
del SimVar
|
1160 |
+
del ref_dict, up_dict
|
1161 |
+
del linenum_var1, UserPortfolio
|
1162 |
+
del up_array
|
1163 |
+
del CleanPortfolio
|
1164 |
del vec_projection_map
|
1165 |
del vec_stdev_map
|
1166 |
del sample_arrays
|
|
|
1199 |
|
1200 |
for col in columns_to_replace:
|
1201 |
st.session_state.Sim_Winner_Export[col].replace(replace_dict, inplace=True)
|
1202 |
+
|
|
|
1203 |
player_freq = pd.DataFrame(np.column_stack(np.unique(st.session_state.Sim_Winner_Frame.iloc[:,0:9].values, return_counts=True)),
|
1204 |
columns=['Player','Freq']).sort_values('Freq', ascending=False).reset_index(drop=True)
|
1205 |
player_freq['Freq'] = player_freq['Freq'].astype(int)
|
|
|
1304 |
|
1305 |
st.session_state.dst_freq = dst_freq[['Player', 'Team', 'Position', 'Salary', 'Proj Own', 'Exposure', 'Edge']]
|
1306 |
del dst_freq
|
1307 |
+
|
1308 |
+
del Sim_size
|
1309 |
del maps_dict
|
1310 |
+
del team_list
|
1311 |
+
del item_list
|
1312 |
+
|
1313 |
with st.container():
|
1314 |
simulate_container = st.empty()
|
1315 |
if 'player_freq' in st.session_state:
|