Skip to content

Period

kloppy.domain.Period dataclass

Period(id, start_timestamp, end_timestamp)

Period

ATTRIBUTE DESCRIPTION
id

1 for first half, 2 for second half, 3 for first half of overtime, 4 for second half of overtime, 5 for penalty shootout

TYPE: int

start_timestamp

The UTC datetime of the kick-off or, if the absolute datetime is not available, the offset between the start of the data feed and the period's kick-off

TYPE: Union[datetime, timedelta]

start_time

Same as start_timestamp, but as a Time object.

TYPE: Time

end_timestamp

The UTC datetime of the final whistle or, if the absolute datetime is not available, the offset between the start of the data feed and the period's final whistle

TYPE: Optional[Union[datetime, timedelta]]

end_time

Same as end_timestamp, but as a Time object.

TYPE: Time

duration

The length of the period.

TYPE: timedelta

prev_period

Period before this period.

TYPE: Optional[Period]

next_period

Period after this period.

TYPE: Optional[Period]

id instance-attribute

id

start_timestamp instance-attribute

start_timestamp

end_timestamp instance-attribute

end_timestamp

prev_period class-attribute instance-attribute

prev_period = field(init=False)

next_period class-attribute instance-attribute

next_period = field(init=False)

start_time property

start_time

end_time property

end_time

duration property

duration

contains

contains(timestamp)
Source code in kloppy/domain/models/time.py
def contains(self, timestamp: datetime):
    if isinstance(self.start_timestamp, datetime) and isinstance(
        self.end_timestamp, datetime
    ):
        return self.start_timestamp <= timestamp <= self.end_timestamp
    raise KloppyError(
        "This method can only be used when start_timestamp and end_timestamp are a datetime"
    )

set_refs

set_refs(prev, next_)

Set references to other periods

PARAMETER DESCRIPTION
prev

Period before this period

TYPE: Optional[Period]

next_

Period after this period

TYPE: Optional[Period]

Source code in kloppy/domain/models/time.py
def set_refs(
    self,
    prev: Optional["Period"],
    next_: Optional["Period"],
):
    """
    Set references to other periods

    Parameters:
        prev: Period before this period
        next_: Period after this period
    """
    self.prev_period = prev
    self.next_period = next_