瀏覽代碼

Some initial statistics.

Heikki Hokkanen 18 年之前
父節點
當前提交
8293f6e37e
共有 2 個檔案被更改,包括 105 行新增7 行删除
  1. 27
    2
      TODO.txt
  2. 78
    5
      statgit

+ 27
- 2
TODO.txt 查看文件

@@ -5,7 +5,10 @@
5 5
 	- perl or python?
6 6
 
7 7
 - make git data collection part separate so that portage to other DVCS's is easier
8
+	- DataCollector
9
+
8 10
 - make output thingies modular as well (HTML first, plain text later etc)
11
+	- ReportCreator
9 12
 
10 13
 [Information]
11 14
 - git-log
@@ -28,11 +31,25 @@
28 31
 	- Authors
29 32
 
30 33
 - Authors
31
-	- Total number of authors
32
-	- List of names
34
+	- List of authors
33 35
 	- (T): author, commits (%), LOC?, first commit, last commit
34 36
 	- (T): Developer of the Month: month, author, commits, LOC?
35 37
 
38
+- Tags
39
+	- (T): Name, Date, LOC?, Developers
40
+
41
+- Author page for each author
42
+	- Name, mail
43
+	- Total commits (%)
44
+	- LOC (%)
45
+	- Last commit: date
46
+	- First commit: date
47
+	- Activity by Clock Time
48
+		- (G) Hour of Day
49
+		- (G) Day of Week
50
+	- (T) Activity in Directories: Directory, Changes, LOC, LOC/change
51
+	- (Most Recent Commits?)
52
+
36 53
 [Stats in StatSVN]
37 54
 - General
38 55
 	- Report Period (first/last date of commits)
@@ -74,3 +91,11 @@
74 91
 [Graphics]
75 92
 - Use gnuplot, graphviz etc ?
76 93
 
94
+[Usage]
95
+- $ statgit [-o html] /path/to/git /output/dir
96
+
97
+[name]
98
+- statgit or gitstats (no google hits for either)
99
+
100
+[Misc]
101
+- use sortable.js ?

+ 78
- 5
statgit 查看文件

@@ -1,6 +1,8 @@
1 1
 #!/usr/bin/python
2 2
 # Copyright (c) 2007 Heikki Hokkanen <hoxu@users.sf.net>
3 3
 # GPLv2
4
+import commands
5
+import datetime
4 6
 import os
5 7
 import re
6 8
 import sys
@@ -11,8 +13,50 @@ class DataCollector:
11 13
 	
12 14
 	def collect(self, dir):
13 15
 		self.dir = dir
16
+	
17
+	##
18
+	# TODO: get a dictionary of author
19
+	def getAuthorInfo(self, author):
20
+		return None
21
+	
22
+	##
23
+	# Get a list of authors
24
+	def getAuthors(self):
25
+		return []
26
+	
27
+	def getTotalAuthors(self):
28
+		return -1
29
+	
30
+	def getTotalCommits(self):
31
+		return -1
32
+		
33
+	def getTotalFiles(self):
34
+		return -1
35
+	
36
+	def getTotalLOC(self):
37
+		return -1
14 38
 
15 39
 class GitDataCollector(DataCollector):
40
+	def collect(self, dir):
41
+		DataCollector.collect(self, dir)
42
+	
43
+	def getAuthorInfo(self, author):
44
+		res = { 'commits' : -1, 'commits_frac' : 1.5, 'date_first' : '0000-00-00', 'date_last' : '0000-00-00' }
45
+		return res
46
+	
47
+	def getAuthors(self):
48
+		lines = commands.getoutput('git-rev-list --all --pretty=format:%an |grep -v ^commit |sort |uniq')
49
+		return lines.split('\n')
50
+	
51
+	def getTotalAuthors(self):
52
+		return int(commands.getoutput('git-log |git-shortlog -s |wc -l'))
53
+	
54
+	def getTotalCommits(self):
55
+		return int(commands.getoutput('git-rev-list --all |wc -l'))
56
+
57
+	def getTotalFiles(self):
58
+		files = commands.getoutput('git-ls-files |wc -l')
59
+		return int(files)
16 60
 	pass
17 61
 
18 62
 class ReportCreator:
@@ -23,13 +67,40 @@ class ReportCreator:
23 67
 		self.data = data
24 68
 		self.path = path
25 69
 
26
-class ConsoleReportCreator(ReportCreator):
70
+class HTMLReportCreator(ReportCreator):
27 71
 	def create(self, data, path):
28
-		ReportCreator.create(data, path)
72
+		ReportCreator.create(self, data, path)
29 73
 
30
-	pass
74
+		f = open(path + "/index.html", 'w')
75
+		f.write("""<html>
76
+<head>
77
+	<title>StatGit</title>
78
+</head>
79
+<body>
80
+""")
31 81
 
32
-class HTMLReportCreator(ReportCreator):
82
+		f.write('<h1>StatGit</h1>')
83
+
84
+		f.write('<dl>');
85
+		f.write('<dt>Generated</dt><dd>%s</dd>' % datetime.datetime.now().strftime('%Y-%m-%d %H:%m:%S'));
86
+		f.write('<dt>Report Period</dt><dd>%s to %s</dd>' % ('0000-00-00', '0000-00-00'))
87
+		f.write('<dt>Total Files</dt><dd>%s</dd>' % data.getTotalFiles())
88
+		f.write('<dt>Total Lines of Code</dt><dd>%s</dd>' % data.getTotalLOC())
89
+		f.write('<dt>Total Commits</dt><dd>%s</dd>' % data.getTotalCommits())
90
+		f.write('<dt>Authors</dt><dd>%s</dd>' % data.getTotalAuthors())
91
+		f.write('</dl>');
92
+
93
+		f.write('<h2>Authors</h2>')
94
+
95
+		f.write('<table class="authors">')
96
+		f.write('<tr><th>Author</th><th>Commits (%)</th><th>First commit</th><th>Last commit</th></tr>')
97
+		for author in data.getAuthors():
98
+			info = data.getAuthorInfo(author)
99
+			f.write('<tr><td>%s</td><td>%d (%.2f)</td><td>%s</td><td>%s</td></tr>' % (author, info['commits'], info['commits_frac'], info['date_first'], info['date_last']))
100
+		f.write('</table>')
101
+
102
+		f.write('</body>\n</html>');
103
+		f.close()
33 104
 	pass
34 105
 
35 106
 usage = """
@@ -49,10 +120,12 @@ outputpath = sys.argv[2]
49 120
 print 'Git path: %s' % gitpath
50 121
 print 'Output path: %s' % outputpath
51 122
 
123
+os.chdir(gitpath)
124
+
52 125
 data = GitDataCollector()
53 126
 data.collect(gitpath)
54 127
 
55
-report = ConsoleReportCreator()
128
+report = HTMLReportCreator()
56 129
 report.create(data, outputpath)
57 130
 
58 131