API
Data models for the ILC project
- class ilc_models.BaseEvent(*, team: str, time: EventTime)[source]
Abstract base class for events.
- abstractmethod players() list[BasePlayer][source]
Get the players involved in this event
- class ilc_models.Card(*, team: str, time: EventTime, event_type: Literal['card'] = 'card', color: Literal['Y', 'R'], player: BasePlayer)[source]
Represents a red or yellow card.
- Parameters:
event_type (str) – The literal string ‘card’
card_type (str) – One of ‘R’ (red card), ‘Y’ (yellow card)
player (
BasePlayer) – Player receiving the card
- players() list[BasePlayer][source]
Get the players involved in this event
- class ilc_models.Deduction(*, team: str, points: Annotated[int, Gt(gt=0)], date: Annotated[str, WrapValidator(func=validate_deduction_date, json_schema_input_type=PydanticUndefined)] = '')[source]
A points deduction.
- class ilc_models.EventInfo(*, date: date, teams: Teams, score: Score, event: Event)[source]
Event data with match info added.
- Parameters:
date (
datetime.date) – Date of matchteams (
Teams) – Teams involved in the matchscore (
Score) – Match scoreevent (
Event) – Event info
- class ilc_models.EventTime(*, minutes: Annotated[int, Gt(gt=0), Le(le=120)], plus: Annotated[int, Ge(ge=0)] = 0)[source]
The time an event occurred during a match.
- Parameters:
- class ilc_models.Goal(*, team: str, time: EventTime, event_type: Literal['goal'] = 'goal', goal_type: Literal['N', 'O', 'P'] = 'N', scorer: BasePlayer)[source]
Represents a goal.
- Parameters:
event_type (str) – The literal string ‘goal’
goal_type (str) – One of ‘N’ (normal goal), ‘O’ (own goal), ‘P’ (penalty) (default=’N’)
scorer (
BasePlayer) – Goal scorer
- players() list[BasePlayer][source]
Get the players involved in this event
- class ilc_models.League(*, league_id: Annotated[int, Gt(gt=0)], name: str, year: Annotated[int, Gt(gt=0)], start: Annotated[str, _PydanticGeneralMetadata(pattern='^[12][09]\\d{2}-[01]\\d-[0-3]\\d$')], end: Annotated[str, _PydanticGeneralMetadata(pattern='^[12][09]\\d{2}-[01]\\d-[0-3]\\d$')], current: bool, coverage: dict[str, bool], teams: list[str] = [], rounds: dict[str, list[Match]] = {}, excluded: list[str] = [], deductions: list[Deduction] = [], split: Annotated[int, Ge(ge=0)] = 0, players: dict[str, Player] = {})[source]
Represents a League.
- Parameters:
league_id (int) – API ID of this league
name (str) – Name of this league e.g. Premiership
year (int) – Year this season starts
start (str) – League start date as an ISO format string
end (str) – League end date as an ISO format string
current (bool) – Whether this league is still being played
coverage (dict[str, bool]) – Coverage available from the API
teams (list[str]) – The name of each team in this league (default=[])
rounds (dict[str, list[
Match]]) – This league’s rounds, with matches for each round (default={})excluded (list[str]) – Rounds to exclude from import (default=[])
split (int) – Split point of this league (default=0)
players (dict[int, :class:'Player']) – Players who feature in this league
- events(player: BasePlayer) list[EventInfo][source]
Get all events in this league in which a player is involved.
Also includes a
LineupStatusevent for any matches which include the player in their lineup.- Parameters:
player (
BasePlayer) – Find events featuring this player- Returns:
The events in this league involving the player
- Return type:
list[
EventInfo]
- matches(team: str | None = None) list[Match][source]
Matches in this league.
If
teamis given, return only matches involving this team, otherwise return all matches.
- player_teams(player: BasePlayer) list[str][source]
Get all the teams a player features in during this season.
- Parameters:
player (
BasePlayer) – Find teams this player plays for- Returns:
The teams the player plays for in this league
- Return type:
- table(played: int = 0, split_point: bool = False, date: date | None = None) list[RowTuple][source]
Get the league table.
Returns the league table as a list of
RowTupleitems, ordered by league position.If
playedis non-zero the table will be returned at the first point at which all teams have played at leastplayedmatches.If
split_pointisTruethe table will be returned at the league’s split point.If
dateis notNonethe table will be returned at the given date, i.e. taking account only of matches where the date is earlier than or equal todate.- Parameters:
played (int) – If non-zero, get table after this number of games (default=0)
split_point (bool) – If True get the table at the split point (default=False)
date (
datetime.date) – If given, get the league table on this date (default=None)
- Returns:
The league table as a list of tuples
- Return type:
list[
RowTuple]
- property title: str
Title of this league e.g. Premiership 2023/24
- Returns:
Title of the league
- Return type:
- update_player(old: BasePlayer, new: BasePlayer)[source]
Replace all occurrences of
oldwithnew.Searches all lineups and events in this league and replaces all occurrences of
oldwithnew.- Parameters:
old (
BasePlayer) – Player to be replacednew (
BasePlayer) – New player details
- class ilc_models.Lineup(*, starting: Annotated[list[tuple[int, BasePlayer]], MaxLen(max_length=11)] = [], subs: list[tuple[int, BasePlayer]] = [])[source]
Lineup for one team.
Each lineup entry is an (int, BasePlayer) tuple, with the int being the player’s shirt number if supplied (0 if not).
- Parameters:
starting (list[tuple[int, BasePlayer]]) – Starting XI (default=[])
subs (list[tuple[int, BasePlayer]]) – Substitutes (default=[])
- players() list[BasePlayer][source]
Returns all players in this lineup
- class ilc_models.LineupStatus(*, team: str, time: EventTime, event_type: Literal['status'] = 'status', status: Literal['starting', 'sub'], player: BasePlayer)[source]
Whether a player is in the starting lineup or on the bench.
- Parameters:
event_type (str) – The literal string ‘status’
status (str) – One of ‘starting’ or ‘sub’
player (
BasePlayer) – Player involved
- players() list[BasePlayer][source]
Get the players involved in this event
- class ilc_models.Lineups(*, home: Lineup = Lineup(starting=[], subs=[]), away: Lineup = Lineup(starting=[], subs=[]))[source]
Match lineups for home and away teams.
- Parameters:
- players() list[BasePlayer][source]
Returns all players in this lineup
- class ilc_models.Match(*, match_id: Annotated[int, Gt(gt=0)], kickoff: Annotated[str, _PydanticGeneralMetadata(pattern='^[12][09]\\d{2}-[01]\\d-[0-3]\\dT[0-2]\\d:[0-5]\\d:[0-5]\\d[+-][01]\\d:[0-5]\\d$')], round: str, teams: Teams, status: str, score: Score = Score(home=0, away=0), goals: list[Goal] = [], cards: list[Card] = [], substitutions: list[Substitution] = [], lineups: Lineups = Lineups(home=Lineup(starting=[], subs=[]), away=Lineup(starting=[], subs=[])))[source]
Represents a match.
- Parameters:
match_id (int) – API ID of this match
kickoff (str) – Date of match in ISO string format
round (str) – Round this match is part of
teams (
Teams) – Teams involved in this matchstatus (str) – Match status
score (
Score) – Score in this match (default=0-0)goals (list[
Goal]) – Detail of goals scored in the matchcards (list[
Card]) – Detail of cards shown in the matchsubstitutions (list[
Substitution]) – Detail of substitutions made in the matchlineups (
Lineups) – Match lineups
- events() list[Event][source]
Returns all events in this match in chronological order.
- Returns:
The combined list of goals, cards and subs in the match
- Return type:
list[
Event]
- players() list[BasePlayer][source]
Returns all players involved in this match
- class ilc_models.Player(*, player_id: int, name: str, first_name: str, last_name: str, dob: Annotated[str, WrapValidator(func=validate_dob, json_schema_input_type=PydanticUndefined)], nationality: str)[source]
Full player details.
- Parameters:
- property base_player: BasePlayer
Return a BasePlayer object corresponding to this Player.
- Returns:
The BasePlayer corresponding to this Player
- Return type:
- class ilc_models.Score(*, home: Annotated[int, Ge(ge=0)] = 0, away: Annotated[int, Ge(ge=0)] = 0)[source]
Match score.
- class ilc_models.Substitution(*, team: str, time: EventTime, event_type: Literal['sub'] = 'sub', player_on: BasePlayer, player_off: BasePlayer)[source]
Represents a substitution.
- Parameters:
event_type (str) – The literal string ‘sub’
player_on (
BasePlayer) – Player entering the fieldplayer_off (
BasePlayer) – Player leaving the field
- players() list[BasePlayer][source]
Get the players involved in this event
- class ilc_models.TableRow(*, team: str, won: Annotated[int, Ge(ge=0)] = 0, drawn: Annotated[int, Ge(ge=0)] = 0, lost: Annotated[int, Ge(ge=0)] = 0, scored: Annotated[int, Ge(ge=0)] = 0, conceded: Annotated[int, Ge(ge=0)] = 0, deducted: Annotated[int, Ge(ge=0)] = 0)[source]
A row in a league table.
- Parameters:
- as_tuple() RowTuple[source]
Returns this row as a tuple.
Elements are: (team, played, won, drawn, lost, scored, conceded, gd, points)
- Returns:
This row as a tuple
- Return type:
RowTuple
- classmethod from_tuple(row_tuple: RowTuple) TableRow[source]
Creates a TableRow instance from a RowTuple.
- Parameters:
row_tuple (
RowTuple) – Source tuple- Returns:
Newly created TableRow
- Return type:
- ilc_models.validate_deduction_date(value: Any, handler: ValidatorFunctionWrapHandler) str[source]
Validate that a value conforms to a valid DOB string.
Allows empty string and yyyy-mm-dd. Any other format will raise a
ValueError.- Parameters:
value (
typing.Any) – DOB to validatehandler (
pydantic.ValidatorFunctionWrapHandler) – Pydantic validation handler
- Returns:
Validated value in yyyy-mm-dd format
- Return type:
- Raises:
ValueErrorif format is invalid
- ilc_models.validate_dob(value: Any, handler: ValidatorFunctionWrapHandler) str[source]
Validate that a value conforms to a valid DOB string.
Allows empty string, yyyy-m-d and yyyy-mm-dd. Any other format will raise a
ValueError.- Parameters:
value (
typing.Any) – DOB to validatehandler (
pydantic.ValidatorFunctionWrapHandler) – Pydantic validation handler
- Returns:
Validated value in yyyy-mm-dd format
- Return type:
- Raises:
ValueErrorif format is invalid