Coverage for src/retrospeedlab/docs_site/stack.py: 100%

37 statements  

« prev     ^ index     » next       coverage.py v7.16.2, created at 2026-12-02 22:44 +0000

1from dataclasses import dataclass 

2 

3from retrospeedlab.docs_site.labels import NOT_YET, count_label, rounded 

4from retrospeedlab.docs_site.lake import number_label, source_name 

5from retrospeedlab.docs_site.payloads import SourceNumber, TechStack 

6 

7BUGSINK = "bugsink" 

8OPEN_ISSUES = "open_issues" 

9RESOLVED_ISSUES = "resolved_issues" 

10SINCE_DEPLOY = "since the last deploy" 

11ALL_TIME = "all time" 

12THIS_WEEK = "last 7 days" 

13DAY_LENGTH = len("2026-12-02") 

14 

15 

16@dataclass(slots=True, frozen=True) 

17class Row: 

18 label: str 

19 value: str 

20 window: str 

21 

22 

23@dataclass(slots=True, frozen=True) 

24class LiveGroup: 

25 title: str 

26 rows: list[Row] 

27 

28 

29@dataclass(slots=True, frozen=True) 

30class IssueCounts: 

31 open: int 

32 resolved: int 

33 

34 

35def when(moment: str | None) -> str: 

36 return NOT_YET if moment is None else moment[:DAY_LENGTH] 

37 

38 

39def issue_counts(numbers: list[SourceNumber]) -> IssueCounts | None: 

40 found = {number.metric: number for number in numbers if number.source == BUGSINK} 

41 if OPEN_ISSUES not in found or RESOLVED_ISSUES not in found: 

42 return None 

43 return IssueCounts(int(found[OPEN_ISSUES].value), int(found[RESOLVED_ISSUES].value)) 

44 

45 

46def lake_groups(numbers: list[SourceNumber]) -> list[LiveGroup]: 

47 return [ 

48 LiveGroup( 

49 source_name(source), 

50 [Row(number.label, number_label(number), number.window) for number in numbers if number.source == source], 

51 ) 

52 for source in sorted({number.source for number in numbers}) 

53 ] 

54 

55 

56def live_groups(stack: TechStack) -> list[LiveGroup]: 

57 backend, lab, maintainer = stack.backend, stack.lab, stack.maintainer 

58 median = NOT_YET if backend.median_response_ms is None else f"{rounded(backend.median_response_ms)} ms" 

59 return [ 

60 LiveGroup( 

61 "API", 

62 [ 

63 Row("Up since", when(backend.up_since), SINCE_DEPLOY), 

64 Row("Requests served", count_label(backend.requests), SINCE_DEPLOY), 

65 Row("Median response", median, SINCE_DEPLOY), 

66 Row("Live updates", count_label(backend.live_updates), SINCE_DEPLOY), 

67 Row("Movie parts relayed", count_label(backend.movie_parts), SINCE_DEPLOY), 

68 ], 

69 ), 

70 LiveGroup( 

71 "Lab", 

72 [ 

73 Row("Games on the bench", count_label(lab.games), ALL_TIME), 

74 Row("Lab runs", count_label(lab.lab_runs), ALL_TIME), 

75 Row("Lab runs", count_label(lab.lab_runs_this_week), THIS_WEEK), 

76 Row("First lab run", when(lab.started_at), ALL_TIME), 

77 Row("Latest lab run", when(lab.latest_lab_run_at), ALL_TIME), 

78 ], 

79 ), 

80 LiveGroup( 

81 "Maintainer", 

82 [ 

83 Row("Runs", count_label(maintainer.runs), ALL_TIME), 

84 Row("Runs", count_label(maintainer.runs_this_week), THIS_WEEK), 

85 Row("Pull requests opened", count_label(maintainer.pull_requests), ALL_TIME), 

86 Row("Bugsink issues fixed", count_label(maintainer.resolved_issues), ALL_TIME), 

87 Row("Latest run", when(maintainer.latest_run_at), ALL_TIME), 

88 ], 

89 ), 

90 *lake_groups(stack.numbers), 

91 ]