Skip to content

Commit 0e16140

Browse files
committed
Add script to compute the number of authors per weekday
1 parent 78e9a12 commit 0e16140

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Prints the number of authors per weekday.
4+
#
5+
# <weekday> <total> <average>
6+
7+
# * `git log`
8+
# - Show logs.
9+
# * `awk '{}'`
10+
# - Compute average number of authors per weekday.
11+
git log --format=format:"%ad %aN" --date=format:"%a %b %d %Y" --use-mailmap | awk '
12+
BEGIN {
13+
split("Mon Tue Wed Thu Fri Sat Sun", days);
14+
15+
# Get the date of the first commit:
16+
cmd = "git log --reverse --date=short | grep Date | head -n 1"
17+
(cmd | getline tmp)
18+
close(cmd)
19+
20+
split(tmp, date, OFS)
21+
split(date[2], t1, "-")
22+
23+
# Get the date for "now":
24+
cmd = "date '\''+%Y %m %d'\''"
25+
(cmd | getline now)
26+
close(cmd)
27+
28+
split(now, t2, OFS)
29+
30+
# Compute the number of days between the first commit and "now":
31+
num = daynum(t1[1], t2[1], 0+t1[2], 0+t2[2], 0+t1[3], 0+t2[3])
32+
}
33+
34+
{
35+
day = $4 OFS $2 OFS $3
36+
name = $5 $6
37+
key = day SUBSEP name
38+
if (key in lines) {
39+
next
40+
}
41+
lines[day,name] = 1
42+
counts[$1] += 1
43+
}
44+
45+
END {
46+
weeks = int(num/7)
47+
for (i = 1; i <= 7; i++) {
48+
count = counts[days[i]]
49+
print days[i] OFS count OFS count/weeks
50+
}
51+
}
52+
53+
# Computes the number of days between a start date and an end date.
54+
#
55+
# Parameters:
56+
# y1 - start year
57+
# y2 - end year
58+
# m1 - start month
59+
# m2 - end month
60+
# d1 - start day
61+
# d2 - end day
62+
#
63+
# Returns:
64+
# number of days
65+
#
66+
function daynum(y1, y2, m1, m2, d1, d2, days, i, n) {
67+
split("31 28 31 30 31 30 31 31 30 31 30 31", days)
68+
69+
# 365 days in a year, plus one during a leap year:
70+
if (y2 > y1) {
71+
n = (y2-y1)*365 + int((y2-y1)/4)
72+
}
73+
# Adjust number of days in February if leap year...
74+
if (y2 % 4 == 0) {
75+
days[2] += 1
76+
}
77+
if ( m2 > m1 ) {
78+
for (i = m1; i < m2; i++) {
79+
n += days[i]
80+
}
81+
} else if ( m2 < m1 ) {
82+
for (i = m1; i >= m2; i--) {
83+
n -= days[i]
84+
}
85+
}
86+
return n + d2 - d1
87+
}
88+
'

0 commit comments

Comments
 (0)