Skip to content

Commit

Permalink
fix(spadl): do not insert synthetic dribbles before offensive fouls
Browse files Browse the repository at this point in the history
This makes sure that no dribbles are added at the end location of actions that
are followed by a foul of the receiving player (or a teammate).

Closes #594
  • Loading branch information
probberechts committed Dec 30, 2023
1 parent 46a96ae commit a6c8155
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion socceraction/spadl/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ def _add_dribbles(actions: pd.DataFrame) -> pd.DataFrame:

same_team = actions.team_id == next_actions.team_id
# not_clearance = actions.type_id != actiontypes.index("clearance")
not_offensive_foul = same_team & (
next_actions.type_id != spadlconfig.actiontypes.index('foul')
)

dx = actions.end_x - next_actions.start_x
dy = actions.end_y - next_actions.start_y
Expand All @@ -49,7 +52,9 @@ def _add_dribbles(actions: pd.DataFrame) -> pd.DataFrame:
same_phase = dt < max_dribble_duration
same_period = actions.period_id == next_actions.period_id

dribble_idx = same_team & far_enough & not_too_far & same_phase & same_period
dribble_idx = (
same_team & far_enough & not_too_far & same_phase & same_period & not_offensive_foul
)

dribbles = pd.DataFrame()
prev = actions[dribble_idx]
Expand Down

0 comments on commit a6c8155

Please sign in to comment.