James McCool
commited on
Commit
·
50f79c6
1
Parent(s):
d33556d
Enhance portfolio distribution logic in distribute_preset.py by adding player exposure calculations and refining the handling of 'Similarity Score'. This update improves the accuracy of player selection and provides a summary of player exposure in the final output, ensuring a more comprehensive analysis of the lineup distribution process.
Browse files
global_func/distribute_preset.py
CHANGED
@@ -2,6 +2,50 @@ import pandas as pd
|
|
2 |
|
3 |
def distribute_preset(portfolio: pd.DataFrame, lineup_target: int, exclude_cols: list):
|
4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
for slack_var in range(1, 20):
|
6 |
concat_portfolio = pd.DataFrame(columns=portfolio.columns)
|
7 |
|
@@ -23,5 +67,5 @@ def distribute_preset(portfolio: pd.DataFrame, lineup_target: int, exclude_cols:
|
|
23 |
|
24 |
if len(concat_portfolio) >= lineup_target:
|
25 |
return concat_portfolio.sort_values(by='median', ascending=True).head(lineup_target)
|
26 |
-
|
27 |
return concat_portfolio.sort_values(by='median', ascending=True)
|
|
|
2 |
|
3 |
def distribute_preset(portfolio: pd.DataFrame, lineup_target: int, exclude_cols: list):
|
4 |
|
5 |
+
excluded_cols = ['salary', 'median', 'Own', 'Finish_percentile', 'Dupes', 'Stack', 'Size', 'Win%', 'Lineup Edge', 'Weighted Own', 'Geomean', 'Similarity Score']
|
6 |
+
for slack_var in range(1, 20):
|
7 |
+
init_portfolio = pd.DataFrame(columns=portfolio.columns)
|
8 |
+
|
9 |
+
for team in portfolio['Stack'].unique():
|
10 |
+
rows_to_drop = []
|
11 |
+
working_portfolio = portfolio.copy()
|
12 |
+
working_portfolio = working_portfolio[working_portfolio['Stack'] == team].sort_values(by='median', ascending = False)
|
13 |
+
working_portfolio = working_portfolio.reset_index(drop=True)
|
14 |
+
curr_own_type_max = working_portfolio.loc[0, 'Similarity Score'] + (slack_var / 20 * working_portfolio.loc[0, 'Similarity Score'])
|
15 |
+
|
16 |
+
for i in range(1, len(working_portfolio)):
|
17 |
+
if working_portfolio.loc[i, 'Similarity Score'] > curr_own_type_max:
|
18 |
+
rows_to_drop.append(i)
|
19 |
+
else:
|
20 |
+
curr_own_type_max = working_portfolio.loc[i, 'Similarity Score'] + (slack_var / 20 * working_portfolio.loc[i, 'Similarity Score'])
|
21 |
+
|
22 |
+
working_portfolio = working_portfolio.drop(rows_to_drop).reset_index(drop=True)
|
23 |
+
init_portfolio = pd.concat([init_portfolio, working_portfolio])
|
24 |
+
|
25 |
+
if len(init_portfolio) >= lineup_target:
|
26 |
+
init_portfolio.sort_values(by='median', ascending=True).head(lineup_target)
|
27 |
+
|
28 |
+
player_list = set()
|
29 |
+
player_stats = []
|
30 |
+
for cols in init_portfolio.columns:
|
31 |
+
if cols not in excluded_cols:
|
32 |
+
player_list.update(init_portfolio[cols].unique())
|
33 |
+
|
34 |
+
for player in player_list:
|
35 |
+
player_mask = init_portfolio[~excluded_cols].apply(
|
36 |
+
lambda row: player in list(row), axis=1
|
37 |
+
)
|
38 |
+
|
39 |
+
if player_mask.any():
|
40 |
+
player_stats.append({
|
41 |
+
'Player': player,
|
42 |
+
'Lineup Count': player_mask.sum(),
|
43 |
+
'Exposure': player_mask.sum() / len(init_portfolio)
|
44 |
+
})
|
45 |
+
|
46 |
+
player_summary = pd.DataFrame(player_stats)
|
47 |
+
print(player_summary.sort_values('Lineup Count', ascending=False).head(10))
|
48 |
+
|
49 |
for slack_var in range(1, 20):
|
50 |
concat_portfolio = pd.DataFrame(columns=portfolio.columns)
|
51 |
|
|
|
67 |
|
68 |
if len(concat_portfolio) >= lineup_target:
|
69 |
return concat_portfolio.sort_values(by='median', ascending=True).head(lineup_target)
|
70 |
+
|
71 |
return concat_portfolio.sort_values(by='median', ascending=True)
|