Skip to content

Commit a6c8155

Browse files
committed
fix(spadl): do not insert synthetic dribbles before offensive fouls
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
1 parent 46a96ae commit a6c8155

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

socceraction/spadl/base.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ def _add_dribbles(actions: pd.DataFrame) -> pd.DataFrame:
3939

4040
same_team = actions.team_id == next_actions.team_id
4141
# not_clearance = actions.type_id != actiontypes.index("clearance")
42+
not_offensive_foul = same_team & (
43+
next_actions.type_id != spadlconfig.actiontypes.index('foul')
44+
)
4245

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

52-
dribble_idx = same_team & far_enough & not_too_far & same_phase & same_period
55+
dribble_idx = (
56+
same_team & far_enough & not_too_far & same_phase & same_period & not_offensive_foul
57+
)
5358

5459
dribbles = pd.DataFrame()
5560
prev = actions[dribble_idx]

0 commit comments

Comments
 (0)