Skip to content

Team

kloppy.domain.Team dataclass

1
2
3
4
5
6
7
8
Team(
    team_id,
    name,
    ground,
    starting_formation=None,
    formations=TimeContainer(),
    players=list(),
)

A team in a match.

ATTRIBUTE DESCRIPTION
team_id

Identifier given by the provider.

TYPE: str

name

Readable name of the team.

TYPE: str

ground

The team's ground (home or away).

TYPE: Ground

players

The team's players.

TYPE: List[Player]

starting_formation

The team's starting formation.

TYPE: FormationType

team_id instance-attribute

team_id

name instance-attribute

name

ground instance-attribute

ground

starting_formation class-attribute instance-attribute

starting_formation = None

formations class-attribute instance-attribute

1
2
3
formations = field(
    default_factory=TimeContainer, compare=False
)

players class-attribute instance-attribute

players = field(default_factory=list)

get_player_by_jersey_number

get_player_by_jersey_number(jersey_no)

Get a player by their jersey number.

PARAMETER DESCRIPTION
jersey_no

The jersey number of the player.

TYPE: int

RETURNS DESCRIPTION
Player

The player with the given jersey number or None if no player with that jersey number is found.

TYPE: Optional[Player]

Source code in kloppy/domain/models/common.py
def get_player_by_jersey_number(self, jersey_no: int) -> Optional[Player]:
    """Get a player by their jersey number.

    Args:
        jersey_no (int): The jersey number of the player.

    Returns:
        Player: The player with the given jersey number or `None` if no
                player with that jersey number is found.
    """
    jersey_no = int(jersey_no)
    for player in self.players:
        if player.jersey_no == jersey_no:
            return player

    return None

get_player_by_position

get_player_by_position(position, time)

Get a player by their position at a given time.

PARAMETER DESCRIPTION
position

The position.

TYPE: PositionType

time

The time for which the position should be retrieved.

TYPE: Time

RETURNS DESCRIPTION
Player

The player with the given position or None if no player with that position is found.

TYPE: Optional[Player]

Source code in kloppy/domain/models/common.py
def get_player_by_position(
    self, position: PositionType, time: Time
) -> Optional[Player]:
    """Get a player by their position at a given time.

    Args:
        position (PositionType): The position.
        time (Time): The time for which the position should be retrieved.

    Returns:
        Player: The player with the given position or `None` if no player
                with that position is found.
    """
    for player in self.players:
        if player.positions.items:
            try:
                player_position = player.positions.value_at(time)
            except KeyError:  # player that is subbed in later
                continue
            if player_position and player_position == position:
                return player

    return None

get_player_by_id

get_player_by_id(player_id)

Get a player by their identifier.

PARAMETER DESCRIPTION
player_id

The identifier of the player.

TYPE: int or str

RETURNS DESCRIPTION
Player

The player with the given identifier or None if no player with that identifier is found.

TYPE: Optional[Player]

Source code in kloppy/domain/models/common.py
def get_player_by_id(self, player_id: Union[int, str]) -> Optional[Player]:
    """Get a player by their identifier.

    Args:
        player_id (int or str): The identifier of the player.

    Returns:
        Player: The player with the given identifier or `None` if no player
                with that identifier is found.
    """
    player_id = str(player_id)

    for player in self.players:
        if player.player_id == player_id:
            return player

    return None

set_formation

set_formation(time, formation)
Source code in kloppy/domain/models/common.py
def set_formation(self, time: Time, formation: Optional[FormationType]):
    self.formations.set(time, formation)