codeyear 0.2.14__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.
- codeyear/__init__.py +3 -0
- codeyear/__main__.py +6 -0
- codeyear/card.py +720 -0
- codeyear/cli.py +450 -0
- codeyear/config.py +114 -0
- codeyear/github_public.py +590 -0
- codeyear/gui.py +960 -0
- codeyear/html_report.py +1663 -0
- codeyear/i18n.py +345 -0
- codeyear/keywords.py +98 -0
- codeyear/languages.py +132 -0
- codeyear/personas.py +171 -0
- codeyear/poster.py +992 -0
- codeyear/profile.py +180 -0
- codeyear/report_theme.py +890 -0
- codeyear/runner.py +304 -0
- codeyear/scanner.py +491 -0
- codeyear/server.py +293 -0
- codeyear/stats.py +736 -0
- codeyear/updater.py +238 -0
- codeyear/wizard.py +221 -0
- codeyear-0.2.14.dist-info/METADATA +559 -0
- codeyear-0.2.14.dist-info/RECORD +27 -0
- codeyear-0.2.14.dist-info/WHEEL +5 -0
- codeyear-0.2.14.dist-info/entry_points.txt +5 -0
- codeyear-0.2.14.dist-info/licenses/LICENSE +21 -0
- codeyear-0.2.14.dist-info/top_level.txt +1 -0
codeyear/html_report.py
ADDED
|
@@ -0,0 +1,1663 @@
|
|
|
1
|
+
"""Render the CodeYear annual report as an "engineering field-notes" page.
|
|
2
|
+
|
|
3
|
+
Design: warm paper background, ink text, one vermilion accent, serif display
|
|
4
|
+
+ mono data, visible hairlines, square corners. Every number on the page comes
|
|
5
|
+
from the runner's own git history; nothing is uploaded anywhere.
|
|
6
|
+
|
|
7
|
+
Pure vanilla JS (no dependencies): scroll progress, live clock, reveal-on-scroll,
|
|
8
|
+
count-up numbers, a real commit ticker, and an index-table filter. Honors
|
|
9
|
+
``prefers-reduced-motion``.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
import json
|
|
15
|
+
from datetime import date, datetime, timedelta
|
|
16
|
+
from html import escape
|
|
17
|
+
from pathlib import Path
|
|
18
|
+
|
|
19
|
+
from .card import THEMES as CARD_THEMES
|
|
20
|
+
from .card import build_svg as build_card_svg
|
|
21
|
+
from .stats import (
|
|
22
|
+
ReportStats,
|
|
23
|
+
date_window,
|
|
24
|
+
fmt_human,
|
|
25
|
+
fmt_int,
|
|
26
|
+
language_breakdown,
|
|
27
|
+
parse_daily,
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
CSS = r"""
|
|
31
|
+
:root{
|
|
32
|
+
--paper:#f4f1e8; --paper2:#eceadf; --ink:#171512; --ink2:#403c33;
|
|
33
|
+
--muted:#6f6a5e; --line:#d9d3c2; --line2:#c8c1ac;
|
|
34
|
+
--acc:#d4491f; --acc2:#b23a15;
|
|
35
|
+
--serif:Georgia,"Times New Roman","Songti SC","SimSun","Noto Serif CJK SC",serif;
|
|
36
|
+
--sans:-apple-system,BlinkMacSystemFont,"Segoe UI","Microsoft YaHei","PingFang SC",sans-serif;
|
|
37
|
+
--mono:"Cascadia Mono",Consolas,"SFMono-Regular",Menlo,monospace;
|
|
38
|
+
--ease:cubic-bezier(.22,1,.36,1);
|
|
39
|
+
}
|
|
40
|
+
*{box-sizing:border-box}
|
|
41
|
+
html{scroll-behavior:smooth}
|
|
42
|
+
body{margin:0;background:var(--paper);color:var(--ink);font-family:var(--sans);
|
|
43
|
+
font-size:15px;line-height:1.7;-webkit-font-smoothing:antialiased}
|
|
44
|
+
::selection{background:var(--acc);color:var(--paper)}
|
|
45
|
+
body::before{content:"";position:fixed;inset:0;pointer-events:none;z-index:0;opacity:.5;
|
|
46
|
+
background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 .035 0'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)'/%3E%3C/svg%3E")}
|
|
47
|
+
body::after{content:"";position:fixed;inset:0;pointer-events:none;z-index:0;opacity:.55;
|
|
48
|
+
background-image:linear-gradient(var(--line) 1px,transparent 1px);
|
|
49
|
+
background-size:100% 220px;
|
|
50
|
+
mask-image:linear-gradient(180deg,transparent,#000 140px,#000 calc(100% - 200px),transparent)}
|
|
51
|
+
.wrap{max-width:1160px;margin:0 auto;padding:0 28px;position:relative;z-index:1}
|
|
52
|
+
a{color:inherit}
|
|
53
|
+
h1,h2,h3{margin:0;font-weight:600}
|
|
54
|
+
|
|
55
|
+
#progress{position:fixed;top:0;left:0;height:2px;width:0;background:var(--acc);z-index:99}
|
|
56
|
+
header{position:sticky;top:0;z-index:50;background:rgba(244,241,232,.88);
|
|
57
|
+
backdrop-filter:blur(10px);border-bottom:1px solid var(--line)}
|
|
58
|
+
.nav{max-width:1160px;margin:0 auto;padding:0 28px;height:58px;display:flex;
|
|
59
|
+
align-items:center;justify-content:space-between;gap:24px}
|
|
60
|
+
.logo{font-family:var(--mono);font-size:13px;letter-spacing:.22em;text-decoration:none;
|
|
61
|
+
display:inline-flex;align-items:center;gap:9px}
|
|
62
|
+
.logo i{width:9px;height:9px;background:var(--acc);display:inline-block}
|
|
63
|
+
.nav-links{display:flex;gap:22px}
|
|
64
|
+
.nav-links a{color:var(--ink2);text-decoration:none;font-family:var(--mono);font-size:12px}
|
|
65
|
+
.nav-meta{display:flex;align-items:center;gap:16px;font-family:var(--mono);font-size:11px;
|
|
66
|
+
color:var(--muted)}
|
|
67
|
+
.badge{border:1px solid var(--ink);padding:5px 11px;font-size:10px;letter-spacing:.1em;
|
|
68
|
+
color:var(--ink)}
|
|
69
|
+
|
|
70
|
+
.u{color:var(--ink);text-decoration:none;
|
|
71
|
+
background:linear-gradient(var(--acc),var(--acc)) no-repeat 0 100%/0 2px;
|
|
72
|
+
transition:background-size .35s var(--ease);padding-bottom:2px}
|
|
73
|
+
.u:hover{background-size:100% 2px}
|
|
74
|
+
|
|
75
|
+
.hero{padding:84px 0 60px;display:grid;grid-template-columns:1.25fr .75fr;gap:48px;align-items:end}
|
|
76
|
+
.kicker{font-family:var(--mono);font-size:11px;letter-spacing:.2em;color:var(--acc);margin:0 0 22px;
|
|
77
|
+
overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
78
|
+
h1{font-family:var(--serif);font-size:clamp(44px,6vw,78px);line-height:1.08;
|
|
79
|
+
letter-spacing:-.02em}
|
|
80
|
+
h1 em{font-style:normal;color:var(--acc)}
|
|
81
|
+
.lede{margin:26px 0 0;font-size:16px;line-height:1.85;color:var(--ink2);max-width:600px}
|
|
82
|
+
.lede b{color:var(--ink);font-weight:600}
|
|
83
|
+
.hero-stats{display:grid;grid-template-columns:1fr 1fr;border-left:1px solid var(--line)}
|
|
84
|
+
.hs{padding:18px 20px;border-bottom:1px solid var(--line)}
|
|
85
|
+
.hs:nth-child(odd){border-right:1px solid var(--line)}
|
|
86
|
+
.hs:nth-last-child(-n+2){border-bottom:0}
|
|
87
|
+
.hs b{display:block;font-family:var(--mono);font-size:29px;font-weight:500;
|
|
88
|
+
letter-spacing:-.02em;font-variant-numeric:tabular-nums}
|
|
89
|
+
.hs span{font-size:11px;color:var(--muted);font-family:var(--mono);letter-spacing:.06em}
|
|
90
|
+
.scroll-hint{font-family:var(--mono);font-size:10px;letter-spacing:.24em;color:var(--muted);
|
|
91
|
+
margin-top:26px;display:flex;align-items:center;gap:12px}
|
|
92
|
+
.scroll-hint::after{content:"";flex:1;height:1px;background:var(--line)}
|
|
93
|
+
|
|
94
|
+
.ticker{border-top:1px solid var(--ink);border-bottom:1px solid var(--ink);background:var(--ink);
|
|
95
|
+
color:var(--paper);overflow:hidden;position:relative;z-index:1}
|
|
96
|
+
.ticker-inner{display:flex;align-items:center;height:46px}
|
|
97
|
+
.tick-label{flex:none;padding:0 18px;border-right:1px solid rgba(244,241,232,.25);
|
|
98
|
+
font-family:var(--mono);font-size:10px;letter-spacing:.18em;display:flex;align-items:center;
|
|
99
|
+
gap:8px;height:100%}
|
|
100
|
+
.tick-label i{width:7px;height:7px;border-radius:50%;background:var(--acc);
|
|
101
|
+
animation:pulse 1.6s ease-in-out infinite}
|
|
102
|
+
@keyframes pulse{50%{opacity:.25}}
|
|
103
|
+
.tick-viewport{flex:1;overflow:hidden;height:100%;display:flex;align-items:center;
|
|
104
|
+
mask-image:linear-gradient(90deg,transparent,#000 40px,#000 calc(100% - 40px),transparent)}
|
|
105
|
+
.tick-track{display:flex;gap:44px;width:max-content;animation:tick 70s linear infinite;
|
|
106
|
+
padding-left:44px}
|
|
107
|
+
.ticker:hover .tick-track{animation-play-state:paused}
|
|
108
|
+
@keyframes tick{to{transform:translateX(-50%)}}
|
|
109
|
+
.tick-item{display:flex;align-items:baseline;gap:10px;font-size:12.5px;white-space:nowrap}
|
|
110
|
+
.tick-item b{font-family:var(--mono);font-size:10px;color:var(--acc);font-weight:500}
|
|
111
|
+
|
|
112
|
+
section{padding:86px 0 0;scroll-margin-top:70px}
|
|
113
|
+
.sec-head{display:flex;align-items:baseline;justify-content:space-between;gap:20px;
|
|
114
|
+
flex-wrap:wrap;border-bottom:2px solid var(--ink);padding-bottom:14px;margin-bottom:8px}
|
|
115
|
+
.sec-index{font-family:var(--mono);font-size:10px;letter-spacing:.24em;color:var(--acc)}
|
|
116
|
+
.sec-head h2{font-family:var(--serif);font-size:34px;letter-spacing:-.01em}
|
|
117
|
+
.sec-sub{color:var(--muted);font-size:13.5px;font-family:var(--mono)}
|
|
118
|
+
.sec-line{height:2px;background:var(--ink);transform:scaleX(0);transform-origin:left;
|
|
119
|
+
transition:transform .9s var(--ease) .1s}
|
|
120
|
+
.sec-line.in{transform:scaleX(1)}
|
|
121
|
+
|
|
122
|
+
.archive{display:grid;grid-template-columns:.92fr 1.08fr;gap:40px;padding:42px 0;
|
|
123
|
+
border-bottom:1px solid var(--line)}
|
|
124
|
+
.archive.flip .plate-wrap{order:2}
|
|
125
|
+
.plate-wrap{display:flex;flex-direction:column;gap:12px}
|
|
126
|
+
.plate{border:1px solid var(--ink);background:var(--paper2);padding:22px;flex:1}
|
|
127
|
+
.plate .big{display:flex;gap:26px;flex-wrap:wrap}
|
|
128
|
+
.plate .big b{display:block;font-family:var(--mono);font-size:26px;font-weight:500;
|
|
129
|
+
letter-spacing:-.01em;font-variant-numeric:tabular-nums}
|
|
130
|
+
.plate .big span{font-size:10.5px;color:var(--muted);font-family:var(--mono)}
|
|
131
|
+
.plate .langs{display:flex;gap:6px;flex-wrap:wrap;margin:16px 0 4px}
|
|
132
|
+
.plate .langs span{font-size:10.5px;font-family:var(--mono);border:1px solid var(--line2);
|
|
133
|
+
padding:3px 8px;color:var(--ink2);background:var(--paper)}
|
|
134
|
+
.plate .rec{margin-top:14px;font-family:var(--mono);font-size:11px;line-height:1.9;color:var(--ink2)}
|
|
135
|
+
.plate .rec b{color:var(--acc);font-weight:500;font-size:10px;margin-right:8px}
|
|
136
|
+
.plate .rec div{border-top:1px dashed var(--line2);padding:6px 0}
|
|
137
|
+
.case-top{display:flex;align-items:center;justify-content:space-between;margin-bottom:14px}
|
|
138
|
+
.case-no{font-family:var(--mono);font-size:12px;color:var(--acc);letter-spacing:.14em}
|
|
139
|
+
.stamp{font-family:var(--mono);font-size:10px;letter-spacing:.14em;border:1px solid var(--ink);
|
|
140
|
+
padding:4px 10px;display:inline-flex;align-items:center;gap:7px}
|
|
141
|
+
.stamp i{width:6px;height:6px;background:var(--acc);display:inline-block}
|
|
142
|
+
.stamp.sleep i{background:var(--muted)}
|
|
143
|
+
.archive h3{font-family:var(--serif);font-size:29px;letter-spacing:-.01em;margin-bottom:12px}
|
|
144
|
+
.readme-quote{border-left:2px solid var(--acc);padding:4px 0 4px 14px;color:var(--ink2);
|
|
145
|
+
font-size:14px;margin:0 0 18px;font-style:italic}
|
|
146
|
+
.how{list-style:none;margin:0 0 20px;padding:0;font-family:var(--mono);font-size:12.5px;line-height:1.6}
|
|
147
|
+
.how li{padding:9px 0 9px 20px;border-top:1px dashed var(--line2);position:relative;color:var(--ink2)}
|
|
148
|
+
.how li::before{content:"—";position:absolute;left:0;color:var(--acc)}
|
|
149
|
+
.case-link{font-family:var(--mono);font-size:12px;letter-spacing:.08em;display:inline-block;
|
|
150
|
+
margin-top:4px}
|
|
151
|
+
|
|
152
|
+
.filters{display:flex;gap:6px;flex-wrap:wrap;margin:20px 0 14px}
|
|
153
|
+
.filter{background:transparent;border:1px solid var(--ink);color:var(--ink);border-radius:0;
|
|
154
|
+
padding:6px 12px;font-size:11.5px;cursor:pointer;font-family:var(--mono);
|
|
155
|
+
transition:background .15s,color .15s}
|
|
156
|
+
.filter span{color:var(--muted);margin-left:5px;font-size:10px}
|
|
157
|
+
.filter.on{background:var(--ink);color:var(--paper)}
|
|
158
|
+
.filter.on span{color:rgba(244,241,232,.6)}
|
|
159
|
+
.filter:hover:not(.on){background:var(--paper2)}
|
|
160
|
+
.index-table{width:100%;border-collapse:collapse;font-size:13px}
|
|
161
|
+
.index-table th{font-family:var(--mono);font-size:10px;letter-spacing:.14em;color:var(--muted);
|
|
162
|
+
text-align:left;font-weight:500;padding:9px 12px;border-bottom:2px solid var(--ink)}
|
|
163
|
+
.index-table td{padding:12px;border-bottom:1px solid var(--line);vertical-align:top}
|
|
164
|
+
.index-table tbody tr{transition:background .15s}
|
|
165
|
+
.index-table tbody tr:hover{background:var(--paper2)}
|
|
166
|
+
.t-no{font-family:var(--mono);font-size:11px;color:var(--muted);width:34px}
|
|
167
|
+
.t-name{font-weight:600;white-space:nowrap}
|
|
168
|
+
.t-name a{text-decoration:none}
|
|
169
|
+
.t-name a:hover{color:var(--acc)}
|
|
170
|
+
.t-desc{color:var(--ink2)}
|
|
171
|
+
.t-desc.none{color:var(--muted);font-style:italic}
|
|
172
|
+
.t-stack{font-family:var(--mono);font-size:11px;color:var(--muted)}
|
|
173
|
+
.t-loc{font-family:var(--mono);font-size:12px;font-variant-numeric:tabular-nums}
|
|
174
|
+
.t-status{font-family:var(--mono);font-size:11px;white-space:nowrap}
|
|
175
|
+
.t-status.hot{color:var(--acc)}
|
|
176
|
+
.index-note{font-family:var(--mono);font-size:10.5px;color:var(--muted);margin-top:12px}
|
|
177
|
+
|
|
178
|
+
.num-grid{display:grid;grid-template-columns:1.1fr .9fr;gap:26px;margin-top:34px}
|
|
179
|
+
.num-panel{border:1px solid var(--ink);padding:22px;background:var(--paper)}
|
|
180
|
+
.num-panel h3{font-family:var(--mono);font-size:10.5px;letter-spacing:.18em;color:var(--muted);
|
|
181
|
+
font-weight:500;margin-bottom:18px}
|
|
182
|
+
.num-panel h3 b{color:var(--acc);font-weight:500}
|
|
183
|
+
.stack{display:flex;height:14px;border:1px solid var(--ink)}
|
|
184
|
+
.stack i{display:block;height:100%}
|
|
185
|
+
.stack-labels{display:flex;justify-content:space-between;font-size:10.5px;color:var(--muted);
|
|
186
|
+
margin-top:8px;font-family:var(--mono)}
|
|
187
|
+
.bar-row{display:flex;align-items:center;gap:12px;margin:10px 0;font-size:12.5px}
|
|
188
|
+
.bar-name{width:150px;color:var(--ink2);overflow:hidden;text-overflow:ellipsis;
|
|
189
|
+
white-space:nowrap;font-family:var(--mono);font-size:11.5px}
|
|
190
|
+
.bar-track{flex:1;height:10px;border:1px solid var(--ink);background:var(--paper)}
|
|
191
|
+
.bar-track i{display:block;height:100%;background:var(--ink);transform-origin:left;
|
|
192
|
+
transform:scaleX(0);transition:transform 1s var(--ease)}
|
|
193
|
+
.in .bar-track i{transform:scaleX(1)}
|
|
194
|
+
.bar-val{width:56px;text-align:right;font-family:var(--mono);font-size:11px;color:var(--muted)}
|
|
195
|
+
.lang-bar{display:flex;height:26px;border:1px solid var(--ink);margin-bottom:14px}
|
|
196
|
+
.lang-bar i{display:block;height:100%}
|
|
197
|
+
.lang-bar i+i{border-left:1px solid var(--paper)}
|
|
198
|
+
.lang-legend{display:grid;grid-template-columns:1fr 1fr;gap:8px 20px;font-size:12px}
|
|
199
|
+
.lang-legend div{display:flex;align-items:center;gap:8px;color:var(--ink2);
|
|
200
|
+
font-family:var(--mono);font-size:11.5px}
|
|
201
|
+
.lang-legend b{margin-left:auto;font-weight:500;color:var(--ink)}
|
|
202
|
+
.sq{width:9px;height:9px;flex:none}
|
|
203
|
+
.hour-chart{display:flex;align-items:flex-end;gap:3px;height:120px}
|
|
204
|
+
.hour-bar{flex:1;background:var(--ink);min-height:2px;transform-origin:bottom;
|
|
205
|
+
transform:scaleY(0);transition:transform .8s var(--ease)}
|
|
206
|
+
.in .hour-bar{transform:scaleY(1)}
|
|
207
|
+
.hour-bar.peak{background:var(--acc)}
|
|
208
|
+
.hour-labels{display:flex;gap:3px;margin-top:8px;font-family:var(--mono);font-size:9px;
|
|
209
|
+
color:var(--muted)}
|
|
210
|
+
.hour-labels span{flex:1;text-align:center}
|
|
211
|
+
.heat-panel{margin-top:26px}
|
|
212
|
+
.heat-wrap{width:max-content;max-width:100%;margin:0 auto;overflow-x:auto;padding:6px 2px 2px;
|
|
213
|
+
border:1px solid var(--ink);background:var(--paper)}
|
|
214
|
+
.months{display:grid;grid-template-columns:repeat(12,1fr);font-family:var(--mono);font-size:9px;
|
|
215
|
+
color:var(--muted);margin-bottom:6px}
|
|
216
|
+
.heat{display:grid;grid-auto-flow:column;grid-template-rows:repeat(7,13px);
|
|
217
|
+
grid-auto-columns:13px;gap:3px}
|
|
218
|
+
.cell{width:13px;height:13px;background:var(--paper2)}
|
|
219
|
+
.cell.out{background:transparent}
|
|
220
|
+
.cell.l1{background:#ddd6c4}.cell.l2{background:#a89f88}.cell.l3{background:#5c554a}
|
|
221
|
+
.cell.l4{background:var(--ink)}
|
|
222
|
+
.cell.today{outline:2px solid var(--acc);outline-offset:1px}
|
|
223
|
+
.heat-legend{display:flex;align-items:center;justify-content:center;gap:4px;font-size:10px;
|
|
224
|
+
color:var(--muted);margin-top:12px;font-family:var(--mono)}
|
|
225
|
+
.heat-legend .cell{width:10px;height:10px}
|
|
226
|
+
.num-note{font-family:var(--mono);font-size:10.5px;color:var(--muted);margin-top:16px;line-height:1.9}
|
|
227
|
+
|
|
228
|
+
/* ---- year records ---- */
|
|
229
|
+
.records{display:grid;grid-template-columns:repeat(3,1fr);border-top:1px solid var(--ink);
|
|
230
|
+
border-left:1px solid var(--ink);margin-top:26px}
|
|
231
|
+
.record{border-right:1px solid var(--ink);border-bottom:1px solid var(--ink);padding:20px 22px;
|
|
232
|
+
min-height:150px;display:flex;flex-direction:column;justify-content:space-between}
|
|
233
|
+
.record .k{font-family:var(--mono);font-size:10px;letter-spacing:.16em;color:var(--muted)}
|
|
234
|
+
.record .v{font-family:var(--serif);font-size:31px;line-height:1.15;margin:10px 0 6px;
|
|
235
|
+
letter-spacing:-.01em}
|
|
236
|
+
.record .v small{font-family:var(--sans);font-size:13px;color:var(--muted);letter-spacing:0}
|
|
237
|
+
.record .s{font-family:var(--mono);font-size:10.5px;color:var(--muted);line-height:1.65;
|
|
238
|
+
overflow:hidden;text-overflow:ellipsis}
|
|
239
|
+
|
|
240
|
+
/* ---- monthly rhythm ---- */
|
|
241
|
+
.month-chart{display:flex;align-items:flex-end;gap:6px;height:150px;margin-top:8px;
|
|
242
|
+
padding-top:16px}
|
|
243
|
+
.month-col{position:relative;flex:1;height:100%;display:flex;
|
|
244
|
+
flex-direction:column;justify-content:flex-end}
|
|
245
|
+
.month-col i{display:block;background:var(--ink);min-height:2px;transform-origin:bottom;
|
|
246
|
+
transform:scaleY(0);transition:transform .85s var(--ease)}
|
|
247
|
+
.in .month-col i{transform:scaleY(1)}
|
|
248
|
+
.month-col.peak i{background:var(--acc)}
|
|
249
|
+
.month-col b{position:absolute;left:-3px;right:-3px;text-align:center;
|
|
250
|
+
font-family:var(--mono);font-size:9px;font-weight:400;line-height:1;
|
|
251
|
+
color:var(--muted);pointer-events:none}
|
|
252
|
+
.month-labels{display:flex;gap:6px;margin-top:7px;font-family:var(--mono);font-size:9px;
|
|
253
|
+
color:var(--muted)}
|
|
254
|
+
.month-labels span{flex:1;text-align:center}
|
|
255
|
+
|
|
256
|
+
/* ---- 7x24 clock ---- */
|
|
257
|
+
.clock-wrap{overflow-x:auto}
|
|
258
|
+
.clock{display:grid;grid-template-columns:34px repeat(24,28px);gap:3px;
|
|
259
|
+
justify-content:center;min-width:748px;padding:2px 0}
|
|
260
|
+
.clock .wd{font-family:var(--mono);font-size:9.5px;color:var(--muted);text-align:right;
|
|
261
|
+
padding-right:6px;align-self:center}
|
|
262
|
+
.clock .hh{font-family:var(--mono);font-size:8px;color:var(--muted);text-align:center;height:14px}
|
|
263
|
+
.clock .c{width:28px;height:16px;background:var(--paper2)}
|
|
264
|
+
.clock .c.l1{background:#ddd6c4}.clock .c.l2{background:#a89f88}
|
|
265
|
+
.clock .c.l3{background:#5c554a}.clock .c.l4{background:var(--ink)}
|
|
266
|
+
|
|
267
|
+
/* ---- lifecycle bars ---- */
|
|
268
|
+
.lc-months{display:grid;grid-template-columns:190px 1fr 96px;gap:10px;
|
|
269
|
+
font-family:var(--mono);font-size:9px;color:var(--muted);margin-bottom:6px}
|
|
270
|
+
.lc-month-ticks{display:grid;grid-template-columns:repeat(12,1fr)}
|
|
271
|
+
.lc-month-ticks span{text-align:left}
|
|
272
|
+
.lc-end{text-align:right}
|
|
273
|
+
.lc-row{display:grid;grid-template-columns:190px 1fr 96px;gap:10px;
|
|
274
|
+
align-items:center;margin:7px 0}
|
|
275
|
+
.lc-name{font-family:var(--mono);font-size:10.5px;color:var(--ink2);overflow:hidden;
|
|
276
|
+
text-overflow:ellipsis;white-space:nowrap}
|
|
277
|
+
.lc-track{height:10px;background-color:var(--paper2);
|
|
278
|
+
background-image:linear-gradient(90deg,var(--line) 1px,transparent 1px);
|
|
279
|
+
background-size:calc(100% / 12) 100%;border:1px solid var(--line2);position:relative}
|
|
280
|
+
.lc-track i{position:absolute;top:0;bottom:0;background:var(--ink);z-index:1;min-width:1px}
|
|
281
|
+
.lc-track i.hot{background:var(--acc)}
|
|
282
|
+
.lc-track i.dot{width:7px;height:7px;top:50%;bottom:auto;transform:translateY(-50%)}
|
|
283
|
+
.lc-date{font-family:var(--mono);font-size:9.5px;color:var(--muted);text-align:right}
|
|
284
|
+
|
|
285
|
+
/* ---- keyword chips / churn ---- */
|
|
286
|
+
.chips-cloud{display:flex;gap:6px;flex-wrap:wrap}
|
|
287
|
+
.chips-cloud span{font-family:var(--mono);font-size:10.5px;border:1px solid var(--line2);
|
|
288
|
+
padding:4px 9px;color:var(--ink2);background:var(--paper)}
|
|
289
|
+
.chips-cloud b{color:var(--acc);font-weight:500;margin-left:5px}
|
|
290
|
+
.pair{display:flex;height:18px;border:1px solid var(--ink);margin:10px 0}
|
|
291
|
+
.pair i{display:block;height:100%}
|
|
292
|
+
|
|
293
|
+
.year-span{display:flex;justify-content:space-between;gap:16px;flex-wrap:wrap;
|
|
294
|
+
margin-top:14px;padding-bottom:10px;border-bottom:1px solid var(--line);
|
|
295
|
+
font-family:var(--mono);font-size:10.5px;color:var(--muted)}
|
|
296
|
+
.year-span b{color:var(--ink);font-weight:500}
|
|
297
|
+
|
|
298
|
+
.sub-head{font-family:var(--mono);font-size:9.5px;letter-spacing:.12em;color:var(--muted);
|
|
299
|
+
margin:16px 0 2px}
|
|
300
|
+
|
|
301
|
+
.mini-stats{display:grid;grid-template-columns:1fr 1fr;gap:14px 18px}
|
|
302
|
+
.mini-stats b{display:block;font-family:var(--mono);font-size:24px;font-weight:500;
|
|
303
|
+
letter-spacing:-.01em}
|
|
304
|
+
.mini-stats span{font-size:10px;color:var(--muted);font-family:var(--mono)}
|
|
305
|
+
|
|
306
|
+
.file-line{padding:10px 0;border-top:1px dashed var(--line2)}
|
|
307
|
+
.file-line:first-child{border-top:0;padding-top:0}
|
|
308
|
+
.file-path{font-family:var(--mono);font-size:11px;color:var(--ink2);line-height:1.55;
|
|
309
|
+
word-break:break-all;margin-bottom:6px}
|
|
310
|
+
.file-meta{display:flex;align-items:center;gap:10px}
|
|
311
|
+
.file-meta .bar-track{flex:1}
|
|
312
|
+
|
|
313
|
+
.q-chart{display:flex;align-items:flex-end;gap:26px;height:190px;margin-top:8px}
|
|
314
|
+
.q-col{flex:1;display:flex;flex-direction:column;height:100%}
|
|
315
|
+
.q-stack{flex:1;display:flex;flex-direction:column-reverse;border:1px solid var(--ink);
|
|
316
|
+
background:var(--paper2)}
|
|
317
|
+
.q-stack i{display:block;width:100%}
|
|
318
|
+
.q-none{flex:1;display:flex;align-items:center;justify-content:center;
|
|
319
|
+
font-family:var(--mono);font-size:9.5px;color:var(--muted)}
|
|
320
|
+
.q-label{font-family:var(--mono);font-size:10px;color:var(--muted);text-align:center;
|
|
321
|
+
margin-top:6px}
|
|
322
|
+
.q-legend{display:flex;gap:18px;flex-wrap:wrap;font-family:var(--mono);font-size:10.5px;
|
|
323
|
+
color:var(--muted);margin-top:14px}
|
|
324
|
+
.q-legend span{display:flex;align-items:center;gap:6px}
|
|
325
|
+
.q-legend i{display:inline-block;width:9px;height:9px}
|
|
326
|
+
|
|
327
|
+
.dormant-row{display:grid;grid-template-columns:1fr 170px 70px;gap:12px;
|
|
328
|
+
padding:9px 0;border-top:1px dashed var(--line2);font-family:var(--mono);font-size:11px}
|
|
329
|
+
.dormant-row:first-child{border-top:0}
|
|
330
|
+
.d-name{color:var(--ink2)}
|
|
331
|
+
.d-last{color:var(--muted)}
|
|
332
|
+
.d-days{text-align:right;color:var(--acc)}
|
|
333
|
+
|
|
334
|
+
#tip{position:fixed;left:0;top:0;z-index:90;pointer-events:none;opacity:0;
|
|
335
|
+
background:var(--paper);border:1px solid var(--ink);box-shadow:4px 4px 0 var(--acc);
|
|
336
|
+
font-family:var(--mono);font-size:11px;line-height:1.5;color:var(--ink);
|
|
337
|
+
padding:6px 9px;max-width:300px;transition:opacity .12s var(--ease)}
|
|
338
|
+
#tip.show{opacity:1}
|
|
339
|
+
|
|
340
|
+
@media(min-width:921px){.num-grid .span2{grid-column:span 2}}
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
.about{border:1px solid var(--ink);padding:26px;background:var(--paper)}
|
|
344
|
+
.about ul{margin:0;padding:0;list-style:none;font-family:var(--mono);font-size:12px;color:var(--ink2)}
|
|
345
|
+
.about li{padding:9px 0 9px 20px;border-top:1px dashed var(--line2);position:relative}
|
|
346
|
+
.about li:first-child{border-top:0}
|
|
347
|
+
.about li::before{content:"—";position:absolute;left:0;color:var(--acc)}
|
|
348
|
+
.quote{margin:44px 0 0;padding:6px 0 6px 26px;border-left:3px solid var(--acc);
|
|
349
|
+
font-family:var(--serif);font-size:25px;line-height:1.5;color:var(--ink)}
|
|
350
|
+
.quote small{display:block;font-family:var(--mono);font-size:10.5px;color:var(--muted);
|
|
351
|
+
margin-top:10px;letter-spacing:.1em}
|
|
352
|
+
|
|
353
|
+
footer{border-top:2px solid var(--ink);margin-top:90px;padding:24px 0 44px}
|
|
354
|
+
.foot-in{max-width:1160px;margin:0 auto;padding:0 28px;display:flex;
|
|
355
|
+
justify-content:space-between;gap:14px;flex-wrap:wrap;font-family:var(--mono);
|
|
356
|
+
font-size:11px;color:var(--muted)}
|
|
357
|
+
|
|
358
|
+
.rv{opacity:0;transform:translateY(20px);transition:opacity .75s var(--ease),
|
|
359
|
+
transform .75s var(--ease);transition-delay:var(--d,0ms)}
|
|
360
|
+
.rv.in{opacity:1;transform:none}
|
|
361
|
+
.rv-line{opacity:0;transform:translateY(30px);transition:opacity .85s var(--ease),
|
|
362
|
+
transform .85s var(--ease);transition-delay:var(--d,0ms)}
|
|
363
|
+
.rv-line.in{opacity:1;transform:none}
|
|
364
|
+
|
|
365
|
+
@media(max-width:920px){
|
|
366
|
+
.hero{grid-template-columns:1fr;gap:36px;padding-top:56px}
|
|
367
|
+
.hero-stats{border-left:0;grid-template-columns:repeat(4,1fr)}
|
|
368
|
+
.hs{border-right:0!important;border-bottom:1px solid var(--line)}
|
|
369
|
+
.hs:nth-last-child(-n+2){border-bottom:1px solid var(--line)}
|
|
370
|
+
.archive,.archive.flip{grid-template-columns:1fr}
|
|
371
|
+
.archive.flip .plate-wrap{order:0}
|
|
372
|
+
.num-grid{grid-template-columns:1fr}
|
|
373
|
+
.records{grid-template-columns:repeat(2,1fr)}
|
|
374
|
+
}
|
|
375
|
+
@media(max-width:640px){
|
|
376
|
+
.wrap,.nav,.foot-in{padding-left:20px;padding-right:20px}
|
|
377
|
+
.hero-stats{grid-template-columns:1fr 1fr}
|
|
378
|
+
.nav-links{display:none}
|
|
379
|
+
h1{font-size:42px}
|
|
380
|
+
.index-table .t-stack,.index-table .t-desc{display:none}
|
|
381
|
+
.records{grid-template-columns:1fr}
|
|
382
|
+
.lc-row{grid-template-columns:120px 1fr 76px}
|
|
383
|
+
.lc-months{grid-template-columns:120px 1fr 76px}
|
|
384
|
+
.dormant-row{grid-template-columns:1fr 120px 52px}
|
|
385
|
+
.q-chart{gap:10px}
|
|
386
|
+
}
|
|
387
|
+
@media (prefers-reduced-motion: reduce){
|
|
388
|
+
*,*::before,*::after{animation:none!important;transition:none!important}
|
|
389
|
+
.rv,.rv-line{opacity:1!important;transform:none!important}
|
|
390
|
+
.sec-line,.bar-track i,.hour-bar{transform:none!important;opacity:1!important}
|
|
391
|
+
.tick-track{animation:none!important}
|
|
392
|
+
}
|
|
393
|
+
@media print{
|
|
394
|
+
.rv,.rv-line{opacity:1!important;transform:none!important}
|
|
395
|
+
.sec-line,.bar-track i,.hour-bar{transform:none!important}
|
|
396
|
+
.tick-track{animation:none!important}
|
|
397
|
+
}
|
|
398
|
+
"""
|
|
399
|
+
|
|
400
|
+
JS = r"""
|
|
401
|
+
(function(){
|
|
402
|
+
const RM = matchMedia('(prefers-reduced-motion: reduce)').matches;
|
|
403
|
+
const $$ = (s,c)=> [...(c||document).querySelectorAll(s)];
|
|
404
|
+
|
|
405
|
+
const bar = document.getElementById('progress');
|
|
406
|
+
const onScroll = ()=>{
|
|
407
|
+
const h = document.documentElement;
|
|
408
|
+
const p = h.scrollTop / (h.scrollHeight - h.clientHeight || 1);
|
|
409
|
+
if(bar) bar.style.width = (p*100).toFixed(2)+'%';
|
|
410
|
+
};
|
|
411
|
+
addEventListener('scroll', onScroll, {passive:true}); onScroll();
|
|
412
|
+
|
|
413
|
+
const clock = document.getElementById('clock');
|
|
414
|
+
const pad = n=> String(n).padStart(2,'0');
|
|
415
|
+
const tickClock = ()=>{
|
|
416
|
+
const d = new Date();
|
|
417
|
+
clock.textContent = pad(d.getHours())+':'+pad(d.getMinutes())+':'+pad(d.getSeconds());
|
|
418
|
+
};
|
|
419
|
+
if(clock){ tickClock(); setInterval(tickClock, 1000); }
|
|
420
|
+
|
|
421
|
+
const targets = $$('.rv, .rv-line, .sec-line');
|
|
422
|
+
if(RM || !('IntersectionObserver' in window)){
|
|
423
|
+
targets.forEach(el=>el.classList.add('in'));
|
|
424
|
+
}else{
|
|
425
|
+
const io = new IntersectionObserver(es=>{
|
|
426
|
+
es.forEach(e=>{ if(e.isIntersecting){ e.target.classList.add('in'); io.unobserve(e.target);} });
|
|
427
|
+
},{threshold:.1, rootMargin:'0px 0px -30px 0px'});
|
|
428
|
+
targets.forEach(el=>io.observe(el));
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
const counters = $$('[data-count]');
|
|
432
|
+
const finalText = el=>{
|
|
433
|
+
const t = parseFloat(el.dataset.count), dec = parseInt(el.dataset.dec||'0',10);
|
|
434
|
+
let s = t.toFixed(dec);
|
|
435
|
+
if('sep' in el.dataset) s = Number(s).toLocaleString('en-US');
|
|
436
|
+
return s + (el.dataset.suffix||'');
|
|
437
|
+
};
|
|
438
|
+
const run = el=>{
|
|
439
|
+
const target = parseFloat(el.dataset.count);
|
|
440
|
+
const dec = parseInt(el.dataset.dec||'0',10);
|
|
441
|
+
const suffix = el.dataset.suffix||'';
|
|
442
|
+
const sep = 'sep' in el.dataset;
|
|
443
|
+
const dur = 1300, t0 = performance.now();
|
|
444
|
+
const step = now=>{
|
|
445
|
+
const p = Math.min((now-t0)/dur, 1);
|
|
446
|
+
const e = 1-Math.pow(1-p,3);
|
|
447
|
+
let s = (target*e).toFixed(dec);
|
|
448
|
+
if(sep) s = Number(s).toLocaleString('en-US');
|
|
449
|
+
el.textContent = s + suffix;
|
|
450
|
+
if(p<1) requestAnimationFrame(step);
|
|
451
|
+
};
|
|
452
|
+
requestAnimationFrame(step);
|
|
453
|
+
};
|
|
454
|
+
if(RM || !('IntersectionObserver' in window)){
|
|
455
|
+
counters.forEach(el=>el.textContent = finalText(el));
|
|
456
|
+
}else{
|
|
457
|
+
const cio = new IntersectionObserver(es=>{
|
|
458
|
+
es.forEach(e=>{ if(e.isIntersecting){ run(e.target); cio.unobserve(e.target);} });
|
|
459
|
+
},{threshold:.5});
|
|
460
|
+
counters.forEach(el=>cio.observe(el));
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
const filters = $$('.filter');
|
|
464
|
+
const rows = $$('.index-table tbody tr');
|
|
465
|
+
const countEl = document.getElementById('row-count');
|
|
466
|
+
const searchEl = document.getElementById('repo-search');
|
|
467
|
+
const applyFilter = ()=>{
|
|
468
|
+
const active = document.querySelector('.filter.on');
|
|
469
|
+
const f = active ? active.dataset.filter : 'all';
|
|
470
|
+
const q = searchEl ? searchEl.value.trim().toLowerCase() : '';
|
|
471
|
+
let n=0;
|
|
472
|
+
rows.forEach(r=>{
|
|
473
|
+
const show = (f==='all' || r.dataset.cat===f) &&
|
|
474
|
+
(!q || r.textContent.toLowerCase().includes(q));
|
|
475
|
+
r.style.display = show ? '' : 'none';
|
|
476
|
+
if(show) n++;
|
|
477
|
+
});
|
|
478
|
+
if(countEl) countEl.textContent = n+' / '+rows.length;
|
|
479
|
+
};
|
|
480
|
+
filters.forEach(btn=>btn.addEventListener('click',()=>{
|
|
481
|
+
filters.forEach(b=>b.classList.toggle('on', b===btn));
|
|
482
|
+
applyFilter();
|
|
483
|
+
}));
|
|
484
|
+
if(searchEl) searchEl.addEventListener('input', applyFilter);
|
|
485
|
+
|
|
486
|
+
/* paper-style tooltip (replaces native title bubbles) */
|
|
487
|
+
const tip = document.getElementById('tip');
|
|
488
|
+
if(tip){
|
|
489
|
+
let target = null;
|
|
490
|
+
const place = ev=>{
|
|
491
|
+
const gap = 14;
|
|
492
|
+
let x = ev.clientX + gap, y = ev.clientY + gap;
|
|
493
|
+
const r = tip.getBoundingClientRect();
|
|
494
|
+
if(x + r.width > innerWidth - 8) x = ev.clientX - r.width - gap;
|
|
495
|
+
if(y + r.height > innerHeight - 8) y = ev.clientY - r.height - gap;
|
|
496
|
+
tip.style.transform = 'translate('+x+'px,'+y+'px)';
|
|
497
|
+
};
|
|
498
|
+
document.addEventListener('mouseover', ev=>{
|
|
499
|
+
const el = ev.target.closest ? ev.target.closest('[data-tip]') : null;
|
|
500
|
+
if(!el) return;
|
|
501
|
+
target = el;
|
|
502
|
+
tip.textContent = el.dataset.tip;
|
|
503
|
+
tip.classList.add('show');
|
|
504
|
+
place(ev);
|
|
505
|
+
});
|
|
506
|
+
document.addEventListener('mouseout', ev=>{
|
|
507
|
+
if(!target) return;
|
|
508
|
+
if(ev.relatedTarget && target.contains(ev.relatedTarget)) return;
|
|
509
|
+
target = null;
|
|
510
|
+
tip.classList.remove('show');
|
|
511
|
+
});
|
|
512
|
+
document.addEventListener('mousemove', ev=>{ if(target) place(ev); });
|
|
513
|
+
addEventListener('scroll', ()=>{ target=null; tip.classList.remove('show'); }, {passive:true});
|
|
514
|
+
addEventListener('blur', ()=>{ target=null; tip.classList.remove('show'); });
|
|
515
|
+
}
|
|
516
|
+
})();
|
|
517
|
+
"""
|
|
518
|
+
|
|
519
|
+
|
|
520
|
+
def _stamp_for(
|
|
521
|
+
last_iso: str, generated: str, year: int | None = None
|
|
522
|
+
) -> tuple[str, bool]:
|
|
523
|
+
"""(label, is_active) based on how recently the repo was touched."""
|
|
524
|
+
try:
|
|
525
|
+
last = datetime.strptime(last_iso, "%Y.%m.%d").date()
|
|
526
|
+
gen = datetime.strptime(generated, "%Y-%m-%d %H:%M").date()
|
|
527
|
+
if year is not None and year < gen.year:
|
|
528
|
+
gen = date(year, 12, 31)
|
|
529
|
+
days = (gen - last).days
|
|
530
|
+
except ValueError:
|
|
531
|
+
return "未知", False
|
|
532
|
+
if days <= 7:
|
|
533
|
+
return "活跃", True
|
|
534
|
+
if days <= 30:
|
|
535
|
+
return "进行中", True
|
|
536
|
+
return "休眠", False
|
|
537
|
+
|
|
538
|
+
|
|
539
|
+
def build_ticker(stats: ReportStats) -> str:
|
|
540
|
+
if not stats.ticker:
|
|
541
|
+
return ""
|
|
542
|
+
items = "".join(
|
|
543
|
+
f'<span class="tick-item"><b>{escape(t["repo"])}</b>{escape(t["subject"])}</span>'
|
|
544
|
+
for t in stats.ticker
|
|
545
|
+
)
|
|
546
|
+
return f"""
|
|
547
|
+
<div class="ticker" aria-label="最近的真实提交记录">
|
|
548
|
+
<div class="ticker-inner">
|
|
549
|
+
<div class="tick-label"><i></i>LIVE · GIT</div>
|
|
550
|
+
<div class="tick-viewport"><div class="tick-track">{items}{items}</div></div>
|
|
551
|
+
</div>
|
|
552
|
+
</div>
|
|
553
|
+
"""
|
|
554
|
+
|
|
555
|
+
|
|
556
|
+
def _web_url(remote: str) -> str | None:
|
|
557
|
+
"""Normalize a git remote (https or ssh) to a clickable web URL."""
|
|
558
|
+
remote = (remote or "").strip()
|
|
559
|
+
if not remote:
|
|
560
|
+
return None
|
|
561
|
+
if remote.startswith("git@") and ":" in remote:
|
|
562
|
+
host, path = remote[4:].split(":", 1)
|
|
563
|
+
return f"https://{host}/{path.removesuffix('.git')}"
|
|
564
|
+
if remote.startswith(("http://", "https://")):
|
|
565
|
+
return remote.removesuffix(".git")
|
|
566
|
+
return None
|
|
567
|
+
|
|
568
|
+
|
|
569
|
+
def build_archives(stats: ReportStats) -> str:
|
|
570
|
+
blocks = []
|
|
571
|
+
for i, repo in enumerate(stats.repo_details[:3]):
|
|
572
|
+
stamp, active = _stamp_for(repo["last"], stats.generated_at, stats.year)
|
|
573
|
+
langs = "".join(
|
|
574
|
+
f'<span>{escape(str(lang))} {(n / max(repo["lines"], 1) * 100):.0f}%</span>'
|
|
575
|
+
for lang, n in repo["langs"]
|
|
576
|
+
)
|
|
577
|
+
recents = "".join(
|
|
578
|
+
f'<div><b>{escape(r["date"])}</b><span data-raw>{escape(r["subject"])}</span></div>'
|
|
579
|
+
for r in repo.get("recent", [])
|
|
580
|
+
)
|
|
581
|
+
has_readme = bool(repo.get("readme"))
|
|
582
|
+
readme = escape(repo["readme"]) if has_readme else "(这个仓库的 README 还没写简介)"
|
|
583
|
+
readme_raw = " data-raw" if has_readme else ""
|
|
584
|
+
top_file = repo.get("top_file")
|
|
585
|
+
facts = [
|
|
586
|
+
f'首次提交 {repo["first"]} → 最近提交 {repo["last"]}',
|
|
587
|
+
"语言:" + " · ".join(f"{lang} {n}" for lang, n in repo["langs"]),
|
|
588
|
+
]
|
|
589
|
+
if top_file:
|
|
590
|
+
facts.append(f'最常改的文件:{top_file[0]}({fmt_human(top_file[1])} 行变更)')
|
|
591
|
+
facts.append("提交 " + fmt_int(repo["commits"]) + " 次(已按 hash 去重)")
|
|
592
|
+
how = "".join(f"<li>{escape(f)}</li>" for f in facts)
|
|
593
|
+
link = ""
|
|
594
|
+
url = _web_url(repo.get("remote") or "")
|
|
595
|
+
if url:
|
|
596
|
+
link = f'<a class="u case-link" href="{escape(url)}" target="_blank" rel="noopener">GITHUB ↗</a>'
|
|
597
|
+
name_html = escape(repo["name"])
|
|
598
|
+
blocks.append(f"""
|
|
599
|
+
<article class="archive{' flip' if i % 2 else ''}">
|
|
600
|
+
<div class="plate-wrap">
|
|
601
|
+
<div class="plate">
|
|
602
|
+
<div class="big">
|
|
603
|
+
<div><b>{fmt_int(repo["commits"])}</b><span>次提交</span></div>
|
|
604
|
+
<div><b>{fmt_human(repo["lines"])}</b><span>行代码变更</span></div>
|
|
605
|
+
<div><b>{len(repo["langs"])}</b><span>种主要语言</span></div>
|
|
606
|
+
</div>
|
|
607
|
+
<div class="langs">{langs}</div>
|
|
608
|
+
<div class="rec">{recents if recents else '<div>(最近没有提交)</div>'}</div>
|
|
609
|
+
</div>
|
|
610
|
+
</div>
|
|
611
|
+
<div class="case-body">
|
|
612
|
+
<div class="case-top">
|
|
613
|
+
<span class="case-no">№ {i + 1:02d}</span>
|
|
614
|
+
<span class="stamp{' sleep' if not active else ''}"><i></i>{stamp}</span>
|
|
615
|
+
</div>
|
|
616
|
+
<h3 data-raw>{name_html}</h3>
|
|
617
|
+
<p class="readme-quote"{readme_raw}>{readme}</p>
|
|
618
|
+
<ul class="how">{how}</ul>
|
|
619
|
+
{link}
|
|
620
|
+
</div>
|
|
621
|
+
</article>
|
|
622
|
+
""")
|
|
623
|
+
return "".join(blocks)
|
|
624
|
+
|
|
625
|
+
|
|
626
|
+
def build_table(stats: ReportStats) -> str:
|
|
627
|
+
lang_counts: dict[str, int] = {}
|
|
628
|
+
for repo in stats.repo_details:
|
|
629
|
+
if repo["langs"]:
|
|
630
|
+
lang_counts[repo["langs"][0][0]] = lang_counts.get(repo["langs"][0][0], 0) + 1
|
|
631
|
+
top_langs = sorted(lang_counts.items(), key=lambda kv: -kv[1])[:5]
|
|
632
|
+
known = {lang for lang, _ in top_langs}
|
|
633
|
+
|
|
634
|
+
cats = [("all", "全部")] + [(lang, lang) for lang, _ in top_langs]
|
|
635
|
+
if any(repo["langs"] and repo["langs"][0][0] not in known for repo in stats.repo_details):
|
|
636
|
+
cats.append(("__other", "其他"))
|
|
637
|
+
|
|
638
|
+
def cat_of(repo: dict) -> str:
|
|
639
|
+
if not repo["langs"]:
|
|
640
|
+
return "__other"
|
|
641
|
+
lang = repo["langs"][0][0]
|
|
642
|
+
return lang if lang in known else "__other"
|
|
643
|
+
|
|
644
|
+
filters = "".join(
|
|
645
|
+
f'<button class="filter{" on" if key == "all" else ""}" data-filter="{escape(key)}">'
|
|
646
|
+
f'{escape(label)}<span>{sum(1 for r in stats.repo_details if key == "all" or cat_of(r) == key)}</span></button>'
|
|
647
|
+
for key, label in cats
|
|
648
|
+
)
|
|
649
|
+
|
|
650
|
+
rows = []
|
|
651
|
+
for i, repo in enumerate(stats.repo_details, 1):
|
|
652
|
+
stamp, active = _stamp_for(repo["last"], stats.generated_at, stats.year)
|
|
653
|
+
name = escape(repo["name"])
|
|
654
|
+
url = _web_url(repo.get("remote") or "")
|
|
655
|
+
if url:
|
|
656
|
+
name = f'<a href="{escape(url)}" target="_blank" rel="noopener">{name} ↗</a>'
|
|
657
|
+
has_readme = bool(repo.get("readme"))
|
|
658
|
+
readme = escape(repo["readme"]) if has_readme else "(README 没写简介)"
|
|
659
|
+
none_cls = ' data-raw' if has_readme else ' class="t-desc none"'
|
|
660
|
+
hot = ' class="t-status hot"' if active else ""
|
|
661
|
+
stack = " · ".join(escape(str(lang)) for lang, _ in repo["langs"])
|
|
662
|
+
rows.append(
|
|
663
|
+
f'<tr data-cat="{cat_of(repo)}">'
|
|
664
|
+
f'<td class="t-no">{i:02d}</td>'
|
|
665
|
+
f'<td class="t-name" data-raw>{name}</td>'
|
|
666
|
+
f'<td class="t-desc"{none_cls}>{readme}</td>'
|
|
667
|
+
f'<td class="t-stack">{stack}</td>'
|
|
668
|
+
f'<td class="t-loc">{fmt_human(repo["lines"])}</td>'
|
|
669
|
+
f'<td class="t-stack">{repo["last"]}</td>'
|
|
670
|
+
f'<td class="t-status"{hot}>{stamp}</td>'
|
|
671
|
+
f"</tr>"
|
|
672
|
+
)
|
|
673
|
+
return f"""
|
|
674
|
+
<div class="filters">{filters}
|
|
675
|
+
<input class="repo-search" id="repo-search" type="search"
|
|
676
|
+
placeholder="搜索仓库 / 语言 / 简介" aria-label="搜索仓库">
|
|
677
|
+
</div>
|
|
678
|
+
<table class="index-table">
|
|
679
|
+
<thead><tr>
|
|
680
|
+
<th>NO</th><th>仓库</th><th>一句话(README 原文)</th><th>栈</th>
|
|
681
|
+
<th>自有代码</th><th>最近提交</th><th>状态</th>
|
|
682
|
+
</tr></thead>
|
|
683
|
+
<tbody>{''.join(rows)}</tbody>
|
|
684
|
+
</table>
|
|
685
|
+
<p class="index-note"><span id="row-count">{len(stats.repo_details)} / {len(stats.repo_details)}</span></p>
|
|
686
|
+
"""
|
|
687
|
+
|
|
688
|
+
|
|
689
|
+
def build_heatmap(stats: ReportStats) -> str:
|
|
690
|
+
daily = parse_daily(stats.daily)
|
|
691
|
+
start, end = date_window(stats)
|
|
692
|
+
grid_start = start - timedelta(days=start.weekday())
|
|
693
|
+
grid_end = end + timedelta(days=6 - end.weekday())
|
|
694
|
+
today = date.today()
|
|
695
|
+
|
|
696
|
+
cells: list[str] = []
|
|
697
|
+
cursor = grid_start
|
|
698
|
+
while cursor <= grid_end:
|
|
699
|
+
if cursor < start or cursor > end:
|
|
700
|
+
cls, tip = "out", ""
|
|
701
|
+
else:
|
|
702
|
+
count = daily.get(cursor, 0)
|
|
703
|
+
if count == 0:
|
|
704
|
+
cls = "l0"
|
|
705
|
+
elif count == 1:
|
|
706
|
+
cls = "l1"
|
|
707
|
+
elif count <= 3:
|
|
708
|
+
cls = "l2"
|
|
709
|
+
elif count <= 6:
|
|
710
|
+
cls = "l3"
|
|
711
|
+
else:
|
|
712
|
+
cls = "l4"
|
|
713
|
+
if cursor == today:
|
|
714
|
+
cls += " today"
|
|
715
|
+
tip = f"{cursor.isoformat()} · {count} 次提交"
|
|
716
|
+
if tip:
|
|
717
|
+
cells.append(
|
|
718
|
+
f'<span class="cell {cls}" data-tip="{escape(tip)}" '
|
|
719
|
+
f'aria-label="{escape(tip)}"></span>'
|
|
720
|
+
)
|
|
721
|
+
else:
|
|
722
|
+
cells.append(f'<span class="cell {cls}"></span>')
|
|
723
|
+
cursor += timedelta(days=1)
|
|
724
|
+
|
|
725
|
+
months = "".join(f"<span>{m:02d}</span>" for m in range(1, 13))
|
|
726
|
+
legend = "".join(f'<span class="cell l{i}"></span>' for i in range(5))
|
|
727
|
+
return f"""
|
|
728
|
+
<div class="num-panel heat-panel rv span2">
|
|
729
|
+
<h3>{stats.year} 活跃热力图 <b>· {stats.active_days} 个活跃日</b></h3>
|
|
730
|
+
<div class="heat-wrap">
|
|
731
|
+
<div class="months">{months}</div>
|
|
732
|
+
<div class="heat" role="img" aria-label="全年提交热力图">{''.join(cells)}</div>
|
|
733
|
+
</div>
|
|
734
|
+
<div class="heat-legend">{legend}<span style="margin-left:6px">少 → 多 · 框出今天</span></div>
|
|
735
|
+
</div>
|
|
736
|
+
"""
|
|
737
|
+
|
|
738
|
+
|
|
739
|
+
def _panel(title: str, body: str, *, span: bool = False) -> str:
|
|
740
|
+
cls = "num-panel rv span2" if span else "num-panel rv"
|
|
741
|
+
return f'<div class="{cls}"><h3>{title}</h3>{body}</div>'
|
|
742
|
+
|
|
743
|
+
|
|
744
|
+
def build_records(stats: ReportStats) -> str:
|
|
745
|
+
cards: list[str] = []
|
|
746
|
+
|
|
747
|
+
def add(label: str, value: str, sub: str) -> None:
|
|
748
|
+
cards.append(
|
|
749
|
+
f'<div class="record rv"><div class="k">{label}</div>'
|
|
750
|
+
f'<div class="v">{value}</div><div class="s">{sub}</div></div>'
|
|
751
|
+
)
|
|
752
|
+
|
|
753
|
+
if stats.busiest_day:
|
|
754
|
+
day, count = stats.busiest_day
|
|
755
|
+
add("最忙的一天", f"{count} <small>次提交</small>", day.replace("-", "."))
|
|
756
|
+
if stats.busiest_week:
|
|
757
|
+
week, count = stats.busiest_week
|
|
758
|
+
add("最忙的一周", f"{count} <small>次提交</small>",
|
|
759
|
+
f"{week} · 起于 {stats.busiest_week_start or '—'}")
|
|
760
|
+
add("最长连续", f"{stats.longest_streak} <small>天</small>",
|
|
761
|
+
f"当前连续 {stats.current_streak} 天")
|
|
762
|
+
if stats.longest_gap:
|
|
763
|
+
days, start, end = stats.longest_gap
|
|
764
|
+
add("最长空窗", f"{days} <small>天</small>", f"{start} → {end}")
|
|
765
|
+
if stats.largest_commit:
|
|
766
|
+
lc = stats.largest_commit
|
|
767
|
+
add("最大单次提交", f"{fmt_int(lc['lines'])} <small>行</small>",
|
|
768
|
+
f"{escape(lc['repo'])} · {lc['date']}")
|
|
769
|
+
add("最长的 commit", f"{len(stats.longest_subject)} <small>字符</small>",
|
|
770
|
+
f'<span data-raw>{escape(stats.longest_subject[:90])}</span>')
|
|
771
|
+
if getattr(stats, "latest_night_commit", None):
|
|
772
|
+
nc = stats.latest_night_commit
|
|
773
|
+
add("最晚的一次熬夜", f"{escape(nc['time'])}",
|
|
774
|
+
f"{escape(nc['repo'])} · {escape(nc['date'])} · {escape(nc['subject'][:42])}")
|
|
775
|
+
|
|
776
|
+
span = ""
|
|
777
|
+
if stats.first_commit and stats.last_commit:
|
|
778
|
+
fc, lc = stats.first_commit, stats.last_commit
|
|
779
|
+
fc_sub = f" · {escape(fc['subject'][:40])}" if fc.get("subject") else ""
|
|
780
|
+
lc_sub = f" · {escape(lc['subject'][:40])}" if lc.get("subject") else ""
|
|
781
|
+
span = (
|
|
782
|
+
f'<div class="year-span rv">'
|
|
783
|
+
f'<span>第一次提交 <b>{escape(fc["date"])}</b> · {escape(fc["repo"])}{fc_sub}</span>'
|
|
784
|
+
f'<span>最后一次提交 <b>{escape(lc["date"])}</b> · {escape(lc["repo"])}{lc_sub}</span>'
|
|
785
|
+
f'</div>'
|
|
786
|
+
)
|
|
787
|
+
return f'<div class="records">{"".join(cards)}</div>{span}'
|
|
788
|
+
|
|
789
|
+
|
|
790
|
+
def build_monthly(stats: ReportStats) -> str:
|
|
791
|
+
max_v = max(stats.monthly) or 1
|
|
792
|
+
peak = stats.monthly.index(max_v) + 1
|
|
793
|
+
|
|
794
|
+
def column(month: int, value: int) -> str:
|
|
795
|
+
pct = max(value / max_v * 100, 1.5)
|
|
796
|
+
label = (
|
|
797
|
+
f'<b style="bottom:calc({pct:.1f}% + 3px)">{value:,}</b>'
|
|
798
|
+
if value else ""
|
|
799
|
+
)
|
|
800
|
+
return (
|
|
801
|
+
f'<div class="month-col{" peak" if value == max_v and value > 0 else ""}" '
|
|
802
|
+
f'data-tip="{month} 月 · {value} 次提交" '
|
|
803
|
+
f'aria-label="{month} 月 · {value} 次提交">'
|
|
804
|
+
f'<i style="height:{pct:.1f}%"></i>{label}</div>'
|
|
805
|
+
)
|
|
806
|
+
|
|
807
|
+
cols = "".join(column(m + 1, v) for m, v in enumerate(stats.monthly))
|
|
808
|
+
labels = "".join(f"<span>{m:02d}</span>" for m in range(1, 13))
|
|
809
|
+
return _panel(
|
|
810
|
+
f"月度节奏 <b>· 峰值 {peak:02d} 月 · {max_v} 次</b>",
|
|
811
|
+
f'<div class="month-chart" role="img" aria-label="月度提交次数">{cols}</div>'
|
|
812
|
+
f'<div class="month-labels">{labels}</div>',
|
|
813
|
+
span=True,
|
|
814
|
+
)
|
|
815
|
+
|
|
816
|
+
|
|
817
|
+
def build_clock(stats: ReportStats) -> str:
|
|
818
|
+
flat = [v for row in stats.hour_weekday for v in row]
|
|
819
|
+
max_v = max(flat) or 1
|
|
820
|
+
|
|
821
|
+
def level(v: int) -> str:
|
|
822
|
+
if v == 0:
|
|
823
|
+
return "l0"
|
|
824
|
+
if v <= max_v * 0.15:
|
|
825
|
+
return "l1"
|
|
826
|
+
if v <= max_v * 0.35:
|
|
827
|
+
return "l2"
|
|
828
|
+
if v <= max_v * 0.6:
|
|
829
|
+
return "l3"
|
|
830
|
+
return "l4"
|
|
831
|
+
|
|
832
|
+
days = ["周一", "周二", "周三", "周四", "周五", "周六", "周日"]
|
|
833
|
+
head = '<span class="wd"></span>' + "".join(
|
|
834
|
+
f'<span class="hh">{h if h % 3 == 0 else ""}</span>' for h in range(24)
|
|
835
|
+
)
|
|
836
|
+
rows = []
|
|
837
|
+
for wd, row in enumerate(stats.hour_weekday):
|
|
838
|
+
cells = "".join(
|
|
839
|
+
f'<span class="c {level(v)}" data-tip="{days[wd]} {h:02d}:00 · {v} 次提交" '
|
|
840
|
+
f'aria-label="{days[wd]} {h:02d}:00 · {v} 次提交"></span>'
|
|
841
|
+
for h, v in enumerate(row)
|
|
842
|
+
)
|
|
843
|
+
rows.append(f'<span class="wd">{days[wd]}</span>{cells}')
|
|
844
|
+
|
|
845
|
+
totals = [sum(stats.hour_weekday[wd][h] for wd in range(7)) for h in range(24)]
|
|
846
|
+
peak = totals.index(max(totals))
|
|
847
|
+
return _panel(
|
|
848
|
+
f"7×24 提交时钟 <b>· 峰值 {peak:02d}:00</b>",
|
|
849
|
+
f'<div class="clock-wrap"><div class="clock" role="img" '
|
|
850
|
+
f'aria-label="7×24 提交时钟">{head}{"".join(rows)}</div></div>'
|
|
851
|
+
f'<p class="num-note">周末占 {stats.weekend_share:.0%},'
|
|
852
|
+
f'深夜(22:00–05:00)占 {stats.night_share:.0%}。</p>',
|
|
853
|
+
span=True,
|
|
854
|
+
)
|
|
855
|
+
|
|
856
|
+
|
|
857
|
+
def build_sizes(stats: ReportStats) -> str:
|
|
858
|
+
max_v = max((v for _, v in stats.size_buckets), default=1) or 1
|
|
859
|
+
rows = "".join(
|
|
860
|
+
f'<div class="bar-row"><span class="bar-name">{label} 行</span>'
|
|
861
|
+
f'<div class="bar-track"><i style="width:{v / max_v * 100:.1f}%"></i></div>'
|
|
862
|
+
f'<span class="bar-val">{v}</span></div>'
|
|
863
|
+
for label, v in stats.size_buckets
|
|
864
|
+
)
|
|
865
|
+
return _panel("提交规模 <b>· 小步快跑还是大爆炸</b>", rows)
|
|
866
|
+
|
|
867
|
+
|
|
868
|
+
def build_types(stats: ReportStats) -> str:
|
|
869
|
+
if not stats.commit_types:
|
|
870
|
+
return _panel("提交类型 <b>· 约定式提交</b>",
|
|
871
|
+
'<p class="num-note">没有识别到 Conventional Commits 类型。</p>')
|
|
872
|
+
max_v = max(v for _, v in stats.commit_types) or 1
|
|
873
|
+
rows = "".join(
|
|
874
|
+
f'<div class="bar-row"><span class="bar-name">{escape(name)}</span>'
|
|
875
|
+
f'<div class="bar-track"><i style="width:{v / max_v * 100:.1f}%"></i></div>'
|
|
876
|
+
f'<span class="bar-val">{v}</span></div>'
|
|
877
|
+
for name, v in stats.commit_types
|
|
878
|
+
)
|
|
879
|
+
return _panel(f"提交类型 <b>· 约定式占 {stats.conventional_share:.0%}</b>", rows)
|
|
880
|
+
|
|
881
|
+
|
|
882
|
+
def build_keywords(stats: ReportStats) -> str:
|
|
883
|
+
if not stats.keywords:
|
|
884
|
+
return _panel("高频词 <b>· 口头禅</b>",
|
|
885
|
+
'<p class="num-note">提交信息太短,没有提取到关键词。</p>')
|
|
886
|
+
chips = "".join(
|
|
887
|
+
f"<span>{escape(word)}<b>{count}</b></span>" for word, count in stats.keywords[:16]
|
|
888
|
+
)
|
|
889
|
+
return _panel(
|
|
890
|
+
"高频词 <b>· commit message 里的口头禅</b>",
|
|
891
|
+
f'<div class="chips-cloud">{chips}</div>'
|
|
892
|
+
f'<p class="num-note">平均每条 {stats.avg_subject_len} 字符。</p>',
|
|
893
|
+
)
|
|
894
|
+
|
|
895
|
+
|
|
896
|
+
def build_messages(stats: ReportStats) -> str:
|
|
897
|
+
max_v = max((v for _, v in stats.message_buckets), default=1) or 1
|
|
898
|
+
rows = "".join(
|
|
899
|
+
f'<div class="bar-row"><span class="bar-name">{label} 字符</span>'
|
|
900
|
+
f'<div class="bar-track"><i style="width:{v / max_v * 100:.1f}%"></i></div>'
|
|
901
|
+
f'<span class="bar-val">{v}</span></div>'
|
|
902
|
+
for label, v in stats.message_buckets
|
|
903
|
+
)
|
|
904
|
+
return _panel(
|
|
905
|
+
f"消息长度 <b>· 平均 {stats.avg_subject_len} 字符</b>",
|
|
906
|
+
rows + '<p class="num-note">最长的一条见「年度之最」。</p>',
|
|
907
|
+
)
|
|
908
|
+
|
|
909
|
+
|
|
910
|
+
def build_adddel(stats: ReportStats) -> str:
|
|
911
|
+
ins, deleted = stats.insertions, stats.deletions
|
|
912
|
+
total = max(ins + deleted, 1)
|
|
913
|
+
ratio = deleted / max(ins, 1)
|
|
914
|
+
body = (
|
|
915
|
+
f'<div class="pair">'
|
|
916
|
+
f'<i style="width:{ins / total * 100:.1f}%;background:var(--ink)"></i>'
|
|
917
|
+
f'<i style="width:{deleted / total * 100:.1f}%;background:var(--acc)"></i></div>'
|
|
918
|
+
f'<div class="stack-labels"><span>新增 {fmt_human(ins)} 行</span>'
|
|
919
|
+
f'<span>删除 {fmt_human(deleted)} 行</span></div>'
|
|
920
|
+
f'<p class="num-note">删除 / 新增 = {ratio:.0%}。'
|
|
921
|
+
)
|
|
922
|
+
if stats.largest_deletion:
|
|
923
|
+
ld = stats.largest_deletion
|
|
924
|
+
body += (f'最大的一次删除 {fmt_int(ld["lines"])} 行'
|
|
925
|
+
f'({escape(ld["repo"])},{ld["date"]})。')
|
|
926
|
+
body += "</p>"
|
|
927
|
+
|
|
928
|
+
top_del = sorted(stats.repo_details, key=lambda d: -d["deleted"])[:3]
|
|
929
|
+
if top_del:
|
|
930
|
+
max_del = max(d["deleted"] for d in top_del) or 1
|
|
931
|
+
body += '<div class="sub-head">删除最多的仓库</div>'
|
|
932
|
+
body += "".join(
|
|
933
|
+
f'<div class="bar-row"><span class="bar-name">{escape(d["name"])}</span>'
|
|
934
|
+
f'<div class="bar-track"><i style="width:{d["deleted"] / max_del * 100:.1f}%;'
|
|
935
|
+
f'background:var(--acc)"></i></div>'
|
|
936
|
+
f'<span class="bar-val">{fmt_human(d["deleted"])}</span></div>'
|
|
937
|
+
for d in top_del
|
|
938
|
+
)
|
|
939
|
+
return _panel("增删比 <b>· 建设 vs 重构</b>", body)
|
|
940
|
+
|
|
941
|
+
|
|
942
|
+
def build_sessions(stats: ReportStats) -> str:
|
|
943
|
+
s = stats.sessions
|
|
944
|
+
if not s.get("count"):
|
|
945
|
+
body = '<p class="num-note">没有足够的提交时间数据。</p>'
|
|
946
|
+
else:
|
|
947
|
+
hours = s["longest_minutes"] // 60
|
|
948
|
+
mins = s["longest_minutes"] % 60
|
|
949
|
+
body = (
|
|
950
|
+
f'<div class="mini-stats">'
|
|
951
|
+
f'<div><b>{s["count"]}</b><span>次编码会话</span></div>'
|
|
952
|
+
f'<div><b>{hours}h {mins:02d}m</b><span>最长一次连续编码</span></div>'
|
|
953
|
+
f'<div><b>{s["longest_commits"]}</b><span>最长会话里的提交</span></div>'
|
|
954
|
+
f'<div><b>{s["avg_minutes"]}m</b><span>平均会话时长</span></div>'
|
|
955
|
+
f'</div>'
|
|
956
|
+
f'<p class="num-note">间隔 ≤ 2 小时算同一会话。最长一次:'
|
|
957
|
+
f'{escape(s["longest_start"])} → {escape(s["longest_end"])}。</p>'
|
|
958
|
+
)
|
|
959
|
+
return _panel("工作节奏 <b>· 会话而不是次数</b>", body)
|
|
960
|
+
|
|
961
|
+
|
|
962
|
+
def build_language_quarters(stats: ReportStats) -> str:
|
|
963
|
+
if not stats.language_quarters:
|
|
964
|
+
return _panel("语言栈变化 <b>· 按季度占比</b>",
|
|
965
|
+
'<p class="num-note">没有足够数据。</p>', span=True)
|
|
966
|
+
palette = ["#171512", "#d4491f", "#8f8672", "#b3ab97", "#c8c1ac"]
|
|
967
|
+
names = [name for name, _ in stats.language_quarters[0]["rows"]]
|
|
968
|
+
cols = []
|
|
969
|
+
for q in stats.language_quarters:
|
|
970
|
+
raw_total = sum(v for _, v in q["rows"])
|
|
971
|
+
total = raw_total or 1
|
|
972
|
+
segs = []
|
|
973
|
+
if raw_total == 0:
|
|
974
|
+
segs.append('<span class="q-none">无提交</span>')
|
|
975
|
+
for i, (name, value) in enumerate(q["rows"]):
|
|
976
|
+
if value <= 0:
|
|
977
|
+
continue
|
|
978
|
+
pct = value / total * 100
|
|
979
|
+
segs.append(
|
|
980
|
+
f'<i style="height:{pct:.2f}%;background:{palette[i % len(palette)]}" '
|
|
981
|
+
f'data-tip="{escape(name)} · {pct:.0f}% · {fmt_human(value)} 行"></i>'
|
|
982
|
+
)
|
|
983
|
+
cols.append(
|
|
984
|
+
f'<div class="q-col"><div class="q-stack">{"".join(segs)}</div>'
|
|
985
|
+
f'<span class="q-label">{q["q"]}</span></div>'
|
|
986
|
+
)
|
|
987
|
+
legend = "".join(
|
|
988
|
+
f'<span><i style="background:{palette[i % len(palette)]}"></i>{escape(name)}</span>'
|
|
989
|
+
for i, name in enumerate(names)
|
|
990
|
+
)
|
|
991
|
+
return _panel(
|
|
992
|
+
"语言栈变化 <b>· 按季度占比</b>",
|
|
993
|
+
f'<div class="q-chart" role="img" aria-label="语言栈季度变化">'
|
|
994
|
+
f'{"".join(cols)}</div>'
|
|
995
|
+
f'<div class="q-legend">{legend}</div>',
|
|
996
|
+
span=True,
|
|
997
|
+
)
|
|
998
|
+
|
|
999
|
+
|
|
1000
|
+
def build_lifecycle(stats: ReportStats) -> str:
|
|
1001
|
+
start, end = date_window(stats)
|
|
1002
|
+
span_days = max((end - start).days, 1)
|
|
1003
|
+
ordered = sorted(stats.repo_details, key=lambda r: (r["first"], -r["commits"]))[:10]
|
|
1004
|
+
|
|
1005
|
+
months = "".join(f"<span>{m:02d}</span>" for m in range(1, 13))
|
|
1006
|
+
head = (
|
|
1007
|
+
f'<div class="lc-months"><span></span>'
|
|
1008
|
+
f'<div class="lc-month-ticks">{months}</div>'
|
|
1009
|
+
f'<span class="lc-end">首次–最近</span></div>'
|
|
1010
|
+
)
|
|
1011
|
+
|
|
1012
|
+
rows = []
|
|
1013
|
+
for repo in ordered:
|
|
1014
|
+
try:
|
|
1015
|
+
first = datetime.strptime(repo["first"], "%Y.%m.%d").date()
|
|
1016
|
+
last = datetime.strptime(repo["last"], "%Y.%m.%d").date()
|
|
1017
|
+
except ValueError:
|
|
1018
|
+
continue
|
|
1019
|
+
left = max(0.0, min(100.0, (first - start).days / span_days * 100))
|
|
1020
|
+
width = max(0.0, min(100.0 - left, (last - first).days / span_days * 100))
|
|
1021
|
+
_stamp, active = _stamp_for(repo["last"], stats.generated_at, stats.year)
|
|
1022
|
+
hot = " hot" if active else ""
|
|
1023
|
+
if (last - first).days == 0:
|
|
1024
|
+
bar = f'<i class="dot{hot}" style="left:calc({left:.2f}% - 3px)"></i>'
|
|
1025
|
+
dates = repo["first"][5:]
|
|
1026
|
+
else:
|
|
1027
|
+
bar = f'<i class="{hot.strip()}" style="left:{left:.1f}%;width:{width:.2f}%"></i>'
|
|
1028
|
+
dates = f'{repo["first"][5:]}–{repo["last"][5:]}'
|
|
1029
|
+
rows.append(
|
|
1030
|
+
f'<div class="lc-row">'
|
|
1031
|
+
f'<span class="lc-name" data-tip="{escape(repo["name"])} · '
|
|
1032
|
+
f'{repo["commits"]} 次提交 · {repo["active_days"]} 个活跃日">'
|
|
1033
|
+
f'{escape(repo["name"])}</span>'
|
|
1034
|
+
f'<div class="lc-track" data-tip="{repo["commits"]} 次提交 · '
|
|
1035
|
+
f'{fmt_human(repo["lines"])} 行变更 · {repo["active_days"]} 个活跃日">'
|
|
1036
|
+
f'{bar}</div>'
|
|
1037
|
+
f'<span class="lc-date">{dates}</span></div>'
|
|
1038
|
+
)
|
|
1039
|
+
return _panel(
|
|
1040
|
+
f"仓库生命周期 <b>· {stats.year} 活跃区间</b>",
|
|
1041
|
+
f'<div class="lc-chart">{head}{"".join(rows)}</div>',
|
|
1042
|
+
span=True,
|
|
1043
|
+
)
|
|
1044
|
+
|
|
1045
|
+
|
|
1046
|
+
def build_deleted_files(stats: ReportStats) -> str:
|
|
1047
|
+
rows_data = getattr(stats, "top_deleted_files", None) or []
|
|
1048
|
+
if not rows_data:
|
|
1049
|
+
return ""
|
|
1050
|
+
max_del = max((n for _, n in rows_data), default=1) or 1
|
|
1051
|
+
rows = "".join(
|
|
1052
|
+
f'<div class="file-row"><span class="idx">{i:02d}</span>'
|
|
1053
|
+
f'<span class="f-path">{escape(path)}</span>'
|
|
1054
|
+
f'<div class="f-bar"><i style="width:{n / max_del * 100:.1f}%;background:var(--acc)"></i></div>'
|
|
1055
|
+
f'<span class="f-num">-{fmt_int(n)}</span></div>'
|
|
1056
|
+
for i, (path, n) in enumerate(rows_data[:8], 1)
|
|
1057
|
+
)
|
|
1058
|
+
return (
|
|
1059
|
+
'<div class="num-panel rv span2">'
|
|
1060
|
+
'<h3>文件级重构榜 <b>· 删除行数最多的文件</b></h3>'
|
|
1061
|
+
f'{rows}'
|
|
1062
|
+
'</div>'
|
|
1063
|
+
)
|
|
1064
|
+
|
|
1065
|
+
|
|
1066
|
+
def build_dormant(stats: ReportStats) -> str:
|
|
1067
|
+
if not stats.dormant:
|
|
1068
|
+
return _panel("仓库墓园 <b>· 30 天没动</b>",
|
|
1069
|
+
'<p class="num-note">没有休眠超过 30 天的仓库。</p>', span=True)
|
|
1070
|
+
rows = "".join(
|
|
1071
|
+
f'<div class="dormant-row"><span class="d-name">{escape(d["name"])}</span>'
|
|
1072
|
+
f'<span class="d-last">最后提交 {d["last"]}</span>'
|
|
1073
|
+
f'<span class="d-days">{d["days"]} 天</span></div>'
|
|
1074
|
+
for d in stats.dormant
|
|
1075
|
+
)
|
|
1076
|
+
return _panel(
|
|
1077
|
+
f"仓库墓园 <b>· {len(stats.dormant)} 个仓库超过 30 天没动</b>",
|
|
1078
|
+
rows, span=True,
|
|
1079
|
+
)
|
|
1080
|
+
|
|
1081
|
+
|
|
1082
|
+
def build_compare(stats: ReportStats) -> str:
|
|
1083
|
+
"""Year-over-year panel: metric table plus a month-by-month chart."""
|
|
1084
|
+
previous = stats.previous
|
|
1085
|
+
if not previous:
|
|
1086
|
+
return ""
|
|
1087
|
+
|
|
1088
|
+
prev_year = previous.get("year", stats.year - 1)
|
|
1089
|
+
prev_commits = previous.get("previous_commits")
|
|
1090
|
+
if prev_commits is None: # reports generated before raw values were stored
|
|
1091
|
+
prev_commits = stats.commit_count - previous.get("commits", 0)
|
|
1092
|
+
|
|
1093
|
+
head = (
|
|
1094
|
+
f'<div class="num-panel rv span2 cmp-panel">'
|
|
1095
|
+
f'<h3>同比去年 <b>· {prev_year} vs {stats.year}</b></h3>'
|
|
1096
|
+
)
|
|
1097
|
+
hint = ""
|
|
1098
|
+
if prev_commits == 0:
|
|
1099
|
+
hint = (
|
|
1100
|
+
f'<p class="cmp-hint">{prev_year} 年在扫描范围内没有提交,'
|
|
1101
|
+
"以下按 0 计算。</p>"
|
|
1102
|
+
'<p class="cmp-hint">如果当时用过其他邮箱或名字,可以用 '
|
|
1103
|
+
"<code>--alias</code> 把旧身份合并进来后重新生成。</p>"
|
|
1104
|
+
)
|
|
1105
|
+
|
|
1106
|
+
def human(value: int) -> str:
|
|
1107
|
+
return fmt_human(value).replace(" ", "")
|
|
1108
|
+
|
|
1109
|
+
def delta_int(value: int, pct: float | None) -> str:
|
|
1110
|
+
text = f"{value:+,}" if value else "0"
|
|
1111
|
+
if pct is not None:
|
|
1112
|
+
text += " (0%)" if not pct else f" ({pct:+.0%})"
|
|
1113
|
+
return text
|
|
1114
|
+
|
|
1115
|
+
def delta_human(value: int, pct: float | None) -> str:
|
|
1116
|
+
text = (
|
|
1117
|
+
("+" if value > 0 else "-") + human(abs(value))
|
|
1118
|
+
if value else "0"
|
|
1119
|
+
)
|
|
1120
|
+
if pct is not None:
|
|
1121
|
+
text += " (0%)" if not pct else f" ({pct:+.0%})"
|
|
1122
|
+
return text
|
|
1123
|
+
|
|
1124
|
+
def pp_parts(before: float, now: float) -> tuple[str, str, str]:
|
|
1125
|
+
before_pct = round(before * 100)
|
|
1126
|
+
now_pct = round(now * 100)
|
|
1127
|
+
delta = now_pct - before_pct
|
|
1128
|
+
return (
|
|
1129
|
+
f"{before_pct}%",
|
|
1130
|
+
f"{now_pct}%",
|
|
1131
|
+
f"{delta:+d} 个百分点" if delta else "0",
|
|
1132
|
+
)
|
|
1133
|
+
|
|
1134
|
+
prev_weekend = previous.get("previous_weekend_share", 0.0)
|
|
1135
|
+
prev_night = previous.get("previous_night_share", 0.0)
|
|
1136
|
+
weekend_before, weekend_now, weekend_delta = pp_parts(
|
|
1137
|
+
prev_weekend, stats.weekend_share
|
|
1138
|
+
)
|
|
1139
|
+
night_before, night_now, night_delta = pp_parts(
|
|
1140
|
+
prev_night, stats.night_share
|
|
1141
|
+
)
|
|
1142
|
+
rows = [
|
|
1143
|
+
("提交", f"{prev_commits:,}", f"{stats.commit_count:,}",
|
|
1144
|
+
delta_int(previous["commits"], previous.get("commits_pct"))),
|
|
1145
|
+
("代码行变更", human(previous.get("previous_lines", 0)),
|
|
1146
|
+
human(stats.lines_changed),
|
|
1147
|
+
delta_human(previous["lines"], previous.get("lines_pct"))),
|
|
1148
|
+
("新增行", human(previous.get("previous_insertions", 0)),
|
|
1149
|
+
human(stats.insertions),
|
|
1150
|
+
delta_human(previous.get("insertions", 0),
|
|
1151
|
+
previous.get("insertions_pct"))),
|
|
1152
|
+
("删除行", human(previous.get("previous_deletions", 0)),
|
|
1153
|
+
human(stats.deletions),
|
|
1154
|
+
delta_human(previous.get("deletions", 0),
|
|
1155
|
+
previous.get("deletions_pct"))),
|
|
1156
|
+
("活跃日", f'{previous.get("previous_active_days", 0):,}',
|
|
1157
|
+
f"{stats.active_days:,}",
|
|
1158
|
+
delta_int(previous["active_days"], previous.get("active_days_pct"))),
|
|
1159
|
+
("涉及仓库", f'{previous.get("previous_repos", 0):,}',
|
|
1160
|
+
f"{stats.repo_count:,}",
|
|
1161
|
+
delta_int(previous["repos"], previous.get("repos_pct"))),
|
|
1162
|
+
("最长连续(天)", f'{previous.get("previous_streak", 0):,}',
|
|
1163
|
+
f"{stats.longest_streak:,}",
|
|
1164
|
+
delta_int(previous["streak"], previous.get("streak_pct"))),
|
|
1165
|
+
("平均提交信息(字符)", f'{previous.get("previous_avg_subject_len", 0):,}',
|
|
1166
|
+
f"{stats.avg_subject_len:,}",
|
|
1167
|
+
delta_int(previous.get("avg_subject_len", 0),
|
|
1168
|
+
previous.get("avg_subject_len_pct"))),
|
|
1169
|
+
("周末占比", weekend_before, weekend_now, weekend_delta),
|
|
1170
|
+
("深夜占比", night_before, night_now, night_delta),
|
|
1171
|
+
]
|
|
1172
|
+
table = "".join(
|
|
1173
|
+
f'<div class="cmp-row"><span class="cmp-k">{label}</span>'
|
|
1174
|
+
f'<span class="cmp-v">{before}</span>'
|
|
1175
|
+
f'<span class="cmp-v cur">{now}</span>'
|
|
1176
|
+
f'<span class="cmp-d{" zero" if change in ("0", "0pp") else ""}">{change}</span>'
|
|
1177
|
+
"</div>"
|
|
1178
|
+
for label, before, now, change in rows
|
|
1179
|
+
)
|
|
1180
|
+
|
|
1181
|
+
prev_monthly = list(previous.get("previous_monthly") or [])
|
|
1182
|
+
prev_monthly += [0] * (12 - len(prev_monthly))
|
|
1183
|
+
cur_monthly = list(stats.monthly) + [0] * (12 - len(stats.monthly))
|
|
1184
|
+
chart_max = max([1, *prev_monthly[:12], *cur_monthly[:12]])
|
|
1185
|
+
cols = []
|
|
1186
|
+
for i in range(12):
|
|
1187
|
+
pv, cv = prev_monthly[i], cur_monthly[i]
|
|
1188
|
+
pp = pv / chart_max * 100
|
|
1189
|
+
cp = cv / chart_max * 100
|
|
1190
|
+
prev_label = (
|
|
1191
|
+
f'<b style="bottom:calc({pp:.1f}% + 3px)">{pv:,}</b>' if pv else ""
|
|
1192
|
+
)
|
|
1193
|
+
cur_label = (
|
|
1194
|
+
f'<b style="bottom:calc({cp:.1f}% + 3px)">{cv:,}</b>' if cv else ""
|
|
1195
|
+
)
|
|
1196
|
+
cols.append(
|
|
1197
|
+
f'<div class="cmp-col"><div class="cmp-bars">'
|
|
1198
|
+
f'<div class="cmp-bar prev"><i style="height:{pp:.1f}%" '
|
|
1199
|
+
f'data-tip="{prev_year} · {i + 1} 月 · {pv} 次提交"></i>'
|
|
1200
|
+
f"{prev_label}</div>"
|
|
1201
|
+
f'<div class="cmp-bar cur"><i style="height:{cp:.1f}%" '
|
|
1202
|
+
f'data-tip="{stats.year} · {i + 1} 月 · {cv} 次提交"></i>'
|
|
1203
|
+
f"{cur_label}</div>"
|
|
1204
|
+
f'</div><span>{i + 1}</span></div>'
|
|
1205
|
+
)
|
|
1206
|
+
notes = []
|
|
1207
|
+
cur_peak = max(cur_monthly[:12])
|
|
1208
|
+
prev_peak = max(prev_monthly[:12])
|
|
1209
|
+
if cur_peak:
|
|
1210
|
+
notes.append(
|
|
1211
|
+
f"<span>今年峰值 {cur_monthly.index(cur_peak) + 1} 月 · "
|
|
1212
|
+
f"{cur_peak:,} 次</span>"
|
|
1213
|
+
)
|
|
1214
|
+
if prev_peak:
|
|
1215
|
+
notes.append(
|
|
1216
|
+
f"<span>去年峰值 {prev_monthly.index(prev_peak) + 1} 月 · "
|
|
1217
|
+
f"{prev_peak:,} 次</span>"
|
|
1218
|
+
)
|
|
1219
|
+
|
|
1220
|
+
chart = (
|
|
1221
|
+
f'<div class="cmp-chart" role="img" aria-label="月度同比柱状图">'
|
|
1222
|
+
f'<div class="cmp-cols">{"".join(cols)}</div>'
|
|
1223
|
+
f'<div class="cmp-legend"><span><i class="prev"></i>{prev_year}</span>'
|
|
1224
|
+
f'<span><i class="cur"></i>{stats.year}</span></div></div>'
|
|
1225
|
+
)
|
|
1226
|
+
note_html = f'<div class="cmp-note">{"".join(notes)}</div>' if notes else ""
|
|
1227
|
+
return (
|
|
1228
|
+
head + hint
|
|
1229
|
+
+ '<div class="cmp-row cmp-head"><span class="cmp-k">指标</span>'
|
|
1230
|
+
f'<span class="cmp-v">{prev_year}</span>'
|
|
1231
|
+
f'<span class="cmp-v cur">{stats.year}</span>'
|
|
1232
|
+
'<span class="cmp-d">变化</span></div>'
|
|
1233
|
+
+ table + chart + note_html + "</div>"
|
|
1234
|
+
)
|
|
1235
|
+
|
|
1236
|
+
|
|
1237
|
+
def build_numbers(stats: ReportStats) -> str:
|
|
1238
|
+
total_lines = max(stats.lines_changed, 1)
|
|
1239
|
+
details = stats.repo_details
|
|
1240
|
+
by_lines = sorted(details, key=lambda d: (-d["lines"], -d["commits"]))
|
|
1241
|
+
top = by_lines[0] if by_lines else None
|
|
1242
|
+
top_share = top["lines"] / total_lines * 100 if top else 0
|
|
1243
|
+
others = [d for d in by_lines[1:6] if d["lines"] > 0]
|
|
1244
|
+
max_other = max((d["lines"] for d in others), default=1)
|
|
1245
|
+
other_rows = "".join(
|
|
1246
|
+
f'<div class="bar-row"><span class="bar-name">{escape(d["name"])}</span>'
|
|
1247
|
+
f'<div class="bar-track"><i style="width:{d["lines"] / max_other * 100:.1f}%"></i></div>'
|
|
1248
|
+
f'<span class="bar-val">{fmt_human(d["lines"])}</span></div>'
|
|
1249
|
+
for d in others
|
|
1250
|
+
)
|
|
1251
|
+
other_note = (
|
|
1252
|
+
f'<div class="stack-labels"><span>{escape(top["name"])} · {fmt_human(top["lines"])}</span>'
|
|
1253
|
+
f'<span>其余 {len(details) - 1} 个仓库 · {fmt_human(total_lines - top["lines"])}</span></div>'
|
|
1254
|
+
if top and len(details) > 1 else
|
|
1255
|
+
f'<div class="stack-labels"><span>{escape(top["name"]) if top else "—"}</span></div>'
|
|
1256
|
+
)
|
|
1257
|
+
|
|
1258
|
+
rows_lang, _total = language_breakdown(stats.languages, limit=6, min_share=0.01)
|
|
1259
|
+
lang_total = sum(v for _, v in rows_lang) or 1
|
|
1260
|
+
palette = ["#171512", "#d4491f", "#8f8672", "#b3ab97", "#6f6a5e", "#c8c1ac"]
|
|
1261
|
+
lang_bar = "".join(
|
|
1262
|
+
f'<i style="width:{n / lang_total * 100:.2f}%;background:{palette[i % len(palette)]}"></i>'
|
|
1263
|
+
for i, (_name, n) in enumerate(rows_lang)
|
|
1264
|
+
)
|
|
1265
|
+
lang_legend = "".join(
|
|
1266
|
+
f'<div><span class="sq" style="background:{palette[i % len(palette)]}"></span>'
|
|
1267
|
+
f'{escape(name)}<b>{n / lang_total * 100:.0f}%</b></div>'
|
|
1268
|
+
for i, (name, n) in enumerate(rows_lang)
|
|
1269
|
+
)
|
|
1270
|
+
|
|
1271
|
+
max_file = max((n for _, n in stats.top_files), default=1)
|
|
1272
|
+
file_rows = "".join(
|
|
1273
|
+
f'<div class="file-line"><div class="file-path">{escape(path)}</div>'
|
|
1274
|
+
f'<div class="file-meta"><div class="bar-track">'
|
|
1275
|
+
f'<i style="width:{n / max_file * 100:.1f}%"></i></div>'
|
|
1276
|
+
f'<span class="bar-val">{fmt_human(n)}</span></div></div>'
|
|
1277
|
+
for path, n in stats.top_files[:8]
|
|
1278
|
+
) or '<p class="num-note">没有可统计的代码文件。</p>'
|
|
1279
|
+
|
|
1280
|
+
return f"""
|
|
1281
|
+
<div class="num-grid">
|
|
1282
|
+
{build_compare(stats)}
|
|
1283
|
+
{build_monthly(stats)}
|
|
1284
|
+
{build_clock(stats)}
|
|
1285
|
+
<div class="num-panel rv">
|
|
1286
|
+
<h3>代码构成 <b>· 头部集中度(按行数)</b></h3>
|
|
1287
|
+
<div class="stack">
|
|
1288
|
+
<i style="width:{top_share:.1f}%;background:var(--acc)"></i>
|
|
1289
|
+
<i style="width:{100 - top_share:.1f}%;background:var(--ink)"></i>
|
|
1290
|
+
</div>
|
|
1291
|
+
{other_note}
|
|
1292
|
+
{other_rows}
|
|
1293
|
+
</div>
|
|
1294
|
+
<div class="num-panel rv" style="--d:90ms">
|
|
1295
|
+
<h3>语言构成 <b>· 按行变更估算</b></h3>
|
|
1296
|
+
<div class="lang-bar">{lang_bar}</div>
|
|
1297
|
+
<div class="lang-legend">{lang_legend}</div>
|
|
1298
|
+
</div>
|
|
1299
|
+
{build_language_quarters(stats)}
|
|
1300
|
+
{build_sizes(stats)}
|
|
1301
|
+
{build_types(stats)}
|
|
1302
|
+
{build_keywords(stats)}
|
|
1303
|
+
{build_messages(stats)}
|
|
1304
|
+
{build_adddel(stats)}
|
|
1305
|
+
{build_sessions(stats)}
|
|
1306
|
+
{build_lifecycle(stats)}
|
|
1307
|
+
{build_dormant(stats)}
|
|
1308
|
+
<div class="num-panel rv span2">
|
|
1309
|
+
<h3>最常改的文件 <b>· 改动热区(完整路径)</b></h3>
|
|
1310
|
+
{file_rows}
|
|
1311
|
+
</div>
|
|
1312
|
+
{build_deleted_files(stats)}
|
|
1313
|
+
{build_heatmap(stats)}
|
|
1314
|
+
</div>
|
|
1315
|
+
"""
|
|
1316
|
+
|
|
1317
|
+
|
|
1318
|
+
def _theme_color_map(base_dict: dict, target_dict: dict) -> dict[str, str]:
|
|
1319
|
+
mapping: dict[str, str] = {}
|
|
1320
|
+
for k in ("ink", "ink2", "muted", "line", "accent", "bar"):
|
|
1321
|
+
mapping[base_dict[k].lower()] = target_dict[k]
|
|
1322
|
+
for src, dst in zip(base_dict["palette"], target_dict["palette"]):
|
|
1323
|
+
mapping.setdefault(src.lower(), dst)
|
|
1324
|
+
for src, dst in zip(base_dict["levels"], target_dict["levels"]):
|
|
1325
|
+
mapping.setdefault(src.lower(), dst)
|
|
1326
|
+
return mapping
|
|
1327
|
+
|
|
1328
|
+
|
|
1329
|
+
def build_card_preview_widget(stats: ReportStats, *, lang: str = "zh") -> str:
|
|
1330
|
+
en = lang == "en"
|
|
1331
|
+
base_light, base_dark = CARD_THEMES["paper"]
|
|
1332
|
+
maps: dict[str, dict[str, dict[str, str]]] = {}
|
|
1333
|
+
for t_name, (t_light, t_dark) in CARD_THEMES.items():
|
|
1334
|
+
maps[t_name] = {
|
|
1335
|
+
"light": _theme_color_map(base_light, t_light),
|
|
1336
|
+
"dark": _theme_color_map(base_dark, t_dark),
|
|
1337
|
+
}
|
|
1338
|
+
svg_light = build_card_svg(stats, dark=False, theme="paper", lang=lang)
|
|
1339
|
+
svg_dark = build_card_svg(stats, dark=True, theme="paper", lang=lang)
|
|
1340
|
+
suffix = "-en" if en else ""
|
|
1341
|
+
embed_snippet = escape(
|
|
1342
|
+
"<picture>\n"
|
|
1343
|
+
f' <source media="(prefers-color-scheme: dark)" '
|
|
1344
|
+
f'srcset="./codeyear-{stats.year}-card{suffix}-dark.svg">\n'
|
|
1345
|
+
f' <img src="./codeyear-{stats.year}-card{suffix}.svg" width="640" '
|
|
1346
|
+
f'alt="CodeYear {stats.year}">\n'
|
|
1347
|
+
"</picture>"
|
|
1348
|
+
)
|
|
1349
|
+
payload_json = json.dumps(
|
|
1350
|
+
{
|
|
1351
|
+
"year": stats.year,
|
|
1352
|
+
"suffix": suffix,
|
|
1353
|
+
"light": svg_light,
|
|
1354
|
+
"dark": svg_dark,
|
|
1355
|
+
"maps": maps,
|
|
1356
|
+
},
|
|
1357
|
+
ensure_ascii=False,
|
|
1358
|
+
).replace("</", "<\\/")
|
|
1359
|
+
|
|
1360
|
+
heading = "GitHub profile card" if en else "GitHub 主页卡片"
|
|
1361
|
+
note = (
|
|
1362
|
+
"Preview all 4 themes in light or dark mode, download the SVG directly, or paste the snippet into your profile README.md:"
|
|
1363
|
+
if en
|
|
1364
|
+
else "实时预览 4 套主题与浅色/深色效果,可直接下载当前 SVG,或粘贴下方代码到同名 Profile 仓库的 README.md:"
|
|
1365
|
+
)
|
|
1366
|
+
theme_labels = (
|
|
1367
|
+
[("paper", "Paper"), ("mono", "Mono"), ("forest", "Forest"), ("ocean", "Ocean")]
|
|
1368
|
+
if en
|
|
1369
|
+
else [("paper", "纸色 Paper"), ("mono", "黑白 Mono"), ("forest", "森林 Forest"), ("ocean", "海洋 Ocean")]
|
|
1370
|
+
)
|
|
1371
|
+
mode_labels = (
|
|
1372
|
+
[("light", "Light"), ("dark", "Dark")]
|
|
1373
|
+
if en
|
|
1374
|
+
else [("light", "浅色"), ("dark", "深色")]
|
|
1375
|
+
)
|
|
1376
|
+
dl_label = "Download current SVG" if en else "下载当前卡片 SVG"
|
|
1377
|
+
copy_label = "Copy embed snippet" if en else "复制嵌入代码"
|
|
1378
|
+
|
|
1379
|
+
t_btns = "".join(
|
|
1380
|
+
f'<button class="filter{" on" if k == "paper" else ""}" type="button" data-card-theme="{k}">{lbl}</button>'
|
|
1381
|
+
for k, lbl in theme_labels
|
|
1382
|
+
)
|
|
1383
|
+
m_btns = "".join(
|
|
1384
|
+
f'<button class="filter{" on" if k == "light" else ""}" type="button" data-card-mode="{k}">{lbl}</button>'
|
|
1385
|
+
for k, lbl in mode_labels
|
|
1386
|
+
)
|
|
1387
|
+
return f"""<!--CARD_WIDGET_START-->
|
|
1388
|
+
<div class="sub-head" style="margin-top:24px">{heading}</div>
|
|
1389
|
+
<p class="num-note" style="margin:6px 0 10px">{note}</p>
|
|
1390
|
+
<div class="filters" style="margin:8px 0 10px;display:flex;gap:6px;flex-wrap:wrap;align-items:center">
|
|
1391
|
+
{t_btns}
|
|
1392
|
+
<span style="margin:0 4px;color:var(--line2)">|</span>
|
|
1393
|
+
{m_btns}
|
|
1394
|
+
<button class="filter" type="button" id="download-card-svg" style="margin-left:auto">{dl_label}</button>
|
|
1395
|
+
</div>
|
|
1396
|
+
<div id="card-preview-stage" style="border:1px solid var(--line);padding:16px;margin:0 0 12px;display:flex;justify-content:center;background:var(--paper);transition:background .18s">
|
|
1397
|
+
<div id="card-preview-inner" style="width:100%;max-width:460px">{svg_light}</div>
|
|
1398
|
+
</div>
|
|
1399
|
+
<pre class="embed-code" id="embed-snippet" style="background:var(--paper2);border:1px solid var(--line);padding:12px;font-family:var(--mono);font-size:11.5px;overflow-x:auto;margin:0 0 8px">{embed_snippet}</pre>
|
|
1400
|
+
<button class="filter" type="button" id="copy-embed" onclick="navigator.clipboard&&navigator.clipboard.writeText(document.getElementById('embed-snippet').textContent)">{copy_label}</button>
|
|
1401
|
+
<script>
|
|
1402
|
+
(function(){{
|
|
1403
|
+
const data = {payload_json};
|
|
1404
|
+
let curTheme = "paper", curMode = "light";
|
|
1405
|
+
const stage = document.getElementById("card-preview-stage");
|
|
1406
|
+
const inner = document.getElementById("card-preview-inner");
|
|
1407
|
+
const dlBtn = document.getElementById("download-card-svg");
|
|
1408
|
+
function currentSvg() {{
|
|
1409
|
+
const raw = curMode === "dark" ? data.dark : data.light;
|
|
1410
|
+
const cmap = (data.maps[curTheme] || data.maps.paper)[curMode];
|
|
1411
|
+
return raw.replace(/#[0-9a-f]{{6}}/gi, m => cmap[m.toLowerCase()] || m);
|
|
1412
|
+
}}
|
|
1413
|
+
function updateView() {{
|
|
1414
|
+
if (!inner || !stage) return;
|
|
1415
|
+
const svg = currentSvg();
|
|
1416
|
+
inner.innerHTML = svg;
|
|
1417
|
+
const svgEl = inner.querySelector("svg");
|
|
1418
|
+
if (svgEl) {{ svgEl.style.width = "100%"; svgEl.style.height = "auto"; }}
|
|
1419
|
+
stage.style.background = curMode === "dark" ? "#141413" : "var(--paper)";
|
|
1420
|
+
}}
|
|
1421
|
+
document.querySelectorAll("[data-card-theme]").forEach(btn => {{
|
|
1422
|
+
btn.addEventListener("click", () => {{
|
|
1423
|
+
curTheme = btn.getAttribute("data-card-theme") || "paper";
|
|
1424
|
+
document.querySelectorAll("[data-card-theme]").forEach(b => b.classList.toggle("on", b === btn));
|
|
1425
|
+
updateView();
|
|
1426
|
+
}});
|
|
1427
|
+
}});
|
|
1428
|
+
document.querySelectorAll("[data-card-mode]").forEach(btn => {{
|
|
1429
|
+
btn.addEventListener("click", () => {{
|
|
1430
|
+
curMode = btn.getAttribute("data-card-mode") || "light";
|
|
1431
|
+
document.querySelectorAll("[data-card-mode]").forEach(b => b.classList.toggle("on", b === btn));
|
|
1432
|
+
updateView();
|
|
1433
|
+
}});
|
|
1434
|
+
}});
|
|
1435
|
+
if (dlBtn) {{
|
|
1436
|
+
dlBtn.addEventListener("click", () => {{
|
|
1437
|
+
const blob = new Blob([currentSvg()], {{type: "image/svg+xml;charset=utf-8"}});
|
|
1438
|
+
const url = URL.createObjectURL(blob);
|
|
1439
|
+
const a = document.createElement("a");
|
|
1440
|
+
const darkPart = curMode === "dark" ? "-dark" : "";
|
|
1441
|
+
const themePart = curTheme === "paper" ? "" : "-" + curTheme;
|
|
1442
|
+
a.href = url;
|
|
1443
|
+
a.download = "codeyear-" + data.year + "-card" + data.suffix + themePart + darkPart + ".svg";
|
|
1444
|
+
document.body.appendChild(a);
|
|
1445
|
+
a.click();
|
|
1446
|
+
a.remove();
|
|
1447
|
+
setTimeout(() => URL.revokeObjectURL(url), 1000);
|
|
1448
|
+
}});
|
|
1449
|
+
}}
|
|
1450
|
+
updateView();
|
|
1451
|
+
}})();
|
|
1452
|
+
</script>
|
|
1453
|
+
<!--CARD_WIDGET_END-->"""
|
|
1454
|
+
|
|
1455
|
+
|
|
1456
|
+
def build_about(stats: ReportStats) -> str:
|
|
1457
|
+
public = stats.public_source
|
|
1458
|
+
if public:
|
|
1459
|
+
privacy_line = "这份报告根据公开 GitHub 数据生成;没有读取或上传本机代码。"
|
|
1460
|
+
identity_line = (
|
|
1461
|
+
"只统计该账号名下的公开仓库,以及 GitHub 能关联到该账号的提交;"
|
|
1462
|
+
"不读取私有仓库。"
|
|
1463
|
+
)
|
|
1464
|
+
merge_line = f"只统计 {stats.year} 年的提交;合并提交不计入。"
|
|
1465
|
+
else:
|
|
1466
|
+
privacy_line = "这份报告由 CodeYear 在你的电脑上生成,代码从未离开这台机器。"
|
|
1467
|
+
if stats.identity_label:
|
|
1468
|
+
identity_line = (
|
|
1469
|
+
f"只统计你本人作者的提交({escape(stats.identity_label)});"
|
|
1470
|
+
f"已过滤 {stats.filtered_commits} 次他人提交。"
|
|
1471
|
+
)
|
|
1472
|
+
else:
|
|
1473
|
+
identity_line = "未检测到 git 身份,统计了所有作者的提交(可用 --all-authors 显式开启)。"
|
|
1474
|
+
merge_line = f"只统计 {stats.year} 年的提交;合并提交(--no-merges)不计入。"
|
|
1475
|
+
quote_tail = (
|
|
1476
|
+
"尤其是加了 --no-merges 的时候。" if not public
|
|
1477
|
+
else "尤其是只读公开数据的时候。"
|
|
1478
|
+
)
|
|
1479
|
+
card_widget = build_card_preview_widget(stats, lang="zh")
|
|
1480
|
+
return f"""
|
|
1481
|
+
<div class="about rv">
|
|
1482
|
+
<ul>
|
|
1483
|
+
<li>{privacy_line}</li>
|
|
1484
|
+
<li>{identity_line}</li>
|
|
1485
|
+
<li>{merge_line}</li>
|
|
1486
|
+
<li>同一项目出现在多个目录时只保留提交最多的一个;同一 commit 只计一次。</li>
|
|
1487
|
+
<li>时间取 author date;跨时区协作时以提交者本地时间为准。</li>
|
|
1488
|
+
<li>「自有代码」= 非空行;已剔除第三方库、生成工程与二进制。</li>
|
|
1489
|
+
</ul>
|
|
1490
|
+
{card_widget}
|
|
1491
|
+
</div>
|
|
1492
|
+
<div class="quote rv">「git 不会说谎——<em style="font-style:normal;color:var(--acc)">{quote_tail}</em>」
|
|
1493
|
+
<small>CODEYEAR · {stats.generated_at}</small>
|
|
1494
|
+
</div>
|
|
1495
|
+
"""
|
|
1496
|
+
|
|
1497
|
+
|
|
1498
|
+
def build_persona_block(stats: ReportStats) -> str:
|
|
1499
|
+
persona = stats.persona
|
|
1500
|
+
badges = "".join(
|
|
1501
|
+
f"<span>{escape(badge)}</span>" for badge in persona.badges
|
|
1502
|
+
)
|
|
1503
|
+
summary = getattr(persona, "summary", persona.subtitle)
|
|
1504
|
+
return f"""
|
|
1505
|
+
<div class="persona-block">
|
|
1506
|
+
<div>
|
|
1507
|
+
<div class="persona-kicker">YEAR AT A GLANCE · {stats.year}</div>
|
|
1508
|
+
<h2 class="persona-name" data-persona-name>{escape(persona.title)}</h2>
|
|
1509
|
+
<p class="persona-summary" data-persona-summary>{escape(summary)}</p>
|
|
1510
|
+
</div>
|
|
1511
|
+
<div class="persona-badges" data-persona-badges>{badges}</div>
|
|
1512
|
+
</div>
|
|
1513
|
+
"""
|
|
1514
|
+
|
|
1515
|
+
|
|
1516
|
+
def build_html(stats: ReportStats) -> str:
|
|
1517
|
+
public = stats.public_source
|
|
1518
|
+
total_k = stats.lines_changed / 10000
|
|
1519
|
+
if stats.lines_changed >= 10000:
|
|
1520
|
+
lines_value, lines_dec, lines_suffix = total_k, 1, "万"
|
|
1521
|
+
else:
|
|
1522
|
+
lines_value, lines_dec, lines_suffix = float(stats.lines_changed), 0, ""
|
|
1523
|
+
span = "—"
|
|
1524
|
+
if stats.first_dt and stats.last_dt:
|
|
1525
|
+
span = f"{stats.first_dt:%Y.%m.%d} — {stats.last_dt:%Y.%m.%d}"
|
|
1526
|
+
busiest = stats.busiest_day[0].replace("-", ".") if stats.busiest_day else "—"
|
|
1527
|
+
|
|
1528
|
+
hero_stats = f"""
|
|
1529
|
+
<div class="hs rv" style="--d:120ms"><b data-count="{lines_value:.4g}" data-dec="{lines_dec}" data-suffix="{lines_suffix}">0</b><span>行代码变更</span></div>
|
|
1530
|
+
<div class="hs rv" style="--d:190ms"><b data-count="{stats.commit_count}" data-sep>0</b><span>次提交</span></div>
|
|
1531
|
+
<div class="hs rv" style="--d:260ms"><b data-count="{stats.active_days}">0</b><span>个活跃日</span></div>
|
|
1532
|
+
<div class="hs rv" style="--d:330ms"><b data-count="{stats.repo_count}">0</b><span>个有提交的仓库</span></div>
|
|
1533
|
+
"""
|
|
1534
|
+
|
|
1535
|
+
return f"""<!doctype html>
|
|
1536
|
+
<html lang="zh-CN">
|
|
1537
|
+
<head>
|
|
1538
|
+
<meta charset="utf-8">
|
|
1539
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
1540
|
+
<title>CodeYear {stats.year} · {escape(stats.persona.title)}</title>
|
|
1541
|
+
<meta name="description" content="CodeYear 年度代码手账:{escape(stats.persona.subtitle)}">
|
|
1542
|
+
<link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Crect width='32' height='32' fill='%23d4491f'/%3E%3Ctext x='16' y='23' font-family='monospace' font-size='19' fill='%23f4f1e8' text-anchor='middle'%3EC%3C/text%3E%3C/svg%3E">
|
|
1543
|
+
<style>{CSS}</style>
|
|
1544
|
+
<noscript><style>.rv,.rv-line{{opacity:1!important;transform:none!important}}
|
|
1545
|
+
.sec-line{{transform:none!important}}</style></noscript>
|
|
1546
|
+
</head>
|
|
1547
|
+
<body>
|
|
1548
|
+
<a class="skip" href="#records">跳到主要内容</a>
|
|
1549
|
+
<div id="progress"></div>
|
|
1550
|
+
<header>
|
|
1551
|
+
<div class="nav">
|
|
1552
|
+
<a class="logo" href="#top"><i></i>CODEYEAR</a>
|
|
1553
|
+
<div class="nav-links" aria-label="主导航">
|
|
1554
|
+
<a href="#records">之最</a><a href="#archives">档案</a><a href="#index">索引</a>
|
|
1555
|
+
<a href="#numbers">数据分析</a><a href="#about">关于</a>
|
|
1556
|
+
</div>
|
|
1557
|
+
<div class="nav-meta">
|
|
1558
|
+
<span id="clock">--:--:--</span>
|
|
1559
|
+
<span class="badge">{'PUBLIC DATA · 来自 GitHub' if public else 'LOCAL ONLY · 数据未上传'}</span>
|
|
1560
|
+
</div>
|
|
1561
|
+
</div>
|
|
1562
|
+
</header>
|
|
1563
|
+
|
|
1564
|
+
<main id="top">
|
|
1565
|
+
<div class="wrap">
|
|
1566
|
+
<section class="hero">
|
|
1567
|
+
<div>
|
|
1568
|
+
<p class="kicker rv">SCAN · {escape(stats.root)} · {stats.year}</p>
|
|
1569
|
+
<h1 class="rv-line"><span>{stats.year} 年,</span><br><em>{fmt_int(stats.commit_count)} 次提交,<span style="white-space:nowrap">{fmt_human(stats.lines_changed)} 行。</span></em></h1>
|
|
1570
|
+
<p class="lede rv" style="--d:160ms">{escape(stats.persona.subtitle)}
|
|
1571
|
+
代码行变更是 <b>+{fmt_human(stats.insertions)} / -{fmt_human(stats.deletions)}</b>,最忙的一天是 <b>{busiest}</b>。
|
|
1572
|
+
下面每个数字都来自{'公开 GitHub 数据' if public else '本机 git'}——<b>{'没有读取或上传本地代码' if public else '这份报告没有上传任何东西'}</b>。</p>
|
|
1573
|
+
</div>
|
|
1574
|
+
<div>
|
|
1575
|
+
<div class="hero-stats">{hero_stats}</div>
|
|
1576
|
+
<p class="scroll-hint rv" style="--d:420ms">SCROLL — 全部来自你的仓库</p>
|
|
1577
|
+
</div>
|
|
1578
|
+
</section>
|
|
1579
|
+
{build_persona_block(stats)}
|
|
1580
|
+
</div>
|
|
1581
|
+
|
|
1582
|
+
{build_ticker(stats)}
|
|
1583
|
+
|
|
1584
|
+
<div class="wrap">
|
|
1585
|
+
<section id="records">
|
|
1586
|
+
<div class="sec-head rv">
|
|
1587
|
+
<div><div class="sec-index">01 / YEAR IN REVIEW</div><h2>年度之最</h2></div>
|
|
1588
|
+
<span class="sec-sub">先看几个最极端的数字</span>
|
|
1589
|
+
</div>
|
|
1590
|
+
<div class="sec-line"></div>
|
|
1591
|
+
{build_records(stats)}
|
|
1592
|
+
</section>
|
|
1593
|
+
|
|
1594
|
+
<section id="archives">
|
|
1595
|
+
<div class="sec-head rv">
|
|
1596
|
+
<div><div class="sec-index">02 / REPO ARCHIVES</div><h2>仓库档案</h2></div>
|
|
1597
|
+
<span class="sec-sub">提交最多的三个仓库 · 时间线与热区</span>
|
|
1598
|
+
</div>
|
|
1599
|
+
<div class="sec-line"></div>
|
|
1600
|
+
{build_archives(stats)}
|
|
1601
|
+
</section>
|
|
1602
|
+
|
|
1603
|
+
<section id="index">
|
|
1604
|
+
<div class="sec-head rv">
|
|
1605
|
+
<div><div class="sec-index">03 / FULL INDEX</div><h2>全部仓库索引</h2></div>
|
|
1606
|
+
<span class="sec-sub">包括休眠的和没写 README 的</span>
|
|
1607
|
+
</div>
|
|
1608
|
+
<div class="sec-line"></div>
|
|
1609
|
+
{build_table(stats)}
|
|
1610
|
+
</section>
|
|
1611
|
+
|
|
1612
|
+
<section id="numbers">
|
|
1613
|
+
<div class="sec-head rv">
|
|
1614
|
+
<div><div class="sec-index">04 / BY THE NUMBERS</div><h2>数据分析</h2></div>
|
|
1615
|
+
<span class="sec-sub">git 里能查到的,不靠形容词</span>
|
|
1616
|
+
</div>
|
|
1617
|
+
<div class="sec-line"></div>
|
|
1618
|
+
{build_numbers(stats)}
|
|
1619
|
+
</section>
|
|
1620
|
+
|
|
1621
|
+
<section id="about">
|
|
1622
|
+
<div class="sec-head rv">
|
|
1623
|
+
<div><div class="sec-index">05 / ABOUT THIS REPORT</div><h2>关于本报告</h2></div>
|
|
1624
|
+
<span class="sec-sub">口径与方法</span>
|
|
1625
|
+
</div>
|
|
1626
|
+
<div class="sec-line"></div>
|
|
1627
|
+
{build_about(stats)}
|
|
1628
|
+
</section>
|
|
1629
|
+
</div>
|
|
1630
|
+
</main>
|
|
1631
|
+
|
|
1632
|
+
<footer>
|
|
1633
|
+
<div class="foot-in">
|
|
1634
|
+
<span>CODEYEAR · 代码手账 {stats.year}</span>
|
|
1635
|
+
<span>扫描范围 {escape(stats.root)} · {escape(span)}</span>
|
|
1636
|
+
<span>由 CodeYear {'根据公开 GitHub 数据生成' if public else '在本机生成'} · {escape(stats.generated_at)} · {'没有读取或上传本地代码' if public else '代码从未离开这台电脑'}</span>
|
|
1637
|
+
</div>
|
|
1638
|
+
</footer>
|
|
1639
|
+
|
|
1640
|
+
<div id="tip" aria-hidden="true"></div>
|
|
1641
|
+
<script>{JS}</script>
|
|
1642
|
+
</body>
|
|
1643
|
+
</html>
|
|
1644
|
+
"""
|
|
1645
|
+
|
|
1646
|
+
|
|
1647
|
+
def render(stats: ReportStats, out_path: str | Path) -> Path:
|
|
1648
|
+
from .report_theme import decorate
|
|
1649
|
+
|
|
1650
|
+
path = Path(out_path)
|
|
1651
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
1652
|
+
path.write_text(decorate(build_html(stats), stats), encoding="utf-8")
|
|
1653
|
+
return path
|
|
1654
|
+
|
|
1655
|
+
|
|
1656
|
+
def render_en(stats: ReportStats, out_path: str | Path) -> Path:
|
|
1657
|
+
from .report_theme import decorate, to_english
|
|
1658
|
+
|
|
1659
|
+
path = Path(out_path)
|
|
1660
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
1661
|
+
html = decorate(build_html(stats), stats)
|
|
1662
|
+
path.write_text(to_english(html, stats), encoding="utf-8")
|
|
1663
|
+
return path
|