Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -128,7 +128,7 @@ def sim_contest(Sim_size, FinalPortfolio, CleanPortfolio, maps_dict, up_dict, in
|
|
128 |
|
129 |
return Sim_Winners
|
130 |
|
131 |
-
def run_seed_frame(seed_depth1, Strength_var, strength_grow, Teams_used, Total_Runs):
|
132 |
RunsVar = 1
|
133 |
seed_depth_def = seed_depth1
|
134 |
Strength_var_def = Strength_var
|
@@ -138,31 +138,31 @@ def run_seed_frame(seed_depth1, Strength_var, strength_grow, Teams_used, Total_R
|
|
138 |
while RunsVar <= seed_depth_def:
|
139 |
if RunsVar <= 3:
|
140 |
FieldStrength = Strength_var_def
|
141 |
-
FinalPortfolio, maps_dict = get_correlated_portfolio_for_sim(Total_Runs_def * .1, sharp_split)
|
142 |
-
FinalPortfolio2, maps_dict2 = get_uncorrelated_portfolio_for_sim(Total_Runs_def * .1, sharp_split)
|
143 |
-
|
144 |
maps_dict.update(maps_dict2)
|
145 |
elif RunsVar > 3 and RunsVar <= 4:
|
146 |
FieldStrength += (strength_grow_def + ((30 - len(Teams_used_def)) * .001))
|
147 |
-
FinalPortfolio3, maps_dict3 = get_correlated_portfolio_for_sim(Total_Runs_def * .1, sharp_split)
|
148 |
-
FinalPortfolio4, maps_dict4 = get_uncorrelated_portfolio_for_sim(Total_Runs_def * .1, sharp_split)
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
maps_dict.update(maps_dict3)
|
153 |
maps_dict.update(maps_dict4)
|
154 |
elif RunsVar > 4:
|
155 |
FieldStrength = 1
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
maps_dict.update(
|
162 |
-
maps_dict.update(
|
163 |
RunsVar += 1
|
164 |
|
165 |
-
return
|
166 |
|
167 |
def create_stack_options(player_data, wr_var):
|
168 |
merged_frame = pd.DataFrame(columns = ['QB', 'Player'])
|
@@ -218,7 +218,7 @@ def calculate_range_var(count, min_val, FieldStrength, field_growth):
|
|
218 |
|
219 |
return min(var, len(count[0]))
|
220 |
|
221 |
-
def create_random_portfolio(Total_Sample_Size, raw_baselines):
|
222 |
|
223 |
O_merge, full_pos_player_dict = get_overall_merged_df()
|
224 |
max_var = len(raw_baselines[raw_baselines['Position'] == 'QB'])
|
@@ -251,11 +251,11 @@ def create_random_portfolio(Total_Sample_Size, raw_baselines):
|
|
251 |
|
252 |
return RandomPortfolio, maps_dict, ranges_dict, full_pos_player_dict
|
253 |
|
254 |
-
def get_correlated_portfolio_for_sim(Total_Sample_Size, sharp_split):
|
255 |
|
256 |
sizesplit = round(Total_Sample_Size * sharp_split)
|
257 |
|
258 |
-
RandomPortfolio, maps_dict, ranges_dict, full_pos_player_dict = create_random_portfolio(sizesplit, raw_baselines)
|
259 |
stack_num = random.randint(1, 3)
|
260 |
stacking_dict = create_stack_options(raw_baselines, stack_num)
|
261 |
|
@@ -360,11 +360,11 @@ def get_correlated_portfolio_for_sim(Total_Sample_Size, sharp_split):
|
|
360 |
|
361 |
return RandomPortfolio, maps_dict
|
362 |
|
363 |
-
def get_uncorrelated_portfolio_for_sim(Total_Sample_Size, sharp_split):
|
364 |
|
365 |
sizesplit = round(Total_Sample_Size * (1-sharp_split))
|
366 |
|
367 |
-
RandomPortfolio, maps_dict, ranges_dict, full_pos_player_dict = create_random_portfolio(sizesplit, raw_baselines)
|
368 |
|
369 |
RandomPortfolio['QB'] = pd.Series(list(RandomPortfolio['QB'].map(qb_dict)), dtype="string[pyarrow]")
|
370 |
RandomPortfolio['RB1'] = pd.Series(list(RandomPortfolio['RB1'].map(full_pos_player_dict['pos_dicts'][0])), dtype="string[pyarrow]")
|
@@ -467,7 +467,6 @@ def get_uncorrelated_portfolio_for_sim(Total_Sample_Size, sharp_split):
|
|
467 |
|
468 |
return RandomPortfolio, maps_dict
|
469 |
|
470 |
-
|
471 |
dk_roo_raw = load_dk_player_projections()
|
472 |
fd_roo_raw = load_fd_player_projections()
|
473 |
t_stamp = f"Last Update: " + str(dk_roo_raw['timestamp'][0]) + f" CST"
|
@@ -834,6 +833,22 @@ with tab2:
|
|
834 |
sharp_split = .75
|
835 |
Strength_var = .01
|
836 |
scaling_var = 15
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
837 |
|
838 |
with col2:
|
839 |
with st.container():
|
@@ -842,24 +857,6 @@ with tab2:
|
|
842 |
st.write('Contest Simulation Starting')
|
843 |
for key in st.session_state.keys():
|
844 |
del st.session_state[key]
|
845 |
-
if Contest_Size <= 1000:
|
846 |
-
strength_grow = .01
|
847 |
-
elif Contest_Size > 1000 and Contest_Size <= 2500:
|
848 |
-
strength_grow = .025
|
849 |
-
elif Contest_Size > 2500 and Contest_Size <= 5000:
|
850 |
-
strength_grow = .05
|
851 |
-
elif Contest_Size > 5000 and Contest_Size <= 20000:
|
852 |
-
strength_grow = .075
|
853 |
-
elif Contest_Size > 20000:
|
854 |
-
strength_grow = .1
|
855 |
-
|
856 |
-
field_growth = 100 * strength_grow
|
857 |
-
|
858 |
-
Sort_function = 'Median'
|
859 |
-
if Sort_function == 'Median':
|
860 |
-
Sim_function = 'Projection'
|
861 |
-
elif Sort_function == 'Own':
|
862 |
-
Sim_function = 'Own'
|
863 |
|
864 |
if slate_var1 == 'User':
|
865 |
initial_proj = proj_dataframe[['Player', 'Team', 'Position', 'Median', 'Own', 'Floor', 'Ceiling', 'Salary']].copy()
|
@@ -1074,7 +1071,7 @@ with tab2:
|
|
1074 |
}
|
1075 |
|
1076 |
st.write('Seed frame creation')
|
1077 |
-
FinalPortfolio, maps_dict = run_seed_frame(10, Strength_var, strength_grow, Teams_used, 1000000)
|
1078 |
|
1079 |
Sim_Winners = sim_contest(2500, FinalPortfolio, CleanPortfolio, maps_dict, up_dict, insert_port)
|
1080 |
|
@@ -1297,5 +1294,5 @@ del dk_roo_raw, fd_roo_raw
|
|
1297 |
del t_stamp
|
1298 |
del dkid_dict, fdid_dict
|
1299 |
del static_exposure, overall_exposure
|
1300 |
-
del insert_port1, Contest_Size, sharp_split, Strength_var, scaling_var
|
1301 |
del raw_baselines
|
|
|
128 |
|
129 |
return Sim_Winners
|
130 |
|
131 |
+
def run_seed_frame(seed_depth1, Strength_var, strength_grow, Teams_used, Total_Runs, field_growth):
|
132 |
RunsVar = 1
|
133 |
seed_depth_def = seed_depth1
|
134 |
Strength_var_def = Strength_var
|
|
|
138 |
while RunsVar <= seed_depth_def:
|
139 |
if RunsVar <= 3:
|
140 |
FieldStrength = Strength_var_def
|
141 |
+
FinalPortfolio, maps_dict = get_correlated_portfolio_for_sim(Total_Runs_def * .1, sharp_split, field_growth)
|
142 |
+
FinalPortfolio2, maps_dict2 = get_uncorrelated_portfolio_for_sim(Total_Runs_def * .1, sharp_split, field_growth)
|
143 |
+
FinalPortfolio_init = pd.concat([FinalPortfolio, FinalPortfolio2], axis=0)
|
144 |
maps_dict.update(maps_dict2)
|
145 |
elif RunsVar > 3 and RunsVar <= 4:
|
146 |
FieldStrength += (strength_grow_def + ((30 - len(Teams_used_def)) * .001))
|
147 |
+
FinalPortfolio3, maps_dict3 = get_correlated_portfolio_for_sim(Total_Runs_def * .1, sharp_split, field_growth)
|
148 |
+
FinalPortfolio4, maps_dict4 = get_uncorrelated_portfolio_for_sim(Total_Runs_def * .1, sharp_split, field_growth)
|
149 |
+
FinalPortfolio_merge_3 = pd.concat([FinalPortfolio_init, FinalPortfolio3], axis=0)
|
150 |
+
FinalPortfolio_merge_4 = pd.concat([FinalPortfolio_merge_3, FinalPortfolio4], axis=0)
|
151 |
+
FinalPortfolio_step_2 = FinalPortfolio_merge_4.drop_duplicates(subset = ['Projection', 'Own'],keep = 'last').reset_index(drop = True)
|
152 |
maps_dict.update(maps_dict3)
|
153 |
maps_dict.update(maps_dict4)
|
154 |
elif RunsVar > 4:
|
155 |
FieldStrength = 1
|
156 |
+
FinalPortfolio5, maps_dict5 = get_correlated_portfolio_for_sim(Total_Runs_def * .1, sharp_split, field_growth)
|
157 |
+
FinalPortfolio6, maps_dict6 = get_uncorrelated_portfolio_for_sim(Total_Runs_def * .1, sharp_split, field_growth)
|
158 |
+
FinalPortfolio_merge_5 = pd.concat([FinalPortfolio_step_2, FinalPortfolio5], axis=0)
|
159 |
+
FinalPortfolio_merge_6 = pd.concat([FinalPortfolio_merge_5, FinalPortfolio6], axis=0)
|
160 |
+
FinalPortfolio_export = FinalPortfolio_merge_6.drop_duplicates(subset = ['Projection', 'Own'],keep = 'last').reset_index(drop = True)
|
161 |
+
maps_dict.update(maps_dict5)
|
162 |
+
maps_dict.update(maps_dict6)
|
163 |
RunsVar += 1
|
164 |
|
165 |
+
return FinalPortfolio_export, maps_dict
|
166 |
|
167 |
def create_stack_options(player_data, wr_var):
|
168 |
merged_frame = pd.DataFrame(columns = ['QB', 'Player'])
|
|
|
218 |
|
219 |
return min(var, len(count[0]))
|
220 |
|
221 |
+
def create_random_portfolio(Total_Sample_Size, raw_baselines, field_growth):
|
222 |
|
223 |
O_merge, full_pos_player_dict = get_overall_merged_df()
|
224 |
max_var = len(raw_baselines[raw_baselines['Position'] == 'QB'])
|
|
|
251 |
|
252 |
return RandomPortfolio, maps_dict, ranges_dict, full_pos_player_dict
|
253 |
|
254 |
+
def get_correlated_portfolio_for_sim(Total_Sample_Size, sharp_split, field_growth):
|
255 |
|
256 |
sizesplit = round(Total_Sample_Size * sharp_split)
|
257 |
|
258 |
+
RandomPortfolio, maps_dict, ranges_dict, full_pos_player_dict = create_random_portfolio(sizesplit, raw_baselines, field_growth)
|
259 |
stack_num = random.randint(1, 3)
|
260 |
stacking_dict = create_stack_options(raw_baselines, stack_num)
|
261 |
|
|
|
360 |
|
361 |
return RandomPortfolio, maps_dict
|
362 |
|
363 |
+
def get_uncorrelated_portfolio_for_sim(Total_Sample_Size, sharp_split, field_growth):
|
364 |
|
365 |
sizesplit = round(Total_Sample_Size * (1-sharp_split))
|
366 |
|
367 |
+
RandomPortfolio, maps_dict, ranges_dict, full_pos_player_dict = create_random_portfolio(sizesplit, raw_baselines, field_growth)
|
368 |
|
369 |
RandomPortfolio['QB'] = pd.Series(list(RandomPortfolio['QB'].map(qb_dict)), dtype="string[pyarrow]")
|
370 |
RandomPortfolio['RB1'] = pd.Series(list(RandomPortfolio['RB1'].map(full_pos_player_dict['pos_dicts'][0])), dtype="string[pyarrow]")
|
|
|
467 |
|
468 |
return RandomPortfolio, maps_dict
|
469 |
|
|
|
470 |
dk_roo_raw = load_dk_player_projections()
|
471 |
fd_roo_raw = load_fd_player_projections()
|
472 |
t_stamp = f"Last Update: " + str(dk_roo_raw['timestamp'][0]) + f" CST"
|
|
|
833 |
sharp_split = .75
|
834 |
Strength_var = .01
|
835 |
scaling_var = 15
|
836 |
+
|
837 |
+
Sort_function = 'Median'
|
838 |
+
Sim_function = 'Projection'
|
839 |
+
|
840 |
+
if Contest_Size <= 1000:
|
841 |
+
strength_grow = .01
|
842 |
+
elif Contest_Size > 1000 and Contest_Size <= 2500:
|
843 |
+
strength_grow = .025
|
844 |
+
elif Contest_Size > 2500 and Contest_Size <= 5000:
|
845 |
+
strength_grow = .05
|
846 |
+
elif Contest_Size > 5000 and Contest_Size <= 20000:
|
847 |
+
strength_grow = .075
|
848 |
+
elif Contest_Size > 20000:
|
849 |
+
strength_grow = .1
|
850 |
+
|
851 |
+
field_growth = 100 * strength_grow
|
852 |
|
853 |
with col2:
|
854 |
with st.container():
|
|
|
857 |
st.write('Contest Simulation Starting')
|
858 |
for key in st.session_state.keys():
|
859 |
del st.session_state[key]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
860 |
|
861 |
if slate_var1 == 'User':
|
862 |
initial_proj = proj_dataframe[['Player', 'Team', 'Position', 'Median', 'Own', 'Floor', 'Ceiling', 'Salary']].copy()
|
|
|
1071 |
}
|
1072 |
|
1073 |
st.write('Seed frame creation')
|
1074 |
+
FinalPortfolio, maps_dict = run_seed_frame(10, Strength_var, strength_grow, Teams_used, 1000000, field_growth)
|
1075 |
|
1076 |
Sim_Winners = sim_contest(2500, FinalPortfolio, CleanPortfolio, maps_dict, up_dict, insert_port)
|
1077 |
|
|
|
1294 |
del t_stamp
|
1295 |
del dkid_dict, fdid_dict
|
1296 |
del static_exposure, overall_exposure
|
1297 |
+
del insert_port1, Contest_Size, sharp_split, Strength_var, scaling_var, Sort_function, Sim_function, strength_grow, field_growth
|
1298 |
del raw_baselines
|