소스 검색

Add statistics about changed lines in time

Stats are calculated for months of year and years. Activity page in
sections 'Commits by year/month' and 'Commits by Year' are enhanced by
this statistic.

Signed-off-by: Heikki Hokkanen <hoxu@users.sf.net>
Karel Rank 14 년 전
부모
커밋
2acf4392ad
1개의 변경된 파일19개의 추가작업 그리고 4개의 파일을 삭제
  1. 19
    4
      gitstats

+ 19
- 4
gitstats 파일 보기

@@ -116,6 +116,10 @@ class DataCollector:
116 116
 		self.author_of_year = {} # year -> author -> commits
117 117
 		self.commits_by_month = {} # month -> commits
118 118
 		self.commits_by_year = {} # year -> commits
119
+		self.lines_added_by_month = {} # month -> lines added
120
+		self.lines_added_by_year = {} # year -> lines added
121
+		self.lines_removed_by_month = {} # month -> lines removed
122
+		self.lines_removed_by_year = {} # year -> lines removed
119 123
 		self.first_commit_stamp = 0
120 124
 		self.last_commit_stamp = 0
121 125
 		self.last_active_day = None
@@ -449,6 +453,16 @@ class GitDataCollector(DataCollector):
449 453
 					try:
450 454
 						(stamp, author) = (int(line[:pos]), line[pos+1:])
451 455
 						self.changes_by_date[stamp] = { 'files': files, 'ins': inserted, 'del': deleted, 'lines': total_lines }
456
+
457
+						date = datetime.datetime.fromtimestamp(stamp)
458
+						yymm = date.strftime('%Y-%m')
459
+						self.lines_added_by_month[yymm] = self.lines_added_by_month.get(yymm, 0) + inserted
460
+						self.lines_removed_by_month[yymm] = self.lines_removed_by_month.get(yymm, 0) + deleted
461
+
462
+						yy = date.year
463
+						self.lines_added_by_year[yy] = self.lines_added_by_year.get(yy,0) + inserted
464
+						self.lines_removed_by_year[yy] = self.lines_removed_by_year.get(yy, 0) + deleted
465
+
452 466
 						files, inserted, deleted = 0, 0, 0
453 467
 					except ValueError:
454 468
 						print 'Warning: unexpected line "%s"' % line
@@ -462,6 +476,7 @@ class GitDataCollector(DataCollector):
462 476
 					total_lines -= deleted
463 477
 					self.total_lines_added += inserted
464 478
 					self.total_lines_removed += deleted
479
+
465 480
 				else:
466 481
 					print 'Warning: failed to handle line "%s"' % line
467 482
 					(files, inserted, deleted) = (0, 0, 0)
@@ -817,9 +832,9 @@ class HTMLReportCreator(ReportCreator):
817 832
 
818 833
 		# Commits by year/month
819 834
 		f.write(html_header(2, 'Commits by year/month'))
820
-		f.write('<div class="vtable"><table><tr><th>Month</th><th>Commits</th></tr>')
835
+		f.write('<div class="vtable"><table><tr><th>Month</th><th>Commits</th><th>Lines added</th><th>Lines removed</th></tr>')
821 836
 		for yymm in reversed(sorted(data.commits_by_month.keys())):
822
-			f.write('<tr><td>%s</td><td>%d</td></tr>' % (yymm, data.commits_by_month[yymm]))
837
+			f.write('<tr><td>%s</td><td>%d</td><td>%d</td><td>%d</td></tr>' % (yymm, data.commits_by_month[yymm], data.lines_added_by_month[yymm], data.lines_removed_by_month[yymm]))
823 838
 		f.write('</table></div>')
824 839
 		f.write('<img src="commits_by_year_month.png" alt="Commits by year/month" />')
825 840
 		fg = open(path + '/commits_by_year_month.dat', 'w')
@@ -829,9 +844,9 @@ class HTMLReportCreator(ReportCreator):
829 844
 
830 845
 		# Commits by year
831 846
 		f.write(html_header(2, 'Commits by Year'))
832
-		f.write('<div class="vtable"><table><tr><th>Year</th><th>Commits (% of all)</th></tr>')
847
+		f.write('<div class="vtable"><table><tr><th>Year</th><th>Commits (% of all)</th><th>Lines added</th><th>Lines removed</th></tr>')
833 848
 		for yy in reversed(sorted(data.commits_by_year.keys())):
834
-			f.write('<tr><td>%s</td><td>%d (%.2f%%)</td></tr>' % (yy, data.commits_by_year[yy], (100.0 * data.commits_by_year[yy]) / data.getTotalCommits()))
849
+			f.write('<tr><td>%s</td><td>%d (%.2f%%)</td><td>%d</td><td>%d</td></tr>' % (yy, data.commits_by_year[yy], (100.0 * data.commits_by_year[yy]) / data.getTotalCommits(), data.lines_added_by_year[yy], data.lines_removed_by_year[yy]))
835 850
 		f.write('</table></div>')
836 851
 		f.write('<img src="commits_by_year.png" alt="Commits by Year" />')
837 852
 		fg = open(path + '/commits_by_year.dat', 'w')