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.
- github_statistics/__init__.py +14 -0
- github_statistics/__main__.py +10 -0
- github_statistics/_version.py +24 -0
- github_statistics/cli/__init__.py +9 -0
- github_statistics/cli/app.py +104 -0
- github_statistics/cli/cache.py +159 -0
- github_statistics/cli/collect.py +219 -0
- github_statistics/cli/common.py +128 -0
- github_statistics/cli/config.py +80 -0
- github_statistics/cli/doctor.py +214 -0
- github_statistics/cli/export.py +111 -0
- github_statistics/cli/options.py +175 -0
- github_statistics/cli/render.py +126 -0
- github_statistics/cli/run.py +137 -0
- github_statistics/cli/scope.py +96 -0
- github_statistics/cli/site.py +150 -0
- github_statistics/client/__init__.py +40 -0
- github_statistics/client/accounting.py +99 -0
- github_statistics/client/budget.py +125 -0
- github_statistics/client/cooldown.py +113 -0
- github_statistics/client/errors.py +60 -0
- github_statistics/client/graphql.py +281 -0
- github_statistics/client/paging.py +92 -0
- github_statistics/client/policy.py +243 -0
- github_statistics/client/transport.py +437 -0
- github_statistics/collect/__init__.py +44 -0
- github_statistics/collect/common.py +69 -0
- github_statistics/collect/enrich_items.py +423 -0
- github_statistics/collect/items.py +238 -0
- github_statistics/collect/jobs.py +194 -0
- github_statistics/collect/listed.py +42 -0
- github_statistics/collect/members.py +70 -0
- github_statistics/collect/reader.py +124 -0
- github_statistics/collect/run.py +354 -0
- github_statistics/collect/runs.py +436 -0
- github_statistics/collect/slices.py +55 -0
- github_statistics/collect/steps.py +154 -0
- github_statistics/collect/sweep.py +70 -0
- github_statistics/config/__init__.py +37 -0
- github_statistics/config/loader.py +430 -0
- github_statistics/config/models.py +156 -0
- github_statistics/config/schema.py +245 -0
- github_statistics/export/__init__.py +11 -0
- github_statistics/export/csv.py +93 -0
- github_statistics/export/documents.py +189 -0
- github_statistics/export/json.py +33 -0
- github_statistics/py.typed +2 -0
- github_statistics/render/__init__.py +44 -0
- github_statistics/render/bars3d.py +420 -0
- github_statistics/render/charts.py +214 -0
- github_statistics/render/demo.py +133 -0
- github_statistics/render/images.py +31 -0
- github_statistics/render/layout.py +341 -0
- github_statistics/render/model.py +260 -0
- github_statistics/render/palette.py +41 -0
- github_statistics/scope/__init__.py +17 -0
- github_statistics/scope/apply.py +95 -0
- github_statistics/scope/resolver.py +228 -0
- github_statistics/series/__init__.py +22 -0
- github_statistics/series/actors.py +128 -0
- github_statistics/series/coverage.py +86 -0
- github_statistics/series/daily.py +229 -0
- github_statistics/series/leaderboard.py +221 -0
- github_statistics/series/repositories.py +154 -0
- github_statistics/site/__init__.py +9 -0
- github_statistics/site/assets/site.css +281 -0
- github_statistics/site/build.py +392 -0
- github_statistics/site/templates/base.html.j2 +25 -0
- github_statistics/site/templates/index.html.j2 +30 -0
- github_statistics/site/templates/macros.html.j2 +5 -0
- github_statistics/site/templates/site.js.j2 +66 -0
- github_statistics/site/templates/target.html.j2 +95 -0
- github_statistics/store/__init__.py +40 -0
- github_statistics/store/activity.py +311 -0
- github_statistics/store/aggregates.py +294 -0
- github_statistics/store/base.py +163 -0
- github_statistics/store/codec.py +263 -0
- github_statistics/store/models.py +136 -0
- github_statistics/store/paths.py +36 -0
- github_statistics/store/schema.py +169 -0
- github_statistics/store/sqlite.py +299 -0
- github_statistics-0.1.0.dist-info/METADATA +308 -0
- github_statistics-0.1.0.dist-info/RECORD +86 -0
- github_statistics-0.1.0.dist-info/WHEEL +4 -0
- github_statistics-0.1.0.dist-info/entry_points.txt +2 -0
- github_statistics-0.1.0.dist-info/licenses/LICENSE +201 -0
|
@@ -0,0 +1,420 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
# SPDX-FileCopyrightText: 2026 The Linux Foundation
|
|
3
|
+
"""The 2.5D bar chart: two rows of bars, one bar per day per row.
|
|
4
|
+
|
|
5
|
+
Each bar is three flat polygons (right side, top, front) in an oblique
|
|
6
|
+
projection. The back row is drawn before the front row, both left to
|
|
7
|
+
right, so painter ordering alone hides the right pixels and no depth
|
|
8
|
+
buffer is needed. The larger value of each day always stands in the
|
|
9
|
+
back row, so the smaller value is always visible in front.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
from collections.abc import Sequence
|
|
15
|
+
from pathlib import Path
|
|
16
|
+
|
|
17
|
+
import matplotlib
|
|
18
|
+
import matplotlib.style
|
|
19
|
+
from matplotlib.axes import Axes
|
|
20
|
+
from matplotlib.backends.backend_agg import FigureCanvasAgg
|
|
21
|
+
from matplotlib.collections import PolyCollection
|
|
22
|
+
from matplotlib.colors import to_rgb
|
|
23
|
+
from matplotlib.figure import Figure
|
|
24
|
+
|
|
25
|
+
from .layout import (
|
|
26
|
+
LEGEND_TEXT_X,
|
|
27
|
+
LEGEND_TEXT_Y,
|
|
28
|
+
NO_DATA_LABEL,
|
|
29
|
+
PARTIAL_DATA_LABEL,
|
|
30
|
+
SWATCH_DX,
|
|
31
|
+
SWATCH_DY,
|
|
32
|
+
SWATCH_HEIGHT,
|
|
33
|
+
SWATCH_WIDTH,
|
|
34
|
+
Geometry,
|
|
35
|
+
Point,
|
|
36
|
+
Polygon,
|
|
37
|
+
faces,
|
|
38
|
+
legend_box,
|
|
39
|
+
place_peak_labels,
|
|
40
|
+
plan_chart,
|
|
41
|
+
)
|
|
42
|
+
from .model import (
|
|
43
|
+
Bar,
|
|
44
|
+
ChartPlan,
|
|
45
|
+
ChartSpec,
|
|
46
|
+
Coverage,
|
|
47
|
+
PeakLabel,
|
|
48
|
+
RenderedChart,
|
|
49
|
+
Style,
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
RGB = tuple[float, float, float]
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def shade(colour: str, factor: float) -> RGB:
|
|
56
|
+
"""Scale the channels of ``colour`` by ``factor``, clamped to 1."""
|
|
57
|
+
red, green, blue = to_rgb(colour)
|
|
58
|
+
return (min(red * factor, 1.0), min(green * factor, 1.0), min(blue * factor, 1.0))
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def _px_to_pt(style: Style, pixels: float) -> float:
|
|
62
|
+
"""Convert design pixels to points, so line widths scale with ``dpi``."""
|
|
63
|
+
return pixels * 72 / style.reference_dpi
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def _draw_backdrop(ax: Axes, plan: ChartPlan, style: Style, geo: Geometry) -> None:
|
|
67
|
+
"""Draw the floor, the back wall, its gridlines and tick labels, and month furniture."""
|
|
68
|
+
floor = [
|
|
69
|
+
(geo.left, geo.bottom),
|
|
70
|
+
(geo.right, geo.bottom),
|
|
71
|
+
(geo.right + geo.floor_dx, geo.bottom + geo.floor_dy),
|
|
72
|
+
(geo.left + geo.floor_dx, geo.bottom + geo.floor_dy),
|
|
73
|
+
]
|
|
74
|
+
wall_left, wall_right = geo.left + geo.floor_dx, geo.right + geo.floor_dx
|
|
75
|
+
wall_bottom = geo.bottom + geo.floor_dy
|
|
76
|
+
wall = [
|
|
77
|
+
(wall_left, wall_bottom),
|
|
78
|
+
(wall_right, wall_bottom),
|
|
79
|
+
(wall_right, geo.top),
|
|
80
|
+
(wall_left, geo.top),
|
|
81
|
+
]
|
|
82
|
+
ax.add_collection(
|
|
83
|
+
PolyCollection(
|
|
84
|
+
[floor, wall], facecolors=[style.floor, style.wall], linewidths=0, zorder=1
|
|
85
|
+
)
|
|
86
|
+
)
|
|
87
|
+
scale = geo.scale(plan.y_max)
|
|
88
|
+
grid = [
|
|
89
|
+
[(wall_left, wall_bottom + t * scale), (wall_right, wall_bottom + t * scale)]
|
|
90
|
+
for t in plan.ticks[1:]
|
|
91
|
+
]
|
|
92
|
+
ax.add_collection(
|
|
93
|
+
_lines(
|
|
94
|
+
grid, style.gridline, _px_to_pt(style, style.gridline_width_px), zorder=2
|
|
95
|
+
)
|
|
96
|
+
)
|
|
97
|
+
for tick in plan.ticks:
|
|
98
|
+
ax.text(
|
|
99
|
+
geo.left - style.tick_label_gap,
|
|
100
|
+
wall_bottom + tick * scale,
|
|
101
|
+
f"{tick:,}",
|
|
102
|
+
ha="right",
|
|
103
|
+
va="center",
|
|
104
|
+
fontsize=style.tick_pt,
|
|
105
|
+
color=style.muted,
|
|
106
|
+
zorder=9,
|
|
107
|
+
)
|
|
108
|
+
half_gap = (geo.pitch - geo.width) / 2
|
|
109
|
+
separators = []
|
|
110
|
+
for start in plan.month_starts:
|
|
111
|
+
x = geo.left + start * geo.pitch - half_gap
|
|
112
|
+
separators.append(
|
|
113
|
+
[(x, geo.bottom), (x + geo.floor_dx, geo.bottom + geo.floor_dy)]
|
|
114
|
+
)
|
|
115
|
+
ax.add_collection(
|
|
116
|
+
_lines(
|
|
117
|
+
separators,
|
|
118
|
+
style.separator,
|
|
119
|
+
_px_to_pt(style, style.separator_width_px),
|
|
120
|
+
zorder=2,
|
|
121
|
+
)
|
|
122
|
+
)
|
|
123
|
+
for label in plan.month_labels:
|
|
124
|
+
ax.text(
|
|
125
|
+
geo.left + label.centre * geo.pitch - half_gap,
|
|
126
|
+
geo.bottom - style.month_label_gap,
|
|
127
|
+
label.text,
|
|
128
|
+
ha="center",
|
|
129
|
+
va="top",
|
|
130
|
+
fontsize=style.month_pt,
|
|
131
|
+
color=style.muted,
|
|
132
|
+
zorder=9,
|
|
133
|
+
)
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def _lines(
|
|
137
|
+
segments: list[list[Point]], colour: str, width: float, zorder: float
|
|
138
|
+
) -> PolyCollection:
|
|
139
|
+
"""Draw open polylines as a collection of unfilled polygons."""
|
|
140
|
+
return PolyCollection(
|
|
141
|
+
segments,
|
|
142
|
+
closed=False,
|
|
143
|
+
facecolors="none",
|
|
144
|
+
edgecolors=colour,
|
|
145
|
+
linewidths=width,
|
|
146
|
+
zorder=zorder,
|
|
147
|
+
)
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def _gap_colour(style: Style, coverage: Coverage) -> str:
|
|
151
|
+
"""The slab colour for a gap of ``coverage``."""
|
|
152
|
+
return style.no_data if coverage is Coverage.NONE else style.partial_data
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def _draw_gaps(ax: Axes, plan: ChartPlan, style: Style, geo: Geometry) -> int:
|
|
156
|
+
"""Draw a hatched slab, wall-high and floor-deep, over each gap span."""
|
|
157
|
+
height = geo.top - geo.bottom - geo.floor_dy
|
|
158
|
+
for span in plan.gaps:
|
|
159
|
+
x0 = geo.left + span.start * geo.pitch
|
|
160
|
+
width = (span.stop - span.start - 1) * geo.pitch + geo.width
|
|
161
|
+
colour = _gap_colour(style, span.coverage)
|
|
162
|
+
ax.add_collection(
|
|
163
|
+
PolyCollection(
|
|
164
|
+
list(faces(x0, geo.bottom, height, width, geo.floor_dx, geo.floor_dy)),
|
|
165
|
+
facecolors=[(*to_rgb(colour), style.gap_alpha)],
|
|
166
|
+
edgecolors=colour,
|
|
167
|
+
hatch=style.gap_hatch,
|
|
168
|
+
linewidths=_px_to_pt(style, style.edge_width_px),
|
|
169
|
+
zorder=3,
|
|
170
|
+
)
|
|
171
|
+
)
|
|
172
|
+
return len(plan.gaps)
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
def _bar_height(value: int, scale: float) -> float:
|
|
176
|
+
"""The pixel height of a bar of ``value``."""
|
|
177
|
+
return value * scale
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
def _drawable(spec: ChartSpec, bars: Sequence[Bar]) -> list[Bar]:
|
|
181
|
+
"""The bars of a row that are drawn: covered days with a positive value."""
|
|
182
|
+
return [
|
|
183
|
+
bar
|
|
184
|
+
for bar in bars
|
|
185
|
+
if bar.value > 0 and spec.coverage[bar.day] is Coverage.COMPLETE
|
|
186
|
+
]
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
def _draw_shadows(
|
|
190
|
+
ax: Axes, spec: ChartSpec, plan: ChartPlan, style: Style, geo: Geometry
|
|
191
|
+
) -> None:
|
|
192
|
+
"""Cast a soft, translucent shadow on the floor to the right of each bar."""
|
|
193
|
+
scale = geo.scale(plan.y_max)
|
|
194
|
+
shadows: list[Polygon] = []
|
|
195
|
+
for row, bars in ((1, plan.back), (0, plan.front)):
|
|
196
|
+
for bar in _drawable(spec, bars):
|
|
197
|
+
x0, y0 = geo.bar_origin(bar.day, row)
|
|
198
|
+
length = min(
|
|
199
|
+
style.shadow_ratio * _bar_height(bar.value, scale),
|
|
200
|
+
style.shadow_max_pitch * geo.pitch,
|
|
201
|
+
)
|
|
202
|
+
x1 = x0 + geo.width
|
|
203
|
+
shadows.append(
|
|
204
|
+
[
|
|
205
|
+
(x1, y0),
|
|
206
|
+
(x1 + length, y0),
|
|
207
|
+
(x1 + length + geo.dx, y0 + geo.dy),
|
|
208
|
+
(x1 + geo.dx, y0 + geo.dy),
|
|
209
|
+
]
|
|
210
|
+
)
|
|
211
|
+
ax.add_collection(
|
|
212
|
+
PolyCollection(shadows, facecolors=[style.shadow_rgba], linewidths=0, zorder=4)
|
|
213
|
+
)
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
def _draw_rows(
|
|
217
|
+
ax: Axes, spec: ChartSpec, plan: ChartPlan, style: Style, geo: Geometry
|
|
218
|
+
) -> int:
|
|
219
|
+
"""Draw the back row, then the front row, each left to right; return the polygon count."""
|
|
220
|
+
colours = {spec.first.key: spec.first.colour, spec.second.key: spec.second.colour}
|
|
221
|
+
scale = geo.scale(plan.y_max)
|
|
222
|
+
factors = (style.side_shade, style.top_shade, style.front_shade)
|
|
223
|
+
count = 0
|
|
224
|
+
for row, bars in ((1, plan.back), (0, plan.front)):
|
|
225
|
+
polygons: list[Polygon] = []
|
|
226
|
+
fills: list[RGB] = []
|
|
227
|
+
edges: list[RGB] = []
|
|
228
|
+
for bar in _drawable(spec, bars):
|
|
229
|
+
x0, y0 = geo.bar_origin(bar.day, row)
|
|
230
|
+
base = colours[bar.series]
|
|
231
|
+
for polygon, factor in zip(
|
|
232
|
+
faces(x0, y0, _bar_height(bar.value, scale), geo.width, geo.dx, geo.dy),
|
|
233
|
+
factors,
|
|
234
|
+
strict=True,
|
|
235
|
+
):
|
|
236
|
+
polygons.append(polygon)
|
|
237
|
+
fills.append(shade(base, factor))
|
|
238
|
+
edges.append(shade(base, style.edge_shade))
|
|
239
|
+
ax.add_collection(
|
|
240
|
+
PolyCollection(
|
|
241
|
+
polygons,
|
|
242
|
+
facecolors=fills,
|
|
243
|
+
edgecolors=edges,
|
|
244
|
+
linewidths=_px_to_pt(style, style.edge_width_px),
|
|
245
|
+
zorder=5 + (1 - row),
|
|
246
|
+
)
|
|
247
|
+
)
|
|
248
|
+
count += len(polygons)
|
|
249
|
+
return count
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
def _draw_peaks(ax: Axes, labels: Sequence[PeakLabel], style: Style) -> None:
|
|
253
|
+
"""Draw each series' peak label at its planned position."""
|
|
254
|
+
for label in labels:
|
|
255
|
+
ax.text(
|
|
256
|
+
label.x,
|
|
257
|
+
label.y,
|
|
258
|
+
label.text,
|
|
259
|
+
ha="center",
|
|
260
|
+
va="bottom",
|
|
261
|
+
fontsize=style.annotation_pt,
|
|
262
|
+
color=style.text,
|
|
263
|
+
zorder=9,
|
|
264
|
+
)
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
def _swatch(
|
|
268
|
+
ax: Axes, x: float, y: float, colour: str, style: Style, *, hatch: str | None = None
|
|
269
|
+
) -> None:
|
|
270
|
+
"""Draw a small 3D bar as a legend swatch with its front-bottom-left corner at ``(x, y)``."""
|
|
271
|
+
polygons = list(faces(x, y, SWATCH_HEIGHT, SWATCH_WIDTH, SWATCH_DX, SWATCH_DY))
|
|
272
|
+
if hatch is None:
|
|
273
|
+
fills = [
|
|
274
|
+
shade(colour, f)
|
|
275
|
+
for f in (style.side_shade, style.top_shade, style.front_shade)
|
|
276
|
+
]
|
|
277
|
+
ax.add_collection(
|
|
278
|
+
PolyCollection(
|
|
279
|
+
polygons,
|
|
280
|
+
facecolors=fills,
|
|
281
|
+
edgecolors=[shade(colour, style.edge_shade)],
|
|
282
|
+
linewidths=_px_to_pt(style, style.edge_width_px),
|
|
283
|
+
zorder=9,
|
|
284
|
+
)
|
|
285
|
+
)
|
|
286
|
+
else:
|
|
287
|
+
ax.add_collection(
|
|
288
|
+
PolyCollection(
|
|
289
|
+
polygons,
|
|
290
|
+
facecolors=[(*to_rgb(colour), style.gap_alpha)],
|
|
291
|
+
edgecolors=colour,
|
|
292
|
+
hatch=hatch,
|
|
293
|
+
linewidths=_px_to_pt(style, style.edge_width_px),
|
|
294
|
+
zorder=9,
|
|
295
|
+
)
|
|
296
|
+
)
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
def _draw_legend(ax: Axes, spec: ChartSpec, plan: ChartPlan, style: Style) -> None:
|
|
300
|
+
"""List the series and any gap kinds at the top right, each with a 3D swatch."""
|
|
301
|
+
entries: list[tuple[str, str, str | None]] = [
|
|
302
|
+
(spec.first.label, spec.first.colour, None),
|
|
303
|
+
(spec.second.label, spec.second.colour, None),
|
|
304
|
+
]
|
|
305
|
+
if NO_DATA_LABEL in plan.legend:
|
|
306
|
+
entries.append((NO_DATA_LABEL, style.no_data, style.gap_hatch))
|
|
307
|
+
if PARTIAL_DATA_LABEL in plan.legend:
|
|
308
|
+
entries.append((PARTIAL_DATA_LABEL, style.partial_data, style.gap_hatch))
|
|
309
|
+
for index, (label, colour, hatch) in enumerate(entries):
|
|
310
|
+
y = style.legend_y - index * style.legend_step
|
|
311
|
+
_swatch(ax, style.legend_x, y, colour, style, hatch=hatch)
|
|
312
|
+
ax.text(
|
|
313
|
+
style.legend_x + LEGEND_TEXT_X,
|
|
314
|
+
y + LEGEND_TEXT_Y,
|
|
315
|
+
label,
|
|
316
|
+
ha="left",
|
|
317
|
+
va="center",
|
|
318
|
+
fontsize=style.legend_pt,
|
|
319
|
+
color=style.text,
|
|
320
|
+
zorder=9,
|
|
321
|
+
)
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
def _draw_text(ax: Axes, spec: ChartSpec, style: Style) -> None:
|
|
325
|
+
"""Place the title, subtitle and footer."""
|
|
326
|
+
ax.text(
|
|
327
|
+
style.text_x,
|
|
328
|
+
style.title_y,
|
|
329
|
+
spec.title,
|
|
330
|
+
ha="left",
|
|
331
|
+
va="top",
|
|
332
|
+
fontsize=style.title_pt,
|
|
333
|
+
fontweight="bold",
|
|
334
|
+
color=style.text,
|
|
335
|
+
)
|
|
336
|
+
ax.text(
|
|
337
|
+
style.text_x,
|
|
338
|
+
style.subtitle_y,
|
|
339
|
+
spec.subtitle,
|
|
340
|
+
ha="left",
|
|
341
|
+
va="top",
|
|
342
|
+
fontsize=style.subtitle_pt,
|
|
343
|
+
color=style.muted,
|
|
344
|
+
)
|
|
345
|
+
ax.text(
|
|
346
|
+
style.text_x,
|
|
347
|
+
style.footer_y,
|
|
348
|
+
spec.footer,
|
|
349
|
+
ha="left",
|
|
350
|
+
va="bottom",
|
|
351
|
+
fontsize=style.footer_pt,
|
|
352
|
+
color=style.muted,
|
|
353
|
+
)
|
|
354
|
+
|
|
355
|
+
|
|
356
|
+
def render_chart(
|
|
357
|
+
spec: ChartSpec, path: Path, *, style: Style = Style()
|
|
358
|
+
) -> RenderedChart:
|
|
359
|
+
"""Render ``spec`` to a PNG at ``path`` and report what was drawn.
|
|
360
|
+
|
|
361
|
+
The file is always a PNG written at exactly ``path``; its suffix
|
|
362
|
+
neither selects the format nor gains a ``.png``.
|
|
363
|
+
|
|
364
|
+
Uses the Agg canvas directly, without ``pyplot``, so no global
|
|
365
|
+
backend or figure state changes. Renders start from matplotlib's
|
|
366
|
+
default settings, so a caller's rcParams or matplotlibrc (a tight
|
|
367
|
+
``savefig.bbox``, say) cannot change the output. Two renders of one
|
|
368
|
+
spec and style produce identical bytes.
|
|
369
|
+
"""
|
|
370
|
+
plan = plan_chart(spec, style)
|
|
371
|
+
geo = Geometry.build(style, len(spec.days))
|
|
372
|
+
legend = legend_box(plan.legend, style)
|
|
373
|
+
labels = place_peak_labels(spec, plan, style, legend)
|
|
374
|
+
width_in = style.canvas_width / style.reference_dpi
|
|
375
|
+
height_in = style.canvas_height / style.reference_dpi
|
|
376
|
+
with (
|
|
377
|
+
matplotlib.style.context("default"),
|
|
378
|
+
matplotlib.rc_context(
|
|
379
|
+
{
|
|
380
|
+
"font.family": style.font_family,
|
|
381
|
+
"hatch.linewidth": style.hatch_width_pt,
|
|
382
|
+
"savefig.bbox": "standard",
|
|
383
|
+
}
|
|
384
|
+
),
|
|
385
|
+
):
|
|
386
|
+
figure = Figure(
|
|
387
|
+
figsize=(width_in, height_in), dpi=style.dpi, facecolor=style.background
|
|
388
|
+
)
|
|
389
|
+
FigureCanvasAgg(figure)
|
|
390
|
+
ax = figure.add_axes((0.0, 0.0, 1.0, 1.0))
|
|
391
|
+
ax.set_xlim(0, style.canvas_width)
|
|
392
|
+
ax.set_ylim(0, style.canvas_height)
|
|
393
|
+
ax.set_axis_off()
|
|
394
|
+
_draw_backdrop(ax, plan, style, geo)
|
|
395
|
+
slabs = _draw_gaps(ax, plan, style, geo)
|
|
396
|
+
_draw_shadows(ax, spec, plan, style, geo)
|
|
397
|
+
polygons = _draw_rows(ax, spec, plan, style, geo)
|
|
398
|
+
_draw_peaks(ax, labels, style)
|
|
399
|
+
_draw_legend(ax, spec, plan, style)
|
|
400
|
+
_draw_text(ax, spec, style)
|
|
401
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
402
|
+
figure.savefig(
|
|
403
|
+
path,
|
|
404
|
+
format="png",
|
|
405
|
+
dpi=style.dpi,
|
|
406
|
+
facecolor=style.background,
|
|
407
|
+
metadata={"Software": None},
|
|
408
|
+
)
|
|
409
|
+
width, height = (round(v) for v in figure.get_size_inches() * style.dpi)
|
|
410
|
+
return RenderedChart(
|
|
411
|
+
path=path,
|
|
412
|
+
width=width,
|
|
413
|
+
height=height,
|
|
414
|
+
plan=plan,
|
|
415
|
+
bar_polygons=polygons,
|
|
416
|
+
gap_slabs=slabs,
|
|
417
|
+
legend=plan.legend,
|
|
418
|
+
legend_box=legend,
|
|
419
|
+
peak_labels=labels,
|
|
420
|
+
)
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
# SPDX-FileCopyrightText: 2026 The Linux Foundation
|
|
3
|
+
"""The charts of one target, from its daily series (design §8.4).
|
|
4
|
+
|
|
5
|
+
One chart per enabled metric and per view in ``classes``, written as
|
|
6
|
+
``<out>/<owner>/img/<metric>-<class>.png`` with one derivative per
|
|
7
|
+
width in ``render.derivatives``. Reads no store and no clock: the
|
|
8
|
+
generation date comes from the ``now`` argument, so two renders on one
|
|
9
|
+
day give identical files.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
from collections.abc import Sequence
|
|
15
|
+
from dataclasses import dataclass
|
|
16
|
+
from datetime import datetime
|
|
17
|
+
from pathlib import Path
|
|
18
|
+
from typing import TYPE_CHECKING
|
|
19
|
+
|
|
20
|
+
from github_statistics import __version__
|
|
21
|
+
|
|
22
|
+
from ..store import path_component
|
|
23
|
+
from .bars3d import render_chart
|
|
24
|
+
from .images import write_derivatives
|
|
25
|
+
from .model import ChartSpec, Coverage, RenderedChart, Series, Style
|
|
26
|
+
from .palette import series_colour
|
|
27
|
+
|
|
28
|
+
if TYPE_CHECKING:
|
|
29
|
+
from ..config import Config, Target
|
|
30
|
+
from ..series import TargetSeries
|
|
31
|
+
|
|
32
|
+
_GLOB = frozenset("*?[")
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@dataclass(frozen=True)
|
|
36
|
+
class _Metric:
|
|
37
|
+
"""How one metric's chart is titled and which two series it draws."""
|
|
38
|
+
|
|
39
|
+
name: str
|
|
40
|
+
title: str
|
|
41
|
+
first: str
|
|
42
|
+
second: str
|
|
43
|
+
back_on_tie: str
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
_METRICS = (
|
|
47
|
+
_Metric("pull_requests", "pull requests per day", "opened", "closed", "closed"),
|
|
48
|
+
_Metric("issues", "issues per day", "opened", "closed", "closed"),
|
|
49
|
+
_Metric("workflows", "workflow runs and jobs per day", "runs", "jobs", "jobs"),
|
|
50
|
+
_Metric(
|
|
51
|
+
"workflow_outcomes",
|
|
52
|
+
"workflow outcomes per day",
|
|
53
|
+
"succeeded",
|
|
54
|
+
"failed",
|
|
55
|
+
"failed",
|
|
56
|
+
),
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
VIEW_LABELS = {
|
|
60
|
+
"all": "everyone",
|
|
61
|
+
"member": "members",
|
|
62
|
+
"external": "external contributors",
|
|
63
|
+
"org_bot": "our bots",
|
|
64
|
+
"external_bot": "external bots",
|
|
65
|
+
"humans": "humans",
|
|
66
|
+
"bots": "bots",
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
@dataclass(frozen=True)
|
|
71
|
+
class TargetChart:
|
|
72
|
+
"""One chart of a target: what it showed and the files it wrote."""
|
|
73
|
+
|
|
74
|
+
metric: str
|
|
75
|
+
view: str
|
|
76
|
+
spec: ChartSpec
|
|
77
|
+
chart: RenderedChart
|
|
78
|
+
derivatives: tuple[Path, ...]
|
|
79
|
+
|
|
80
|
+
@property
|
|
81
|
+
def paths(self) -> tuple[Path, ...]:
|
|
82
|
+
"""The master, then each derivative."""
|
|
83
|
+
return (self.chart.path, *self.derivatives)
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def _style(width: int, height: int) -> Style:
|
|
87
|
+
"""The default style rendered at ``width`` by ``height`` pixels.
|
|
88
|
+
|
|
89
|
+
The renderer's geometry is fixed on its design canvas, so only the
|
|
90
|
+
raster size changes, and only by a whole number of dots per inch.
|
|
91
|
+
"""
|
|
92
|
+
base = Style()
|
|
93
|
+
dpi, remainder = divmod(base.reference_dpi * width, base.canvas_width)
|
|
94
|
+
if remainder or width * base.canvas_height != height * base.canvas_width or not dpi:
|
|
95
|
+
raise ValueError(
|
|
96
|
+
f"render size {width}x{height} must be a multiple of"
|
|
97
|
+
f" {base.canvas_width // base.reference_dpi}x"
|
|
98
|
+
f"{base.canvas_height // base.reference_dpi}"
|
|
99
|
+
)
|
|
100
|
+
return Style(dpi=dpi)
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def _subject(target: Target) -> str:
|
|
104
|
+
"""The owner, or ``owner/repo`` for a target that selects one repository."""
|
|
105
|
+
if len(target.include) == 1 and not _GLOB & set(target.include[0]):
|
|
106
|
+
return f"{target.owner}/{target.include[0]}"
|
|
107
|
+
return target.owner
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def _count(count: int, one: str, many: str) -> str:
|
|
111
|
+
"""``1 <one>`` or ``<count> <many>``."""
|
|
112
|
+
return f"{count} {one if count == 1 else many}"
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def _days(count: int) -> str:
|
|
116
|
+
"""``1 day`` or ``<count> days``."""
|
|
117
|
+
return _count(count, "day", "days")
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def _footer(coverage: Sequence[Coverage], now: datetime) -> str:
|
|
121
|
+
"""Coverage in words, the tool version and the generation date."""
|
|
122
|
+
complete = sum(day is Coverage.COMPLETE for day in coverage)
|
|
123
|
+
missing = sum(day is Coverage.NONE for day in coverage)
|
|
124
|
+
parts = [f"Coverage: {complete} of {_days(len(coverage))} complete"]
|
|
125
|
+
if missing:
|
|
126
|
+
parts.append(f"{_days(missing)} without data")
|
|
127
|
+
parts.append(f"github-statistics {__version__}")
|
|
128
|
+
parts.append(f"generated {now.date().isoformat()}")
|
|
129
|
+
return " · ".join(parts)
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def _series(
|
|
133
|
+
series: TargetSeries, config: Config, metric: str, key: str, view: str
|
|
134
|
+
) -> Series:
|
|
135
|
+
"""One series of a chart, coloured by the palette or its override."""
|
|
136
|
+
return Series(
|
|
137
|
+
key=key,
|
|
138
|
+
label=key.capitalize(),
|
|
139
|
+
colour=config.render.palette.get(key) or series_colour(key),
|
|
140
|
+
values=series.values(metric, key, view),
|
|
141
|
+
)
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def render_target(
|
|
145
|
+
series: TargetSeries,
|
|
146
|
+
config: Config,
|
|
147
|
+
target: Target,
|
|
148
|
+
out_dir: Path,
|
|
149
|
+
*,
|
|
150
|
+
now: datetime,
|
|
151
|
+
) -> list[TargetChart]:
|
|
152
|
+
"""Render every chart of ``target`` under ``out_dir`` and return them in order.
|
|
153
|
+
|
|
154
|
+
Metrics run in a fixed order (pull requests, issues, workflows,
|
|
155
|
+
workflow outcomes), each over the views in ``config.classes``. A
|
|
156
|
+
metric off in ``config.metrics`` renders nothing; a view with no
|
|
157
|
+
events still renders. ``render.svg`` raises `ValueError` before any
|
|
158
|
+
file is written: the renderer draws PNG alone, and a partial output
|
|
159
|
+
must not pass for the one configured. So does a width in
|
|
160
|
+
``render.derivatives`` outside ``1..render.width``, which would
|
|
161
|
+
otherwise fail after the first charts were written.
|
|
162
|
+
"""
|
|
163
|
+
if config.render.svg:
|
|
164
|
+
raise ValueError(
|
|
165
|
+
"render.svg is not supported yet: the renderer writes PNG only;"
|
|
166
|
+
" turn render.svg off"
|
|
167
|
+
)
|
|
168
|
+
style = _style(config.render.width, config.render.height)
|
|
169
|
+
oversized = [
|
|
170
|
+
width
|
|
171
|
+
for width in config.render.derivatives
|
|
172
|
+
if not 0 < width <= config.render.width
|
|
173
|
+
]
|
|
174
|
+
if oversized:
|
|
175
|
+
raise ValueError(
|
|
176
|
+
f"render.derivatives {', '.join(map(str, oversized))} must lie"
|
|
177
|
+
f" within 1..{config.render.width}, the render.width of the master"
|
|
178
|
+
)
|
|
179
|
+
images = Path(out_dir) / path_component(target.owner, "owner") / "img"
|
|
180
|
+
subject = _subject(target)
|
|
181
|
+
window = f"{_days(len(series.days))} to {series.days[-1].isoformat()} (UTC)"
|
|
182
|
+
repositories = _count(series.repositories[-1], "repository", "repositories")
|
|
183
|
+
charts: list[TargetChart] = []
|
|
184
|
+
for metric in _METRICS:
|
|
185
|
+
if not getattr(config.metrics, metric.name):
|
|
186
|
+
continue
|
|
187
|
+
coverage = series.coverage[metric.name]
|
|
188
|
+
footer = _footer(coverage, now)
|
|
189
|
+
back = getattr(config.render.back_on_tie, metric.name, metric.back_on_tie)
|
|
190
|
+
for view in config.classes:
|
|
191
|
+
spec = ChartSpec(
|
|
192
|
+
title=f"{subject} — {metric.title}",
|
|
193
|
+
subtitle=" · ".join(
|
|
194
|
+
(
|
|
195
|
+
window,
|
|
196
|
+
repositories,
|
|
197
|
+
VIEW_LABELS[view],
|
|
198
|
+
f"{metric.first} vs {metric.second}",
|
|
199
|
+
)
|
|
200
|
+
),
|
|
201
|
+
footer=footer,
|
|
202
|
+
days=series.days,
|
|
203
|
+
first=_series(series, config, metric.name, metric.first, view),
|
|
204
|
+
second=_series(series, config, metric.name, metric.second, view),
|
|
205
|
+
coverage=coverage,
|
|
206
|
+
back_on_tie=back,
|
|
207
|
+
)
|
|
208
|
+
stem = f"{metric.name}-{view}".replace("_", "-")
|
|
209
|
+
chart = render_chart(spec, images / f"{stem}.png", style=style)
|
|
210
|
+
derivatives = write_derivatives(chart.path, config.render.derivatives)
|
|
211
|
+
charts.append(
|
|
212
|
+
TargetChart(metric.name, view, spec, chart, tuple(derivatives))
|
|
213
|
+
)
|
|
214
|
+
return charts
|