James McCool
commited on
Commit
·
abd4533
1
Parent(s):
8fd7943
Add position eligibility check in exposure_spread function to filter comparable players based on overlapping positions, improving accuracy in player comparisons.
Browse files
global_func/exposure_spread.py
CHANGED
|
@@ -15,12 +15,23 @@ def exposure_spread(working_frame, exposure_player, exposure_target, exposure_st
|
|
| 15 |
comp_salary_low = comparable_players['salary'][0] - 500
|
| 16 |
comp_projection_high = comparable_players['median'][0]
|
| 17 |
comp_projection_low = comparable_players['median'][0] - (comparable_players['median'][0] * .75)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
comparable_players = projections_df[
|
| 20 |
(projections_df['salary'] >= comp_salary_low) &
|
| 21 |
(projections_df['salary'] <= comp_salary_high) &
|
| 22 |
(projections_df['median'] >= comp_projection_low) &
|
| 23 |
-
(projections_df['median'] <= comp_projection_high)
|
|
|
|
| 24 |
]
|
| 25 |
|
| 26 |
# Create a list of comparable players
|
|
|
|
| 15 |
comp_salary_low = comparable_players['salary'][0] - 500
|
| 16 |
comp_projection_high = comparable_players['median'][0]
|
| 17 |
comp_projection_low = comparable_players['median'][0] - (comparable_players['median'][0] * .75)
|
| 18 |
+
# players can be eligible at multiple positions, so we need to find all the positions the player is eligible at
|
| 19 |
+
# the position column can have positions designated as 1B/OF which means they are eligible at 1B and OF
|
| 20 |
+
comp_player_position = comparable_players['position'].tolist()
|
| 21 |
+
comp_player_position = [pos.split('/') for pos in comp_player_position]
|
| 22 |
+
comp_player_position = [item for sublist in comp_player_position for item in sublist]
|
| 23 |
+
comp_player_position = list(set(comp_player_position))
|
| 24 |
+
|
| 25 |
+
def has_position_overlap(player_positions, target_positions):
|
| 26 |
+
player_pos_list = player_positions.split('/')
|
| 27 |
+
return any(pos in target_positions for pos in player_pos_list)
|
| 28 |
|
| 29 |
comparable_players = projections_df[
|
| 30 |
(projections_df['salary'] >= comp_salary_low) &
|
| 31 |
(projections_df['salary'] <= comp_salary_high) &
|
| 32 |
(projections_df['median'] >= comp_projection_low) &
|
| 33 |
+
(projections_df['median'] <= comp_projection_high) &
|
| 34 |
+
(projections_df['position'].apply(lambda x: has_position_overlap(x, comp_player_position)))
|
| 35 |
]
|
| 36 |
|
| 37 |
# Create a list of comparable players
|