File: author_days_active

package info (click to toggle)
node-stdlib 0.0.96%2Bds1%2B~cs0.0.429-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 421,476 kB
  • sloc: javascript: 1,562,831; ansic: 109,702; lisp: 49,823; cpp: 27,224; python: 7,871; sh: 6,807; makefile: 6,089; fortran: 3,102; awk: 387
file content (105 lines) | stat: -rwxr-xr-x 2,492 bytes parent folder | download
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
#!/usr/bin/env bash
#
# @license Apache-2.0
#
# Copyright (c) 2017 The Stdlib Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Prints the number of days an author has committed.
#
# <author_first_name> <author_last_name> <number_of_days> <percentage>
#
# Notes:
#
# -   The percentage is computed based on the date of the first repository commit.

# * `git log`
#   - Show logs.
# * `awk '{}'`
#   - Compute statistics.
# * `sort -k3nr`
#   - Sort in reverse numerical order based on the number of days active.
git log --format=format:"%ad %aN" --date=format:"%b %d %Y" --use-mailmap | awk '
BEGIN {
	# Get the date of the first commit:
	cmd = "git log --reverse --date=short | grep Date | head -n 1"
	(cmd | getline tmp)
	close(cmd)

	split(tmp, date, OFS)
	split(date[2], t1, "-")

	# Get the date for "now":
	cmd = "date '\''+%Y %m %d'\''"
	(cmd | getline now)
	close(cmd)

	split(now, t2, OFS)

	# Compute the number of days between the first commit and "now":
	num = daynum(t1[1], t2[1], 0+t1[2], 0+t2[2], 0+t1[3], 0+t2[3])
}
{
	day = $1 OFS $2 OFS $3
	lines[day,$4,$5] = 1
}
END {
	for (k in lines) {
		split(k, keys, SUBSEP)
		name = keys[2] OFS keys[3]
		names[name] += 1
	}
	for (k in names) {
		n = names[k]
		pct = n/num
		print k OFS n OFS pct
	}
}

# Computes the number of days between a start date and an end date.
#
# Parameters:
#   y1 - start year
#   y2 - end year
#   m1 - start month
#   m2 - end month
#   d1 - start day
#   d2 - end day
#
# Returns:
#   number of days
#
function daynum(y1, y2, m1, m2, d1, d2,   days, i, n) {
	split("31 28 31 30 31 30 31 31 30 31 30 31", days)

	# 365 days in a year, plus one during a leap year:
	if (y2 > y1) {
		n = (y2-y1)*365 + int((y2-y1)/4)
	}
	# Adjust number of days in February if leap year...
	if (y2 % 4 == 0) {
		days[2] += 1
	}
	if ( m2 > m1 ) {
		for (i = m1; i < m2; i++) {
			n += days[i]
		}
	} else if ( m2 < m1 ) {
		for (i = m1; i >= m2; i--) {
			n -= days[i]
		}
	}
	return n + d2 - d1
}
' | sort -k3nr