Skip to content

Index

kloppy.domain.DataRecord dataclass

DataRecord(period, timestamp, statistics, ball_owning_team, ball_state)

Bases: ABC

Base class for a data record in a dataset.

ATTRIBUTE DESCRIPTION
dataset

The dataset to which the record belongs.

TYPE: Dataset

prev_record

The previous record in the dataset.

TYPE: Optional[Self]

next_record

The next record in the dataset.

TYPE: Optional[Self]

record_id

The unique identifier of the record. Given by the provider.

TYPE: Union[int, str]

period

The match period in which the observation occurred.

TYPE: Period

timestamp

Timestamp of occurrence, relative to the period kick-off.

TYPE: timedelta

time

The time of the observation. Combines period and timestamp.

TYPE: Time

attacking_direction

The attacking direction of the home team.

ball_owning_team

The team that had possession of the ball.

TYPE: Optional[Team]

ball_state

The state of the ball at the time of the observation.

TYPE: Optional[BallState]

dataset class-attribute instance-attribute

dataset = field(init=False)

prev_record class-attribute instance-attribute

prev_record = field(init=False)

next_record class-attribute instance-attribute

next_record = field(init=False)

period instance-attribute

period

timestamp instance-attribute

timestamp

statistics instance-attribute

statistics

ball_owning_team instance-attribute

ball_owning_team

ball_state instance-attribute

ball_state

record_id abstractmethod property

record_id

time property

time

attacking_direction property

attacking_direction

set_refs

set_refs(dataset, prev, next_)
Source code in kloppy/domain/models/common.py
def set_refs(
    self,
    dataset: "Dataset",
    prev: Optional[Self],
    next_: Optional[Self],
):
    if hasattr(self, "dataset"):
        # TODO: determine if next/prev record should be affected
        # by Dataset.filter
        return

    self.dataset = dataset
    self.prev_record = prev
    self.next_record = next_

matches

matches(filter_)
Source code in kloppy/domain/models/common.py
def matches(
    self, filter_: Optional[Union[str, Callable[[Self], bool]]]
) -> bool:
    if filter_ is None:
        return True
    elif callable(filter_):
        return filter_(self)
    else:
        raise InvalidFilterError()

prev

prev(filter_=None)
Source code in kloppy/domain/models/common.py
def prev(
    self, filter_: Optional[Union[str, Callable[[Self], bool]]] = None
) -> Optional[Self]:
    if self.prev_record:
        prev_record = self.prev_record
        while prev_record:
            if prev_record.matches(filter_):
                return prev_record
            prev_record = prev_record.prev_record

next

next(filter_=None)
Source code in kloppy/domain/models/common.py
def next(
    self, filter_: Optional[Union[str, Callable[[Self], bool]]] = None
) -> Optional[Self]:
    if self.next_record:
        next_record = self.next_record
        while next_record:
            if next_record.matches(filter_):
                return next_record
            next_record = next_record.next_record

replace

replace(**changes)
Source code in kloppy/domain/models/common.py
def replace(self, **changes):
    return replace(self, **changes)