github-statistics 0.1.0__py3-none-any.whl

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.
Files changed (86) hide show
  1. github_statistics/__init__.py +14 -0
  2. github_statistics/__main__.py +10 -0
  3. github_statistics/_version.py +24 -0
  4. github_statistics/cli/__init__.py +9 -0
  5. github_statistics/cli/app.py +104 -0
  6. github_statistics/cli/cache.py +159 -0
  7. github_statistics/cli/collect.py +219 -0
  8. github_statistics/cli/common.py +128 -0
  9. github_statistics/cli/config.py +80 -0
  10. github_statistics/cli/doctor.py +214 -0
  11. github_statistics/cli/export.py +111 -0
  12. github_statistics/cli/options.py +175 -0
  13. github_statistics/cli/render.py +126 -0
  14. github_statistics/cli/run.py +137 -0
  15. github_statistics/cli/scope.py +96 -0
  16. github_statistics/cli/site.py +150 -0
  17. github_statistics/client/__init__.py +40 -0
  18. github_statistics/client/accounting.py +99 -0
  19. github_statistics/client/budget.py +125 -0
  20. github_statistics/client/cooldown.py +113 -0
  21. github_statistics/client/errors.py +60 -0
  22. github_statistics/client/graphql.py +281 -0
  23. github_statistics/client/paging.py +92 -0
  24. github_statistics/client/policy.py +243 -0
  25. github_statistics/client/transport.py +437 -0
  26. github_statistics/collect/__init__.py +44 -0
  27. github_statistics/collect/common.py +69 -0
  28. github_statistics/collect/enrich_items.py +423 -0
  29. github_statistics/collect/items.py +238 -0
  30. github_statistics/collect/jobs.py +194 -0
  31. github_statistics/collect/listed.py +42 -0
  32. github_statistics/collect/members.py +70 -0
  33. github_statistics/collect/reader.py +124 -0
  34. github_statistics/collect/run.py +354 -0
  35. github_statistics/collect/runs.py +436 -0
  36. github_statistics/collect/slices.py +55 -0
  37. github_statistics/collect/steps.py +154 -0
  38. github_statistics/collect/sweep.py +70 -0
  39. github_statistics/config/__init__.py +37 -0
  40. github_statistics/config/loader.py +430 -0
  41. github_statistics/config/models.py +156 -0
  42. github_statistics/config/schema.py +245 -0
  43. github_statistics/export/__init__.py +11 -0
  44. github_statistics/export/csv.py +93 -0
  45. github_statistics/export/documents.py +189 -0
  46. github_statistics/export/json.py +33 -0
  47. github_statistics/py.typed +2 -0
  48. github_statistics/render/__init__.py +44 -0
  49. github_statistics/render/bars3d.py +420 -0
  50. github_statistics/render/charts.py +214 -0
  51. github_statistics/render/demo.py +133 -0
  52. github_statistics/render/images.py +31 -0
  53. github_statistics/render/layout.py +341 -0
  54. github_statistics/render/model.py +260 -0
  55. github_statistics/render/palette.py +41 -0
  56. github_statistics/scope/__init__.py +17 -0
  57. github_statistics/scope/apply.py +95 -0
  58. github_statistics/scope/resolver.py +228 -0
  59. github_statistics/series/__init__.py +22 -0
  60. github_statistics/series/actors.py +128 -0
  61. github_statistics/series/coverage.py +86 -0
  62. github_statistics/series/daily.py +229 -0
  63. github_statistics/series/leaderboard.py +221 -0
  64. github_statistics/series/repositories.py +154 -0
  65. github_statistics/site/__init__.py +9 -0
  66. github_statistics/site/assets/site.css +281 -0
  67. github_statistics/site/build.py +392 -0
  68. github_statistics/site/templates/base.html.j2 +25 -0
  69. github_statistics/site/templates/index.html.j2 +30 -0
  70. github_statistics/site/templates/macros.html.j2 +5 -0
  71. github_statistics/site/templates/site.js.j2 +66 -0
  72. github_statistics/site/templates/target.html.j2 +95 -0
  73. github_statistics/store/__init__.py +40 -0
  74. github_statistics/store/activity.py +311 -0
  75. github_statistics/store/aggregates.py +294 -0
  76. github_statistics/store/base.py +163 -0
  77. github_statistics/store/codec.py +263 -0
  78. github_statistics/store/models.py +136 -0
  79. github_statistics/store/paths.py +36 -0
  80. github_statistics/store/schema.py +169 -0
  81. github_statistics/store/sqlite.py +299 -0
  82. github_statistics-0.1.0.dist-info/METADATA +308 -0
  83. github_statistics-0.1.0.dist-info/RECORD +86 -0
  84. github_statistics-0.1.0.dist-info/WHEEL +4 -0
  85. github_statistics-0.1.0.dist-info/entry_points.txt +2 -0
  86. github_statistics-0.1.0.dist-info/licenses/LICENSE +201 -0
