Skip to content

Commit

Permalink
Rename HOME_TEAM and AWAY_TEAM orientations
Browse files Browse the repository at this point in the history
  • Loading branch information
probberechts committed Sep 1, 2023
1 parent a1fd6f9 commit 48ba32c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
12 changes: 6 additions & 6 deletions kloppy/domain/models/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,8 @@ class Orientation(Enum):
ACTION_EXECUTING_TEAM = "action-executing-team"

# changes during half-time
HOME_TEAM = "home-team"
AWAY_TEAM = "away-team"
HOME_AWAY = "home-away"
AWAY_HOME = "away-home"

# won't change during match
FIXED_HOME_AWAY = "fixed-home-away"
Expand All @@ -305,15 +305,15 @@ def get_attacking_direction(self, period: Period) -> AttackingDirection:
return AttackingDirection.HOME_AWAY
if self == Orientation.FIXED_AWAY_HOME:
return AttackingDirection.AWAY_HOME
if self == Orientation.HOME_TEAM:
if self == Orientation.HOME_AWAY:
dirmap = {
1: AttackingDirection.HOME_AWAY,
2: AttackingDirection.AWAY_HOME,
3: AttackingDirection.HOME_AWAY,
4: AttackingDirection.AWAY_HOME,
}
return dirmap.get(period.id, period.attacking_direction)
if self == Orientation.AWAY_TEAM:
if self == Orientation.AWAY_HOME:
dirmap = {
1: AttackingDirection.AWAY_HOME,
2: AttackingDirection.HOME_AWAY,
Expand All @@ -335,15 +335,15 @@ def get_orientation_factor(
return 1
if self == Orientation.FIXED_AWAY_HOME:
return -1
if self == Orientation.HOME_TEAM:
if self == Orientation.HOME_AWAY:
if period.id == 1 or period.id == 3:
return 1
if period.id == 2 or period.id == 4:
return -1
raise OrientationError(
f"AttackingDirection not defined for period with id {period.id}"
)
if self == Orientation.AWAY_TEAM:
if self == Orientation.AWAY_HOME:
if period.id == 1 or period.id == 3:
return -1
if period.id == 2 or period.id == 4:
Expand Down
20 changes: 10 additions & 10 deletions kloppy/tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def _get_tracking_dataset(self):
pitch_dimensions=PitchDimensions(
x_dim=Dimension(0, 100), y_dim=Dimension(-50, 50)
),
orientation=Orientation.HOME_TEAM,
orientation=Orientation.HOME_AWAY,
frame_rate=25,
periods=periods,
teams=teams,
Expand Down Expand Up @@ -108,7 +108,7 @@ def test_transform(self):

# orientation change AND dimension scale
transformed_dataset = tracking_data.transform(
to_orientation="AWAY_TEAM",
to_orientation="AWAY_HOME",
to_pitch_dimensions=[[0, 1], [0, 1]],
)

Expand All @@ -119,7 +119,7 @@ def test_transform(self):
x=1, y=0, z=1
)
assert (
transformed_dataset.metadata.orientation == Orientation.AWAY_TEAM
transformed_dataset.metadata.orientation == Orientation.AWAY_HOME
)
assert transformed_dataset.metadata.coordinate_system is None
assert (
Expand Down Expand Up @@ -153,11 +153,11 @@ def test_transform_to_pitch_dimensions(self):

def test_transform_to_orientation(self):
# Create a dataset with the KLOPPY pitch dimensions
# and HOME_TEAM orientation
# and HOME_AWAY orientation
original = self._get_tracking_dataset().transform(
to_pitch_dimensions=[[0, 1], [0, 1]],
)
assert original.metadata.orientation == Orientation.HOME_TEAM
assert original.metadata.orientation == Orientation.HOME_AWAY
assert original.frames[0].ball_coordinates == Point3D(x=1, y=0, z=0)
assert original.frames[1].ball_coordinates == Point3D(x=0, y=1, z=1)
# the frames should have the correct attacking direction
Expand All @@ -179,12 +179,12 @@ def test_transform_to_orientation(self):
== AttackingDirection.AWAY_HOME
)

# Transform to AWAY_TEAM orientation
# Transform to AWAY_HOME orientation
transform1 = original.transform(
to_orientation=Orientation.AWAY_TEAM,
to_orientation=Orientation.AWAY_HOME,
to_pitch_dimensions=[[0, 1], [0, 1]],
)
assert transform1.metadata.orientation == Orientation.AWAY_TEAM
assert transform1.metadata.orientation == Orientation.AWAY_HOME
# all coordinates should be flipped
assert transform1.frames[0].ball_coordinates == Point3D(x=0, y=1, z=0)
assert transform1.frames[1].ball_coordinates == Point3D(x=1, y=0, z=1)
Expand Down Expand Up @@ -265,9 +265,9 @@ def test_transform_to_orientation(self):
for period in transform4.metadata.periods:
assert period.attacking_direction == AttackingDirection.NOT_SET

# Transform back to the original HOME_TEAM orientation
# Transform back to the original HOME_AWAY orientation
transform5 = transform4.transform(
to_orientation=Orientation.HOME_TEAM,
to_orientation=Orientation.HOME_AWAY,
to_pitch_dimensions=[[0, 1], [0, 1]],
)
# we should be back at the original
Expand Down

0 comments on commit 48ba32c

Please sign in to comment.