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/personas.py
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
"""Turn raw numbers into a short, factual year-at-a-glance summary."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@dataclass
|
|
9
|
+
class Persona:
|
|
10
|
+
title: str
|
|
11
|
+
subtitle: str
|
|
12
|
+
traits: list[str]
|
|
13
|
+
badges: list[str]
|
|
14
|
+
badges_en: list[str]
|
|
15
|
+
title_en: str
|
|
16
|
+
subtitle_en: str
|
|
17
|
+
summary: str
|
|
18
|
+
summary_en: str
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def _pct(value: float) -> str:
|
|
22
|
+
return f"{value * 100:.0f}%"
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def build_persona(
|
|
26
|
+
*,
|
|
27
|
+
year: int,
|
|
28
|
+
commits: int,
|
|
29
|
+
repos: int,
|
|
30
|
+
lines: int,
|
|
31
|
+
insertions: int,
|
|
32
|
+
deletions: int,
|
|
33
|
+
active_days: int,
|
|
34
|
+
longest_streak: int,
|
|
35
|
+
current_streak: int,
|
|
36
|
+
night_commits: int,
|
|
37
|
+
early_commits: int,
|
|
38
|
+
weekend_commits: int,
|
|
39
|
+
peak_hour: int,
|
|
40
|
+
fix_commits: int,
|
|
41
|
+
feat_commits: int,
|
|
42
|
+
typed_commits: int,
|
|
43
|
+
lang_count: int,
|
|
44
|
+
busiest_count: int,
|
|
45
|
+
) -> Persona:
|
|
46
|
+
total = max(commits, 1)
|
|
47
|
+
night_share = night_commits / total
|
|
48
|
+
early_share = early_commits / total
|
|
49
|
+
weekend_share = weekend_commits / total
|
|
50
|
+
fix_share = fix_commits / max(typed_commits, 1)
|
|
51
|
+
feat_share = feat_commits / max(typed_commits, 1)
|
|
52
|
+
avg_per_active = commits / max(active_days, 1)
|
|
53
|
+
delete_ratio = deletions / max(insertions + deletions, 1)
|
|
54
|
+
|
|
55
|
+
if night_share >= 0.35:
|
|
56
|
+
time_window = "22:00–05:00"
|
|
57
|
+
time_share = night_share
|
|
58
|
+
time_label_en = "late-night"
|
|
59
|
+
elif early_share >= 0.28:
|
|
60
|
+
time_window = "05:00–09:00"
|
|
61
|
+
time_share = early_share
|
|
62
|
+
time_label_en = "early-morning"
|
|
63
|
+
elif weekend_share >= 0.35:
|
|
64
|
+
time_window = "周末"
|
|
65
|
+
time_share = weekend_share
|
|
66
|
+
time_label_en = "weekend"
|
|
67
|
+
elif 9 <= peak_hour <= 18:
|
|
68
|
+
time_window = f"{peak_hour:02d}:00 前后"
|
|
69
|
+
time_share = 0.0
|
|
70
|
+
time_label_en = "daytime"
|
|
71
|
+
else:
|
|
72
|
+
time_window = f"{peak_hour:02d}:00 前后"
|
|
73
|
+
time_share = 0.0
|
|
74
|
+
time_label_en = "night"
|
|
75
|
+
|
|
76
|
+
if delete_ratio >= 0.5:
|
|
77
|
+
title, title_en = "删代码比写代码还多的人", "Deletes more than writes"
|
|
78
|
+
elif fix_share >= 0.35:
|
|
79
|
+
title, title_en = "主要在和 bug 打交道的人", "Mostly fixing bugs"
|
|
80
|
+
elif feat_share >= 0.35:
|
|
81
|
+
title, title_en = "一直在加功能的人", "Always adding features"
|
|
82
|
+
elif night_share >= 0.5:
|
|
83
|
+
title, title_en = "夜里出活的人", "Works late at night"
|
|
84
|
+
elif night_share >= 0.35:
|
|
85
|
+
title, title_en = "偶尔熬到深夜的人", "Sometimes up late"
|
|
86
|
+
elif early_share >= 0.28:
|
|
87
|
+
title, title_en = "早起写代码的人", "Early-morning coder"
|
|
88
|
+
elif weekend_share >= 0.35:
|
|
89
|
+
title, title_en = "周末才有点空写代码的人", "Weekend coder"
|
|
90
|
+
elif lang_count >= 8:
|
|
91
|
+
title, title_en = "什么语言都碰一点的人", "Touches everything"
|
|
92
|
+
elif longest_streak >= 21:
|
|
93
|
+
title, title_en = "很少断更的人", "Rarely breaks the streak"
|
|
94
|
+
elif avg_per_active >= 5:
|
|
95
|
+
title, title_en = "一天能提交很多次的人", "Commits a lot"
|
|
96
|
+
else:
|
|
97
|
+
title, title_en = "稳稳当当写代码的人", "Steady coder"
|
|
98
|
+
|
|
99
|
+
if time_share:
|
|
100
|
+
time_sentence = f"{_pct(time_share)} 的提交发生在 {time_window}"
|
|
101
|
+
time_sentence_en = (
|
|
102
|
+
f"{_pct(time_share)} of commits happened in the {time_label_en} "
|
|
103
|
+
f"window"
|
|
104
|
+
)
|
|
105
|
+
else:
|
|
106
|
+
time_sentence = f"提交高峰在 {time_window}"
|
|
107
|
+
time_sentence_en = f"Peak hour was around {peak_hour:02d}:00"
|
|
108
|
+
|
|
109
|
+
style_parts = []
|
|
110
|
+
style_parts_en = []
|
|
111
|
+
if typed_commits:
|
|
112
|
+
style_parts.append(f"修复类占 {_pct(fix_share)}")
|
|
113
|
+
style_parts_en.append(f"fixes {_pct(fix_share)}")
|
|
114
|
+
style_parts.append(f"功能类占 {_pct(feat_share)}")
|
|
115
|
+
style_parts_en.append(f"features {_pct(feat_share)}")
|
|
116
|
+
style_parts.append(f"{lang_count} 种语言")
|
|
117
|
+
style_parts_en.append(f"{lang_count} languages")
|
|
118
|
+
|
|
119
|
+
subtitle = (
|
|
120
|
+
f"{year} 年,你在 {repos} 个仓库里提交了 {commits:,} 次,"
|
|
121
|
+
f"改了 {lines:,} 行代码。{time_sentence}。"
|
|
122
|
+
)
|
|
123
|
+
subtitle_en = (
|
|
124
|
+
f"In {year} you made {commits:,} commits across {repos} repositories, "
|
|
125
|
+
f"changing {lines:,} lines. {time_sentence_en}."
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
badges = [
|
|
129
|
+
f"{commits:,} 次提交",
|
|
130
|
+
f"{lang_count} 种语言",
|
|
131
|
+
f"{repos} 个仓库",
|
|
132
|
+
f"{active_days} 个活跃日",
|
|
133
|
+
]
|
|
134
|
+
badges_en = [
|
|
135
|
+
f"{commits:,} commits",
|
|
136
|
+
f"{lang_count} languages",
|
|
137
|
+
f"{repos} repositories",
|
|
138
|
+
f"{active_days} active days",
|
|
139
|
+
]
|
|
140
|
+
|
|
141
|
+
style_text_en = ", ".join(style_parts_en)
|
|
142
|
+
style_text_en = style_text_en[:1].upper() + style_text_en[1:]
|
|
143
|
+
|
|
144
|
+
summary = subtitle + (
|
|
145
|
+
",".join(style_parts)
|
|
146
|
+
+ f";最长连续 {longest_streak} 天,"
|
|
147
|
+
f"每个活跃日平均 {avg_per_active:.1f} 次提交。"
|
|
148
|
+
)
|
|
149
|
+
summary_en = subtitle_en + (
|
|
150
|
+
" " + style_text_en
|
|
151
|
+
+ f"; longest streak {longest_streak} days, "
|
|
152
|
+
f"{avg_per_active:.1f} commits per active day."
|
|
153
|
+
)
|
|
154
|
+
|
|
155
|
+
traits = [
|
|
156
|
+
f"{active_days} 个活跃日",
|
|
157
|
+
f"最长连续 {longest_streak} 天",
|
|
158
|
+
f"单日最高 {busiest_count} 次",
|
|
159
|
+
f"{lang_count} 种语言",
|
|
160
|
+
]
|
|
161
|
+
return Persona(
|
|
162
|
+
title=title,
|
|
163
|
+
subtitle=subtitle,
|
|
164
|
+
traits=traits,
|
|
165
|
+
badges=badges,
|
|
166
|
+
badges_en=badges_en,
|
|
167
|
+
title_en=title_en,
|
|
168
|
+
subtitle_en=subtitle_en,
|
|
169
|
+
summary=summary,
|
|
170
|
+
summary_en=summary_en,
|
|
171
|
+
)
|