Skip to content

Event

Dataset

kloppy.domain.models.event.EventDataset dataclass

EventDataset

Attributes:

Name Type Description
metadata Metadata

See Metadata

records List[Event]

See Event

dataset_type DatasetType

DatasetType.EVENT (See DatasetType)

events

alias for records

add_state(self, *args, **kwargs)

See add_state

Source code in kloppy/domain/models/event.py
def add_state(self, *args, **kwargs):
    """
    See [add_state][kloppy.domain.services.state_builder.add_state]
    """
    from kloppy import add_state

    return add_state(self, *args, **kwargs)

filter(self, filter_fn) inherited

Filter all records used filter_fn

Parameters:

Name Type Description Default
- filter_fn required

Examples:

>>> from kloppy.domain import EventType
>>> dataset = dataset.filter(lambda event: event.event_type == EventType.PASS)
Source code in kloppy/domain/models/event.py
def filter(self, filter_fn: Callable[[DataRecord], bool]):
    """
    Filter all records used `filter_fn`

    Arguments:
        - filter_fn:

    Examples:
        >>> from kloppy.domain import EventType
        >>> dataset = dataset.filter(lambda event: event.event_type == EventType.PASS)
    """
    return replace(
        self,
        records=[record for record in self.records if filter_fn(record)],
    )

to_pandas(self, *args, **kwargs) inherited

See to_pandas

Source code in kloppy/domain/models/event.py
def to_pandas(self, *args, **kwargs):
    """
    See [to_pandas][kloppy.helpers.to_pandas]
    """
    from kloppy import to_pandas

    return to_pandas(
        self,
        *args,
        **kwargs,
    )

transform(self, *args, **kwargs) inherited

See transform

Source code in kloppy/domain/models/event.py
def transform(self, *args, **kwargs):
    """
    See [transform][kloppy.helpers.transform]
    """
    from kloppy import transform

    return transform(self, *args, **kwargs)

Events

Event base class

kloppy.domain.models.event.Event dataclass

Abstract event baseclass. All other event classes inherit from this class.

Attributes:

Name Type Description
period Period

See Period

timestamp float

Timestamp of occurrence

ball_owning_team Optional[kloppy.domain.models.common.Team]

See Team

ball_state Optional[kloppy.domain.models.common.BallState]

See Team

event_id str

identifier given by provider

team Team

See Team

player Player

See Player

coordinates Point

Coordinates where event happened. See Point

raw_event Dict

Dict

state Dict[str, Any]

Dict[str, Any]

qualifiers List[kloppy.domain.models.event.Qualifier]

See Qualifier

get_qualifier_value(self, qualifier_type)

Returns the Qualifier of a certain type, or None if qualifier is not present.

Parameters:

Name Type Description Default
qualifier_type Type[kloppy.domain.models.event.Qualifier]

one of the following QualifierTypes: SetPieceQualifier BodyPartQualifier PassQualifier

required

Examples:

>>> from kloppy.domain import SetPieceQualifier
>>> pass_event.get_qualifier_value(SetPieceQualifier)
<SetPieceType.GOAL_KICK: 'GOAL_KICK'>
Source code in kloppy/domain/models/event.py
def get_qualifier_value(self, qualifier_type: Type[Qualifier]):
    """
    Returns the Qualifier of a certain type, or None if qualifier is not present.

    Arguments:
        qualifier_type: one of the following QualifierTypes: [`SetPieceQualifier`][kloppy.domain.models.event.SetPieceQualifier]
            [`BodyPartQualifier`][kloppy.domain.models.event.BodyPartQualifier] [`PassQualifier`][kloppy.domain.models.event.PassQualifier]

    Examples:
        >>> from kloppy.domain import SetPieceQualifier
        >>> pass_event.get_qualifier_value(SetPieceQualifier)
        <SetPieceType.GOAL_KICK: 'GOAL_KICK'>
    """
    if self.qualifiers:
        for qualifier in self.qualifiers:
            if isinstance(qualifier, qualifier_type):
                return qualifier.value
    return None

kloppy.domain.models.event.ShotEvent dataclass

ShotEvent

Attributes:

Name Type Description
period Period

See Period

timestamp float

Timestamp of occurrence

ball_owning_team Optional[kloppy.domain.models.common.Team]

See Team

