2 # Copyright (c) 2007-2008 Heikki Hokkanen <hoxu@users.sf.net>
13 GNUPLOT_COMMON
= 'set terminal png transparent\nset size 0.5,0.5\n'
15 exectime_internal
= 0.0
16 exectime_external
= 0.0
17 time_start
= time
.time()
19 # By default, gnuplot is searched from path, but can be overridden with the
20 # environment variable "GNUPLOT"
21 gnuplot_cmd
= 'gnuplot'
22 if 'GNUPLOT' in os
.environ
:
23 gnuplot_cmd
= os
.environ
['GNUPLOT']
25 def getpipeoutput(cmds
, quiet
= False):
26 def beautify_name(cmds
):
32 global exectime_external
35 print '>> ', beautify_name(cmds
)
37 p0
= subprocess
.Popen(cmds
[0], stdout
= subprocess
.PIPE
, shell
= True)
40 p
= subprocess
.Popen(x
, stdin
= p0
.stdout
, stdout
= subprocess
.PIPE
, shell
= True)
42 output
= p
.communicate()[0]
45 print '\r[%.5f] >> %s' % (end
- start
, beautify_name(cmds
))
46 exectime_external
+= (end
- start
)
47 return output
.rstrip('\n')
49 def getkeyssortedbyvalues(dict):
50 return map(lambda el
: el
[1], sorted(map(lambda el
: (el
[1], el
[0]), dict.items())))
52 # dict['author'] = { 'commits': 512 } - ...key(dict, 'commits')
53 def getkeyssortedbyvaluekey(d
, key
):
54 return map(lambda el
: el
[1], sorted(map(lambda el
: (d
[el
][key
], el
), d
.keys())))
57 """Manages data collection from a revision control repository."""
59 self
.stamp_created
= time
.time()
63 # This should be the main function to extract data from the repository.
64 def collect(self
, dir):
66 self
.projectname
= os
.path
.basename(os
.path
.abspath(dir))
69 # Produce any additional statistics from the extracted data.
74 # : get a dictionary of author
75 def getAuthorInfo(self
, author
):
78 def getActivityByDayOfWeek(self
):
81 def getActivityByHourOfDay(self
):
85 # Get a list of authors
89 def getFirstCommitDate(self
):
90 return datetime
.datetime
.now()
92 def getLastCommitDate(self
):
93 return datetime
.datetime
.now()
95 def getStampCreated(self
):
96 return self
.stamp_created
101 def getTotalAuthors(self
):
104 def getTotalCommits(self
):
107 def getTotalFiles(self
):
110 def getTotalLOC(self
):
113 class GitDataCollector(DataCollector
):
114 def collect(self
, dir):
115 DataCollector
.collect(self
, dir)
118 self
.total_authors
= int(getpipeoutput(('git-log', 'git-shortlog -s', 'wc -l')))
120 self
.total_authors
= 0
121 #self.total_lines = int(getoutput('git-ls-files -z |xargs -0 cat |wc -l'))
123 self
.activity_by_hour_of_day
= {} # hour -> commits
124 self
.activity_by_day_of_week
= {} # day -> commits
125 self
.activity_by_month_of_year
= {} # month [1-12] -> commits
126 self
.activity_by_hour_of_week
= {} # weekday -> hour -> commits
128 self
.authors
= {} # name -> {commits, first_commit_stamp, last_commit_stamp}
130 # author of the month
131 self
.author_of_month
= {} # month -> author -> commits
132 self
.author_of_year
= {} # year -> author -> commits
133 self
.commits_by_month
= {} # month -> commits
134 self
.commits_by_year
= {} # year -> commits
135 self
.first_commit_stamp
= 0
136 self
.last_commit_stamp
= 0
140 lines
= getpipeoutput((('git-show-ref --tags'),)).split('\n')
144 print "line = ", line
145 splitted_str
= line
.split(' ')
146 print "splitted_str = ", splitted_str
147 (hash, tag
) = splitted_str
149 tag
= tag
.replace('refs/tags/', '')
150 output
= getpipeoutput((('git-log "%s" --pretty=format:"%%at %%an" -n 1' % hash),))
152 parts
= output
.split(' ')
155 stamp
= int(parts
[0])
158 self
.tags
[tag
] = { 'stamp': stamp
, 'hash' : hash, 'date' : datetime
.datetime
.fromtimestamp(stamp
).strftime('%Y-%m-%d') }
161 # Collect revision statistics
162 # Outputs "<stamp> <author>"
163 lines
= getpipeoutput(('git-rev-list --pretty=format:"%at %an" HEAD', 'grep -v ^commit')).split('\n')
165 # linux-2.6 says "<unknown>" for one line O_o
166 parts
= line
.split(' ')
169 stamp
= int(parts
[0])
171 print "lines = ", lines
172 print "line = ", line
176 author
= ' '.join(parts
[1:])
177 date
= datetime
.datetime
.fromtimestamp(float(stamp
))
179 # First and last commit stamp
180 if self
.last_commit_stamp
== 0:
181 self
.last_commit_stamp
= stamp
182 self
.first_commit_stamp
= stamp
187 if hour
in self
.activity_by_hour_of_day
:
188 self
.activity_by_hour_of_day
[hour
] += 1
190 self
.activity_by_hour_of_day
[hour
] = 1
194 if day
in self
.activity_by_day_of_week
:
195 self
.activity_by_day_of_week
[day
] += 1
197 self
.activity_by_day_of_week
[day
] = 1
200 if day
not in self
.activity_by_hour_of_week
:
201 self
.activity_by_hour_of_week
[day
] = {}
202 if hour
not in self
.activity_by_hour_of_week
[day
]:
203 self
.activity_by_hour_of_week
[day
][hour
] = 1
205 self
.activity_by_hour_of_week
[day
][hour
] += 1
209 if month
in self
.activity_by_month_of_year
:
210 self
.activity_by_month_of_year
[month
] += 1
212 self
.activity_by_month_of_year
[month
] = 1
215 if author
not in self
.authors
:
216 self
.authors
[author
] = {}
218 if 'last_commit_stamp' not in self
.authors
[author
]:
219 self
.authors
[author
]['last_commit_stamp'] = stamp
220 self
.authors
[author
]['first_commit_stamp'] = stamp
221 if 'commits' in self
.authors
[author
]:
222 self
.authors
[author
]['commits'] += 1
224 self
.authors
[author
]['commits'] = 1
226 # author of the month/year
227 yymm
= datetime
.datetime
.fromtimestamp(stamp
).strftime('%Y-%m')
228 if yymm
in self
.author_of_month
:
229 if author
in self
.author_of_month
[yymm
]:
230 self
.author_of_month
[yymm
][author
] += 1
232 self
.author_of_month
[yymm
][author
] = 1
234 self
.author_of_month
[yymm
] = {}
235 self
.author_of_month
[yymm
][author
] = 1
236 if yymm
in self
.commits_by_month
:
237 self
.commits_by_month
[yymm
] += 1
239 self
.commits_by_month
[yymm
] = 1
241 yy
= datetime
.datetime
.fromtimestamp(stamp
).year
242 if yy
in self
.author_of_year
:
243 if author
in self
.author_of_year
[yy
]:
244 self
.author_of_year
[yy
][author
] += 1
246 self
.author_of_year
[yy
][author
] = 1
248 self
.author_of_year
[yy
] = {}
249 self
.author_of_year
[yy
][author
] = 1
250 if yy
in self
.commits_by_year
:
251 self
.commits_by_year
[yy
] += 1
253 self
.commits_by_year
[yy
] = 1
255 # TODO Optimize this, it's the worst bottleneck
256 # outputs "<stamp> <files>" for each revision
257 self
.files_by_stamp
= {} # stamp -> files
258 lines
= getpipeoutput(('git-rev-list --pretty=format:"%at %H" HEAD',
259 'grep -v ^commit')).strip().split('\n')
260 #'sh while read line; do set $line; echo "$1 $(git-ls-tree -r "$2" |wc -l)"; done')).split('\n')
261 tmp
= [None] * len(lines
)
262 for idx
in xrange(len(lines
)):
263 (a
, b
) = lines
[idx
].split(" ")
264 tmp
[idx
] = a
+ getpipeoutput(('git-ls-tree -r ' + b
, 'wc -l')).strip('\n')
267 self
.total_commits
= len(lines
)
269 parts
= line
.split(' ')
272 (stamp
, files
) = parts
[0:2]
274 self
.files_by_stamp
[int(stamp
)] = int(files
)
276 print 'Warning: failed to parse line "%s"' % line
279 self
.extensions
= {} # extension -> files, lines
280 lines
= getpipeoutput(('git-ls-files',)).split('\n')
281 self
.total_files
= len(lines
)
283 base
= os
.path
.basename(line
)
284 if base
.find('.') == -1:
287 ext
= base
[(base
.rfind('.') + 1):]
289 if ext
not in self
.extensions
:
290 self
.extensions
[ext
] = {'files': 0, 'lines': 0}
292 self
.extensions
[ext
]['files'] += 1
294 # Escaping could probably be improved here
295 self
.extensions
[ext
]['lines'] += int(getpipeoutput(('wc -l "%s"' % line
,)).split()[0])
297 print 'Warning: Could not count lines for file "%s"' % line
301 # N files changed, N insertions (+), N deletions(-)
303 self
.changes_by_date
= {} # stamp -> { files, ins, del }
304 lines
= getpipeoutput(('git-log --shortstat --pretty=format:"%at %an"',)).split('\n')
306 files
= 0; inserted
= 0; deleted
= 0; total_lines
= 0
312 if line
.find('files changed,') == -1:
315 (stamp
, author
) = (int(line
[:pos
]), line
[pos
+1:])
316 self
.changes_by_date
[stamp
] = { 'files': files
, 'ins': inserted
, 'del': deleted
, 'lines': total_lines
}
318 print 'Warning: unexpected line "%s"' % line
320 numbers
= re
.findall('\d+', line
)
321 if len(numbers
) == 3:
322 (files
, inserted
, deleted
) = map(lambda el
: int(el
), numbers
)
323 total_lines
+= inserted
324 total_lines
-= deleted
326 print 'Warning: failed to handle line "%s"' % line
327 (files
, inserted
, deleted
) = (0, 0, 0)
328 #self.changes_by_date[stamp] = { 'files': files, 'ins': inserted, 'del': deleted }
329 self
.total_lines
= total_lines
333 # name -> {place_by_commits, commits_frac, date_first, date_last, timedelta}
334 authors_by_commits
= getkeyssortedbyvaluekey(self
.authors
, 'commits')
335 authors_by_commits
.reverse() # most first
336 for i
, name
in enumerate(authors_by_commits
):
337 self
.authors
[name
]['place_by_commits'] = i
+ 1
339 for name
in self
.authors
.keys():
340 a
= self
.authors
[name
]
341 a
['commits_frac'] = (100 * float(a
['commits'])) / self
.getTotalCommits()
342 date_first
= datetime
.datetime
.fromtimestamp(a
['first_commit_stamp'])
343 date_last
= datetime
.datetime
.fromtimestamp(a
['last_commit_stamp'])
344 delta
= date_last
- date_first
345 a
['date_first'] = date_first
.strftime('%Y-%m-%d')
346 a
['date_last'] = date_last
.strftime('%Y-%m-%d')
347 a
['timedelta'] = delta
349 def getActivityByDayOfWeek(self
):
350 return self
.activity_by_day_of_week
352 def getActivityByHourOfDay(self
):
353 return self
.activity_by_hour_of_day
355 def getAuthorInfo(self
, author
):
356 return self
.authors
[author
]
358 def getAuthors(self
):
359 return self
.authors
.keys()
361 def getFirstCommitDate(self
):
362 return datetime
.datetime
.fromtimestamp(self
.first_commit_stamp
)
364 def getLastCommitDate(self
):
365 return datetime
.datetime
.fromtimestamp(self
.last_commit_stamp
)
368 lines
= getpipeoutput(('git-show-ref --tags',
370 return lines
.split('\n')
372 def getTagDate(self
, tag
):
373 return self
.revToDate('tags/' + tag
)
375 def getTotalAuthors(self
):
376 return self
.total_authors
378 def getTotalCommits(self
):
379 return self
.total_commits
381 def getTotalFiles(self
):
382 return self
.total_files
384 def getTotalLOC(self
):
385 return self
.total_lines
387 def revToDate(self
, rev
):
388 stamp
= int(getpipeoutput(('git-log --pretty=format:%%at "%s" -n 1' % rev
,)))
389 return datetime
.datetime
.fromtimestamp(stamp
).strftime('%Y-%m-%d')
392 """Creates the actual report based on given data."""
396 def create(self
, data
, path
):
400 def html_linkify(text
):
401 return text
.lower().replace(' ', '_')
403 def html_header(level
, text
):
404 name
= html_linkify(text
)
405 return '\n<h%d><a href="#%s" name="%s">%s</a></h%d>\n\n' % (level
, name
, name
, text
, level
)
407 class HTMLReportCreator(ReportCreator
):
408 def create(self
, data
, path
):
409 ReportCreator
.create(self
, data
, path
)
410 self
.title
= data
.projectname
412 # TODO copy the CSS if it does not exist
413 if not os
.path
.exists(path
+ '/gitstats.css'):
414 basedir
= os
.path
.dirname(os
.path
.abspath(__file__
))
415 shutil
.copyfile(basedir
+ '/gitstats.css', path
+ '/gitstats.css')
418 f
= open(path
+ "/index.html", 'w')
419 format
= '%Y-%m-%d %H:%m:%S'
422 f
.write('<h1>GitStats - %s</h1>' % data
.projectname
)
427 f
.write('<dt>Project name</dt><dd>%s</dd>' % (data
.projectname
))
428 f
.write('<dt>Generated</dt><dd>%s (in %d seconds)</dd>' % (datetime
.datetime
.now().strftime(format
), time
.time() - data
.getStampCreated()));
429 f
.write('<dt>Report Period</dt><dd>%s to %s</dd>' % (data
.getFirstCommitDate().strftime(format
), data
.getLastCommitDate().strftime(format
)))
430 f
.write('<dt>Total Files</dt><dd>%s</dd>' % data
.getTotalFiles())
431 f
.write('<dt>Total Lines of Code</dt><dd>%s</dd>' % data
.getTotalLOC())
432 f
.write('<dt>Total Commits</dt><dd>%s</dd>' % data
.getTotalCommits())
433 f
.write('<dt>Authors</dt><dd>%s</dd>' % data
.getTotalAuthors())
436 f
.write('</body>\n</html>');
441 f
= open(path
+ '/activity.html', 'w')
443 f
.write('<h1>Activity</h1>')
446 #f.write('<h2>Last 30 days</h2>')
448 #f.write('<h2>Last 12 months</h2>')
451 f
.write(html_header(2, 'Hour of Day'))
452 hour_of_day
= data
.getActivityByHourOfDay()
453 f
.write('<table><tr><th>Hour</th>')
454 for i
in range(1, 25):
455 f
.write('<th>%d</th>' % i
)
456 f
.write('</tr>\n<tr><th>Commits</th>')
457 fp
= open(path
+ '/hour_of_day.dat', 'w')
458 for i
in range(0, 24):
460 f
.write('<td>%d</td>' % hour_of_day
[i
])
461 fp
.write('%d %d\n' % (i
, hour_of_day
[i
]))
463 f
.write('<td>0</td>')
464 fp
.write('%d 0\n' % i
)
466 f
.write('</tr>\n<tr><th>%</th>')
467 totalcommits
= data
.getTotalCommits()
468 for i
in range(0, 24):
470 f
.write('<td>%.2f</td>' % ((100.0 * hour_of_day
[i
]) / totalcommits
))
472 f
.write('<td>0.00</td>')
473 f
.write('</tr></table>')
474 f
.write('<img src="hour_of_day.png" alt="Hour of Day" />')
475 fg
= open(path
+ '/hour_of_day.dat', 'w')
476 for i
in range(0, 24):
478 fg
.write('%d %d\n' % (i
+ 1, hour_of_day
[i
]))
480 fg
.write('%d 0\n' % (i
+ 1))
484 f
.write(html_header(2, 'Day of Week'))
485 day_of_week
= data
.getActivityByDayOfWeek()
486 f
.write('<div class="vtable"><table>')
487 f
.write('<tr><th>Day</th><th>Total (%)</th></tr>')
488 fp
= open(path
+ '/day_of_week.dat', 'w')
489 for d
in range(0, 7):
492 commits
= day_of_week
[d
]
493 fp
.write('%d %d\n' % (d
+ 1, commits
))
495 f
.write('<th>%d</th>' % (d
+ 1))
497 f
.write('<td>%d (%.2f%%)</td>' % (day_of_week
[d
], (100.0 * day_of_week
[d
]) / totalcommits
))
499 f
.write('<td>0</td>')
501 f
.write('</table></div>')
502 f
.write('<img src="day_of_week.png" alt="Day of Week" />')
506 f
.write(html_header(2, 'Hour of Week'))
509 f
.write('<tr><th>Weekday</th>')
510 for hour
in range(0, 24):
511 f
.write('<th>%d</th>' % (hour
+ 1))
514 for weekday
in range(0, 7):
515 f
.write('<tr><th>%d</th>' % (weekday
+ 1))
516 for hour
in range(0, 24):
518 commits
= data
.activity_by_hour_of_week
[weekday
][hour
]
522 f
.write('<td>%d</td>' % commits
)
530 f
.write(html_header(2, 'Month of Year'))
531 f
.write('<div class="vtable"><table>')
532 f
.write('<tr><th>Month</th><th>Commits (%)</th></tr>')
533 fp
= open (path
+ '/month_of_year.dat', 'w')
534 for mm
in range(1, 13):
536 if mm
in data
.activity_by_month_of_year
:
537 commits
= data
.activity_by_month_of_year
[mm
]
538 f
.write('<tr><td>%d</td><td>%d (%.2f %%)</td></tr>' % (mm
, commits
, (100.0 * commits
) / data
.getTotalCommits()))
539 fp
.write('%d %d\n' % (mm
, commits
))
541 f
.write('</table></div>')
542 f
.write('<img src="month_of_year.png" alt="Month of Year" />')
544 # Commits by year/month
545 f
.write(html_header(2, 'Commits by year/month'))
546 f
.write('<div class="vtable"><table><tr><th>Month</th><th>Commits</th></tr>')
547 for yymm
in reversed(sorted(data
.commits_by_month
.keys())):
548 f
.write('<tr><td>%s</td><td>%d</td></tr>' % (yymm
, data
.commits_by_month
[yymm
]))
549 f
.write('</table></div>')
550 f
.write('<img src="commits_by_year_month.png" alt="Commits by year/month" />')
551 fg
= open(path
+ '/commits_by_year_month.dat', 'w')
552 for yymm
in sorted(data
.commits_by_month
.keys()):
553 fg
.write('%s %s\n' % (yymm
, data
.commits_by_month
[yymm
]))
557 f
.write(html_header(2, 'Commits by Year'))
558 f
.write('<div class="vtable"><table><tr><th>Year</th><th>Commits (% of all)</th></tr>')
559 for yy
in reversed(sorted(data
.commits_by_year
.keys())):
560 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()))
561 f
.write('</table></div>')
562 f
.write('<img src="commits_by_year.png" alt="Commits by Year" />')
563 fg
= open(path
+ '/commits_by_year.dat', 'w')
564 for yy
in sorted(data
.commits_by_year
.keys()):
565 fg
.write('%d %d\n' % (yy
, data
.commits_by_year
[yy
]))
568 f
.write('</body></html>')
573 f
= open(path
+ '/authors.html', 'w')
576 f
.write('<h1>Authors</h1>')
579 # Authors :: List of authors
580 f
.write(html_header(2, 'List of Authors'))
582 f
.write('<table class="authors">')
583 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>')
584 for author
in sorted(data
.getAuthors()):
585 info
= data
.getAuthorInfo(author
)
586 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']))
589 # Authors :: Author of Month
590 f
.write(html_header(2, 'Author of Month'))
592 f
.write('<tr><th>Month</th><th>Author</th><th>Commits (%)</th><th>Next top 5</th></tr>')
593 for yymm
in reversed(sorted(data
.author_of_month
.keys())):
594 authordict
= data
.author_of_month
[yymm
]
595 authors
= getkeyssortedbyvalues(authordict
)
597 commits
= data
.author_of_month
[yymm
][authors
[0]]
598 next
= ', '.join(authors
[1:5])
599 f
.write('<tr><td>%s</td><td>%s</td><td>%d (%.2f%% of %d)</td><td>%s</td></tr>' % (yymm
, authors
[0], commits
, (100 * commits
) / data
.commits_by_month
[yymm
], data
.commits_by_month
[yymm
], next
))
603 f
.write(html_header(2, 'Author of Year'))
604 f
.write('<table><tr><th>Year</th><th>Author</th><th>Commits (%)</th><th>Next top 5</th></tr>')
605 for yy
in reversed(sorted(data
.author_of_year
.keys())):
606 authordict
= data
.author_of_year
[yy
]
607 authors
= getkeyssortedbyvalues(authordict
)
609 commits
= data
.author_of_year
[yy
][authors
[0]]
610 next
= ', '.join(authors
[1:5])
611 f
.write('<tr><td>%s</td><td>%s</td><td>%d (%.2f%% of %d)</td><td>%s</td></tr>' % (yy
, authors
[0], commits
, (100 * commits
) / data
.commits_by_year
[yy
], data
.commits_by_year
[yy
], next
))
614 f
.write('</body></html>')
619 f
= open(path
+ '/files.html', 'w')
621 f
.write('<h1>Files</h1>')
625 f
.write('<dt>Total files</dt><dd>%d</dd>' % data
.getTotalFiles())
626 f
.write('<dt>Total lines</dt><dd>%d</dd>' % data
.getTotalLOC())
627 f
.write('<dt>Average file size</dt><dd>%.2f bytes</dd>' % ((100.0 * data
.getTotalLOC()) / data
.getTotalFiles()))
630 # Files :: File count by date
631 f
.write(html_header(2, 'File count by date'))
633 fg
= open(path
+ '/files_by_date.dat', 'w')
634 for stamp
in sorted(data
.files_by_stamp
.keys()):
635 fg
.write('%s %d\n' % (datetime
.datetime
.fromtimestamp(stamp
).strftime('%Y-%m-%d'), data
.files_by_stamp
[stamp
]))
638 f
.write('<img src="files_by_date.png" alt="Files by Date" />')
640 #f.write('<h2>Average file size by date</h2>')
642 # Files :: Extensions
643 f
.write(html_header(2, 'Extensions'))
644 f
.write('<table><tr><th>Extension</th><th>Files (%)</th><th>Lines (%)</th><th>Lines/file</th></tr>')
645 for ext
in sorted(data
.extensions
.keys()):
646 files
= data
.extensions
[ext
]['files']
647 lines
= data
.extensions
[ext
]['lines']
648 f
.write('<tr><td>%s</td><td>%d (%.2f%%)</td><td>%d (%.2f%%)</td><td>%d</td></tr>' % (ext
, files
, (100.0 * files
) / data
.getTotalFiles(), lines
, (100.0 * lines
) / data
.getTotalLOC(), lines
/ files
))
651 f
.write('</body></html>')
656 f
= open(path
+ '/lines.html', 'w')
658 f
.write('<h1>Lines</h1>')
662 f
.write('<dt>Total lines</dt><dd>%d</dd>' % data
.getTotalLOC())
665 f
.write(html_header(2, 'Lines of Code'))
666 f
.write('<img src="lines_of_code.png" />')
668 fg
= open(path
+ '/lines_of_code.dat', 'w')
669 for stamp
in sorted(data
.changes_by_date
.keys()):
670 fg
.write('%d %d\n' % (stamp
, data
.changes_by_date
[stamp
]['lines']))
673 f
.write('</body></html>')
678 f
= open(path
+ '/tags.html', 'w')
680 f
.write('<h1>Tags</h1>')
684 f
.write('<dt>Total tags</dt><dd>%d</dd>' % len(data
.tags
))
685 if len(data
.tags
) > 0:
686 f
.write('<dt>Average commits per tag</dt><dd>%.2f</dd>' % (data
.getTotalCommits() / len(data
.tags
)))
690 f
.write('<tr><th>Name</th><th>Date</th></tr>')
691 # sort the tags by date desc
692 tags_sorted_by_date_desc
= map(lambda el
: el
[1], reversed(sorted(map(lambda el
: (el
[1]['date'], el
[0]), data
.tags
.items()))))
693 for tag
in tags_sorted_by_date_desc
:
694 f
.write('<tr><td>%s</td><td>%s</td></tr>' % (tag
, data
.tags
[tag
]['date']))
697 f
.write('</body></html>')
700 self
.createGraphs(path
)
703 def createGraphs(self
, path
):
704 print 'Generating graphs...'
707 f
= open(path
+ '/hour_of_day.plot', 'w')
708 f
.write(GNUPLOT_COMMON
)
711 set output 'hour_of_day.png'
713 set xrange [0.5:24.5]
716 plot 'hour_of_day.dat' using 1:2:(0.5) w boxes fs solid
721 f
= open(path
+ '/day_of_week.plot', 'w')
722 f
.write(GNUPLOT_COMMON
)
725 set output 'day_of_week.png'
730 plot 'day_of_week.dat' using 1:2:(0.5) w boxes fs solid
735 f
= open(path
+ '/month_of_year.plot', 'w')
736 f
.write(GNUPLOT_COMMON
)
739 set output 'month_of_year.png'
741 set xrange [0.5:12.5]
744 plot 'month_of_year.dat' using 1:2:(0.5) w boxes fs solid
748 # commits_by_year_month
749 f
= open(path
+ '/commits_by_year_month.plot', 'w')
750 f
.write(GNUPLOT_COMMON
)
753 set output 'commits_by_year_month.png'
758 set xtics rotate by 90 15768000
761 plot 'commits_by_year_month.dat' using 1:2:(0.5) w boxes fs solid
766 f
= open(path
+ '/commits_by_year.plot', 'w')
767 f
.write(GNUPLOT_COMMON
)
770 set output 'commits_by_year.png'
774 plot 'commits_by_year.dat' using 1:2:(0.5) w boxes fs solid
779 f
= open(path
+ '/files_by_date.plot', 'w')
780 f
.write(GNUPLOT_COMMON
)
783 set output 'files_by_date.png'
786 set timefmt "%Y-%m-%d"
787 set format x "%Y-%m-%d"
789 set xtics rotate by 90
791 plot 'files_by_date.dat' using 1:2 smooth csplines
796 f
= open(path
+ '/lines_of_code.plot', 'w')
797 f
.write(GNUPLOT_COMMON
)
800 set output 'lines_of_code.png'
804 set format x "%Y-%m-%d"
806 set xtics rotate by 90
808 plot 'lines_of_code.dat' using 1:2 w lines
813 files
= glob
.glob(path
+ '/*.plot')
815 out
= getpipeoutput((gnuplot_cmd
+ ' "%s"' % f
,))
819 def printHeader(self
, f
, title
= ''):
821 """<?xml version="1.0" encoding="UTF-8"?>
822 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
823 <html xmlns="http://www.w3.org/1999/xhtml">
825 <title>GitStats - %s</title>
826 <link rel="stylesheet" href="gitstats.css" type="text/css" />
827 <meta name="generator" content="GitStats" />
832 def printNav(self
, f
):
836 <li><a href="index.html">General</a></li>
837 <li><a href="activity.html">Activity</a></li>
838 <li><a href="authors.html">Authors</a></li>
839 <li><a href="files.html">Files</a></li>
840 <li><a href="lines.html">Lines</a></li>
841 <li><a href="tags.html">Tags</a></li>
848 Usage: gitstats [options] <gitpath> <outputpath>
853 if len(sys
.argv
) < 3:
857 gitpath
= sys
.argv
[1]
858 outputpath
= os
.path
.abspath(sys
.argv
[2])
862 os
.makedirs(outputpath
)
865 if not os
.path
.isdir(outputpath
):
866 print 'FATAL: Output path is not a directory or does not exist'
869 print 'Git path: %s' % gitpath
870 print 'Output path: %s' % outputpath
874 print 'Collecting data...'
875 data
= GitDataCollector()
876 data
.collect(gitpath
)
877 print 'Refining data...'
882 print 'Generating report...'
883 report
= HTMLReportCreator()
884 report
.create(data
, outputpath
)
886 time_end
= time
.time()
887 exectime_internal
= time_end
- time_start
888 print 'Execution time %.5f secs, %.5f secs (%.2f %%) in external commands)' % (exectime_internal
, exectime_external
, (100.0 * exectime_external
) / exectime_internal
)