Skip to content

Commit 8f5d5ae

Browse files
committed
Add script to compute the number of authors per hour
1 parent 0e16140 commit 8f5d5ae

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed

tools/git/scripts/authors_per_hour

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 authors per hour.
4+
#
5+
# <hour> <total> <average>
6+
7+
# * `git log`
8+
# - Show logs.
9+
# * `awk '{}'`
10+
# - Compute average number of authors per hour.
11+
# * `sort -n`
12+
# - Sort in numerical order.
13+
git log --format=format:"%ad %aN" --date=format:"%T %b %d %Y" --use-mailmap | awk '
14+
BEGIN {
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+
split($1, time, ":")
36+
hr = time[1]
37+
38+
key = hr OFS $2 OFS $3 OFS $4 OFS $5 OFS $6
39+
if (key in lines) {
40+
next
41+
}
42+
lines[key] = 1
43+
counts[hr] += 1
44+
}
45+
46+
END {
47+
hours = num
48+
for (hr in counts) {
49+
count = counts[hr]
50+
print hr OFS count OFS count/hours
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 -n

0 commit comments

Comments
 (0)