Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -230,15 +230,24 @@ def calculate_range_var(count, min_val, FieldStrength, field_growth):
|
|
230 |
def create_random_portfolio(Total_Sample_Size, raw_baselines, field_growth):
|
231 |
|
232 |
full_pos_player_dict = get_overall_merged_df()
|
|
|
|
|
|
|
233 |
|
234 |
field_growth_rounded = round(field_growth)
|
235 |
ranges_dict = {}
|
236 |
|
237 |
if site_var1 == 'Draftkings':
|
238 |
# Calculate ranges
|
239 |
-
for df, dict_val, min_val, key in zip(ref_dict['pos_dfs'], ref_dict['pos_dicts'], [10, 10, 20,
|
240 |
count = create_overall_dfs(pos_players, df, dict_val, key)
|
241 |
ranges_dict[f"{key.lower()}_range"] = calculate_range_var(count, min_val, FieldStrength, field_growth_rounded)
|
|
|
|
|
|
|
|
|
|
|
|
|
242 |
|
243 |
# Generate random portfolios
|
244 |
rng = np.random.default_rng()
|
@@ -251,9 +260,15 @@ def create_random_portfolio(Total_Sample_Size, raw_baselines, field_growth):
|
|
251 |
|
252 |
elif site_var1 == 'Fanduel':
|
253 |
# Calculate ranges
|
254 |
-
for df, dict_val, min_val, key in zip(ref_dict['pos_dfs'], ref_dict['pos_dicts'], [10, 10, 20,
|
255 |
count = create_overall_dfs(pos_players, df, dict_val, key)
|
256 |
ranges_dict[f"{key.lower()}_range"] = calculate_range_var(count, min_val, FieldStrength, field_growth_rounded)
|
|
|
|
|
|
|
|
|
|
|
|
|
257 |
|
258 |
# Generate random portfolios
|
259 |
rng = np.random.default_rng()
|
@@ -279,7 +294,7 @@ def get_correlated_dk_portfolio_for_sim(Total_Sample_Size, sharp_split, field_gr
|
|
279 |
RandomPortfolio['W3'] = pd.Series(list(RandomPortfolio['W3'].map(full_pos_player_dict['pos_dicts'][1])), dtype="string[pyarrow]")
|
280 |
RandomPortfolio['D1'] = pd.Series(list(RandomPortfolio['D1'].map(full_pos_player_dict['pos_dicts'][2])), dtype="string[pyarrow]")
|
281 |
RandomPortfolio['D2'] = pd.Series(list(RandomPortfolio['D2'].map(full_pos_player_dict['pos_dicts'][2])), dtype="string[pyarrow]")
|
282 |
-
RandomPortfolio['G'] = pd.Series(list(RandomPortfolio['G'].map(
|
283 |
RandomPortfolio['UTIL'] = pd.Series(list(RandomPortfolio['UTIL'].map(full_pos_player_dict['pos_dicts'][3])), dtype="string[pyarrow]")
|
284 |
RandomPortfolio['plyr_list'] = RandomPortfolio[RandomPortfolio.columns.values.tolist()].values.tolist()
|
285 |
RandomPortfolio['plyr_count'] = RandomPortfolio['plyr_list'].apply(lambda x: len(set(x)))
|
@@ -386,7 +401,7 @@ def get_uncorrelated_dk_portfolio_for_sim(Total_Sample_Size, sharp_split, field_
|
|
386 |
RandomPortfolio['W3'] = pd.Series(list(RandomPortfolio['W3'].map(full_pos_player_dict['pos_dicts'][1])), dtype="string[pyarrow]")
|
387 |
RandomPortfolio['D1'] = pd.Series(list(RandomPortfolio['D1'].map(full_pos_player_dict['pos_dicts'][2])), dtype="string[pyarrow]")
|
388 |
RandomPortfolio['D2'] = pd.Series(list(RandomPortfolio['D2'].map(full_pos_player_dict['pos_dicts'][2])), dtype="string[pyarrow]")
|
389 |
-
RandomPortfolio['G'] = pd.Series(list(RandomPortfolio['G'].map(
|
390 |
RandomPortfolio['UTIL'] = pd.Series(list(RandomPortfolio['UTIL'].map(full_pos_player_dict['pos_dicts'][3])), dtype="string[pyarrow]")
|
391 |
RandomPortfolio['plyr_list'] = RandomPortfolio[RandomPortfolio.columns.values.tolist()].values.tolist()
|
392 |
RandomPortfolio['plyr_count'] = RandomPortfolio['plyr_list'].apply(lambda x: len(set(x)))
|
@@ -494,7 +509,7 @@ def get_correlated_fd_portfolio_for_sim(Total_Sample_Size, sharp_split, field_gr
|
|
494 |
RandomPortfolio['D2'] = pd.Series(list(RandomPortfolio['D2'].map(full_pos_player_dict['pos_dicts'][2])), dtype="string[pyarrow]")
|
495 |
RandomPortfolio['UTIL1'] = pd.Series(list(RandomPortfolio['UTIL1'].map(full_pos_player_dict['pos_dicts'][3])), dtype="string[pyarrow]")
|
496 |
RandomPortfolio['UTIL2'] = pd.Series(list(RandomPortfolio['UTIL2'].map(full_pos_player_dict['pos_dicts'][3])), dtype="string[pyarrow]")
|
497 |
-
RandomPortfolio['G'] = pd.Series(list(RandomPortfolio['G'].map(
|
498 |
RandomPortfolio['plyr_list'] = RandomPortfolio[RandomPortfolio.columns.values.tolist()].values.tolist()
|
499 |
RandomPortfolio['plyr_count'] = RandomPortfolio['plyr_list'].apply(lambda x: len(set(x)))
|
500 |
RandomPortfolio = RandomPortfolio[RandomPortfolio['plyr_count'] == 10].drop(columns=['plyr_list','plyr_count']).\
|
@@ -601,7 +616,7 @@ def get_uncorrelated_fd_portfolio_for_sim(Total_Sample_Size, sharp_split, field_
|
|
601 |
RandomPortfolio['D2'] = pd.Series(list(RandomPortfolio['D2'].map(full_pos_player_dict['pos_dicts'][2])), dtype="string[pyarrow]")
|
602 |
RandomPortfolio['UTIL1'] = pd.Series(list(RandomPortfolio['UTIL1'].map(full_pos_player_dict['pos_dicts'][3])), dtype="string[pyarrow]")
|
603 |
RandomPortfolio['UTIL2'] = pd.Series(list(RandomPortfolio['UTIL2'].map(full_pos_player_dict['pos_dicts'][3])), dtype="string[pyarrow]")
|
604 |
-
RandomPortfolio['G'] = pd.Series(list(RandomPortfolio['G'].map(
|
605 |
RandomPortfolio['plyr_list'] = RandomPortfolio[RandomPortfolio.columns.values.tolist()].values.tolist()
|
606 |
RandomPortfolio['plyr_count'] = RandomPortfolio['plyr_list'].apply(lambda x: len(set(x)))
|
607 |
RandomPortfolio = RandomPortfolio[RandomPortfolio['plyr_count'] == 10].drop(columns=['plyr_list','plyr_count']).\
|
@@ -1101,8 +1116,12 @@ with tab2:
|
|
1101 |
gs_raw.dropna(subset=['Median']).reset_index(drop=True)
|
1102 |
gs_raw = gs_raw.reset_index(drop=True)
|
1103 |
gs_raw = gs_raw.sort_values(by=['Own', 'Median'], ascending=False)
|
|
|
|
|
|
|
|
|
1104 |
|
1105 |
-
pos_players = pd.concat([cs_raw, ws_raw, ds_raw
|
1106 |
pos_players.dropna(subset=['Median']).reset_index(drop=True)
|
1107 |
pos_players = pos_players.reset_index(drop=True)
|
1108 |
|
@@ -1423,4 +1442,4 @@ del insert_port1, Contest_Size, sharp_split, Strength_var, scaling_var, Sort_fun
|
|
1423 |
del raw_baselines
|
1424 |
del freq_format
|
1425 |
|
1426 |
-
gc.collect()
|
|
|
230 |
def create_random_portfolio(Total_Sample_Size, raw_baselines, field_growth):
|
231 |
|
232 |
full_pos_player_dict = get_overall_merged_df()
|
233 |
+
g_baselines = raw_baselines[raw_baselines['Position'] == 'G']
|
234 |
+
g_baselines = g_baselines.drop_duplicates(subset='Team')
|
235 |
+
max_var = len(g_baselines[g_baselines['Position'] == 'G'])
|
236 |
|
237 |
field_growth_rounded = round(field_growth)
|
238 |
ranges_dict = {}
|
239 |
|
240 |
if site_var1 == 'Draftkings':
|
241 |
# Calculate ranges
|
242 |
+
for df, dict_val, min_val, key in zip(ref_dict['pos_dfs'], ref_dict['pos_dicts'], [10, 10, 20, 30], ['C', 'W', 'D', 'UTIL']):
|
243 |
count = create_overall_dfs(pos_players, df, dict_val, key)
|
244 |
ranges_dict[f"{key.lower()}_range"] = calculate_range_var(count, min_val, FieldStrength, field_growth_rounded)
|
245 |
+
if max_var <= 10:
|
246 |
+
ranges_dict['g_range'] = round(max_var)
|
247 |
+
elif max_var > 10 and max_var <= 16:
|
248 |
+
ranges_dict['dst_range'] = round(max_var)
|
249 |
+
elif max_var > 16:
|
250 |
+
ranges_dict['dst_range'] = round(max_var)
|
251 |
|
252 |
# Generate random portfolios
|
253 |
rng = np.random.default_rng()
|
|
|
260 |
|
261 |
elif site_var1 == 'Fanduel':
|
262 |
# Calculate ranges
|
263 |
+
for df, dict_val, min_val, key in zip(ref_dict['pos_dfs'], ref_dict['pos_dicts'], [10, 10, 20, 30], ['C', 'W', 'D', 'UTIL']):
|
264 |
count = create_overall_dfs(pos_players, df, dict_val, key)
|
265 |
ranges_dict[f"{key.lower()}_range"] = calculate_range_var(count, min_val, FieldStrength, field_growth_rounded)
|
266 |
+
if max_var <= 10:
|
267 |
+
ranges_dict['g_range'] = round(max_var)
|
268 |
+
elif max_var > 10 and max_var <= 16:
|
269 |
+
ranges_dict['dst_range'] = round(max_var)
|
270 |
+
elif max_var > 16:
|
271 |
+
ranges_dict['dst_range'] = round(max_var)
|
272 |
|
273 |
# Generate random portfolios
|
274 |
rng = np.random.default_rng()
|
|
|
294 |
RandomPortfolio['W3'] = pd.Series(list(RandomPortfolio['W3'].map(full_pos_player_dict['pos_dicts'][1])), dtype="string[pyarrow]")
|
295 |
RandomPortfolio['D1'] = pd.Series(list(RandomPortfolio['D1'].map(full_pos_player_dict['pos_dicts'][2])), dtype="string[pyarrow]")
|
296 |
RandomPortfolio['D2'] = pd.Series(list(RandomPortfolio['D2'].map(full_pos_player_dict['pos_dicts'][2])), dtype="string[pyarrow]")
|
297 |
+
RandomPortfolio['G'] = pd.Series(list(RandomPortfolio['G'].map(gs_dict)), dtype="string[pyarrow]")
|
298 |
RandomPortfolio['UTIL'] = pd.Series(list(RandomPortfolio['UTIL'].map(full_pos_player_dict['pos_dicts'][3])), dtype="string[pyarrow]")
|
299 |
RandomPortfolio['plyr_list'] = RandomPortfolio[RandomPortfolio.columns.values.tolist()].values.tolist()
|
300 |
RandomPortfolio['plyr_count'] = RandomPortfolio['plyr_list'].apply(lambda x: len(set(x)))
|
|
|
401 |
RandomPortfolio['W3'] = pd.Series(list(RandomPortfolio['W3'].map(full_pos_player_dict['pos_dicts'][1])), dtype="string[pyarrow]")
|
402 |
RandomPortfolio['D1'] = pd.Series(list(RandomPortfolio['D1'].map(full_pos_player_dict['pos_dicts'][2])), dtype="string[pyarrow]")
|
403 |
RandomPortfolio['D2'] = pd.Series(list(RandomPortfolio['D2'].map(full_pos_player_dict['pos_dicts'][2])), dtype="string[pyarrow]")
|
404 |
+
RandomPortfolio['G'] = pd.Series(list(RandomPortfolio['G'].map(gs_dict)), dtype="string[pyarrow]")
|
405 |
RandomPortfolio['UTIL'] = pd.Series(list(RandomPortfolio['UTIL'].map(full_pos_player_dict['pos_dicts'][3])), dtype="string[pyarrow]")
|
406 |
RandomPortfolio['plyr_list'] = RandomPortfolio[RandomPortfolio.columns.values.tolist()].values.tolist()
|
407 |
RandomPortfolio['plyr_count'] = RandomPortfolio['plyr_list'].apply(lambda x: len(set(x)))
|
|
|
509 |
RandomPortfolio['D2'] = pd.Series(list(RandomPortfolio['D2'].map(full_pos_player_dict['pos_dicts'][2])), dtype="string[pyarrow]")
|
510 |
RandomPortfolio['UTIL1'] = pd.Series(list(RandomPortfolio['UTIL1'].map(full_pos_player_dict['pos_dicts'][3])), dtype="string[pyarrow]")
|
511 |
RandomPortfolio['UTIL2'] = pd.Series(list(RandomPortfolio['UTIL2'].map(full_pos_player_dict['pos_dicts'][3])), dtype="string[pyarrow]")
|
512 |
+
RandomPortfolio['G'] = pd.Series(list(RandomPortfolio['G'].map(gs_dict)), dtype="string[pyarrow]")
|
513 |
RandomPortfolio['plyr_list'] = RandomPortfolio[RandomPortfolio.columns.values.tolist()].values.tolist()
|
514 |
RandomPortfolio['plyr_count'] = RandomPortfolio['plyr_list'].apply(lambda x: len(set(x)))
|
515 |
RandomPortfolio = RandomPortfolio[RandomPortfolio['plyr_count'] == 10].drop(columns=['plyr_list','plyr_count']).\
|
|
|
616 |
RandomPortfolio['D2'] = pd.Series(list(RandomPortfolio['D2'].map(full_pos_player_dict['pos_dicts'][2])), dtype="string[pyarrow]")
|
617 |
RandomPortfolio['UTIL1'] = pd.Series(list(RandomPortfolio['UTIL1'].map(full_pos_player_dict['pos_dicts'][3])), dtype="string[pyarrow]")
|
618 |
RandomPortfolio['UTIL2'] = pd.Series(list(RandomPortfolio['UTIL2'].map(full_pos_player_dict['pos_dicts'][3])), dtype="string[pyarrow]")
|
619 |
+
RandomPortfolio['G'] = pd.Series(list(RandomPortfolio['G'].map(gs_dict)), dtype="string[pyarrow]")
|
620 |
RandomPortfolio['plyr_list'] = RandomPortfolio[RandomPortfolio.columns.values.tolist()].values.tolist()
|
621 |
RandomPortfolio['plyr_count'] = RandomPortfolio['plyr_list'].apply(lambda x: len(set(x)))
|
622 |
RandomPortfolio = RandomPortfolio[RandomPortfolio['plyr_count'] == 10].drop(columns=['plyr_list','plyr_count']).\
|
|
|
1116 |
gs_raw.dropna(subset=['Median']).reset_index(drop=True)
|
1117 |
gs_raw = gs_raw.reset_index(drop=True)
|
1118 |
gs_raw = gs_raw.sort_values(by=['Own', 'Median'], ascending=False)
|
1119 |
+
|
1120 |
+
gs = gs_raw.head(round(len(gs_raw)))
|
1121 |
+
gs = gs.assign(Var = range(0,len(gs)))
|
1122 |
+
gs_dict = pd.Series(gs.Player.values, index=gs.Var).to_dict()
|
1123 |
|
1124 |
+
pos_players = pd.concat([cs_raw, ws_raw, ds_raw])
|
1125 |
pos_players.dropna(subset=['Median']).reset_index(drop=True)
|
1126 |
pos_players = pos_players.reset_index(drop=True)
|
1127 |
|
|
|
1442 |
del raw_baselines
|
1443 |
del freq_format
|
1444 |
|
1445 |
+
gc.collect()
|