From 63cefbd95c4ffcf8d6a397281fb536ed16d59350 Mon Sep 17 00:00:00 2001 From: Pieter Robberechts Date: Fri, 29 Dec 2023 18:57:21 +0100 Subject: [PATCH] fix(opta): handle x=0 or y=0 coordinates When an event had start- or end-coordinates equal to zero, these were incorrectly handled as missing coordinates. --- socceraction/data/opta/parsers/f24_json.py | 8 ++++---- socceraction/data/opta/parsers/f24_xml.py | 8 ++++---- socceraction/data/opta/parsers/ma3_json.py | 8 ++++---- socceraction/data/opta/parsers/whoscored.py | 8 ++++---- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/socceraction/data/opta/parsers/f24_json.py b/socceraction/data/opta/parsers/f24_json.py index 1f6b88f5..7203c21d 100644 --- a/socceraction/data/opta/parsers/f24_json.py +++ b/socceraction/data/opta/parsers/f24_json.py @@ -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( @@ -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))), diff --git a/socceraction/data/opta/parsers/f24_xml.py b/socceraction/data/opta/parsers/f24_xml.py index 250cbd61..982e0f7c 100644 --- a/socceraction/data/opta/parsers/f24_xml.py +++ b/socceraction/data/opta/parsers/f24_xml.py @@ -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 @@ -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))), diff --git a/socceraction/data/opta/parsers/ma3_json.py b/socceraction/data/opta/parsers/ma3_json.py index 616577b5..b036ba51 100644 --- a/socceraction/data/opta/parsers/ma3_json.py +++ b/socceraction/data/opta/parsers/ma3_json.py @@ -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( @@ -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))), diff --git a/socceraction/data/opta/parsers/whoscored.py b/socceraction/data/opta/parsers/whoscored.py index e4443608..f5156c4c 100644 --- a/socceraction/data/opta/parsers/whoscored.py +++ b/socceraction/data/opta/parsers/whoscored.py @@ -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, @@ -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"))