ilc-models 0.2.2__tar.gz → 0.2.3__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.2 → ilc_models-0.2.3}/CHANGELOG.md +12 -0
- {ilc_models-0.2.2 → ilc_models-0.2.3}/PKG-INFO +2 -2
- {ilc_models-0.2.2 → ilc_models-0.2.3}/README.md +1 -1
- {ilc_models-0.2.2 → ilc_models-0.2.3}/docs/source/conf.py +1 -1
- {ilc_models-0.2.2 → ilc_models-0.2.3}/pyproject.toml +2 -2
- {ilc_models-0.2.2 → ilc_models-0.2.3}/src/ilc_models/__init__.py +94 -23
- {ilc_models-0.2.2 → ilc_models-0.2.3}/tests/test_models.py +67 -1
- {ilc_models-0.2.2 → ilc_models-0.2.3}/uv.lock +1 -1
- {ilc_models-0.2.2 → ilc_models-0.2.3}/.gitignore +0 -0
- {ilc_models-0.2.2 → ilc_models-0.2.3}/.python-version +0 -0
- {ilc_models-0.2.2 → ilc_models-0.2.3}/.readthedocs.yaml +0 -0
- {ilc_models-0.2.2 → ilc_models-0.2.3}/LICENSE.txt +0 -0
- {ilc_models-0.2.2 → ilc_models-0.2.3}/check.zsh +0 -0
- {ilc_models-0.2.2 → ilc_models-0.2.3}/coverage.zsh +0 -0
- {ilc_models-0.2.2 → ilc_models-0.2.3}/docs/requirements.txt +0 -0
- {ilc_models-0.2.2 → ilc_models-0.2.3}/docs/source/api.rst +0 -0
- {ilc_models-0.2.2 → ilc_models-0.2.3}/docs/source/index.rst +0 -0
- {ilc_models-0.2.2 → ilc_models-0.2.3}/src/ilc_models/py.typed +0 -0
- {ilc_models-0.2.2 → ilc_models-0.2.3}/tests/__init__.py +0 -0
- {ilc_models-0.2.2 → ilc_models-0.2.3}/tests/conftest.py +0 -0
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.2.3] - 2026-02-05
|
|
4
|
+
|
|
5
|
+
### Changed
|
|
6
|
+
|
|
7
|
+
- Add `teams` parameter to `Match.players()` method
|
|
8
|
+
- Add `Match.involves_any()` method
|
|
9
|
+
- Add `Match.h2h()` method
|
|
10
|
+
- Add `teams` and `h2h` parameters to `League.matches()` method
|
|
11
|
+
- Add `teams` and `h2h` parameters to `League.match_players()` method
|
|
12
|
+
|
|
3
13
|
## [0.2.2] - 2026-01-21
|
|
4
14
|
|
|
5
15
|
### Changed
|
|
@@ -75,6 +85,8 @@
|
|
|
75
85
|
|
|
76
86
|
_Initial release._
|
|
77
87
|
|
|
88
|
+
[0.2.3]: https://github.com/fourtreestech/ilc-models/releases/tag/v0.2.3
|
|
89
|
+
|
|
78
90
|
[0.2.2]: https://github.com/fourtreestech/ilc-models/releases/tag/v0.2.2
|
|
79
91
|
|
|
80
92
|
[0.2.1]: https://github.com/fourtreestech/ilc-models/releases/tag/v0.2.1
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: ilc-models
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.3
|
|
4
4
|
Summary: Data models for the ILC project
|
|
5
5
|
Project-URL: Repository, https://github.com/fourtreestech/ilc-models
|
|
6
6
|
Author-email: Neil Martin <neil@fourtrees.tech>
|
|
@@ -19,7 +19,7 @@ Description-Content-Type: text/markdown
|
|
|
19
19
|
|
|
20
20
|
# ilc-models
|
|
21
21
|
|
|
22
|
-

|
|
23
23
|

|
|
24
24
|

|
|
25
25
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# ilc-models
|
|
2
2
|
|
|
3
|
-

|
|
4
4
|

|
|
5
5
|

