Skip to content

Wyscout

kloppy.wyscout

Functions for loading Wyscout event data.

load

1
2
3
4
5
6
7
load(
    event_data,
    event_types=None,
    coordinates=None,
    event_factory=None,
    data_version=None,
)

Load Wyscout event data.

PARAMETER DESCRIPTION
event_data

JSON feed with the raw event data of a game.

TYPE: FileLike

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

data_version

The version of the Wyscout data. Supported versions are "V2" and "V3".

TYPE: Optional[str] DEFAULT: None

RETURNS DESCRIPTION
EventDataset

The parsed event data.

Source code in kloppy/_providers/wyscout.py
def load(
    event_data: FileLike,
    event_types: Optional[List[str]] = None,
    coordinates: Optional[str] = None,
    event_factory: Optional[EventFactory] = None,
    data_version: Optional[str] = None,
) -> EventDataset:
    """
    Load Wyscout event data.

    Args:
        event_data: JSON feed with the raw event data of a game.
        event_types: A list of event types to load.
        coordinates: The coordinate system to use.
        event_factory: A custom event factory.
        data_version: The version of the Wyscout data. Supported versions are "V2" and "V3".

    Returns:
        The parsed event data.
    """
    if data_version == "V2":
        deserializer_class = WyscoutDeserializerV2
    elif data_version == "V3":
        deserializer_class = WyscoutDeserializerV3
    else:
        deserializer_class = identify_deserializer(event_data)

    deserializer = deserializer_class(
        event_types=event_types,
        coordinate_system=coordinates,
        event_factory=event_factory or get_config("event_factory"),
    )

    with open_as_file(event_data) as event_data_fp:
        return deserializer.deserialize(
            inputs=WyscoutInputs(event_data=event_data_fp),
        )

load_open_data

1
2
3
4
5
6
load_open_data(
    match_id="2499841",
    event_types=None,
    coordinates=None,
    event_factory=None,
)

Load Wyscout open data.

This dataset is a public release of event stream data, collected by Wyscout containing all matches of the 2017/18 season of the top-5 European leagues (La Liga, Serie A, Bundesliga, Premier League, Ligue 1), the FIFA World Cup 2018, and UEFA Euro Cup 2016. For a detailed description, see Pappalardo et al. [1].

PARAMETER DESCRIPTION
match_id

The id of the match to load data for.

TYPE: Union[str, int] DEFAULT: '2499841'

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.

References

[1] Pappalardo, L., Cintia, P., Rossi, A. et al. A public data set of spatio-temporal match events in soccer competitions. Sci Data 6, 236 (2019). https://doi.org/10.1038/s41597-019-0247-7

Source code in kloppy/_providers/wyscout.py
def load_open_data(
    match_id: Union[str, int] = "2499841",
    event_types: Optional[List[str]] = None,
    coordinates: Optional[str] = None,
    event_factory: Optional[EventFactory] = None,
) -> EventDataset:
    """
    Load Wyscout open data.

    This dataset is a public release of event stream data, collected by Wyscout
    containing all matches of the 2017/18 season of the top-5 European leagues
    (La Liga, Serie A, Bundesliga, Premier League, Ligue 1), the FIFA World
    Cup 2018, and UEFA Euro Cup 2016. For a detailed description,
    see Pappalardo et al. [1].

    Args:
        match_id: The id of the match to load data for.
        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.

    References:
        [1] Pappalardo, L., Cintia, P., Rossi, A. et al. A public data set of spatio-temporal match events in soccer competitions. Sci Data 6, 236 (2019). https://doi.org/10.1038/s41597-019-0247-7
    """
    return load(
        event_data=f"https://raw.githubusercontent.com/koenvo/wyscout-soccer-match-event-dataset/main/processed-v2/files/{match_id}.json",
        event_types=event_types,
        coordinates=coordinates,
        event_factory=event_factory,
    )