Skip to content

Commit 7bf9912

Browse files
committed
Add script to compute the number of days each author has committed
1 parent d332879 commit 7bf9912

File tree

1 file changed

+89
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)