Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Sportec coordinate scaling and own goal issue #216

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 25 additions & 10 deletions kloppy/infra/serializers/event/sportec/deserializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,10 @@ def sportec_metadata_from_xml_elm(match_root) -> SportecMetadata:
if not away_team:
raise DeserializationError("Away team is missing from metadata")

(home_score, away_score,) = match_root.MatchInformation.General.attrib[
(
home_score,
away_score,
) = match_root.MatchInformation.General.attrib[
"Result"
].split(":")
score = Score(home=int(home_score), away=int(away_score))
Expand Down Expand Up @@ -197,13 +200,15 @@ def _event_chain_from_xml_elm(event_elm):
SPORTEC_EVENT_NAME_SHOT_WOODWORK = "ShotWoodWork"
SPORTEC_EVENT_NAME_SHOT_OTHER = "OtherShot"
SPORTEC_EVENT_NAME_SHOT_GOAL = "SuccessfulShot"
SPORTEC_EVENT_NAME_OWN_GOAL = "OwnGoal"
SPORTEC_SHOT_EVENT_NAMES = (
SPORTEC_EVENT_NAME_SHOT_WIDE,
SPORTEC_EVENT_NAME_SHOT_SAVED,
SPORTEC_EVENT_NAME_SHOT_BLOCKED,
SPORTEC_EVENT_NAME_SHOT_WOODWORK,
SPORTEC_EVENT_NAME_SHOT_OTHER,
SPORTEC_EVENT_NAME_SHOT_GOAL,
SPORTEC_EVENT_NAME_OWN_GOAL,
)

SPORTEC_EVENT_NAME_PASS = "Pass"
Expand Down Expand Up @@ -288,6 +293,8 @@ def _parse_shot(event_name: str, event_chain: OrderedDict) -> Dict:
result = ShotResult.POST
elif event_name == SPORTEC_EVENT_NAME_SHOT_GOAL:
result = ShotResult.GOAL
elif event_name == SPORTEC_EVENT_NAME_OWN_GOAL:
result = ShotResult.OWN_GOAL
elif event_name == SPORTEC_EVENT_NAME_SHOT_OTHER:
result = None
else:
Expand Down Expand Up @@ -411,12 +418,12 @@ def deserialize(self, inputs: SportecEventDataInputs) -> EventDataset:
if team_left == home_team.team_id:
# goal of home team is on the left side.
# this means they attack from left to right
orientation = Orientation.FIXED_HOME_AWAY
orientation = Orientation.HOME_TEAM
period.set_attacking_direction(
AttackingDirection.HOME_AWAY
)
else:
orientation = Orientation.FIXED_AWAY_HOME
orientation = Orientation.AWAY_TEAM
period.set_attacking_direction(
AttackingDirection.AWAY_HOME
)
Expand Down Expand Up @@ -538,13 +545,21 @@ def deserialize(self, inputs: SportecEventDataInputs) -> EventDataset:
and previous_event.result == PassResult.COMPLETE
):
if "X-Source-Position" in event_chain["Event"]:
previous_event.receiver_coordinates = Point(
x=float(
event_chain["Event"]["X-Source-Position"]
),
y=float(
event_chain["Event"]["Y-Source-Position"]
),
previous_event.receiver_coordinates = (
transformer.change_point_dimensions(
Point(
x=float(
event_chain["Event"][
"X-Source-Position"
]
),
y=float(
event_chain["Event"][
"Y-Source-Position"
]
),
)
)
)

if (
Expand Down
4 changes: 2 additions & 2 deletions kloppy/infra/serializers/tracking/sportec/deserializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,9 @@ def _iter():
break

orientation = (
Orientation.FIXED_HOME_AWAY
Orientation.HOME_TEAM
if periods[0].attacking_direction == AttackingDirection.HOME_AWAY
else Orientation.FIXED_AWAY_HOME
else Orientation.AWAY_TEAM
)

metadata = Metadata(
Expand Down