ball_state Optional[kloppy.domain.models.common.BallState]

See Team

event_id str

identifier given by provider

team Team

See Team

player Player

See Player

coordinates Point

Coordinates where event happened. See Point

raw_event Dict

Dict

state Dict[str, Any]

Dict[str, Any]

qualifiers List[kloppy.domain.models.event.Qualifier]

See Qualifier

event_type EventType

EventType.SHOT (See EventType)

event_name str

"shot",

result_coordinates Point

See Point

result ShotResult

See ShotResult

kloppy.domain.models.event.PassEvent dataclass

PassEvent

Attributes:

Name Type Description
period Period

See Period

timestamp float

Timestamp of occurrence

ball_owning_team Optional[kloppy.domain.models.common.Team]

See Team

ball_state Optional[kloppy.domain.models.common.BallState]

See Team

event_id str

identifier given by provider

team Team

See Team

player Player

See Player

coordinates Point

Coordinates where event happened. See Point

raw_event Dict

Dict

state Dict[str, Any]

Dict[str, Any]

qualifiers List[kloppy.domain.models.event.Qualifier]

See Qualifier

event_type EventType

EventType.PASS (See EventType)

event_name str

"pass"

receive_timestamp float
receiver_coordinates Point

See Point

receiver_player Player

See Player

result PassResult

See PassResult

kloppy.domain.models.event.TakeOnEvent dataclass

TakeOnEvent

Attributes:

Name Type Description
period Period

See Period

timestamp float

Timestamp of occurrence

ball_owning_team Optional[kloppy.domain.models.common.Team]

See Team

ball_state Optional[kloppy.domain.models.common.BallState]

See Team

event_id str

identifier given by provider

team Team

See Team

player Player

See Player

coordinates Point

Coordinates where event happened. See Point

raw_event Dict

Dict

state Dict[str, Any]

Dict[str, Any]

qualifiers List[kloppy.domain.models.event.Qualifier]

See Qualifier

event_type EventType

EventType.TAKE_ON (See EventType)

event_name str

"take_on",

result TakeOnResult

See TakeOnResult

kloppy.domain.models.event.CarryEvent dataclass

CarryEvent

Attributes:

Name Type Description
period Period

See Period

timestamp float

Timestamp of occurrence

ball_owning_team Optional[kloppy.domain.models.common.Team]

See Team

ball_state Optional[kloppy.domain.models.common.BallState]

See Team

event_id str

identifier given by provider

team Team

See Team

player Player

See Player

coordinates Point

Coordinates where event happened. See Point

raw_event Dict

Dict

state Dict[str, Any]

Dict[str, Any]

qualifiers List[kloppy.domain.models.event.Qualifier]

See Qualifier

event_type EventType

EventType.CARRY (See EventType)

event_name str

"carry",

end_timestamp float
end_coordinates Point

See Point

result CarryResult

See CarryResult

kloppy.domain.models.event.RecoveryEvent dataclass

RecoveryEvent

Attributes:

Name Type Description
period Period

See Period

timestamp float

Timestamp of occurrence

ball_owning_team Optional[kloppy.domain.models.common.Team]

See Team

ball_state Optional[kloppy.domain.models.common.BallState]

See Team

event_id str

identifier given by provider

team Team

See Team

player Player

See Player

coordinates Point

Coordinates where event happened. See Point

raw_event Dict

Dict

state Dict[str, Any]

Dict[str, Any]

qualifiers List[kloppy.domain.models.event.Qualifier]

See Qualifier

event_type EventType

EventType.RECOVERY (See EventType)

event_name str

"recovery"

kloppy.domain.models.event.SubstitutionEvent dataclass

SubstitutionEvent

Attributes:

Name Type Description
period Period

See Period

timestamp float

Timestamp of occurrence

ball_owning_team Optional[kloppy.domain.models.common.Team]

See Team

ball_state Optional[kloppy.domain.models.common.BallState]

See Team

event_id str

identifier given by provider

team Team

See Team

player Player

See Player

coordinates Point

Coordinates where event happened. See Point

raw_event Dict

Dict

state Dict[str, Any]

Dict[str, Any]

qualifiers List[kloppy.domain.models.event.Qualifier]

See Qualifier

event_type EventType

EventType.SUBSTITUTION (See EventType)

event_name str

