Skip to content

Commit

Permalink
Reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
koenvossen committed Sep 1, 2020
1 parent 21e7a5f commit 397859c
Show file tree
Hide file tree
Showing 13 changed files with 83 additions and 38 deletions.
4 changes: 2 additions & 2 deletions examples/datasets/metrica.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions examples/datasets/statsbomb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions examples/pattern_matching/ball_recovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion examples/playing_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion kloppy/cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
8 changes: 4 additions & 4 deletions kloppy/domain/services/enrichers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 & (
Expand Down
30 changes: 20 additions & 10 deletions kloppy/domain/services/transformers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
3 changes: 2 additions & 1 deletion kloppy/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)


Expand Down
24 changes: 18 additions & 6 deletions kloppy/infra/serializers/event/metrica/json_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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(
Expand All @@ -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
26 changes: 20 additions & 6 deletions kloppy/infra/serializers/event/opta/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
5 changes: 4 additions & 1 deletion kloppy/infra/serializers/event/statsbomb/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion kloppy/infra/serializers/tracking/epts/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion kloppy/infra/serializers/tracking/tracab.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 397859c

Please sign in to comment.