Kaynağa Gözat

Activity: Hour of Day.

Heikki Hokkanen 18 yıl önce
ebeveyn
işleme
1940f0cc3c
1 değiştirilmiş dosya ile 75 ekleme ve 7 silme
  1. 75
    7
      statgit

+ 75
- 7
statgit Dosyayı Görüntüle

@@ -26,6 +26,9 @@ class DataCollector:
26 26
 	def getAuthorInfo(self, author):
27 27
 		return None
28 28
 	
29
+	def getActivityByHourOfDay(self):
30
+		return {}
31
+
29 32
 	##
30 33
 	# Get a list of authors
31 34
 	def getAuthors(self):
@@ -60,7 +63,33 @@ class GitDataCollector(DataCollector):
60 63
 		self.total_commits = int(getoutput('git-rev-list --all |wc -l'))
61 64
 		self.total_files = int(getoutput('git-ls-files |wc -l'))
62 65
 		self.total_lines = int(getoutput('git-ls-files |xargs cat |wc -l'))
66
+
67
+		self.activity_by_hour_of_day = {} # hour -> commits
68
+		self.activity_by_day_of_week = {} # day -> commits
69
+
70
+		# activity
71
+		lines = getoutput('git-rev-list --all --pretty=format:%at |grep -v ^commit').split('\n')
72
+		for stamp in lines:
73
+			date = datetime.datetime.fromtimestamp(float(stamp))
74
+
75
+			# hour
76
+			hour = date.hour
77
+			if hour in self.activity_by_hour_of_day:
78
+				self.activity_by_hour_of_day[hour] += 1
79
+			else:
80
+				self.activity_by_hour_of_day[hour] = 1
81
+
82
+			# day
83
+			day = date.weekday()
84
+			if day in self.activity_by_day_of_week:
85
+				self.activity_by_day_of_week[day] += 1
86
+			else:
87
+				self.activity_by_day_of_week[day] = 1
88
+
63 89
 	
90
+	def getActivityByHourOfDay(self):
91
+		return self.activity_by_hour_of_day
92
+
64 93
 	def getAuthorInfo(self, author):
65 94
 		commits = int(getoutput('git-rev-list --all --author="%s" |wc -l' % author))
66 95
 		commits_frac = (100 * float(commits)) / self.getTotalCommits()
@@ -114,14 +143,8 @@ class HTMLReportCreator(ReportCreator):
114 143
 		ReportCreator.create(self, data, path)
115 144
 
116 145
 		f = open(path + "/index.html", 'w')
117
-		f.write("""<html>
118
-<head>
119
-	<title>StatGit</title>
120
-	<link rel="stylesheet" href="statgit.css" type="text/css" />
121
-</head>
122
-<body>
123
-""")
124 146
 		format = '%Y-%m-%d %H:%m:%S'
147
+		self.printHeader(f)
125 148
 
126 149
 		f.write('<h1>StatGit</h1>')
127 150
 
@@ -138,6 +161,7 @@ class HTMLReportCreator(ReportCreator):
138 161
 <li><a href="activity.html">Activity</a></li>
139 162
 <li><a href="authors.html">Authors</a></li>
140 163
 <li><a href="files.html">Files</a></li>
164
+<li><a href="lines.html">Lines</a></li>
141 165
 </ul>
142 166
 """)
143 167
 
@@ -159,8 +183,52 @@ class HTMLReportCreator(ReportCreator):
159 183
 
160 184
 		f.write('</body>\n</html>');
161 185
 		f.close()
186
+
187
+		# activity.html
188
+		f = open(path + '/activity.html', 'w')
189
+		self.printHeader(f)
190
+		f.write('<h1>Activity</h1>')
191
+
192
+		f.write('<h2>Last 30 days</h2>')
193
+
194
+		f.write('<h2>Last 12 months</h2>')
195
+
196
+		f.write('\n<h2>Hour of Day</h2>\n\n')
197
+		hour_of_day = data.getActivityByHourOfDay()
198
+		f.write('<table><tr><th>Hour</th>')
199
+		for i in range(1, 25):
200
+			f.write('<th>%d</th>' % i)
201
+		f.write('</tr>\n<tr><th>Commits</th>')
202
+		for i in range(1, 25):
203
+			if i in hour_of_day:
204
+				f.write('<td>%d</td>' % hour_of_day[i])
205
+			else:
206
+				f.write('<td>0</td>')
207
+		f.write('</tr>\n<tr><th>%</th>')
208
+		totalcommits = data.getTotalCommits()
209
+		for i in range(1, 25):
210
+			if i in hour_of_day:
211
+				f.write('<td>%.2f</td>' % ((100.0 * hour_of_day[i]) / totalcommits))
212
+			else:
213
+				f.write('<td>0.00</td>')
214
+		f.write('</tr></table>')
215
+
216
+		f.write('\n\n<h2>Day of Week</h2>')
217
+		# TODO 7x(24+1)
218
+
219
+		f.close()
162 220
 	pass
163 221
 
222
+	def printHeader(self, f):
223
+		f.write("""<html>
224
+<head>
225
+	<title>StatGit</title>
226
+	<link rel="stylesheet" href="statgit.css" type="text/css" />
227
+</head>
228
+<body>
229
+""")
230
+		
231
+
164 232
 usage = """
165 233
 Usage: statgit [options] <gitpath> <outputpath>
166 234