"substitution",

replacement_player Player

See Player

kloppy.domain.models.event.PlayerOnEvent dataclass

PlayerOnEvent

Attributes:

Name Type Description
period Period

See Period

timestamp float

Timestamp of occurrence

ball_owning_team Optional[kloppy.domain.models.common.Team]

See Team

ball_state Optional[kloppy.domain.models.common.BallState]

See Team

event_id str

identifier given by provider

team Team

See Team

player Player

See Player

coordinates Point

Coordinates where event happened. See Point

raw_event Dict

Dict

state Dict[str, Any]

Dict[str, Any]

qualifiers List[kloppy.domain.models.event.Qualifier]

See Qualifier

event_type EventType

EventType.PLAYER_ON (See EventType)

event_name str

"player_on"

kloppy.domain.models.event.PlayerOffEvent dataclass

PlayerOffEvent

Attributes:

Name Type Description
period Period

See Period

timestamp float

Timestamp of occurrence

ball_owning_team Optional[kloppy.domain.models.common.Team]

See Team

ball_state Optional[kloppy.domain.models.common.BallState]

See Team

event_id str

identifier given by provider

team Team

See Team

player Player

See Player

coordinates Point

Coordinates where event happened. See Point

raw_event Dict

Dict

state Dict[str, Any]

Dict[str, Any]

qualifiers List[kloppy.domain.models.event.Qualifier]

See Qualifier

event_type EventType

EventType.PLAYER_OFF (See EventType)

event_name str

"player_off"

kloppy.domain.models.event.CardEvent dataclass

CardEvent

Attributes:

Name Type Description
period Period

See Period

timestamp float

Timestamp of occurrence

ball_owning_team Optional[kloppy.domain.models.common.Team]

See Team

ball_state Optional[kloppy.domain.models.common.BallState]

See Team

event_id str

identifier given by provider

team Team

See Team

player Player

See Player

coordinates Point

Coordinates where event happened. See Point

raw_event Dict

Dict

state Dict[str, Any]

Dict[str, Any]

qualifiers List[kloppy.domain.models.event.Qualifier]

See Qualifier

event_type EventType

EventType.CARD (See EventType)

event_name str

"card"

card_type CardType

See CardType

kloppy.domain.models.event.FoulCommittedEvent dataclass

FoulCommittedEvent

Attributes:

Name Type Description
period Period

See Period

timestamp float

Timestamp of occurrence

ball_owning_team Optional[kloppy.domain.models.common.Team]

See Team

ball_state Optional[kloppy.domain.models.common.BallState]

See Team

event_id str

identifier given by provider

team Team

See Team

player Player

See Player

coordinates Point

Coordinates where event happened. See Point

raw_event Dict

Dict

state Dict[str, Any]

Dict[str, Any]

qualifiers List[kloppy.domain.models.event.Qualifier]

See Qualifier

event_type EventType

EventType.FOUL_COMMITTED (See EventType)

event_name str

"foul_committed"

kloppy.domain.models.event.BallOutEvent dataclass

BallOutEvent

Attributes:

Name Type Description
period Period

See Period

timestamp float

Timestamp of occurrence

ball_owning_team Optional[kloppy.domain.models.common.Team]

See Team

ball_state Optional[kloppy.domain.models.common.BallState]

See Team

event_id str

identifier given by provider

team Team

See Team

player Player

See Player

coordinates Point

Coordinates where event happened. See Point

raw_event Dict

Dict

state Dict[str, Any]

Dict[str, Any]

qualifiers List[kloppy.domain.models.event.Qualifier]

See Qualifier

event_type EventType

EventType.BALL_OUT (See EventType)

event_name str

"ball_out"

kloppy.domain.models.event.GenericEvent dataclass

GenericEvent

Attributes:

Name Type Description
period Period

See Period

timestamp float

Timestamp of occurrence

ball_owning_team Optional[kloppy.domain.models.common.Team]

See Team

ball_state Optional[kloppy.domain.models.common.BallState]

See Team

event_id str

identifier given by provider

team Team

See Team

player Player

See Player

coordinates Point

Coordinates where event happened. See Point

raw_event Dict

Dict

state Dict[str, Any]

Dict[str, Any]

qualifiers List[kloppy.domain.models.event.Qualifier]

See Qualifier

