瀏覽代碼

Collect line statistics properly.

Heikki Hokkanen 18 年之前
父節點
當前提交
b345047de8
共有 2 個檔案被更改,包括 13 行新增14 行删除
  1. 1
    6
      doc/TODO.txt
  2. 12
    8
      gitstats

+ 1
- 6
doc/TODO.txt 查看文件

@@ -6,13 +6,8 @@
6 6
 - parameter --style default.css
7 7
 - styles/default.css
8 8
 
9
-- Lines
10
-	- get line counts from "git-log --numstat"?
11
-	- git log --shortstat --pretty=format:"%at %an"
12
-		<stamp> <author>
13
-		 N files changed, N insertions (+), N deletions(-)
14
-
15 9
 [0.0.1]
10
+- style: fix table colors
16 11
 - copy/link gitstats.css to target dir
17 12
 	- find out pwd or home dir?
18 13
 

+ 12
- 8
gitstats 查看文件

@@ -240,26 +240,27 @@ class GitDataCollector(DataCollector):
240 240
 
241 241
 		# line statistics
242 242
 		# outputs:
243
-		# <stamp> <author>
244 243
 		#  N files changed, N insertions (+), N deletions(-)
244
+		# <stamp> <author>
245 245
 		self.changes_by_date = {} # stamp -> { files, ins, del }
246
-		lines = getoutput('git-log --shortstat --pretty=format:"%at %an"').split('\n')
247
-		# TODO |tac this and go it through in reverse, to calculate total lines in each rev?
248
-		stamp = 0
249
-		author = ''
246
+		lines = getoutput('git-log --shortstat --pretty=format:"%at %an" |tac').split('\n')
247
+		files = 0; inserted = 0; deleted = 0; total_lines = 0
250 248
 		for line in lines:
251 249
 			# <stamp> <author>
252 250
 			if line.find(',') == -1:
253 251
 				pos = line.find(' ')
254 252
 				(stamp, author) = (line[:pos], line[pos+1:])
253
+				self.changes_by_date[stamp] = { 'files': files, 'ins': inserted, 'del': deleted, 'lines': total_lines }
255 254
 			else:
256 255
 				numbers = re.findall('\d+', line)
257 256
 				if len(numbers) == 3:
258
-					(files, inserted, deleted) = numbers
257
+					(files, inserted, deleted) = map(lambda el : int(el), numbers)
258
+					total_lines += inserted
259
+					total_lines -= deleted
259 260
 				else:
260 261
 					print 'Warning: failed to handle line "%s"' % line
261 262
 					(files, inserted, deleted) = (0, 0, 0)
262
-				self.changes_by_date[stamp] = { 'files': files, 'ins': inserted, 'del': deleted }
263
+				#self.changes_by_date[stamp] = { 'files': files, 'ins': inserted, 'del': deleted }
263 264
 	
264 265
 	def getActivityByDayOfWeek(self):
265 266
 		return self.activity_by_day_of_week
@@ -407,7 +408,10 @@ class HTMLReportCreator(ReportCreator):
407 408
 		f.write('<tr><th>Day</th><th>Total (%)</th></tr>')
408 409
 		fp = open(path + '/day_of_week.dat', 'w')
409 410
 		for d in range(0, 7):
410
-			fp.write('%d %d\n' % (d + 1, day_of_week[d]))
411
+			commits = 0
412
+			if d in day_of_week:
413
+				commits = day_of_week[d]
414
+			fp.write('%d %d\n' % (d + 1, commits))
411 415
 			f.write('<tr>')
412 416
 			f.write('<th>%d</th>' % (d + 1))
413 417
 			if d in day_of_week: