James McCool
commited on
Commit
·
1bd74a1
1
Parent(s):
698043b
Refactor player removal logic in distribute_preset.py to utilize a list of players with the lowest lineup counts. This change enhances the portfolio distribution process by ensuring that the least favorable players are excluded from the lineup, improving overall selection accuracy.
Browse files
global_func/distribute_preset.py
CHANGED
@@ -3,6 +3,7 @@ import pandas as pd
|
|
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 |
|
@@ -47,14 +48,18 @@ def distribute_preset(portfolio: pd.DataFrame, lineup_target: int, exclude_cols:
|
|
47 |
|
48 |
player_summary = pd.DataFrame(player_stats)
|
49 |
print(player_summary.sort_values('Lineup Count', ascending=False).head(10))
|
|
|
50 |
|
51 |
for slack_var in range(1, 20):
|
52 |
concat_portfolio = pd.DataFrame(columns=portfolio.columns)
|
53 |
|
54 |
-
for
|
55 |
rows_to_drop = []
|
56 |
working_portfolio = portfolio.copy()
|
57 |
-
|
|
|
|
|
|
|
58 |
working_portfolio = working_portfolio.reset_index(drop=True)
|
59 |
curr_own_type_max = working_portfolio.loc[0, 'Similarity Score'] + (slack_var / 20 * working_portfolio.loc[0, 'Similarity Score'])
|
60 |
|
|
|
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 |
+
player_columns = [col for col in init_portfolio.columns if col not in excluded_cols]
|
7 |
for slack_var in range(1, 20):
|
8 |
init_portfolio = pd.DataFrame(columns=portfolio.columns)
|
9 |
|
|
|
48 |
|
49 |
player_summary = pd.DataFrame(player_stats)
|
50 |
print(player_summary.sort_values('Lineup Count', ascending=False).head(10))
|
51 |
+
player_remove_list = player_summary.sort_values('Lineup Count', ascending=False).head(5)['Player'].tolist()
|
52 |
|
53 |
for slack_var in range(1, 20):
|
54 |
concat_portfolio = pd.DataFrame(columns=portfolio.columns)
|
55 |
|
56 |
+
for player_out in player_remove_list:
|
57 |
rows_to_drop = []
|
58 |
working_portfolio = portfolio.copy()
|
59 |
+
remove_mask = working_portfolio[player_columns].apply(
|
60 |
+
lambda row: not any(player in list(row) for player in player_out), axis=1
|
61 |
+
)
|
62 |
+
working_portfolio = working_portfolio[remove_mask]
|
63 |
working_portfolio = working_portfolio.reset_index(drop=True)
|
64 |
curr_own_type_max = working_portfolio.loc[0, 'Similarity Score'] + (slack_var / 20 * working_portfolio.loc[0, 'Similarity Score'])
|
65 |
|