@@ -0,0 +1,154 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ # SPDX-FileCopyrightText: 2026 The Linux Foundation
3
+ """The repository table: counts and coverage per repository (design §7.4).
4
+
5
+ One row per repository in scope on any day of the window, with the
6
+ counts the charts draw and, per charted metric, the share of window
7
+ days the repository covers, so a reader can see which repository
8
+ drives a spike or a gap. Counts follow the series rules: ignored logins
9
+ are left out and a scheduled run counts whatever its actor.
10
+ """
11
+
12
+ from __future__ import annotations
13
+
14
+ from collections.abc import Mapping, Sequence
15
+ from dataclasses import dataclass
16
+ from datetime import date
17
+ from types import MappingProxyType
18
+
19
+ from ..collect import runs_horizon
20
+ from ..config import Config, ResolvedIdentities, Target, resolve_identities
21
+ from ..store import DayRange, Store
22
+ from .actors import ActorClass, classify, public_members
23
+ from .coverage import COVERAGE_METRIC, WORKFLOW_OUTCOMES, WORKFLOWS, _covers
24
+ from .daily import _enabled, window
25
+
26
+ COLUMNS: tuple[str, ...] = (
27
+ "prs_opened",
28
+ "prs_closed",
29
+ "issues_opened",
30
+ "issues_closed",
31
+ "runs",
32
+ "jobs",
33
+ )
34
+ _ITEM_QUERIES = {
35
+ "prs_opened": ("pr", "created_at"),
36
+ "prs_closed": ("pr", "closed_at"),
37
+ "issues_opened": ("issue", "created_at"),
38
+ "issues_closed": ("issue", "closed_at"),
39
+ }
40
+ # Shares are rounded so the export stays short and stable.
41
+ _SHARE_DIGITS = 4
42
+ _RUN_METRICS = (WORKFLOWS, WORKFLOW_OUTCOMES)
43
+
44
+
45
+ def _complete(
46
+ metric: str,
47
+ repo: str,
48
+ day: date,
49
+ ranges: Sequence[DayRange],
50
+ horizon: date | None,
51
+ missing_jobs: set[tuple[str, date]],
52
+ ) -> bool:
53
+ """Whether `daily_coverage` grades ``day`` complete for ``repo`` alone."""
54
+ if not _covers(ranges, day):
55
+ return False
56
+ if metric in _RUN_METRICS and horizon is not None and day < horizon:
57
+ return False
58
+ return not (metric == WORKFLOWS and (repo, day) in missing_jobs)
59
+
60
+
61
+ @dataclass(frozen=True)
62
+ class RepositoryRow:
63
+ """One repository's counts, and per metric the share of window days covered."""
64
+
65
+ repo: str
66
+ counts: Mapping[str, int]
67
+ coverage: Mapping[str, float]
68
+
69
+ def record(self) -> dict[str, object]:
70
+ """The row as one record: ``repository``, each count and ``coverage``."""
71
+ return {"repository": self.repo, **self.counts, "coverage": dict(self.coverage)}
72
+
73
+
74
+ def build_repositories(
75
+ store: Store,
76
+ config: Config,
77
+ target: Target,
78
+ *,
79
+ until: date,
80
+ identities: ResolvedIdentities | None = None,
81
+ ) -> list[RepositoryRow]:
82
+ """The rows of ``target``'s repository table, sorted by repository.
83
+
84
+ A repository's coverage share for a metric is the number of window
85
+ days graded ``complete`` for it alone, by the rules of
86
+ `daily_coverage`, over the number of days in the window. The runs
87
+ horizon and the days missing job counts are read once for all rows.
88
+ """
89
+ if identities is None:
90
+ identities = resolve_identities(target, config)
91
+ days = window(config.window.days, until)
92
+ first, last = days[0], days[-1]
93
+ members = public_members(store, identities, owner=target.owner)
94
+ classes: dict[tuple[str | None, str | None], ActorClass | None] = {}
95
+
96
+ def counted(login: str | None, account_type: str | None) -> bool:
97
+ pair = (login, account_type)
98
+ if pair not in classes:
99
+ classes[pair] = classify(login, account_type, identities, members)
100
+ return classes[pair] is not None
101
+
102
+ scope = [set(store.in_scope(day)) for day in days]
103
+ repos = sorted(set().union(*scope))
104
+ counts: dict[str, dict[str, int]] = {
105
+ repo: dict.fromkeys(COLUMNS, 0) for repo in repos
106
+ }
107
+ for column, (kind, field) in _ITEM_QUERIES.items():
108
+ for repo, login, account_type, count in store.item_repository_counts(
109
+ kind, field, first, last
110
+ ):
111
+ if repo in counts and counted(login, account_type):
112
+ counts[repo][column] += count
113
+ for repo, login, account_type, scheduled, runs, jobs in store.run_repository_counts(
114
+ first, last
115
+ ):
116
+ if repo in counts and (scheduled or counted(login, account_type)):
117
+ counts[repo]["runs"] += runs
118
+ counts[repo]["jobs"] += jobs
119
+ metrics = _enabled(config)
120
+ horizon = runs_horizon(store, target.owner)
121
+ missing_jobs = set(store.days_missing_jobs(first, last))
122
+ rows = []
123
+ for repo in repos:
124
+ ranges = {
125
+ store_metric: store.coverage(repo, store_metric)
126
+ for store_metric in {COVERAGE_METRIC[metric] for metric in metrics}
127
+ }
128
+ in_scope = [
129
+ day for day, day_scope in zip(days, scope, strict=True) if repo in day_scope
130
+ ]
131
+ shares = {
132
+ metric: round(
133
+ sum(
134
+ _complete(
135
+ metric,
136
+ repo,
137
+ day,
138
+ ranges[COVERAGE_METRIC[metric]],
139
+ horizon,
140
+ missing_jobs,
141
+ )
142
+ for day in in_scope
143
+ )
144
+ / len(days),
145
+ _SHARE_DIGITS,
146
+ )
147
+ for metric in metrics
148
+ }
149
+ rows.append(
150
+ RepositoryRow(
151
+ repo, MappingProxyType(counts[repo]), MappingProxyType(shares)
152
+ )
153
+ )
154
+ return rows
@@ -0,0 +1,9 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ # SPDX-FileCopyrightText: 2026 The Linux Foundation
3
+ """The static site: a landing page and one page per target (design §8.5)."""
4
+
5
+ from __future__ import annotations
6
+
7
+ from .build import SiteTarget, build_site
8
+
9
+ __all__ = ["SiteTarget", "build_site"]
@@ -0,0 +1,281 @@
1
+ /* SPDX-License-Identifier: Apache-2.0 */
2
+ /* SPDX-FileCopyrightText: 2026 The Linux Foundation */
3
+
4
+ /* Colours follow the chart palette (render/palette.py). */
5
+ :root {
6
+ --background: #ffffff;
7
+ --surface: #f6f7f9;
8
+ --border: #c9d0da;
9
+ --text: #2b3140;
10
+ --muted: #6b7280;
11
+ --link: #0062a0;
12
+ --focus: #e69f00;
13
+ --member: #0072b2;
14
+ --external: #e69f00;
15
+ --org-bot: #009e73;
16
+ --external-bot: #cc79a7;
17
+ --measure: 72rem;
18
+ }
19
+
20
+ *,
21
+ *::before,
22
+ *::after {
23
+ box-sizing: border-box;
24
+ }
25
+
26
+ html {
27
+ font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue",
28
+ Arial, sans-serif;
29
+ line-height: 1.5;
30
+ color: var(--text);
31
+ background: var(--background);
32
+ }
33
+
34
+ body {
35
+ margin: 0;
36
+ }
37
+
38
+ a {
39
+ color: var(--link);
40
+ }
41
+
42
+ a:focus-visible,
43
+ input:focus-visible + label,
44
+ input:focus-visible {
45
+ outline: 3px solid var(--focus);
46
+ outline-offset: 2px;
47
+ }
48
+
49
+ code {
50
+ font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
51
+ font-size: 0.9em;
52
+ }
53
+
54
+ .wrap {
55
+ max-width: var(--measure);
56
+ margin: 0 auto;
57
+ padding: 0 1rem;
58
+ }
59
+
60
+ body > header {
61
+ border-bottom: 1px solid var(--border);
62
+ background: var(--surface);
63
+ }
64
+
65
+ body > header a {
66
+ display: inline-block;
67
+ padding: 0.75rem 0;
68
+ font-weight: 600;
69
+ text-decoration: none;
70
+ color: var(--text);
71
+ }
72
+
73
+ h1 {
74
+ margin: 1.5rem 0 0.25rem;
75
+ font-size: 1.75rem;
76
+ }
77
+
78
+ h2 {
79
+ margin: 2rem 0 0.5rem;
80
+ font-size: 1.35rem;
81
+ }
82
+
83
+ .note,
84
+ .scope,
85
+ .missing {
86
+ color: var(--muted);
87
+ }
88
+
89
+ nav {
90
+ display: flex;
91
+ flex-wrap: wrap;
92
+ gap: 0.25rem 1rem;
93
+ margin: 1rem 0;
94
+ }
95
+
96
+ /* Charts may use the full width of the window, past the reading measure. */
97
+ .chart {
98
+ display: block;
99
+ width: min(100vw - 2rem, 1920px);
100
+ margin-left: 50%;
101
+ transform: translateX(-50%);
102
+ }
103
+
104
+ .chart img {
105
+ display: block;
106
+ width: 100%;
107
+ height: auto;
108
+ }
109
+
110
+ .card {
111
+ margin: 1.5rem 0;
112
+ padding: 1rem;
113
+ border: 1px solid var(--border);
114
+ border-radius: 0.5rem;
115
+ background: var(--surface);
116
+ }
117
+
118
+ .card h2 {
119
+ margin-top: 0;
120
+ }
121
+
122
+ .card .chart {
123
+ width: 100%;
124
+ margin: 1rem 0 0;
125
+ transform: none;
126
+ }
127
+
128
+ .headline {
129
+ display: grid;
130
+ grid-template-columns: repeat(auto-fill, minmax(10rem, 1fr));
131
+ gap: 0.5rem;
132
+ margin: 0;
133
+ }
134
+
135
+ .headline div {
136
+ padding: 0.5rem;
137
+ border-radius: 0.25rem;
138
+ background: var(--background);
139
+ }
140
+
141
+ .headline dt {
142
+ font-size: 0.85rem;
143
+ color: var(--muted);
144
+ }
145
+
146
+ .headline dd {
147
+ margin: 0;
148
+ font-size: 1.25rem;
149
+ font-weight: 600;
150
+ }
151
+
152
+ /* Tabs: radio inputs and labels, one panel per input, no script. */
153
+ .tabs > input {
154
+ position: absolute;
155
+ opacity: 0;
156
+ width: 1px;
157
+ height: 1px;
158
+ }
159
+
160
+ .tabs > label {
161
+ display: inline-block;
162
+ margin: 0 0.25rem 0.25rem 0;
163
+ padding: 0.25rem 0.75rem;
164
+ border: 1px solid var(--border);
165
+ border-radius: 1rem;
166
+ cursor: pointer;
167
+ }
168
+
169
+ .tabs > input:checked + label {
170
+ border-color: var(--member);
171
+ background: var(--member);
172
+ color: #ffffff;
173
+ }
174
+
175
+ .tabs > div > div {
176
+ display: none;
177
+ margin-top: 0.5rem;
178
+ }
179
+
180
+ .tabs > input:nth-of-type(1):checked ~ div > div:nth-child(1),
181
+ .tabs > input:nth-of-type(2):checked ~ div > div:nth-child(2),
182
+ .tabs > input:nth-of-type(3):checked ~ div > div:nth-child(3),
183
+ .tabs > input:nth-of-type(4):checked ~ div > div:nth-child(4),
184
+ .tabs > input:nth-of-type(5):checked ~ div > div:nth-child(5),
185
+ .tabs > input:nth-of-type(6):checked ~ div > div:nth-child(6),
186
+ .tabs > input:nth-of-type(7):checked ~ div > div:nth-child(7) {
187
+ display: block;
188
+ }
189
+
190
+ #contributors > div,
191
+ #repositories > div {
192
+ overflow-x: auto;
193
+ }
194
+
195
+ table.data {
196
+ width: 100%;
197
+ border-collapse: collapse;
198
+ font-size: 0.9rem;
199
+ }
200
+
201
+ table.data th,
202
+ table.data td {
203
+ padding: 0.35rem 0.5rem;
204
+ border-bottom: 1px solid var(--border);
205
+ text-align: right;
206
+ white-space: nowrap;
207
+ }
208
+
209
+ table.data th:first-child,
210
+ table.data td:first-child,
211
+ table.data td:nth-child(2) {
212
+ text-align: left;
213
+ }
214
+
215
+ .filters {
216
+ margin: 0 0 0.75rem;
217
+ border: 0;
218
+ padding: 0;
219
+ }
220
+
221
+ .filters legend {
222
+ float: left;
223
+ margin-right: 0.75rem;
224
+ font-weight: 600;
225
+ }
226
+
227
+ .filters label {
228
+ margin-right: 1rem;
229
+ }
230
+
231
+ .badge {
232
+ display: inline-block;
233
+ padding: 0 0.5rem;
234
+ border-radius: 0.75rem;
235
+ font-size: 0.8rem;
236
+ color: #ffffff;
237
+ }
238
+
239
+ /* Text colours keep each badge above 4.5:1 contrast. */
240
+ tr[data-class="member"] .badge {
241
+ background: var(--member);
242
+ }
243
+
244
+ tr[data-class="external"] .badge {
245
+ background: var(--external);
246
+ color: var(--text);
247
+ }
248
+
249
+ tr[data-class="org_bot"] .badge {
250
+ background: var(--org-bot);
251
+ color: #000000;
252
+ }
253
+
254
+ tr[data-class="external_bot"] .badge {
255
+ background: var(--external-bot);
256
+ color: #000000;
257
+ }
258
+
259
+ .downloads {
260
+ columns: 12rem auto;
261
+ }
262
+
263
+ footer {
264
+ margin-top: 3rem;
265
+ padding-bottom: 2rem;
266
+ border-top: 1px solid var(--border);
267
+ font-size: 0.85rem;
268
+ color: var(--muted);
269
+ }
270
+
271
+ @media (max-width: 40rem) {
272
+ h1 {
273
+ font-size: 1.4rem;
274
+ }
275
+
276
+ .chart {
277
+ width: 100%;
278
+ margin-left: 0;
279
+ transform: none;
280
+ }
281
+ }