|
|
6
6
|
|
|
@@ -15,7 +15,7 @@ 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.3"
|
|
19
19
|
|
|
20
20
|
# -- General configuration ---------------------------------------------------
|
|
21
21
|
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "ilc-models"
|
|
3
|
-
version = "0.2.
|
|
3
|
+
version = "0.2.3"
|
|
4
4
|
description = "Data models for the ILC project"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
authors = [
|
|
@@ -29,7 +29,7 @@ requires = ["hatchling"]
|
|
|
29
29
|
build-backend = "hatchling.build"
|
|
30
30
|
|
|
31
31
|
[tool.bumpver]
|
|
32
|
-
current_version = "0.2.
|
|
32
|
+
current_version = "0.2.3"
|
|
33
33
|
version_pattern = "MAJOR.MINOR.PATCH"
|
|
34
34
|
commit_message = "Bump version {old_version} -> {new_version}"
|
|
35
35
|
tag_message = "{new_version}"
|
|
@@ -18,7 +18,7 @@ from pydantic import (
|
|
|
18
18
|
model_validator,
|
|
19
19
|
)
|
|
20
20
|
|
|
21
|
-
__version__ = "0.2.
|
|
21
|
+
__version__ = "0.2.3"
|
|
22
22
|
|
|
23
23
|
|
|
24
24
|
class RowTuple(NamedTuple):
|
|
@@ -455,6 +455,31 @@ class Match(BaseModel):
|
|
|
455
455
|
"""
|
|
456
456
|
return self.teams.home == team or self.teams.away == team
|
|
457
457
|
|
|
458
|
+
def involves_any(self, teams: list[str]) -> bool:
|
|
459
|
+
"""Returns ``True`` if any of ``teams`` is involved in this match.
|
|
460
|
+
|
|
461
|
+
:param teams: Teams to query
|
|
462
|
+
:type team: list[str]
|
|
463
|
+
:returns: ``True`` if any of ``teams`` are involved in this match, i.e.
|
|
464
|
+
either as the home team or the away team
|
|
465
|
+
:rtype: bool
|
|
466
|
+
"""
|
|
467
|
+
return any(self.involves(team) for team in teams)
|
|
468
|
+
|
|
469
|
+
def h2h(self, team1: str, team2: str) -> bool:
|
|
470
|
+
"""Returns ``True`` if the match is a head to head between these two teams.
|
|
471
|
+
|
|
472
|
+
:param team1: First team
|
|
473
|
+
:type team1: str
|
|
474
|
+
:param team2: Second team
|
|
475
|
+
:type team2: str
|
|
476
|
+
:returns: `True` if the match is between the two teams, `False` otherwise
|
|
477
|
+
:rtype: bool
|
|
478
|
+
"""
|
|
479
|
+
return (self.teams.home == team1 and self.teams.away == team2) or (
|
|
480
|
+
self.teams.home == team2 and self.teams.away == team1
|
|
481
|
+
)
|
|
482
|
+
|
|
458
483
|
def events(self) -> list[Event]:
|
|
459
484
|
"""Returns all events in this match in chronological order.
|
|
460
485
|
|
|
@@ -464,40 +489,53 @@ class Match(BaseModel):
|
|
|
464
489
|
e = self.goals + self.cards + self.substitutions
|
|
465
490
|
return sorted(e, key=attrgetter("time"))
|
|
466
491
|
|
|
467
|
-
def players(
|
|
492
|
+
def players(
|
|
493
|
+
self, team: Optional[str] = None, teams: Optional[list[str]] = None
|
|
494
|
+
) -> list[BasePlayer]:
|
|
468
495
|
"""Get all players involved in this match.
|
|
469
496
|
|
|
470
497
|
If `team` is provided return only players from the team specified.
|
|
498
|
+
If `teams` is provided return only players from one of the teams specified.
|
|
471
499
|
|
|
472
500
|
:param team: Return only players from this team (default=None)
|
|
473
501
|
:type team: str
|
|
502
|
+
:param teams: Return only players from these teams (default=None)
|
|
503
|
+
:type team: list[str]
|
|
474
504
|
:returns: Players involved in the match
|
|
475
505
|
:rtype: list[:class:`BasePlayer`]
|
|
476
506
|
"""
|
|
507
|
+
# Manage team param
|
|
508
|
+
if not teams:
|
|
509
|
+
if team:
|
|
510
|
+
teams = [team]
|
|
511
|
+
|
|
477
512
|
# Get players from lineups
|
|
478
|
-
if
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
elif team == self.teams.away:
|
|
482
|
-
p = self.lineups.away.players()
|
|
483
|
-
else:
|
|
513
|
+
if teams:
|
|
514
|
+
# Neither team - just return empty list
|
|
515
|
+
if self.teams.home not in teams and self.teams.away not in teams:
|
|
484
516
|
return []
|
|
517
|
+
|
|
518
|
+
# Add lineups
|
|
519
|
+
p = []
|
|
520
|
+
if self.teams.home in teams:
|
|
521
|
+
p += self.lineups.home.players()
|
|
522
|
+
if self.teams.away in teams:
|
|
523
|
+
p += self.lineups.away.players()
|
|
485
524
|
else:
|
|
486
525
|
p = self.lineups.players()
|
|
487
526
|
|
|
488
527
|
# Add players from events
|
|
489
528
|
for event in self.events():
|
|
490
529
|
add = False
|
|
491
|
-
if not
|
|
530
|
+
if not teams:
|
|
492
531
|
add = True
|
|
493
|
-
elif event.event_type == "goal":
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
)
|
|
532
|
+
elif event.event_type == "goal" and event.goal_type == "O":
|
|
533
|
+
if event.team == self.teams.home and self.teams.away in teams:
|
|
534
|
+
add = True
|
|
535
|
+
elif event.team == self.teams.away and self.teams.home in teams:
|
|
536
|
+
add = True
|
|
499
537
|
else:
|
|
500
|
-
add = event.team
|
|
538
|
+
add = event.team in teams
|
|
501
539
|
if add:
|
|
502
540
|
for player in event.players():
|
|
503
541
|
if player not in p:
|
|
@@ -877,23 +915,45 @@ class League(BaseModel):
|
|
|
877
915
|
season = year1 if year1 == year2 else f"{year1}/{year2 % 100}"
|
|
878
916
|
return f"{self.name} {season}"
|
|
879
917
|
|
|
880
|
-
def matches(
|
|
918
|
+
def matches(
|
|
919
|
+
self,
|
|
920
|
+
team: Optional[str] = None,
|
|
921
|
+
teams: Optional[list[str]] = None,
|
|
922
|
+
h2h: Optional[tuple[str, str]] = None,
|
|
923
|
+
) -> list[Match]:
|
|
881
924
|
"""Matches in this league.
|
|
882
925
|
|
|
883
|
-
If
|
|
884
|
-
|
|
926
|
+
If `team` is given, return only matches involving this team.
|
|
927
|
+
If `teams` is given, return only matches involving one of these teams.
|
|
928
|
+
If `h2h` is given, return only matches between these two teams.
|
|
885
929
|
|
|
886
930
|
:param team: Get matches for this team (default=None)
|
|
887
931
|
:type team: str
|
|
932
|
+
:param teams: Get matches involving any of these teams (default=None)
|
|
933
|
+
:type teams: list[str]
|
|
934
|
+
:param h2h: Get matches between these two teams (eefault=None)
|
|
935
|
+
:type h2h: tuple[str, str]
|
|
888
936
|
:returns: Matches sorted by date and then home team
|
|
889
937
|
:rtype: list[:class:`Match`]
|
|
890
938
|
"""
|
|
939
|
+
# fn is the function that determines whether to include this match
|
|
940
|
+
if team:
|
|
941
|
+
fn = lambda m: m.involves(team)
|
|
942
|
+
elif teams:
|
|
943
|
+
fn = lambda m: m.involves_any(teams)
|
|
944
|
+
elif h2h:
|
|
945
|
+
fn = lambda m: m.h2h(*h2h)
|
|
946
|
+
else:
|
|
947
|
+
fn = lambda _: True
|
|
948
|
+
|
|
949
|
+
# Extract matches that pass the fn test
|
|
891
950
|
_matches = []
|
|
892
951
|
for m in self.rounds.values():
|
|
893
952
|
for match in m:
|
|
894
|
-
if
|
|
953
|
+
if fn(match):
|
|
895
954
|
_matches.append(match)
|
|
896
955
|
|
|
956
|
+
# Sort and return
|
|
897
957
|
_matches.sort(key=attrgetter("teams.home"))
|
|
898
958
|
_matches.sort(key=attrgetter("date"))
|
|
899
959
|
return _matches
|
|
@@ -1077,19 +1137,30 @@ class League(BaseModel):
|
|
|
1077
1137
|
|
|
1078
1138
|
return list(teams)
|
|
1079
1139
|
|
|
1080
|
-
def match_players(
|
|
1140
|
+
def match_players(
|
|
1141
|
+
self,
|
|
1142
|
+
team: Optional[str] = None,
|
|
1143
|
+
teams: Optional[list[str]] = None,
|
|
1144
|
+
h2h: Optional[tuple[str, str]] = None,
|
|
1145
|
+
) -> list[BasePlayer]:
|
|
1081
1146
|
"""Get all players involved in at least one match in this league.
|
|
1082
1147
|
|
|
1083
1148
|
If `team` is given return only players who have featured for this team.
|
|
1149
|
+
If `teams` is given return only players who have featured for one of these teams.
|
|
1150
|
+
If `h2h` is given return only players who featured in a match between these two teams.
|
|
1084
1151
|
|
|
1085
1152
|
:param team: Get players who played for this team (default=None)
|
|
1086
1153
|
:type team: str
|
|
1154
|
+
:param teams: Get players who played for any of these teams (default=None)
|
|
1155
|
+
:type teams: list[str]
|
|
1156
|
+
:param h2h: Get players who played in a match between these two teams (default=None)
|
|
1157
|
+
:type h2h: tuple[str, str]
|
|
1087
1158
|
:returns: All players involved in a match
|
|
1088
1159
|
:rtype: list[:class:`BasePlayer`]
|
|
1089
1160
|
"""
|
|
1090
1161
|
players = []
|
|
1091
|
-
for match in self.matches(team=team):
|
|
1092
|
-
for p in match.players(team=team):
|
|
1162
|
+
for match in self.matches(team=team, teams=teams, h2h=h2h):
|
|
1163
|
+
for p in match.players(team=team, teams=teams):
|
|
1093
1164
|
if p not in players:
|
|
1094
1165
|
players.append(p)
|
|
1095
1166
|
return players
|
|
@@ -257,6 +257,27 @@ class TestMatch:
|
|
|
257
257
|
assert match.involves(away.name)
|
|
258
258
|
assert not match.involves(other.name)
|
|
259
259
|
|
|
260
|
+
def test_involves_any(self, ilc_fake):
|
|
261
|
+
home = ilc_fake.team()
|
|
262
|
+
away = ilc_fake.team()
|
|
263
|
+
other = ilc_fake.team()
|
|
264
|
+
match = ilc_fake.match(home=home, away=away)
|
|
265
|
+
assert match.involves_any([home.name])
|
|
266
|
+
assert match.involves_any([away.name])
|
|
267
|
+
assert match.involves_any([home.name, away.name])
|
|
268
|
+
assert match.involves_any([other.name, away.name])
|
|
269
|
+
assert not match.involves_any([other.name])
|
|
270
|
+
|
|
271
|
+
def test_h2h(self, ilc_fake):
|
|
272
|
+
home = ilc_fake.team()
|
|
273
|
+
away = ilc_fake.team()
|
|
274
|
+
other = ilc_fake.team()
|
|
275
|
+
match = ilc_fake.match(home=home, away=away)
|
|
276
|
+
assert match.h2h(home.name, away.name)
|
|
277
|
+
assert match.h2h(away.name, home.name)
|
|
278
|
+
assert not match.h2h(home.name, home.name)
|
|
279
|
+
assert not match.h2h(other.name, home.name)
|
|
280
|
+
|
|
260
281
|
def test_events_returns_all_events(self, ilc_fake):
|
|
261
282
|
match = ilc_fake.match()
|
|
262
283
|
assert len(match.events()) == len(match.goals) + len(match.cards) + len(
|
|
@@ -394,6 +415,27 @@ class TestMatch:
|
|
|
394
415
|
for player in event.players():
|
|
395
416
|
assert player in players
|
|
396
417
|
|
|
418
|
+
def test_returns_players_from_teams(self, ilc_fake):
|
|
419
|
+
match = ilc_fake.match()
|
|
420
|
+
players = match.players(teams=[match.teams.home, match.teams.away])
|
|
421
|
+
for player in match.lineups.home.starting:
|
|
422
|
+
assert player[1] in players
|
|
423
|
+
for player in match.lineups.away.starting:
|
|
424
|
+
assert player[1] in players
|
|
425
|
+
|
|
426
|
+
def test_returns_only_players_from_specified_teams(self, ilc_fake):
|
|
427
|
+
match = ilc_fake.match()
|
|
428
|
+
players = match.players(teams=[match.teams.home, "Non-existent United"])
|
|
429
|
+
for player in match.lineups.home.starting:
|
|
430
|
+
assert player[1] in players
|
|
431
|
+
for player in match.lineups.away.starting:
|
|
432
|
+
assert player[1] not in players
|
|
433
|
+
|
|
434
|
+
def test_returns_no_players_if_teams_arent_in_the_match(self, ilc_fake):
|
|
435
|
+
match = ilc_fake.match()
|
|
436
|
+
players = match.players(teams=["Non-existent United"])
|
|
437
|
+
assert not players
|
|
438
|
+
|
|
397
439
|
def test_own_goal_scorer_to_correct_team(self, ilc_fake):
|
|
398
440
|
home = ilc_fake.team()
|
|
399
441
|
away = ilc_fake.team()
|
|
@@ -536,11 +578,23 @@ class TestLeague:
|
|
|
536
578
|
previous = match
|
|
537
579
|
|
|
538
580
|
def test_matches_filtered_by_team(self, fake_league):
|
|
539
|
-
team = fake_league.teams
|
|
581
|
+
team = random.choice(fake_league.teams)
|
|
540
582
|
matches = fake_league.matches(team=team)
|
|
541
583
|
for match in matches:
|
|
542
584
|
assert match.teams.home == team or match.teams.away == team
|
|
543
585
|
|
|
586
|
+
def test_matches_filtered_by_teams(self, fake_league):
|
|
587
|
+
teams = random.sample(fake_league.teams, k=3)
|
|
588
|
+
matches = fake_league.matches(teams=teams)
|
|
589
|
+
for match in matches:
|
|
590
|
+
assert any(team in (match.teams.home, match.teams.away) for team in teams)
|
|
591
|
+
|
|
592
|
+
def test_matches_filtered_by_h2h(self, fake_league):
|
|
593
|
+
teams = tuple(random.sample(fake_league.teams, k=2))
|
|
594
|
+
matches = fake_league.matches(h2h=teams)
|
|
595
|
+
for match in matches:
|
|
596
|
+
assert all(team in (match.teams.home, match.teams.away) for team in teams)
|
|
597
|
+
|
|
544
598
|
def test_events_returns_correct_players_events(self, fake_league):
|
|
545
599
|
player = None
|
|
546
600
|
for match in fake_league.matches():
|
|
@@ -750,6 +804,18 @@ class TestLeague:
|
|
|
750
804
|
for player in lineup.subs:
|
|
751
805
|
assert player[1] in players
|
|
752
806
|
|
|
807
|
+
def test_match_players_returns_for_teams(self, fake_league):
|
|
808
|
+
match = random.choice(fake_league.matches())
|
|
809
|
+
players = fake_league.match_players(teams=[match.teams.home, match.teams.away])
|
|
810
|
+
for player in match.players():
|
|
811
|
+
assert player in players
|
|
812
|
+
|
|
813
|
+
def test_match_players_returns_for_h2h(self, fake_league):
|
|
814
|
+
match = random.choice(fake_league.matches())
|
|
815
|
+
players = fake_league.match_players(h2h=(match.teams.home, match.teams.away))
|
|
816
|
+
for player in match.players():
|
|
817
|
+
assert player in players
|
|
818
|
+
|
|
753
819
|
|
|
754
820
|
class TestLeagueTable:
|
|
755
821
|
def test_league_table_is_correct_size(self, fake_league):
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|