-
Notifications
You must be signed in to change notification settings - Fork 8
/
svnstat.py
126 lines (97 loc) · 3.54 KB
/
svnstat.py
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
#!/usr/bin/python
# sudo pip install numpy matplotlib
import os
import re
from pylab import *
import dateutil
prog = re.compile(r"r(\d+) \| (.+) \| (\d+-\d+-\d+)")
# author, date, commits, additions, deletions
c = {}
def get_contribution(last, revision):
additions = 0
deletions = 0
cmd = "svn diff -r" + last + ":" + revision
p = os.popen(cmd, "r")
for line in p:
if line[0] == "-":
if line[0:2] != "---":
deletions += 1
elif line[0] == "+":
if line[0:2] != "+++":
additions += 1
p.close()
return additions, deletions
def draw_commits(author, dates, commits):
X = [dateutil.parser.parse(s) for s in dates]
fig = figure(figsize=(30, 6), dpi=96)
ax = fig.add_subplot(1, 1, 1)
lc = "total commits = " + str(sum(commits))
ylim(0, max(commits) * 1.2)
#ax.fill_between(X, 0, commits, color='blue', alpha=0.5)
#ax.plot(X, commits, 'o-', color='blue', label=lc)
ax.bar(X, commits, color='blue', label=lc, alpha=0.5)
legend(loc="upper right")
fig.savefig(author + '_commits.png')
def limit(A, D):
m = 0
for a, d in zip(A, D):
m = max(m, a + d)
return m
def draw_lines(author, dates, additions, deletions):
X = [dateutil.parser.parse(s) for s in dates]
fig = figure(figsize=(30, 6), dpi=96)
ax = fig.add_subplot(1, 1, 1)
la = "total additions = " + str(sum(additions))
ld = "total deletions = " + str(sum(deletions))
#ylim(0, max(max(additions), max(deletions)) * 1.1)
#ax.fill_between(X, 0, additions, color='green', alpha=0.25)
#ax.fill_between(X, 0, deletions, color='red', alpha=0.25)
#ax.plot(X, additions, 'o-', color='green', label=la)
#ax.plot(X, deletions, 'o-', color='red', label=ld)
ylim(0, limit(additions, deletions) * 1.1)
ax.bar(X, additions, color='green', label=la, bottom=deletions, alpha=0.6)
ax.bar(X, deletions, color='red', label=ld, alpha=0.6)
legend(loc="upper right")
fig.savefig(author + '_lines.png')
first = True
author = ""
last = ""
revision = ""
p = os.popen("svn log", "r")
for line in p:
result = prog.match(line)
if result:
if first:
revision, author, date = result.groups(1)
first = False
else:
last = result.groups(1)[0]
additions, deletions = get_contribution(last, revision)
if author in c:
if date not in c[author]:
c[author][date] = {'commits': 1, 'additions': additions,
'deletions': deletions}
else:
c[author][date]['commits'] += 1
c[author][date]['additions'] += additions
c[author][date]['deletions'] += deletions
else:
c[author] = {}
c[author][date] = {'commits': 1, 'additions': additions,
'deletions': deletions}
revision, author, date = result.groups(1)
p.close()
for author in c:
dates = []
commits = []
additions = []
deletions = []
for date in sorted(c[author].iterkeys()):
dates.append(date)
commits.append(c[author][date]['commits'])
additions.append(c[author][date]['additions'])
deletions.append(c[author][date]['deletions'])
print author, date, c[author][date]['commits'],
print c[author][date]['additions'], c[author][date]['deletions']
draw_commits(author, dates, commits)
draw_lines(author, dates, additions, deletions)