Skip to content

Stats Perform

kloppy.statsperform

Functions for loading Stats Perform data.

load_event

1
2
3
4
5
6
7
8
9
load_event(
    ma1_data,
    ma3_data,
    pitch_length=None,
    pitch_width=None,
    event_types=None,
    coordinates=None,
    event_factory=None,
)

Load Stats Perform event data.

PARAMETER DESCRIPTION
ma1_data

A MA1 json or xml feed containing the lineup information.

TYPE: FileLike

ma3_data

A MA3 json or xml feed containing the events.

TYPE: FileLike

pitch_length

The length of the pitch (in meters).

TYPE: Optional[float] DEFAULT: None

pitch_width

The width of the pitch (in meters).

TYPE: Optional[float] DEFAULT: None

event_types

A list of event types to load.

TYPE: Optional[List[str]] DEFAULT: None

coordinates

The coordinate system to use.

TYPE: Optional[str] DEFAULT: None

event_factory

A custom event factory.

TYPE: Optional[EventFactory] DEFAULT: None

RETURNS DESCRIPTION
EventDataset

The parsed event data.

Source code in kloppy/_providers/statsperform.py
def load_event(
    ma1_data: FileLike,
    ma3_data: FileLike,
    pitch_length: Optional[float] = None,
    pitch_width: Optional[float] = None,
    event_types: Optional[List[str]] = None,
    coordinates: Optional[str] = None,
    event_factory: Optional[EventFactory] = None,
) -> EventDataset:
    """Load Stats Perform event data.

    Args:
        ma1_data: A MA1 json or xml feed containing the lineup information.
        ma3_data: A MA3 json or xml feed containing the events.
        pitch_length: The length of the pitch (in meters).
        pitch_width: The width of the pitch (in meters).
        event_types: A list of event types to load.
        coordinates: The coordinate system to use.
        event_factory: A custom event factory.

    Returns:
        The parsed event data.
    """
    deserializer = StatsPerformEventDeserializer(
        event_types=event_types,
        coordinate_system=coordinates,
        event_factory=event_factory or get_config("event_factory"),  # type: ignore
    )
    with open_as_file(ma1_data) as ma1_data_fp, open_as_file(
        ma3_data
    ) as ma3_data_fp:
        return deserializer.deserialize(
            inputs=StatsPerformEventInputs(
                meta_data=ma1_data_fp,
                meta_feed="MA1",
                event_data=ma3_data_fp,
                event_feed="MA3",
                pitch_length=pitch_length,
                pitch_width=pitch_width,
            ),
        )

load_tracking

load_tracking(
    ma1_data,
    ma25_data,
    tracking_system="sportvu",
    pitch_length=None,
    pitch_width=None,
    sample_rate=None,
    limit=None,
    coordinates=None,
    only_alive=False,
)

Load Stats Perform tracking data.

PARAMETER DESCRIPTION
ma1_data

A json or xml feed containing the lineup information.

TYPE: FileLike

ma25_data

A txt file linked in the MA25 Match Tracking Feed; also known as an OPT file.

TYPE: FileLike

tracking_system

The system that generated the tracking data.

TYPE: str DEFAULT: 'sportvu'

pitch_length

The length of the pitch (in meters).

TYPE: Optional[float] DEFAULT: None

pitch_width

The width of the pitch (in meters).

TYPE: Optional[float] DEFAULT: None

sample_rate

Sample the data at a specific rate.

TYPE: Optional[float] DEFAULT: None

limit

Limit the number of frames to load to the first limit frames.

TYPE: Optional[int] DEFAULT: None

coordinates

The coordinate system to use.

TYPE: Optional[str] DEFAULT: None

only_alive

Only include frames in which the game is not paused.

TYPE: Optional[bool] DEFAULT: False

RETURNS DESCRIPTION
TrackingDataset

The parsed tracking data.

Source code in kloppy/_providers/statsperform.py
def load_tracking(
    ma1_data: FileLike,
    ma25_data: FileLike,
    tracking_system: str = "sportvu",
    pitch_length: Optional[float] = None,
    pitch_width: Optional[float] = None,
    sample_rate: Optional[float] = None,
    limit: Optional[int] = None,
    coordinates: Optional[str] = None,
    only_alive: Optional[bool] = False,
) -> TrackingDataset:
    """
    Load Stats Perform tracking data.

    Args:
        ma1_data: A json or xml feed containing the lineup information.
        ma25_data: A txt file linked in the MA25 Match Tracking Feed; also known as an OPT file.
        tracking_system: The system that generated the tracking data.
        pitch_length: The length of the pitch (in meters).
        pitch_width: The width of the pitch (in meters).
        sample_rate: Sample the data at a specific rate.
        limit: Limit the number of frames to load to the first `limit` frames.
        coordinates: The coordinate system to use.
        only_alive: Only include frames in which the game is not paused.

    Returns:
        The parsed tracking data.
    """
    deserializer = StatsPerformTrackingDeserializer(
        provider=Provider[tracking_system.upper()],
        sample_rate=sample_rate,
        limit=limit,
        coordinate_system=coordinates,
        only_alive=only_alive,
    )
    with open_as_file(ma1_data) as ma1_data_fp, open_as_file(
        ma25_data
    ) as ma25_data_fp:
        return deserializer.deserialize(
            inputs=StatsPerformTrackingInputs(
                meta_data=ma1_data_fp,
                raw_data=ma25_data_fp,
                pitch_length=pitch_length,
                pitch_width=pitch_width,
            )
        )