-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdesigner.py
More file actions
167 lines (132 loc) Β· 4.95 KB
/
designer.py
File metadata and controls
167 lines (132 loc) Β· 4.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#!/usr/bin/env python3
"""
designer.py β Pattern visualizer for github-alive.
Shows an ASCII preview of the next 52 weeks of the contribution pattern,
with today's position marked. Uses the same deterministic mathematical
function as alive.py β no config or pattern.json needed.
Usage:
python3 designer.py
"""
import datetime
import math
import sys
# ---------------------------------------------------------------------------
# Mathematical pattern (identical to alive.py)
# ---------------------------------------------------------------------------
ANCHOR_DATE = datetime.date(2012, 9, 9)
def base_commits(days_since_anchor: int, day_of_week: int) -> int:
"""
Return the base commit count for a given day.
Produces an organic, multi-scale wave pattern with values in [1, 40].
The pattern is fully deterministic β same date always gives the same result.
Args:
days_since_anchor: days elapsed since ANCHOR_DATE (2012-09-09)
day_of_week: 0=Sun, 1=Mon, ..., 6=Sat (GitHub graph convention)
Returns:
Integer commit count in [1, 40]
"""
t = days_since_anchor / 7.0 # time in weeks
d = day_of_week
w1 = math.sin(2 * math.pi * t / 26 + 0.0) # 26-week primary cycle
w2 = math.sin(2 * math.pi * t / 13 + 1.5) # 13-week harmonic
w3 = math.sin(2 * math.pi * t / 52 + 0.8) # yearly drift
w4 = math.sin(2 * math.pi * d / 7 + t * 0.4) # day-of-week texture
w5 = math.sin(2 * math.pi * (t * 1.3 + d) / 9) # diagonal ripple
combined = w1 * 0.35 + w2 * 0.25 + w3 * 0.15 + w4 * 0.15 + w5 * 0.10
count = round(3 + (combined + 1) * 18.5)
return max(1, min(40, count))
def commits_to_char(n: int) -> str:
"""
Map a commit count to a density character.
Ranges:
1β5 β Β· (empty/sparse)
6β15 β β (light)
16β25 β β (medium)
26β35 β β (heavy)
36β40 β β (full)
"""
if n <= 5:
return 'Β·'
elif n <= 15:
return 'β'
elif n <= 25:
return 'β'
elif n <= 35:
return 'β'
else:
return 'β'
# ---------------------------------------------------------------------------
# Visualization
# ---------------------------------------------------------------------------
DISPLAY_WEEKS = 52
DAY_NAMES = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
def get_week_start(today: datetime.date) -> datetime.date:
"""Return the Sunday that starts the current week."""
dow = today.isoweekday() % 7 # Sun=0
return today - datetime.timedelta(days=dow)
def render_pattern(today: datetime.date) -> None:
"""
Render 52 weeks of the pattern starting from the current week.
Marks today's column with an arrow indicator below.
Args:
today: reference date (normally datetime.date.today())
"""
week_start = get_week_start(today)
today_week = 0 # today is in the first displayed week
# Find which column (week index) today falls in
today_dow = today.isoweekday() % 7 # 0=Sun
# Build grid: grid[day][week] β char
grid = []
for day in range(7):
row = []
for week in range(DISPLAY_WEEKS):
date = week_start + datetime.timedelta(weeks=week, days=day)
days = (date - ANCHOR_DATE).days
n = base_commits(days, day)
ch = commits_to_char(n)
row.append(ch)
grid.append(row)
# Print header
print()
print(" github-alive β pattern preview (next 52 weeks)")
print(f" Anchor: {ANCHOR_DATE} | Today: {today.isoformat()}")
print()
# Legend
print(" Legend: Β· 1β5 β 6β15 β 16β25 β 26β35 β 36β40 commits")
print()
# Grid (day rows Γ week columns)
sep = 'β' * (DISPLAY_WEEKS * 2 + 2)
print(f" {sep}")
for day in range(7):
row_str = ' '.join(grid[day])
print(f" {DAY_NAMES[day]} {row_str}")
print(f" {sep}")
# Today marker: arrow under today's column
# Each cell = 2 chars (char + space), offset = 6 chars for " Sun "
col_offset = 6 + today_dow * 0 # day marker is not per-column but per-week
# Actually mark the week column (today's week = column 0)
# today_week=0, each week cell=2 chars wide
arrow_pos = today_week * 2
prefix = ' ' * (6 + arrow_pos)
print(f" {prefix}β today ({today.strftime('%a %b %d')})")
print()
# Stats
total = sum(
base_commits(
(week_start + datetime.timedelta(weeks=w, days=d) - ANCHOR_DATE).days,
d
)
for w in range(DISPLAY_WEEKS)
for d in range(7)
)
avg = total / (DISPLAY_WEEKS * 7)
print(f" 52-week window: {DISPLAY_WEEKS * 7} days | avg {avg:.1f} commits/day | est. {total} total")
print()
def main():
if '--help' in sys.argv or '-h' in sys.argv:
print(__doc__)
sys.exit(0)
today = datetime.date.today()
render_pattern(today)
if __name__ == '__main__':
main()