From 397859c9ca48b808696ebd68f2273268d6e4bcc2 Mon Sep 17 00:00:00 2001 From: Koen Vossen Date: Tue, 1 Sep 2020 15:22:05 +0200 Subject: [PATCH] Reformat --- examples/datasets/metrica.py | 4 +-- examples/datasets/statsbomb.py | 4 +-- examples/pattern_matching/ball_recovery.py | 4 +-- examples/playing_time.py | 2 +- kloppy/cmdline.py | 3 +- kloppy/domain/services/enrichers/__init__.py | 8 ++--- .../domain/services/transformers/__init__.py | 30 ++++++++++++------- kloppy/helpers.py | 3 +- .../event/metrica/json_serializer.py | 24 +++++++++++---- .../serializers/event/opta/serializer.py | 26 ++++++++++++---- .../serializers/event/statsbomb/serializer.py | 5 +++- .../serializers/tracking/epts/metadata.py | 3 +- kloppy/infra/serializers/tracking/tracab.py | 5 +++- 13 files changed, 83 insertions(+), 38 deletions(-) diff --git a/examples/datasets/metrica.py b/examples/datasets/metrica.py index 698e7d2e..3bcd21eb 100644 --- a/examples/datasets/metrica.py +++ b/examples/datasets/metrica.py @@ -6,8 +6,8 @@ def main(): """ - This example shows the use of Metrica datasets, and how we can pass argument - to the dataset loader. + This example shows the use of Metrica datasets, and how we can pass argument + to the dataset loader. """ logging.basicConfig( stream=sys.stdout, diff --git a/examples/datasets/statsbomb.py b/examples/datasets/statsbomb.py index cae150ac..b2711ae4 100644 --- a/examples/datasets/statsbomb.py +++ b/examples/datasets/statsbomb.py @@ -7,8 +7,8 @@ def main(): """ - This example shows the use of Statsbomb datasets, and how we can pass argument - to the dataset loader. + This example shows the use of Statsbomb datasets, and how we can pass argument + to the dataset loader. """ logging.basicConfig( stream=sys.stdout, diff --git a/examples/pattern_matching/ball_recovery.py b/examples/pattern_matching/ball_recovery.py index 38df46e8..0fc016b6 100644 --- a/examples/pattern_matching/ball_recovery.py +++ b/examples/pattern_matching/ball_recovery.py @@ -8,8 +8,8 @@ def main(): """ - This example shows the use of regular expressions to do - pattern matching. + This example shows the use of regular expressions to do + pattern matching. """ logging.basicConfig( stream=sys.stdout, diff --git a/examples/playing_time.py b/examples/playing_time.py index b67be840..9d62f51e 100644 --- a/examples/playing_time.py +++ b/examples/playing_time.py @@ -10,7 +10,7 @@ def main(): """ - This example shows how to determine playing time + This example shows how to determine playing time """ logging.basicConfig( stream=sys.stdout, diff --git a/kloppy/cmdline.py b/kloppy/cmdline.py index 511a66ff..d86d0b52 100644 --- a/kloppy/cmdline.py +++ b/kloppy/cmdline.py @@ -80,7 +80,8 @@ def run_query(argv=sys.argv[1:]): help="StatsBomb event input files (events.json,lineup.json)", ) parser.add_argument( - "--input-opta", help="Opta event input files (f24.xml,f7.xml)", + "--input-opta", + help="Opta event input files (f24.xml,f7.xml)", ) parser.add_argument("--output-xml", help="Output file") parser.add_argument( diff --git a/kloppy/domain/services/enrichers/__init__.py b/kloppy/domain/services/enrichers/__init__.py index ece40ecf..c3ef8bcc 100644 --- a/kloppy/domain/services/enrichers/__init__.py +++ b/kloppy/domain/services/enrichers/__init__.py @@ -10,12 +10,12 @@ def enrich_inplace( self, tracking_dataset: TrackingDataset, event_dataset: EventDataset ) -> None: """ - Return an enriched tracking data set. + Return an enriched tracking data set. - Use the event data to rebuild game state. + Use the event data to rebuild game state. - Iterate through all tracking data events and apply event data to the GameState whenever - they happen. + Iterate through all tracking data events and apply event data to the GameState whenever + they happen. """ if tracking_dataset.flags & ( diff --git a/kloppy/domain/services/transformers/__init__.py b/kloppy/domain/services/transformers/__init__.py index 4b95c8b2..425ee1c2 100644 --- a/kloppy/domain/services/transformers/__init__.py +++ b/kloppy/domain/services/transformers/__init__.py @@ -56,15 +56,19 @@ def __needs_flip( if self._from_orientation == self._to_orientation: flip = False else: - orientation_factor_from = self._from_orientation.get_orientation_factor( - ball_owning_team=ball_owning_team, - attacking_direction=attacking_direction, - action_executing_team=action_executing_team, + orientation_factor_from = ( + self._from_orientation.get_orientation_factor( + ball_owning_team=ball_owning_team, + attacking_direction=attacking_direction, + action_executing_team=action_executing_team, + ) ) - orientation_factor_to = self._to_orientation.get_orientation_factor( - ball_owning_team=ball_owning_team, - attacking_direction=attacking_direction, - action_executing_team=action_executing_team, + orientation_factor_to = ( + self._to_orientation.get_orientation_factor( + ball_owning_team=ball_owning_team, + attacking_direction=attacking_direction, + action_executing_team=action_executing_team, + ) ) flip = orientation_factor_from != orientation_factor_to return flip @@ -149,10 +153,16 @@ def transform_dataset( for record in dataset.records ] - return TrackingDataset(metadata=metadata, records=frames,) + return TrackingDataset( + metadata=metadata, + records=frames, + ) elif isinstance(dataset, EventDataset): events = list(map(transformer.transform_event, dataset.records)) - return EventDataset(metadata=metadata, records=events,) + return EventDataset( + metadata=metadata, + records=events, + ) else: raise Exception("Unknown Dataset type") diff --git a/kloppy/helpers.py b/kloppy/helpers.py index 3e80eb70..725313eb 100644 --- a/kloppy/helpers.py +++ b/kloppy/helpers.py @@ -97,7 +97,8 @@ def load_opta_event_data( ) as f7_data: return serializer.deserialize( - inputs={"f24_data": f24_data, "f7_data": f7_data}, options=options, + inputs={"f24_data": f24_data, "f7_data": f7_data}, + options=options, ) diff --git a/kloppy/infra/serializers/event/metrica/json_serializer.py b/kloppy/infra/serializers/event/metrica/json_serializer.py index 3bc3e1d0..bc20deb7 100644 --- a/kloppy/infra/serializers/event/metrica/json_serializer.py +++ b/kloppy/infra/serializers/event/metrica/json_serializer.py @@ -72,7 +72,10 @@ def _parse_coordinates(event_start_or_end: dict) -> Point: if x is None: return None - return Point(x=x, y=y,) + return Point( + x=x, + y=y, + ) def _parse_subtypes(event: dict) -> List: @@ -268,10 +271,13 @@ def deserialize( if event_type in MS_PASS_TYPES: pass_event_kwargs = _parse_pass( - event=raw_event, subtypes=subtypes, team=team, + event=raw_event, + subtypes=subtypes, + team=team, ) event = PassEvent( - **pass_event_kwargs, **generic_event_kwargs, + **pass_event_kwargs, + **generic_event_kwargs, ) elif event_type == MS_EVENT_TYPE_SHOT: @@ -288,9 +294,12 @@ def deserialize( **take_on_event_kwargs, **generic_event_kwargs ) elif event_type == MS_EVENT_TYPE_CARRY: - carry_event_kwargs = _parse_carry(event=raw_event,) + carry_event_kwargs = _parse_carry( + event=raw_event, + ) event = CarryEvent( - **carry_event_kwargs, **generic_event_kwargs, + **carry_event_kwargs, + **generic_event_kwargs, ) else: event = GenericEvent( @@ -305,7 +314,10 @@ def deserialize( ): events.append(event) - return EventDataset(metadata=metadata, records=events,) + return EventDataset( + metadata=metadata, + records=events, + ) def serialize(self, data_set: EventDataset) -> Tuple[str, str]: raise NotImplementedError diff --git a/kloppy/infra/serializers/event/opta/serializer.py b/kloppy/infra/serializers/event/opta/serializer.py index 2fcfb5af..8cc961d1 100644 --- a/kloppy/infra/serializers/event/opta/serializer.py +++ b/kloppy/infra/serializers/event/opta/serializer.py @@ -348,8 +348,16 @@ def deserialize( game_elm = f24_root.find("Game") periods = [ - Period(id=1, start_timestamp=None, end_timestamp=None,), - Period(id=2, start_timestamp=None, end_timestamp=None,), + Period( + id=1, + start_timestamp=None, + end_timestamp=None, + ), + Period( + id=2, + start_timestamp=None, + end_timestamp=None, + ), ] possession_team = None events = [] @@ -426,17 +434,20 @@ def deserialize( if type_id == EVENT_TYPE_PASS: pass_event_kwargs = _parse_pass(qualifiers, outcome) event = PassEvent( - **pass_event_kwargs, **generic_event_kwargs, + **pass_event_kwargs, + **generic_event_kwargs, ) elif type_id == EVENT_TYPE_OFFSIDE_PASS: pass_event_kwargs = _parse_offside_pass() event = PassEvent( - **pass_event_kwargs, **generic_event_kwargs, + **pass_event_kwargs, + **generic_event_kwargs, ) elif type_id == EVENT_TYPE_TAKE_ON: take_on_event_kwargs = _parse_take_on(outcome) event = TakeOnEvent( - **take_on_event_kwargs, **generic_event_kwargs, + **take_on_event_kwargs, + **generic_event_kwargs, ) elif type_id in ( EVENT_TYPE_SHOT_MISS, @@ -479,7 +490,10 @@ def deserialize( provider=Provider.OPTA, ) - return EventDataset(metadata=metadata, records=events,) + return EventDataset( + metadata=metadata, + records=events, + ) def serialize(self, data_set: EventDataset) -> Tuple[str, str]: raise NotImplementedError diff --git a/kloppy/infra/serializers/event/statsbomb/serializer.py b/kloppy/infra/serializers/event/statsbomb/serializer.py index 8a68b601..1b700236 100644 --- a/kloppy/infra/serializers/event/statsbomb/serializer.py +++ b/kloppy/infra/serializers/event/statsbomb/serializer.py @@ -439,7 +439,10 @@ def deserialize( provider=Provider.STATSBOMB, ) - return EventDataset(metadata=metadata, records=events,) + return EventDataset( + metadata=metadata, + records=events, + ) def serialize(self, data_set: EventDataset) -> Tuple[str, str]: raise NotImplementedError diff --git a/kloppy/infra/serializers/tracking/epts/metadata.py b/kloppy/infra/serializers/tracking/epts/metadata.py index a2e5c366..237797c7 100644 --- a/kloppy/infra/serializers/tracking/epts/metadata.py +++ b/kloppy/infra/serializers/tracking/epts/metadata.py @@ -157,7 +157,8 @@ def _parse_provider(provider_name: Union[str, None]) -> Provider: return Provider.METRICA else: warnings.warn( - "The Provider is not known to Kloppy.", Warning, + "The Provider is not known to Kloppy.", + Warning, ) else: return None diff --git a/kloppy/infra/serializers/tracking/tracab.py b/kloppy/infra/serializers/tracking/tracab.py index 4cb32aba..0c86cbdc 100644 --- a/kloppy/infra/serializers/tracking/tracab.py +++ b/kloppy/infra/serializers/tracking/tracab.py @@ -241,7 +241,10 @@ def _iter(): flags=DatasetFlag.BALL_OWNING_TEAM | DatasetFlag.BALL_STATE, ) - return TrackingDataset(records=frames, metadata=metadata,) + return TrackingDataset( + records=frames, + metadata=metadata, + ) def serialize(self, dataset: TrackingDataset) -> Tuple[str, str]: raise NotImplementedError