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’
color (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[str,
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]
- match_players(team: str | None = None, teams: list[str] | None = None, h2h: tuple[str, str] | None = None) list[BasePlayer][source]
Get all players involved in at least one match in this league.
If team is given return only players who have featured for this team. If teams is given return only players who have featured for one of these teams. If h2h is given return only players who featured in a match between these two teams.
- Parameters:
- Returns:
All players involved in a match
- Return type:
list[
BasePlayer]
- matches(team: str | None = None, teams: list[str] | None = None, h2h: tuple[str, str] | None = None) list[Match][source]
Matches in this league.
If team is given, return only matches involving this team. If teams is given, return only matches involving one of these teams. If h2h is given, return only matches between these two teams.
- 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, team: str | None = None)[source]
Replace all occurrences of
oldwithnew.Searches all lineups and events in this league and replaces all occurrences of
oldwithnew.If team is given, replace only occurrences where the player features for team.
- Parameters:
old (
BasePlayer) – Player to be replacednew (
BasePlayer) – New player detailsteam (str) – If given, replace only where the player features for this team (default=None)
- 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
- delete_event(event: Event) bool[source]
Delete an event from this match.
- Parameters:
event (
Event) – Event to delete- Returns:
True if the event was successfully deleted
- Raises:
ValueErrorif the event is not found in the match
- 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]
- h2h(team1: str, team2: str) bool[source]
Returns
Trueif the match is a head to head between these two teams.
- involves_any(teams: list[str]) bool[source]
Returns
Trueif any ofteamsis involved in this match.- Parameters:
teams – Teams to query
- Returns:
Trueif any ofteamsare involved in this match, i.e. either as the home team or the away team- Return type:
- players(team: str | None = None, teams: list[str] | None = None) list[BasePlayer][source]
Get all players involved in this match.
If team is provided return only players from the team specified. If teams is provided return only players from one of the teams specified.
- Parameters:
- Returns:
Players involved in the match
- Return type:
list[
BasePlayer]
- replace_event(old: Event, new: Event | None) bool[source]
Replace old with new. If new is None the event will be deleted.
- Parameters:
old (
Event) – Event to replacenew (
Event| None) – New event (None to delete the event)
- Returns:
True if the event was successfully replaced or deleted
- Raises:
ValueErrorif the event is not found in the match- Raises:
TypeErrorif old and new are not the same event type
- 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.RowTuple(team: str, played: int, won: int, drawn: int, lost: int, goals_for: int, goals_against: int, gd: int, points: int, form: str)[source]
Type for a single row of a league table.
Elements are: (team, played, won, drawn, lost, goals_for, goals_against, gd, points, form)
- 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, form: Annotated[str, _PydanticGeneralMetadata(pattern='^[WLD]{0,5}$')] = '')[source]
A row in a league table.
- Parameters:
team (str) – Team name
won (int) – Matches won (default=0)
drawn (int) – Matches drawn (default=0)
lost (int) – Matches lost (default=0)
scored (int) – Goals scored (default=0)
conceded (int) – Goals conceded (default=0)
deducted (int) – Points deducted (default=0)
form (str) – Team form e.g. ‘WDWWL’ (default=’’)
- add_form(result: Literal['W', 'D', 'L']) None[source]
Add a match result to the form field.
Appends ‘W’, ‘D’ or ‘L’ to the team form, removing the oldest form indicator if the form is already displaying five matches, e.g. adding ‘D’ to ‘WWLL’ will result in ‘WWLLD’, while adding ‘D’ to ‘WWLLD’ will result in ‘WLLDD’.
- Parameters:
result (str) – Result to add (‘W’, ‘L’ or ‘D’)
- as_tuple() RowTuple[source]
Returns this row as a tuple.
Elements are: (team, played, won, drawn, lost, scored, conceded, gd, points, form)
- Returns:
This row as a tuple
- Return type:
- classmethod from_tuple(row_tuple: RowTuple) TableRow[source]
Creates a TableRow instance from a RowTuple.
- 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