event_type EventType

EventType.GENERIC (See EventType)

event_name str

"generic"

Results

kloppy.domain.models.event.ShotResult

ShotResult

Attributes:

Name Type Description
GOAL ShotResult

Shot resulted in a goal

OFF_TARGET ShotResult

Shot was off target

POST ShotResult

Shot hit the post

BLOCKED ShotResult

Shot was blocked by another player

SAVED ShotResult

Shot was saved by the keeper

kloppy.domain.models.event.PassResult

PassResult

Attributes:

Name Type Description
COMPLETE PassResult

Complete pass

INCOMPLETE PassResult

Incomplete pass (intercepted)

OUT PassResult

Ball went out

OFFSIDE PassResult

Offside

kloppy.domain.models.event.CarryResult

CarryResult

Attributes:

Name Type Description
COMPLETE CarryResult

Complete carry

INCOMPLETE CarryResult

Incomplete carry

kloppy.domain.models.event.TakeOnResult

TakeOnResult

Attributes:

Name Type Description
COMPLETE TakeOnResult

Complete take-on

INCOMPLETE TakeOnResult

Incomplete take-on

OUT TakeOnResult

Ball went out

Types

kloppy.domain.models.event.EventType

Attributes:

Name Type Description
GENERIC EventType

Unrecognised event type

PASS EventType
SHOT EventType
TAKE_ON EventType
CARRY EventType
SUBSTITUTION EventType
CARD EventType
PLAYER_ON EventType
PLAYER_OFF EventType
RECOVERY EventType
BALL_OUT EventType
FOUL_COMMITTED EventType

kloppy.domain.models.event.CardType

CardType

Attributes:

Name Type Description
FIRST_YELLOW CardType

First yellow card

SECOND_YELLOW CardType

Second yellow card

RED CardType

Red card

Qualifiers

Qualifier specify additional information about certain events. See get_qualifier_value for usage.

kloppy.domain.models.event.Qualifier dataclass

Qualifier(value: None)

to_dict(self)

Return the qualifier as a dict

Source code in kloppy/domain/models/event.py
@abstractmethod
def to_dict(self):
    """
    Return the qualifier as a dict
    """
    pass

kloppy.domain.models.event.SetPieceQualifier dataclass

SetPieceQualifier

Attributes:

Name Type Description
value SetPieceType

Specifies the type of set piece

kloppy.domain.models.event.SetPieceType

SetPieceType

Attributes:

Name Type Description
GOAL_KICK SetPieceType
FREE_KICK SetPieceType
THROW_IN SetPieceType
CORNER_KICK SetPieceType
PENALTY SetPieceType
KICK_OFF SetPieceType

kloppy.domain.models.event.BodyPartQualifier dataclass

BodyPartQualifier(value: kloppy.domain.models.event.BodyPart)

kloppy.domain.models.event.BodyPart

BodyPart

Attributes:

Name Type Description
RIGHT_FOOT BodyPart

Pass or Shot with right foot, save with right foot (for goalkeepers).

LEFT_FOOT BodyPart

Pass or Shot with leftt foot, save with left foot (for goalkeepers).

HEAD BodyPart

Pass or Shot with head, save with head (for goalkeepers).

BOTH_HANDS BodyPart

Goalkeeper only. Save with both hands.

CHEST BodyPart

Goalkeeper only. Save with chest.

LEFT_HAND BodyPart

Goalkeeper only. Save with left hand.

RIGHT_HAND BodyPart

Goalkeeper only. Save with right hand.

DROP_KICK BodyPart

Pass is a keeper drop kick.

KEEPER_ARM BodyPart

Pass thrown from keepers hands.

OTHER BodyPart

Other body part (chest, back, etc.), for Pass and Shot.

NO_TOUCH BodyPart

Pass only. A player deliberately let the pass go past him instead of receiving it to deliver to a teammate behind him. (Also known as a "dummy").

kloppy.domain.models.event.PassQualifier dataclass

PassQualifier(value: kloppy.domain.models.event.PassType)

kloppy.domain.models.event.PassType

PassType

Attributes:

Name Type Description
CROSS PassType
HAND_PASS PassType
HEAD_PASS PassType
HIGH_PASS PassType
LAUNCH PassType
SIMPLE_PASS PassType
SMART_PASS PassType