Coverage for dao/side_age_groups.py: 66.67%

10 statements  

« prev     ^ index     » next       coverage.py v7.10.6, created at 2026-11-30 20:17 +0000

1"""Per-side age groups on matches (SB-1444). 

2 

3A match has one ``age_group_id``. When one side plays up — IFA U15 against the 

4New England Revolution U16 in a friendly — that side's own age group is stored 

5in ``home_age_group_id`` / ``away_age_group_id``. NULL means "same as the 

6match", which is every scraped match and almost every manual one, so writers 

7that know nothing about playing up change nothing. 

8""" 

9 

10 

11def side_age_group(side_age_group_id: int | None, match_age_group_id: int | None) -> int | None: 

12 """Value to store for one side: NULL unless it differs from the match. 

13 

14 Storing the match's own age group again would make two spellings of 

15 "same age group", and every reader would have to treat them alike. 

16 """ 

17 if side_age_group_id is None or side_age_group_id == match_age_group_id: 17 ↛ 19line 17 didn't jump to line 19 because the condition on line 17 was always true

18 return None 

19 return side_age_group_id 

20 

21 

22def effective_side_age_groups(match: dict) -> tuple[int | None, int | None]: 

23 """(home, away) age group each side fielded, resolving NULL to the match's.""" 

24 match_age = match.get("age_group_id") 

25 return ( 

26 match.get("home_age_group_id") or match_age, 

27 match.get("away_age_group_id") or match_age, 

28 ) 

29 

30 

31def team_age_group_filter(team_id: int, age_group_id: int) -> str: 

32 """PostgREST ``or`` filter: matches where ``team_id`` fielded ``age_group_id``. 

33 

34 A side's age group is its own column when set, else the match's. PostgREST 

35 has no COALESCE, so each side is two branches: the override equals the age 

36 group, or there is no override and the match's age group does. 

37 """ 

38 t, a = int(team_id), int(age_group_id) 

39 return ",".join( 

40 [ 

41 f"and(home_team_id.eq.{t},home_age_group_id.eq.{a})", 

42 f"and(home_team_id.eq.{t},home_age_group_id.is.null,age_group_id.eq.{a})", 

43 f"and(away_team_id.eq.{t},away_age_group_id.eq.{a})", 

44 f"and(away_team_id.eq.{t},away_age_group_id.is.null,age_group_id.eq.{a})", 

45 ] 

46 )