ilc-models 0.2.2__tar.gz → 0.2.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ilc_models-0.2.4/.claude/settings.local.json +7 -0
- {ilc_models-0.2.2 → ilc_models-0.2.4}/.gitignore +1 -0
- {ilc_models-0.2.2 → ilc_models-0.2.4}/CHANGELOG.md +33 -0
- ilc_models-0.2.4/CLAUDE.md +75 -0
- ilc_models-0.2.4/PKG-INFO +147 -0
- ilc_models-0.2.4/README.md +127 -0
- {ilc_models-0.2.2 → ilc_models-0.2.4}/docs/source/conf.py +21 -1
- ilc_models-0.2.4/docs/source/index.rst +56 -0
- ilc_models-0.2.4/docs/source/usage.rst +237 -0
- ilc_models-0.2.4/justfile +45 -0
- {ilc_models-0.2.2 → ilc_models-0.2.4}/pyproject.toml +12 -7
- ilc_models-0.2.4/src/ilc_models/__init__.py +1432 -0
- ilc_models-0.2.4/tests/__init__.py +0 -0
- {ilc_models-0.2.2 → ilc_models-0.2.4}/tests/test_models.py +200 -13
- {ilc_models-0.2.2 → ilc_models-0.2.4}/uv.lock +74 -107
- ilc_models-0.2.2/PKG-INFO +0 -32
- ilc_models-0.2.2/README.md +0 -13
- ilc_models-0.2.2/check.zsh +0 -17
- ilc_models-0.2.2/coverage.zsh +0 -3
- ilc_models-0.2.2/docs/source/index.rst +0 -10
- ilc_models-0.2.2/src/ilc_models/__init__.py +0 -1224
- {ilc_models-0.2.2 → ilc_models-0.2.4}/.python-version +0 -0
- {ilc_models-0.2.2 → ilc_models-0.2.4}/.readthedocs.yaml +0 -0
- {ilc_models-0.2.2 → ilc_models-0.2.4}/LICENSE.txt +0 -0
- {ilc_models-0.2.2 → ilc_models-0.2.4}/docs/requirements.txt +0 -0
- /ilc_models-0.2.2/src/ilc_models/py.typed → /ilc_models-0.2.4/docs/source/_static/.gitkeep +0 -0
- {ilc_models-0.2.2 → ilc_models-0.2.4}/docs/source/api.rst +0 -0
- /ilc_models-0.2.2/tests/__init__.py → /ilc_models-0.2.4/src/ilc_models/py.typed +0 -0
- {ilc_models-0.2.2 → ilc_models-0.2.4}/tests/conftest.py +0 -0
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.2.4] - 2026-08-23
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- Add `Match.event_team()` method
|
|
8
|
+
- Add `Match.played_for()` method
|
|
9
|
+
- Add `player` parameter to `League.matches()` method
|
|
10
|
+
|
|
11
|
+
### Fixed
|
|
12
|
+
|
|
13
|
+
- Fix `TableRow.from_tuple()` losing the `deducted` field, so `as_tuple()`/`from_tuple()` round-trips no longer silently drop points deductions
|
|
14
|
+
- Fix date validation to reject impossible calendar dates such as month 19 or 29 February in a non-leap year, as well as malformed ones, on `Player.dob`, `Match.kickoff`, `Deduction.date` and `League.start`/`end`
|
|
15
|
+
|
|
16
|
+
### Documentation
|
|
17
|
+
|
|
18
|
+
- Convert docstrings to Google style, correct inaccurate content, add missing documentation, standardise mood/markup
|
|
19
|
+
- Expand `README.md` and the Sphinx docs with a model map, worked examples, and the package's non-obvious conventions
|
|
20
|
+
- Add a Read the Docs link to the project metadata
|
|
21
|
+
|
|
22
|
+
## [0.2.3] - 2026-02-05
|
|
23
|
+
|
|
24
|
+
### Changed
|
|
25
|
+
|
|
26
|
+
- Add `teams` parameter to `Match.players()` method
|
|
27
|
+
- Add `Match.involves_any()` method
|
|
28
|
+
- Add `Match.h2h()` method
|
|
29
|
+
- Add `teams` and `h2h` parameters to `League.matches()` method
|
|
30
|
+
- Add `teams` and `h2h` parameters to `League.match_players()` method
|
|
31
|
+
|
|
3
32
|
## [0.2.2] - 2026-01-21
|
|
4
33
|
|
|
5
34
|
### Changed
|
|
@@ -75,6 +104,10 @@
|
|
|
75
104
|
|
|
76
105
|
_Initial release._
|
|
77
106
|
|
|
107
|
+
[0.2.4]: https://github.com/fourtreestech/ilc-models/releases/tag/v0.2.4
|
|
108
|
+
|
|
109
|
+
[0.2.3]: https://github.com/fourtreestech/ilc-models/releases/tag/v0.2.3
|
|
110
|
+
|
|
78
111
|
[0.2.2]: https://github.com/fourtreestech/ilc-models/releases/tag/v0.2.2
|
|
79
112
|
|
|
80
113
|
[0.2.1]: https://github.com/fourtreestech/ilc-models/releases/tag/v0.2.1
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# CLAUDE.md
|
|
2
|
+
|
|
3
|
+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
4
|
+
|
|
5
|
+
## Commands
|
|
6
|
+
|
|
7
|
+
Task runner is `just` (see `justfile`); Python tooling is `uv`.
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
just check # ruff check --fix, ruff format, then `ty check` (Astral's type checker)
|
|
11
|
+
just test # uv run pytest
|
|
12
|
+
just cov # pytest with coverage + regenerate the README coverage badge via cov-badge
|
|
13
|
+
just sync # ff-only merge dev -> main, push, switch back to dev
|
|
14
|
+
just tag # tag main with v<version> from pyproject.toml and push
|
|
15
|
+
just publish # rm -rf dist, uv build, then uv publish to PyPI
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Single test / narrower runs:
|
|
19
|
+
|
|
20
|
+
```sh
|
|
21
|
+
uv run pytest tests/test_models.py::TestLeagueTable
|
|
22
|
+
uv run pytest tests/test_models.py::TestMatch::test_players_from_team
|
|
23
|
+
uv run pytest -p no:randomly # pytest-randomly shuffles order; disable when bisecting a failure
|
|
24
|
+
uvx tox # full matrix: Python 3.12 and 3.13
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
There is no `[tool.pytest.ini_options]` section — pytest runs on defaults with `tests/` discovered from the repo root.
|
|
28
|
+
|
|
29
|
+
## Release workflow
|
|
30
|
+
|
|
31
|
+
Work happens on `dev`; `main` only ever receives fast-forward merges via `just sync`.
|
|
32
|
+
|
|
33
|
+
The version string lives in **four** places, kept in sync by bumpver (`[tool.bumpver.file_patterns]` in `pyproject.toml`): `pyproject.toml`, the README badge, `src/ilc_models/__init__.py::__version__`, and `docs/source/conf.py::release`. Never hand-edit them — run `uvx bumpver update --patch` (bumpver is not a project dependency; it commits but does not tag or push). Then add a `CHANGELOG.md` entry by hand (including the link reference at the bottom), run `just tag`, and finally `just publish` to build and upload to PyPI. `just publish` authenticates via a PyPI API token (`pypi-…`) read from `.pypi.token` at the repo root — gitignored, so a fresh clone needs it recreated by hand.
|
|
34
|
+
|
|
35
|
+
## Architecture
|
|
36
|
+
|
|
37
|
+
Everything is one module: `src/ilc_models/__init__.py`. Pure Pydantic v2 models with no I/O and no dependency beyond `pydantic` — this package is the data contract shared across the ILC repos, so a field change here is a breaking change for `ilc-api`, `ilc-app`, and `ilc-admin`.
|
|
38
|
+
|
|
39
|
+
Containment: `League` → `rounds: dict[str, list[Match]]` → `Match` → `Lineups` → `Lineup` → `list[tuple[shirt_no, BasePlayer]]`. Events (`Goal`, `Card`, `Substitution`, `LineupStatus`) subclass the abstract `BaseEvent`, each carrying a frozen `event_type` literal discriminator and implementing `players()`; the `Event` union type aliases them.
|
|
40
|
+
|
|
41
|
+
### Conventions that are easy to violate
|
|
42
|
+
|
|
43
|
+
**`Goal.team` is the team credited with the goal, not the scorer's team.** For an own goal (`goal_type == "O"`) the scorer belongs to the *opposing* team. `Match.event_team(event)` is the single place that resolves the team a given event's players actually play for, flipping it for own goals and passing everything else through unchanged — `Match.players()`, `League.update_player()`, and `League.player_teams()` all call it rather than re-deriving the flip. New code that filters players or events by team should call `Match.event_team()` too, or it will misattribute own goals.
|
|
44
|
+
|
|
45
|
+
**`BasePlayer.__eq__` compares `player_id` alone**, falling back to `name` only when both IDs are `0`. This is deliberate: the upstream API spells player names differently in event payloads versus player downloads. Consequently `player in some_list` is an ID-based membership test throughout, and `Player` equality inherits this (it ignores `first_name`, `dob`, etc.).
|
|
46
|
+
|
|
47
|
+
**`TableRow.__gt__` reverses team-name ordering on ties**, so that the `sorted(..., reverse=True)` in `League.table()` yields alphabetical order among equal teams. Do not "fix" the apparent inversion.
|
|
48
|
+
|
|
49
|
+
**`League.table()` models the Scottish-style split.** Once any team has played more than `League.split` matches, the table freezes the top/bottom halves by position at the split point — computed by recursing into `self.table(split_point=True)` — and sorts each half independently. An odd team count puts the extra team in the top half. Points deductions apply only when `Deduction.date` is empty (season-start) or falls on/before the last match processed, which is why the loop tracks `last_date`.
|
|
50
|
+
|
|
51
|
+
**Dates are validated ISO strings, not `date` objects.** `Match.kickoff` requires a full offset-aware timestamp (strict `Field(pattern=...)`), `League.start`/`end` require `yyyy-mm-dd`. Four `WrapValidator` helpers layer a real-calendar check (via `datetime.date`/`datetime.datetime`) on top of each field's regex, so month 19 or 29 February in a non-leap year raises `ValueError` rather than validating: `validate_dob` and `validate_deduction_date` additionally accept the empty string, and `validate_dob` normalises `yyyy-m-d` to zero-padded form; `validate_kickoff` and `validate_date` run after the `Field(pattern=...)` on `Match.kickoff` and `League.start`/`end` respectively. Derive `datetime.date` via `Match.date`.
|
|
52
|
+
|
|
53
|
+
**`EventTime.plus` is only legal at the end of a half** (45/90/105/120), enforced by a `model_validator(mode="after")`.
|
|
54
|
+
|
|
55
|
+
`League.head_to_head()` predates `League.matches(h2h=...)`; prefer the parameterised `matches()`/`match_players()` filters (`team`, `teams`, `h2h`) for new code.
|
|
56
|
+
|
|
57
|
+
## Docs and docstrings
|
|
58
|
+
|
|
59
|
+
Sphinx autodoc renders the whole module (`docs/source/api.rst` → `automodule:: ilc_models`) and publishes to Read the Docs. Public members need Google-style docstrings matching the existing ones (`Args:` / `Attributes:` / `Returns:` / `Raises:`, parsed by `sphinx.ext.napoleon`). `ruff`'s `D`/`D401` rules (Google convention, see `[tool.ruff.lint.pydocstyle]`) enforce presence and imperative mood as part of `just check`; `tests/*` and `docs/*` are exempted via `per-file-ignores`.
|
|
60
|
+
|
|
61
|
+
Style conventions:
|
|
62
|
+
- Method/function summaries are imperative ("Return the …", "Get the …", "Sort the …"); class summaries stay descriptive ("Represents a goal.").
|
|
63
|
+
- Cross-reference with single backticks only (`` `ClassName` ``, `` `ValueError` ``) — `default_role = "literal"` in `conf.py` renders them as code, so `:class:`/`:exc:`/`:attr:` roles and double backticks are unnecessary and should not be used.
|
|
64
|
+
- Pydantic model fields are documented as `Attributes:` on the class docstring rather than `Args:`, with `(default=…)` noted where a field has one. **Exception:** don't add an `Attributes:` section to a `NamedTuple` (e.g. `RowTuple`) — its fields are separate real attributes that autodoc already documents individually, and a Napoleon `Attributes:` block for the same names produces a "duplicate object description" warning that fails `-W` builds. Describe `NamedTuple` fields in prose instead.
|
|
65
|
+
- Types are omitted from `Args:`/`Attributes:`/`Returns:` entries — `autodoc_typehints = "description"` and `napoleon_attr_annotations` pull them from the annotations instead, so only the description goes in the docstring. This also means **a method's return type only renders if its docstring has a `Returns:` section** (`autodoc_typehints_description_target = "documented_params"`), so every method with a non-`None` return needs one, including dunders like `__eq__`/`__gt__`/`__len__`/`__bool__`/`__str__`.
|
|
66
|
+
|
|
67
|
+
Run `just docs` to build the docs locally (`-W`, so any Napoleon/autodoc warning fails the build). `docs/requirements.txt` is a pinned lockfile for the RTD build and must be updated when the docs dependency group changes.
|
|
68
|
+
|
|
69
|
+
## Tests
|
|
70
|
+
|
|
71
|
+
`tests/test_models.py` is a single file of `Test<Model>` classes. Fixtures come from the sibling `ilc_provider` package's Faker provider, exposed as the session-scoped `ilc_fake` fixture in `tests/conftest.py` (`ilc_fake.league()`, `.match()`, `.player()`, `.base_player()`, `.lineup()`, `.table_row()`, …) — prefer these over hand-built models.
|
|
72
|
+
|
|
73
|
+
Two hazards: `pytest-randomly` shuffles test order, and the `fake_league` fixture is session-scoped but holds mutable models, so a test that mutates it can leak into others. Build a fresh `ilc_fake.league()` when mutating.
|
|
74
|
+
|
|
75
|
+
Coverage sits at 99%; genuinely unreachable defensive branches are marked `# pragma: no cover`.
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: ilc-models
|
|
3
|
+
Version: 0.2.4
|
|
4
|
+
Summary: Data models for the ILC project
|
|
5
|
+
Project-URL: Repository, https://github.com/fourtreestech/ilc-models
|
|
6
|
+
Project-URL: Documentation, https://ilc-models.readthedocs.io/
|
|
7
|
+
Author-email: Neil Martin <neil@fourtrees.tech>
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
License-File: LICENSE.txt
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Natural Language :: English
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
15
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
16
|
+
Classifier: Typing :: Typed
|
|
17
|
+
Requires-Python: >=3.12
|
|
18
|
+
Requires-Dist: pydantic>=2.12.5
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
|
|
21
|
+
# ilc-models
|
|
22
|
+
|
|
23
|
+

|
|
24
|
+

|
|
25
|
+

|
|
26
|
+
|
|
27
|
+
**ilc-models** contains all data models for the *ILC* project.
|
|
28
|
+
|
|
29
|
+
It's a set of pure Pydantic v2 models with no I/O and no dependency beyond
|
|
30
|
+
`pydantic` — a `League` of `Match` objects, each with its `Lineups`,
|
|
31
|
+
`Goal`/`Card`/`Substitution` events, and the `TableRow` results computed
|
|
32
|
+
from them. This package is the shared data contract used across the
|
|
33
|
+
`ilc-api`, `ilc-app` and `ilc-admin` repositories, so a field change here is
|
|
34
|
+
a breaking change for all three.
|
|
35
|
+
|
|
36
|
+
## Installation
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
pip install ilc-models
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Or with [uv](https://docs.astral.sh/uv/):
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
uv add ilc-models
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Quick start
|
|
49
|
+
|
|
50
|
+
```python
|
|
51
|
+
from ilc_models import League, Match, Teams, Score
|
|
52
|
+
|
|
53
|
+
league = League(
|
|
54
|
+
league_id=1,
|
|
55
|
+
name="Premiership",
|
|
56
|
+
year=2025,
|
|
57
|
+
start="2025-08-01",
|
|
58
|
+
end="2026-05-01",
|
|
59
|
+
current=True,
|
|
60
|
+
coverage={"lineups": True},
|
|
61
|
+
teams=["Team A", "Team B"],
|
|
62
|
+
rounds={
|
|
63
|
+
"1": [
|
|
64
|
+
Match(
|
|
65
|
+
match_id=1,
|
|
66
|
+
kickoff="2025-08-09T15:00:00+01:00",
|
|
67
|
+
round="1",
|
|
68
|
+
teams=Teams(home="Team A", away="Team B"),
|
|
69
|
+
status="FT",
|
|
70
|
+
score=Score(home=2, away=1),
|
|
71
|
+
)
|
|
72
|
+
]
|
|
73
|
+
},
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
for row in league.table():
|
|
77
|
+
print(row)
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Model map
|
|
81
|
+
|
|
82
|
+
```
|
|
83
|
+
League
|
|
84
|
+
rounds: dict[str, list[Match]]
|
|
85
|
+
Match
|
|
86
|
+
teams: Teams # home / away team names
|
|
87
|
+
score: Score # home / away goals
|
|
88
|
+
goals: list[Goal]
|
|
89
|
+
cards: list[Card]
|
|
90
|
+
substitutions: list[Substitution]
|
|
91
|
+
lineups: Lineups
|
|
92
|
+
home: Lineup
|
|
93
|
+
away: Lineup
|
|
94
|
+
starting: list[tuple[int, BasePlayer]] # shirt_no, player
|
|
95
|
+
subs: list[tuple[int, BasePlayer]]
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
`Goal`, `Card`, `Substitution` and `LineupStatus` all subclass the abstract
|
|
99
|
+
`BaseEvent` and are aliased together as `Event`. `League.players` holds
|
|
100
|
+
every `Player` who has featured in the league, keyed by `player_id` as a
|
|
101
|
+
string.
|
|
102
|
+
|
|
103
|
+
## Conventions worth knowing
|
|
104
|
+
|
|
105
|
+
A few behaviours are deliberate and easy to trip over — see the [full
|
|
106
|
+
usage guide](https://ilc-models.readthedocs.io/en/latest/usage.html) for
|
|
107
|
+
detail:
|
|
108
|
+
|
|
109
|
+
- **`Goal.team` is the team credited with the goal, not the scorer's team.**
|
|
110
|
+
For an own goal the scorer belongs to the opposing team — call
|
|
111
|
+
`Match.event_team(event)` to resolve the team a player in an event
|
|
112
|
+
actually plays for.
|
|
113
|
+
- **Player equality compares `player_id` alone** (falling back to `name`
|
|
114
|
+
only when both IDs are `0`), because the upstream API spells player names
|
|
115
|
+
differently in event payloads versus player downloads.
|
|
116
|
+
- **`League.table()` models the Scottish-style split** — once a team has
|
|
117
|
+
played more than `League.split` matches, the table freezes the top/bottom
|
|
118
|
+
halves by position at the split point and sorts each half independently.
|
|
119
|
+
- **Dates are validated ISO strings, not `date` objects.** `Match.kickoff`
|
|
120
|
+
is a full offset-aware timestamp; `League.start`/`end` and
|
|
121
|
+
`Deduction.date` are `yyyy-mm-dd`. Use `Match.date` to get a
|
|
122
|
+
`datetime.date`.
|
|
123
|
+
- **`EventTime.plus` (stoppage time) is only valid at the end of a half** —
|
|
124
|
+
i.e. when `minutes` is 45, 90, 105 or 120.
|
|
125
|
+
|
|
126
|
+
## Documentation
|
|
127
|
+
|
|
128
|
+
Full API reference and usage guide:
|
|
129
|
+
[ilc-models.readthedocs.io](https://ilc-models.readthedocs.io/)
|
|
130
|
+
|
|
131
|
+
See [CHANGELOG.md](./CHANGELOG.md) for release history.
|
|
132
|
+
|
|
133
|
+
## Development
|
|
134
|
+
|
|
135
|
+
Task runner is [`just`](https://github.com/casey/just); Python tooling is
|
|
136
|
+
[`uv`](https://docs.astral.sh/uv/).
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
just check # ruff check --fix, ruff format, then ty check (type checking)
|
|
140
|
+
just test # run tests with pytest
|
|
141
|
+
just cov # pytest with coverage, then regenerate the coverage badge
|
|
142
|
+
just docs # build the Sphinx docs locally
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## License
|
|
146
|
+
|
|
147
|
+
MIT — see [LICENSE.txt](./LICENSE.txt).
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# ilc-models
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+

|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
**ilc-models** contains all data models for the *ILC* project.
|
|
8
|
+
|
|
9
|
+
It's a set of pure Pydantic v2 models with no I/O and no dependency beyond
|
|
10
|
+
`pydantic` — a `League` of `Match` objects, each with its `Lineups`,
|
|
11
|
+
`Goal`/`Card`/`Substitution` events, and the `TableRow` results computed
|
|
12
|
+
from them. This package is the shared data contract used across the
|
|
13
|
+
`ilc-api`, `ilc-app` and `ilc-admin` repositories, so a field change here is
|
|
14
|
+
a breaking change for all three.
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
pip install ilc-models
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Or with [uv](https://docs.astral.sh/uv/):
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
uv add ilc-models
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Quick start
|
|
29
|
+
|
|
30
|
+
```python
|
|
31
|
+
from ilc_models import League, Match, Teams, Score
|
|
32
|
+
|
|
33
|
+
league = League(
|
|
34
|
+
league_id=1,
|
|
35
|
+
name="Premiership",
|
|
36
|
+
year=2025,
|
|
37
|
+
start="2025-08-01",
|
|
38
|
+
end="2026-05-01",
|
|
39
|
+
current=True,
|
|
40
|
+
coverage={"lineups": True},
|
|
41
|
+
teams=["Team A", "Team B"],
|
|
42
|
+
rounds={
|
|
43
|
+
"1": [
|
|
44
|
+
Match(
|
|
45
|
+
match_id=1,
|
|
46
|
+
kickoff="2025-08-09T15:00:00+01:00",
|
|
47
|
+
round="1",
|
|
48
|
+
teams=Teams(home="Team A", away="Team B"),
|
|
49
|
+
status="FT",
|
|
50
|
+
score=Score(home=2, away=1),
|
|
51
|
+
)
|
|
52
|
+
]
|
|
53
|
+
},
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
for row in league.table():
|
|
57
|
+
print(row)
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Model map
|
|
61
|
+
|
|
62
|
+
```
|
|
63
|
+
League
|
|
64
|
+
rounds: dict[str, list[Match]]
|
|
65
|
+
Match
|
|
66
|
+
teams: Teams # home / away team names
|
|
67
|
+
score: Score # home / away goals
|
|
68
|
+
goals: list[Goal]
|
|
69
|
+
cards: list[Card]
|
|
70
|
+
substitutions: list[Substitution]
|
|
71
|
+
lineups: Lineups
|
|
72
|
+
home: Lineup
|
|
73
|
+
away: Lineup
|
|
74
|
+
starting: list[tuple[int, BasePlayer]] # shirt_no, player
|
|
75
|
+
subs: list[tuple[int, BasePlayer]]
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
`Goal`, `Card`, `Substitution` and `LineupStatus` all subclass the abstract
|
|
79
|
+
`BaseEvent` and are aliased together as `Event`. `League.players` holds
|
|
80
|
+
every `Player` who has featured in the league, keyed by `player_id` as a
|
|
81
|
+
string.
|
|
82
|
+
|
|
83
|
+
## Conventions worth knowing
|
|
84
|
+
|
|
85
|
+
A few behaviours are deliberate and easy to trip over — see the [full
|
|
86
|
+
usage guide](https://ilc-models.readthedocs.io/en/latest/usage.html) for
|
|
87
|
+
detail:
|
|
88
|
+
|
|
89
|
+
- **`Goal.team` is the team credited with the goal, not the scorer's team.**
|
|
90
|
+
For an own goal the scorer belongs to the opposing team — call
|
|
91
|
+
`Match.event_team(event)` to resolve the team a player in an event
|
|
92
|
+
actually plays for.
|
|
93
|
+
- **Player equality compares `player_id` alone** (falling back to `name`
|
|
94
|
+
only when both IDs are `0`), because the upstream API spells player names
|
|
95
|
+
differently in event payloads versus player downloads.
|
|
96
|
+
- **`League.table()` models the Scottish-style split** — once a team has
|
|
97
|
+
played more than `League.split` matches, the table freezes the top/bottom
|
|
98
|
+
halves by position at the split point and sorts each half independently.
|
|
99
|
+
- **Dates are validated ISO strings, not `date` objects.** `Match.kickoff`
|
|
100
|
+
is a full offset-aware timestamp; `League.start`/`end` and
|
|
101
|
+
`Deduction.date` are `yyyy-mm-dd`. Use `Match.date` to get a
|
|
102
|
+
`datetime.date`.
|
|
103
|
+
- **`EventTime.plus` (stoppage time) is only valid at the end of a half** —
|
|
104
|
+
i.e. when `minutes` is 45, 90, 105 or 120.
|
|
105
|
+
|
|
106
|
+
## Documentation
|
|
107
|
+
|
|
108
|
+
Full API reference and usage guide:
|
|
109
|
+
[ilc-models.readthedocs.io](https://ilc-models.readthedocs.io/)
|
|
110
|
+
|
|
111
|
+
See [CHANGELOG.md](./CHANGELOG.md) for release history.
|
|
112
|
+
|
|
113
|
+
## Development
|
|
114
|
+
|
|
115
|
+
Task runner is [`just`](https://github.com/casey/just); Python tooling is
|
|
116
|
+
[`uv`](https://docs.astral.sh/uv/).
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
just check # ruff check --fix, ruff format, then ty check (type checking)
|
|
120
|
+
just test # run tests with pytest
|
|
121
|
+
just cov # pytest with coverage, then regenerate the coverage badge
|
|
122
|
+
just docs # build the Sphinx docs locally
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## License
|
|
126
|
+
|
|
127
|
+
MIT — see [LICENSE.txt](./LICENSE.txt).
|
|
@@ -15,13 +15,14 @@ sys.path.insert(0, str(Path("..", "..", "src").resolve()))
|
|
|
15
15
|
project = "ilc-models"
|
|
16
16
|
copyright = "2025, Neil Martin"
|
|
17
17
|
author = "Neil Martin"
|
|
18
|
-
release = "0.2.
|
|
18
|
+
release = "0.2.4"
|
|
19
19
|
|
|
20
20
|
# -- General configuration ---------------------------------------------------
|
|
21
21
|
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
|
|
22
22
|
|
|
23
23
|
extensions = [
|
|
24
24
|
"sphinx.ext.autodoc",
|
|
25
|
+
"sphinx.ext.napoleon",
|
|
25
26
|
"sphinx.ext.duration",
|
|
26
27
|
"sphinx.ext.intersphinx",
|
|
27
28
|
"sphinx.ext.viewcode",
|
|
@@ -31,10 +32,29 @@ extensions = [
|
|
|
31
32
|
templates_path = ["_templates"]
|
|
32
33
|
exclude_patterns = []
|
|
33
34
|
|
|
35
|
+
# Render single backticks as literals rather than italic title references
|
|
36
|
+
default_role = "literal"
|
|
37
|
+
|
|
34
38
|
intersphinx_mapping = {
|
|
35
39
|
"python": ("https://docs.python.org/3", None),
|
|
36
40
|
}
|
|
37
41
|
|
|
42
|
+
# -- Napoleon (Google-style docstrings) ---------------------------------------
|
|
43
|
+
# https://www.sphinx-doc.org/en/master/usage/extensions/napoleon.html
|
|
44
|
+
|
|
45
|
+
napoleon_google_docstring = True
|
|
46
|
+
napoleon_numpy_docstring = False
|
|
47
|
+
napoleon_use_param = True
|
|
48
|
+
napoleon_use_rtype = True
|
|
49
|
+
napoleon_use_ivar = False
|
|
50
|
+
napoleon_attr_annotations = True
|
|
51
|
+
napoleon_preprocess_types = True
|
|
52
|
+
|
|
53
|
+
# -- Autodoc -------------------------------------------------------------------
|
|
54
|
+
|
|
55
|
+
autodoc_typehints = "description"
|
|
56
|
+
autodoc_typehints_description_target = "documented_params"
|
|
57
|
+
|
|
38
58
|
# -- Options for HTML output -------------------------------------------------
|
|
39
59
|
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
|
|
40
60
|
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
ilc-models
|
|
2
|
+
==========
|
|
3
|
+
|
|
4
|
+
**Data models for the *ILC* project**
|
|
5
|
+
|
|
6
|
+
`ilc-models` is a set of pure Pydantic v2 models with no I/O and no
|
|
7
|
+
dependency beyond `pydantic`. It forms the shared data contract used across
|
|
8
|
+
the `ilc-api`, `ilc-app` and `ilc-admin` repositories - a `League` of
|
|
9
|
+
`Match` objects, each with its `Lineups`, `Goal`/`Card`/`Substitution`
|
|
10
|
+
events, and the `TableRow` results computed from them.
|
|
11
|
+
|
|
12
|
+
::
|
|
13
|
+
|
|
14
|
+
from ilc_models import League, Match, Teams, Score
|
|
15
|
+
|
|
16
|
+
league = League(
|
|
17
|
+
league_id=1,
|
|
18
|
+
name="Premiership",
|
|
19
|
+
year=2025,
|
|
20
|
+
start="2025-08-01",
|
|
21
|
+
end="2026-05-01",
|
|
22
|
+
current=True,
|
|
23
|
+
coverage={"lineups": True},
|
|
24
|
+
teams=["Team A", "Team B"],
|
|
25
|
+
rounds={
|
|
26
|
+
"1": [
|
|
27
|
+
Match(
|
|
28
|
+
match_id=1,
|
|
29
|
+
kickoff="2025-08-09T15:00:00+01:00",
|
|
30
|
+
round="1",
|
|
31
|
+
teams=Teams(home="Team A", away="Team B"),
|
|
32
|
+
status="FT",
|
|
33
|
+
score=Score(home=2, away=1),
|
|
34
|
+
)
|
|
35
|
+
]
|
|
36
|
+
},
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
for row in league.table():
|
|
40
|
+
print(row)
|
|
41
|
+
|
|
42
|
+
For more detail see the :doc:`usage` documentation.
|
|
43
|
+
|
|
44
|
+
Installation
|
|
45
|
+
------------
|
|
46
|
+
|
|
47
|
+
To install, run::
|
|
48
|
+
|
|
49
|
+
(.venv) $ pip install ilc-models
|
|
50
|
+
|
|
51
|
+
.. toctree::
|
|
52
|
+
:maxdepth: 2
|
|
53
|
+
:caption: Contents:
|
|
54
|
+
|
|
55
|
+
usage
|
|
56
|
+
api
|