Selaa lähdekoodia

Cleanup: added DataCollector.refine()

Any additional statistics based on the extracted data should be produced in it.
Heikki Hokkanen 18 vuotta sitten
vanhempi
commit
f34e1491fc
1 muutettua tiedostoa jossa 27 lisäystä ja 13 poistoa
  1. 27
    13
      gitstats

+ 27
- 13
gitstats Näytä tiedosto

@@ -48,6 +48,11 @@ class DataCollector:
48 48
 		self.dir = dir
49 49
 		self.projectname = os.path.basename(os.path.abspath(dir))
50 50
 	
51
+	##
52
+	# Produce any additional statistics from the extracted data.
53
+	def refine(self):
54
+		pass
55
+
51 56
 	##
52 57
 	# : get a dictionary of author
53 58
 	def getAuthorInfo(self, author):
@@ -288,6 +293,24 @@ class GitDataCollector(DataCollector):
288 293
 				#self.changes_by_date[stamp] = { 'files': files, 'ins': inserted, 'del': deleted }
289 294
 		self.total_lines = total_lines
290 295
 	
296
+	def refine(self):
297
+		# authors
298
+		# name -> {place_by_commits, commits_frac, date_first, date_last, timedelta}
299
+		authors_by_commits = getkeyssortedbyvaluekey(self.authors, 'commits')
300
+		authors_by_commits.reverse() # most first
301
+		for i, name in enumerate(authors_by_commits):
302
+			self.authors[name]['place_by_commits'] = i + 1
303
+
304
+		for name in self.authors.keys():
305
+			a = self.authors[name]
306
+			a['commits_frac'] = (100 * float(a['commits'])) / self.getTotalCommits()
307
+			date_first = datetime.datetime.fromtimestamp(a['first_commit_stamp'])
308
+			date_last = datetime.datetime.fromtimestamp(a['last_commit_stamp'])
309
+			delta = date_last - date_first
310
+			a['date_first'] = date_first.strftime('%Y-%m-%d')
311
+			a['date_last'] = date_last.strftime('%Y-%m-%d')
312
+			a['timedelta'] = delta
313
+	
291 314
 	def getActivityByDayOfWeek(self):
292 315
 		return self.activity_by_day_of_week
293 316
 
@@ -295,16 +318,7 @@ class GitDataCollector(DataCollector):
295 318
 		return self.activity_by_hour_of_day
296 319
 
297 320
 	def getAuthorInfo(self, author):
298
-		a = self.authors[author]
299
-
300
-		commits = a['commits']
301
-		commits_frac = (100 * float(commits)) / self.getTotalCommits()
302
-		date_first = datetime.datetime.fromtimestamp(a['first_commit_stamp'])
303
-		date_last = datetime.datetime.fromtimestamp(a['last_commit_stamp'])
304
-		delta = date_last - date_first
305
-
306
-		res = { 'commits': commits, 'commits_frac': commits_frac, 'date_first': date_first.strftime('%Y-%m-%d'), 'date_last': date_last.strftime('%Y-%m-%d'), 'timedelta' : delta }
307
-		return res
321
+		return self.authors[author]
308 322
 	
309 323
 	def getAuthors(self):
310 324
 		return self.authors.keys()
@@ -530,11 +544,9 @@ class HTMLReportCreator(ReportCreator):
530 544
 
531 545
 		f.write('<table class="authors">')
532 546
 		f.write('<tr><th>Author</th><th>Commits (%)</th><th>First commit</th><th>Last commit</th><th>Age</th><th># by commits</th></tr>')
533
-		authors_by_commits = getkeyssortedbyvaluekey(data.authors, 'commits')
534
-		authors_by_commits.reverse() # most first
535 547
 		for author in sorted(data.getAuthors()):
536 548
 			info = data.getAuthorInfo(author)
537
-			f.write('<tr><td>%s</td><td>%d (%.2f%%)</td><td>%s</td><td>%s</td><td>%s</td><td>%d</td></tr>' % (author, info['commits'], info['commits_frac'], info['date_first'], info['date_last'], info['timedelta'], authors_by_commits.index(author) + 1))
549
+			f.write('<tr><td>%s</td><td>%d (%.2f%%)</td><td>%s</td><td>%s</td><td>%s</td><td>%d</td></tr>' % (author, info['commits'], info['commits_frac'], info['date_first'], info['date_last'], info['timedelta'], info['place_by_commits']))
538 550
 		f.write('</table>')
539 551
 
540 552
 		# Authors :: Author of Month
@@ -825,6 +837,8 @@ os.chdir(gitpath)
825 837
 print 'Collecting data...'
826 838
 data = GitDataCollector()
827 839
 data.collect(gitpath)
840
+print 'Refining data...'
841
+data.refine()
828 842
 
829 843
 os.chdir(rundir)
830 844