Skip to content

Commit

Permalink
fix(opta): handle x=0 or y=0 coordinates
Browse files Browse the repository at this point in the history
When an event had start- or end-coordinates equal to zero, these were
incorrectly handled as missing coordinates.
  • Loading branch information
probberechts committed Dec 29, 2023
1 parent 29aabe7 commit 63cefbd
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
8 changes: 4 additions & 4 deletions socceraction/data/opta/parsers/f24_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ def extract_events(self) -> dict[tuple[int, int], dict[str, Any]]:
}
start_x = float(assertget(attr, 'x'))
start_y = float(assertget(attr, 'y'))
end_x = _get_end_x(qualifiers) or start_x
end_y = _get_end_y(qualifiers) or start_y
end_x = _get_end_x(qualifiers)
end_y = _get_end_y(qualifiers)

event_id = int(assertget(attr, 'id'))
events[(game_id, event_id)] = dict(
Expand All @@ -112,8 +112,8 @@ def extract_events(self) -> dict[tuple[int, int], dict[str, Any]]:
outcome=bool(int(attr.get('outcome', 1))),
start_x=start_x,
start_y=start_y,
end_x=end_x,
end_y=end_y,
end_x=end_x if end_x is not None else start_x,
end_y=end_y if end_y is not None else start_y,
qualifiers=qualifiers,
# Optional fields
assist=bool(int(attr.get('assist', 0))),
Expand Down
8 changes: 4 additions & 4 deletions socceraction/data/opta/parsers/f24_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ def extract_events(self) -> dict[tuple[int, int], dict[str, Any]]:
}
start_x = float(assertget(attr, 'x'))
start_y = float(assertget(attr, 'y'))
end_x = _get_end_x(qualifiers) or start_x
end_y = _get_end_y(qualifiers) or start_y
end_x = _get_end_x(qualifiers)
end_y = _get_end_y(qualifiers)

events[(game_id, event_id)] = dict(
# Fields required by the base schema
Expand All @@ -95,8 +95,8 @@ def extract_events(self) -> dict[tuple[int, int], dict[str, Any]]:
outcome=bool(int(attr["outcome"])) if "outcome" in attr else None,
start_x=start_x,
start_y=start_y,
end_x=end_x,
end_y=end_y,
end_x=end_x if end_x is not None else start_x,
end_y=end_y if end_y is not None else start_y,
qualifiers=qualifiers,
# Optional fields
assist=bool(int(attr.get('assist', 0))),
Expand Down
8 changes: 4 additions & 4 deletions socceraction/data/opta/parsers/ma3_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,8 @@ def extract_events(self) -> dict[tuple[str, int], dict[str, Any]]:
}
start_x = float(assertget(element, "x"))
start_y = float(assertget(element, "y"))
end_x = _get_end_x(qualifiers) or start_x
end_y = _get_end_y(qualifiers) or start_y
end_x = _get_end_x(qualifiers)
end_y = _get_end_y(qualifiers)

event_id = int(assertget(element, "id"))
event = dict(
Expand All @@ -279,8 +279,8 @@ def extract_events(self) -> dict[tuple[str, int], dict[str, Any]]:
outcome=bool(int(element.get("outcome", 1))),
start_x=start_x,
start_y=start_y,
end_x=end_x,
end_y=end_y,
end_x=end_x if end_x is not None else start_x,
end_y=end_y if end_y is not None else start_y,
qualifiers=qualifiers,
# Optional fields
assist=bool(int(element.get("assist", 0))),
Expand Down
8 changes: 4 additions & 4 deletions socceraction/data/opta/parsers/whoscored.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ def extract_events(self) -> dict[tuple[int, int], dict[str, Any]]:
qualifiers = {
int(q["type"]["value"]): q.get("value", True) for q in attr.get("qualifiers", [])
}
end_x = attr.get("endX") or _get_end_x(qualifiers) or start_x
end_y = attr.get("endY") or _get_end_y(qualifiers) or start_y
end_x = attr.get("endX", _get_end_x(qualifiers))
end_y = attr.get("endY", _get_end_y(qualifiers))
events[(self.game_id, event_id)] = dict(
# Fields required by the base schema
game_id=self.game_id,
Expand All @@ -229,8 +229,8 @@ def extract_events(self) -> dict[tuple[int, int], dict[str, Any]]:
outcome=bool(attr["outcomeType"].get("value")) if "outcomeType" in attr else None,
start_x=start_x,
start_y=start_y,
end_x=end_x,
end_y=end_y,
end_x=end_x if end_x is not None else start_x,
end_y=end_y if end_y is not None else start_y,
qualifiers=qualifiers,
# Optional fields
related_player_id=int(attr.get("relatedPlayerId"))
Expand Down

0 comments on commit 63cefbd

Please sign in to comment.