瀏覽代碼

Per-author commit count graph

Signed-off-by: Heikki Hokkanen <hoxu@users.sf.net>
Matthieu Moy 15 年之前
父節點
當前提交
a554942c01
共有 1 個文件被更改,包括 55 次插入11 次删除
  1. 55
    11
      gitstats

+ 55
- 11
gitstats 查看文件

@@ -322,7 +322,6 @@ class GitDataCollector(DataCollector):
322 322
 			if 'last_commit_stamp' not in self.authors[author]:
323 323
 				self.authors[author]['last_commit_stamp'] = stamp
324 324
 			self.authors[author]['first_commit_stamp'] = stamp
325
-			self.authors[author]['commits'] = self.authors[author].get('commits', 0) + 1
326 325
 
327 326
 			# author of the month/year
328 327
 			yymm = date.strftime('%Y-%m')
@@ -472,12 +471,16 @@ class GitDataCollector(DataCollector):
472 471
 					try:
473 472
 						(stamp, author) = (int(line[:pos]), line[pos+1:])
474 473
 						if author not in self.authors:
475
-							self.authors[author] = { 'lines_added' : 0, 'lines_removed' : 0 }
474
+							self.authors[author] = { 'lines_added' : 0, 'lines_removed' : 0, 'commits' : 0}
475
+						self.authors[author]['commits'] = self.authors[author].get('commits', 0) + 1
476 476
 						self.authors[author]['lines_added'] = self.authors[author].get('lines_added', 0) + inserted
477 477
 						self.authors[author]['lines_removed'] = self.authors[author].get('lines_removed', 0) + deleted
478 478
 						if stamp not in self.changes_by_date_by_author:
479 479
 							self.changes_by_date_by_author[stamp] = {}
480
-						self.changes_by_date_by_author[stamp][author] = self.authors[author]['lines_added']
480
+						if author not in self.changes_by_date_by_author[stamp]:
481
+							self.changes_by_date_by_author[stamp][author] = {}
482
+						self.changes_by_date_by_author[stamp][author]['lines_added'] = self.authors[author]['lines_added']
483
+						self.changes_by_date_by_author[stamp][author]['commits'] = self.authors[author]['commits']
481 484
 						files, inserted, deleted = 0, 0, 0
482 485
 					except ValueError:
483 486
 						print 'Warning: unexpected line "%s"' % line
@@ -851,10 +854,16 @@ class HTMLReportCreator(ReportCreator):
851 854
 		f.write(html_header(2, 'Cumulated Added Lines of Code per Author'))
852 855
 		f.write('<img src="lines_of_code_by_author.png" alt="Lines of code per Author" />')
853 856
 		if len(allauthors) > conf['max_authors']:
854
-			rest = allauthors[conf['max_authors']:]
855
-			f.write('<p class="moreauthors">These didn\'t make it to the graph: %s</p>' % ', '.join(rest))
857
+			f.write('<p class="moreauthors">Only top %d authors shown</p>' % conf['max_authors'])
858
+
859
+		f.write(html_header(2, 'Commits per Author'))
860
+		f.write('<img src="commits_by_author.png" alt="Commits per Author" />')
861
+		if len(allauthors) > conf['max_authors']:
862
+			f.write('<p class="moreauthors">Only top %d authors shown</p>' % conf['max_authors'])
863
+
864
+		fgl = open(path + '/lines_of_code_by_author.dat', 'w')
865
+		fgc = open(path + '/commits_by_author.dat', 'w')
856 866
 
857
-		fg = open(path + '/lines_of_code_by_author.dat', 'w')
858 867
 		lines_by_authors = {} # cumulated added lines by
859 868
 		# author. to save memory,
860 869
 		# changes_by_date_by_author[stamp][author] is defined
@@ -864,17 +873,25 @@ class HTMLReportCreator(ReportCreator):
864 873
 
865 874
 		# Don't rely on getAuthors to give the same order each
866 875
 		# time. Be robust and keep the list in a variable.
876
+		commits_by_authors = {} # cumulated added lines by
877
+
867 878
 		self.authors_to_plot = data.getAuthors(conf['max_authors'])
868 879
 		for author in self.authors_to_plot:
869 880
 			lines_by_authors[author] = 0
881
+			commits_by_authors[author] = 0
870 882
 		for stamp in sorted(data.changes_by_date_by_author.keys()):
871
-			fg.write('%d' % stamp)
883
+			fgl.write('%d' % stamp)
884
+			fgc.write('%d' % stamp)
872 885
 			for author in self.authors_to_plot:
873 886
 				if author in data.changes_by_date_by_author[stamp].keys():
874
-					lines_by_authors[author] = data.changes_by_date_by_author[stamp][author]
875
-				fg.write(' %d' % lines_by_authors[author])
876
-			fg.write('\n');
877
-		fg.close()
887
+					lines_by_authors[author] = data.changes_by_date_by_author[stamp][author]['lines_added']
888
+					commits_by_authors[author] = data.changes_by_date_by_author[stamp][author]['commits']
889
+				fgl.write(' %d' % lines_by_authors[author])
890
+				fgc.write(' %d' % commits_by_authors[author])
891
+			fgl.write('\n');
892
+			fgc.write('\n');
893
+		fgl.close()
894
+		fgc.close()
878 895
 
879 896
 		# Authors :: Author of Month
880 897
 		f.write(html_header(2, 'Author of Month'))
@@ -1180,6 +1197,33 @@ plot """
1180 1197
 
1181 1198
 		f.close()
1182 1199
 
1200
+		# Commits per author
1201
+		f = open(path + '/commits_by_author.plot', 'w')
1202
+		f.write(GNUPLOT_COMMON)
1203
+		f.write(
1204
+"""
1205
+set terminal png transparent size 640,480
1206
+set output 'commits_by_author.png'
1207
+set key left top
1208
+set xdata time
1209
+set timefmt "%s"
1210
+set format x "%Y-%m-%d"
1211
+set grid y
1212
+set ylabel "Commits"
1213
+set xtics rotate
1214
+set bmargin 6
1215
+plot """
1216
+)
1217
+		i = 1
1218
+		plots = []
1219
+		for a in self.authors_to_plot:
1220
+			i = i + 1
1221
+			plots.append("""'commits_by_author.dat' using 1:%d title "%s" w lines""" % (i, a.replace("\"", "\\\"")))
1222
+		f.write(", ".join(plots))
1223
+		f.write('\n')
1224
+
1225
+		f.close()
1226
+
1183 1227
 		os.chdir(path)
1184 1228
 		files = glob.glob(path + '/*.plot')
1185 1229
 		for f in files: