2 # Copyright (c) 2007 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 def getoutput(cmd
, quiet
= False):
20 global exectime_external
25 output
= commands
.getoutput(cmd
)
28 print '\r[%.5f] >> %s' % (end
- start
, cmd
)
29 exectime_external
+= (end
- start
)
32 def getkeyssortedbyvalues(dict):
33 return map(lambda el
: el
[1], sorted(map(lambda el
: (el
[1], el
[0]), dict.items())))
35 # dict['author'] = { 'commits': 512 } - ...key(dict, 'commits')
36 def getkeyssortedbyvaluekey(d
, key
):
37 return map(lambda el
: el
[1], sorted(map(lambda el
: (d
[el
][key
], el
), d
.keys())))
40 """Manages data collection from a revision control repository."""
42 self
.stamp_created
= time
.time()
46 # This should be the main function to extract data from the repository.
47 def collect(self
, dir):
49 self
.projectname
= os
.path
.basename(os
.path
.abspath(dir))
52 # : get a dictionary of author
53 def getAuthorInfo(self
, author
):
56 def getActivityByDayOfWeek(self
):
59 def getActivityByHourOfDay(self
):
63 # Get a list of authors
67 def getFirstCommitDate(self
):
68 return datetime
.datetime
.now()
70 def getLastCommitDate(self
):
71 return datetime
.datetime
.now()
73 def getStampCreated(self
):
74 return self
.stamp_created
79 def getTotalAuthors(self
):
82 def getTotalCommits(self
):
85 def getTotalFiles(self
):
88 def getTotalLOC(self
):
91 class GitDataCollector(DataCollector
):
92 def collect(self
, dir):
93 DataCollector
.collect(self
, dir)
95 self
.total_authors
= int(getoutput('git-log |git-shortlog -s |wc -l'))
96 #self.total_lines = int(getoutput('git-ls-files -z |xargs -0 cat |wc -l'))
98 self
.activity_by_hour_of_day
= {} # hour -> commits
99 self
.activity_by_day_of_week
= {} # day -> commits
100 self
.activity_by_month_of_year
= {} # month [1-12] -> commits
101 self
.activity_by_hour_of_week
= {} # weekday -> hour -> commits
103 self
.authors
= {} # name -> {commits, first_commit_stamp, last_commit_stamp}
105 # author of the month
106 self
.author_of_month
= {} # month -> author -> commits
107 self
.author_of_year
= {} # year -> author -> commits
108 self
.commits_by_month
= {} # month -> commits
109 self
.commits_by_year
= {} # year -> commits
110 self
.first_commit_stamp
= 0
111 self
.last_commit_stamp
= 0
115 lines
= getoutput('git-show-ref --tags').split('\n')
119 (hash, tag
) = line
.split(' ')
120 tag
= tag
.replace('refs/tags/', '')
121 output
= getoutput('git-log "%s" --pretty=format:"%%at %%an" -n 1' % hash)
123 parts
= output
.split(' ')
126 stamp
= int(parts
[0])
129 self
.tags
[tag
] = { 'stamp': stamp
, 'hash' : hash, 'date' : datetime
.datetime
.fromtimestamp(stamp
).strftime('%Y-%m-%d') }
132 # Collect revision statistics
133 # Outputs "<stamp> <author>"
134 lines
= getoutput('git-rev-list --pretty=format:"%at %an" HEAD |grep -v ^commit').split('\n')
136 # linux-2.6 says "<unknown>" for one line O_o
137 parts
= line
.split(' ')
140 stamp
= int(parts
[0])
144 author
= ' '.join(parts
[1:])
145 date
= datetime
.datetime
.fromtimestamp(float(stamp
))
147 # First and last commit stamp
148 if self
.last_commit_stamp
== 0:
149 self
.last_commit_stamp
= stamp
150 self
.first_commit_stamp
= stamp
155 if hour
in self
.activity_by_hour_of_day
:
156 self
.activity_by_hour_of_day
[hour
] += 1
158 self
.activity_by_hour_of_day
[hour
] = 1
162 if day
in self
.activity_by_day_of_week
:
163 self
.activity_by_day_of_week
[day
] += 1
165 self
.activity_by_day_of_week
[day
] = 1
168 if day
not in self
.activity_by_hour_of_week
:
169 self
.activity_by_hour_of_week
[day
] = {}
170 if hour
not in self
.activity_by_hour_of_week
[day
]:
171 self
.activity_by_hour_of_week
[day
][hour
] = 1
173 self
.activity_by_hour_of_week
[day
][hour
] += 1
177 if month
in self
.activity_by_month_of_year
:
178 self
.activity_by_month_of_year
[month
] += 1
180 self
.activity_by_month_of_year
[month
] = 1
183 if author
not in self
.authors
:
184 self
.authors
[author
] = {}
186 if 'last_commit_stamp' not in self
.authors
[author
]:
187 self
.authors
[author
]['last_commit_stamp'] = stamp
188 self
.authors
[author
]['first_commit_stamp'] = stamp
189 if 'commits' in self
.authors
[author
]:
190 self
.authors
[author
]['commits'] += 1
192 self
.authors
[author
]['commits'] = 1
194 # author of the month/year
195 yymm
= datetime
.datetime
.fromtimestamp(stamp
).strftime('%Y-%m')
196 if yymm
in self
.author_of_month
:
197 if author
in self
.author_of_month
[yymm
]:
198 self
.author_of_month
[yymm
][author
] += 1
200 self
.author_of_month
[yymm
][author
] = 1
202 self
.author_of_month
[yymm
] = {}
203 self
.author_of_month
[yymm
][author
] = 1
204 if yymm
in self
.commits_by_month
:
205 self
.commits_by_month
[yymm
] += 1
207 self
.commits_by_month
[yymm
] = 1
209 yy
= datetime
.datetime
.fromtimestamp(stamp
).year
210 if yy
in self
.author_of_year
:
211 if author
in self
.author_of_year
[yy
]:
212 self
.author_of_year
[yy
][author
] += 1
214 self
.author_of_year
[yy
][author
] = 1
216 self
.author_of_year
[yy
] = {}
217 self
.author_of_year
[yy
][author
] = 1
218 if yy
in self
.commits_by_year
:
219 self
.commits_by_year
[yy
] += 1
221 self
.commits_by_year
[yy
] = 1
223 # TODO Optimize this, it's the worst bottleneck
224 # outputs "<stamp> <files>" for each revision
225 self
.files_by_stamp
= {} # stamp -> files
226 lines
= getoutput('git-rev-list --pretty=format:"%at %H" HEAD |grep -v ^commit |while read line; do set $line; echo "$1 $(git-ls-tree -r "$2" |wc -l)"; done').split('\n')
227 self
.total_commits
= len(lines
)
229 parts
= line
.split(' ')
232 (stamp
, files
) = parts
[0:2]
234 self
.files_by_stamp
[int(stamp
)] = int(files
)
236 print 'Warning: failed to parse line "%s"' % line
239 self
.extensions
= {} # extension -> files, lines
240 lines
= getoutput('git-ls-files').split('\n')
241 self
.total_files
= len(lines
)
243 base
= os
.path
.basename(line
)
244 if base
.find('.') == -1:
247 ext
= base
[(base
.rfind('.') + 1):]
249 if ext
not in self
.extensions
:
250 self
.extensions
[ext
] = {'files': 0, 'lines': 0}
252 self
.extensions
[ext
]['files'] += 1
254 # Escaping could probably be improved here
255 self
.extensions
[ext
]['lines'] += int(getoutput('wc -l < %s' % re
.sub(r
'(\W)', r
'\\\1', line
), quiet
= True))
257 print 'Warning: Could not count lines for file "%s"' % line
261 # N files changed, N insertions (+), N deletions(-)
263 self
.changes_by_date
= {} # stamp -> { files, ins, del }
264 lines
= getoutput('git-log --shortstat --pretty=format:"%at %an"').split('\n')
266 files
= 0; inserted
= 0; deleted
= 0; total_lines
= 0
272 if line
.find('files changed,') == -1:
275 (stamp
, author
) = (int(line
[:pos
]), line
[pos
+1:])
276 self
.changes_by_date
[stamp
] = { 'files': files
, 'ins': inserted
, 'del': deleted
, 'lines': total_lines
}
278 print 'Warning: unexpected line "%s"' % line
280 numbers
= re
.findall('\d+', line
)
281 if len(numbers
) == 3:
282 (files
, inserted
, deleted
) = map(lambda el
: int(el
), numbers
)
283 total_lines
+= inserted
284 total_lines
-= deleted
286 print 'Warning: failed to handle line "%s"' % line
287 (files
, inserted
, deleted
) = (0, 0, 0)
288 #self.changes_by_date[stamp] = { 'files': files, 'ins': inserted, 'del': deleted }
289 self
.total_lines
= total_lines
291 def getActivityByDayOfWeek(self
):
292 return self
.activity_by_day_of_week
294 def getActivityByHourOfDay(self
):
295 return self
.activity_by_hour_of_day
297 def getAuthorInfo(self
, author
):
298 a
= self
.authors
[author
]
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
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
}
309 def getAuthors(self
):
310 return self
.authors
.keys()
312 def getFirstCommitDate(self
):
313 return datetime
.datetime
.fromtimestamp(self
.first_commit_stamp
)
315 def getLastCommitDate(self
):
316 return datetime
.datetime
.fromtimestamp(self
.last_commit_stamp
)
319 lines
= getoutput('git-show-ref --tags |cut -d/ -f3')
320 return lines
.split('\n')
322 def getTagDate(self
, tag
):
323 return self
.revToDate('tags/' + tag
)
325 def getTotalAuthors(self
):
326 return self
.total_authors
328 def getTotalCommits(self
):
329 return self
.total_commits
331 def getTotalFiles(self
):
332 return self
.total_files
334 def getTotalLOC(self
):
335 return self
.total_lines
337 def revToDate(self
, rev
):
338 stamp
= int(getoutput('git-log --pretty=format:%%at "%s" -n 1' % rev
))
339 return datetime
.datetime
.fromtimestamp(stamp
).strftime('%Y-%m-%d')
342 """Creates the actual report based on given data."""
346 def create(self
, data
, path
):
350 def html_linkify(text
):
351 return text
.lower().replace(' ', '_')
353 def html_header(level
, text
):
354 name
= html_linkify(text
)
355 return '\n<h%d><a href="#%s" name="%s">%s</a></h%d>\n\n' % (level
, name
, name
, text
, level
)
357 class HTMLReportCreator(ReportCreator
):
358 def create(self
, data
, path
):
359 ReportCreator
.create(self
, data
, path
)
360 self
.title
= data
.projectname
362 # TODO copy the CSS if it does not exist
363 if not os
.path
.exists(path
+ '/gitstats.css'):
364 shutil
.copyfile('gitstats.css', path
+ '/gitstats.css')
367 f
= open(path
+ "/index.html", 'w')
368 format
= '%Y-%m-%d %H:%m:%S'
371 f
.write('<h1>GitStats - %s</h1>' % data
.projectname
)
376 f
.write('<dt>Project name</dt><dd>%s</dd>' % (data
.projectname
))
377 f
.write('<dt>Generated</dt><dd>%s (in %d seconds)</dd>' % (datetime
.datetime
.now().strftime(format
), time
.time() - data
.getStampCreated()));
378 f
.write('<dt>Report Period</dt><dd>%s to %s</dd>' % (data
.getFirstCommitDate().strftime(format
), data
.getLastCommitDate().strftime(format
)))
379 f
.write('<dt>Total Files</dt><dd>%s</dd>' % data
.getTotalFiles())
380 f
.write('<dt>Total Lines of Code</dt><dd>%s</dd>' % data
.getTotalLOC())
381 f
.write('<dt>Total Commits</dt><dd>%s</dd>' % data
.getTotalCommits())
382 f
.write('<dt>Authors</dt><dd>%s</dd>' % data
.getTotalAuthors())
385 f
.write('</body>\n</html>');
390 f
= open(path
+ '/activity.html', 'w')
392 f
.write('<h1>Activity</h1>')
395 #f.write('<h2>Last 30 days</h2>')
397 #f.write('<h2>Last 12 months</h2>')
400 f
.write(html_header(2, 'Hour of Day'))
401 hour_of_day
= data
.getActivityByHourOfDay()
402 f
.write('<table><tr><th>Hour</th>')
403 for i
in range(1, 25):
404 f
.write('<th>%d</th>' % i
)
405 f
.write('</tr>\n<tr><th>Commits</th>')
406 fp
= open(path
+ '/hour_of_day.dat', 'w')
407 for i
in range(0, 24):
409 f
.write('<td>%d</td>' % hour_of_day
[i
])
410 fp
.write('%d %d\n' % (i
, hour_of_day
[i
]))
412 f
.write('<td>0</td>')
413 fp
.write('%d 0\n' % i
)
415 f
.write('</tr>\n<tr><th>%</th>')
416 totalcommits
= data
.getTotalCommits()
417 for i
in range(0, 24):
419 f
.write('<td>%.2f</td>' % ((100.0 * hour_of_day
[i
]) / totalcommits
))
421 f
.write('<td>0.00</td>')
422 f
.write('</tr></table>')
423 f
.write('<img src="hour_of_day.png" alt="Hour of Day" />')
424 fg
= open(path
+ '/hour_of_day.dat', 'w')
425 for i
in range(0, 24):
427 fg
.write('%d %d\n' % (i
+ 1, hour_of_day
[i
]))
429 fg
.write('%d 0\n' % (i
+ 1))
433 f
.write(html_header(2, 'Day of Week'))
434 day_of_week
= data
.getActivityByDayOfWeek()
435 f
.write('<div class="vtable"><table>')
436 f
.write('<tr><th>Day</th><th>Total (%)</th></tr>')
437 fp
= open(path
+ '/day_of_week.dat', 'w')
438 for d
in range(0, 7):
441 commits
= day_of_week
[d
]
442 fp
.write('%d %d\n' % (d
+ 1, commits
))
444 f
.write('<th>%d</th>' % (d
+ 1))
446 f
.write('<td>%d (%.2f%%)</td>' % (day_of_week
[d
], (100.0 * day_of_week
[d
]) / totalcommits
))
448 f
.write('<td>0</td>')
450 f
.write('</table></div>')
451 f
.write('<img src="day_of_week.png" alt="Day of Week" />')
455 f
.write(html_header(2, 'Hour of Week'))
458 f
.write('<tr><th>Weekday</th>')
459 for hour
in range(0, 24):
460 f
.write('<th>%d</th>' % (hour
+ 1))
463 for weekday
in range(0, 7):
464 f
.write('<tr><th>%d</th>' % (weekday
+ 1))
465 for hour
in range(0, 24):
467 commits
= data
.activity_by_hour_of_week
[weekday
][hour
]
471 f
.write('<td>%d</td>' % commits
)
479 f
.write(html_header(2, 'Month of Year'))
480 f
.write('<div class="vtable"><table>')
481 f
.write('<tr><th>Month</th><th>Commits (%)</th></tr>')
482 fp
= open (path
+ '/month_of_year.dat', 'w')
483 for mm
in range(1, 13):
485 if mm
in data
.activity_by_month_of_year
:
486 commits
= data
.activity_by_month_of_year
[mm
]
487 f
.write('<tr><td>%d</td><td>%d (%.2f %%)</td></tr>' % (mm
, commits
, (100.0 * commits
) / data
.getTotalCommits()))
488 fp
.write('%d %d\n' % (mm
, commits
))
490 f
.write('</table></div>')
491 f
.write('<img src="month_of_year.png" alt="Month of Year" />')
493 # Commits by year/month
494 f
.write(html_header(2, 'Commits by year/month'))
495 f
.write('<div class="vtable"><table><tr><th>Month</th><th>Commits</th></tr>')
496 for yymm
in reversed(sorted(data
.commits_by_month
.keys())):
497 f
.write('<tr><td>%s</td><td>%d</td></tr>' % (yymm
, data
.commits_by_month
[yymm
]))
498 f
.write('</table></div>')
499 f
.write('<img src="commits_by_year_month.png" alt="Commits by year/month" />')
500 fg
= open(path
+ '/commits_by_year_month.dat', 'w')
501 for yymm
in sorted(data
.commits_by_month
.keys()):
502 fg
.write('%s %s\n' % (yymm
, data
.commits_by_month
[yymm
]))
506 f
.write(html_header(2, 'Commits by Year'))
507 f
.write('<div class="vtable"><table><tr><th>Year</th><th>Commits (% of all)</th></tr>')
508 for yy
in reversed(sorted(data
.commits_by_year
.keys())):
509 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()))
510 f
.write('</table></div>')
511 f
.write('<img src="commits_by_year.png" alt="Commits by Year" />')
512 fg
= open(path
+ '/commits_by_year.dat', 'w')
513 for yy
in sorted(data
.commits_by_year
.keys()):
514 fg
.write('%d %d\n' % (yy
, data
.commits_by_year
[yy
]))
517 f
.write('</body></html>')
522 f
= open(path
+ '/authors.html', 'w')
525 f
.write('<h1>Authors</h1>')
528 # Authors :: List of authors
529 f
.write(html_header(2, 'List of Authors'))
531 f
.write('<table class="authors">')
532 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 for author
in sorted(data
.getAuthors()):
536 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))
540 # Authors :: Author of Month
541 f
.write(html_header(2, 'Author of Month'))
543 f
.write('<tr><th>Month</th><th>Author</th><th>Commits (%)</th><th>Next top 5</th></tr>')
544 for yymm
in reversed(sorted(data
.author_of_month
.keys())):
545 authordict
= data
.author_of_month
[yymm
]
546 authors
= getkeyssortedbyvalues(authordict
)
548 commits
= data
.author_of_month
[yymm
][authors
[0]]
549 next
= ', '.join(authors
[1:5])
550 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
))
554 f
.write(html_header(2, 'Author of Year'))
555 f
.write('<table><tr><th>Year</th><th>Author</th><th>Commits (%)</th><th>Next top 5</th></tr>')
556 for yy
in reversed(sorted(data
.author_of_year
.keys())):
557 authordict
= data
.author_of_year
[yy
]
558 authors
= getkeyssortedbyvalues(authordict
)
560 commits
= data
.author_of_year
[yy
][authors
[0]]
561 next
= ', '.join(authors
[1:5])
562 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
))
565 f
.write('</body></html>')
570 f
= open(path
+ '/files.html', 'w')
572 f
.write('<h1>Files</h1>')
576 f
.write('<dt>Total files</dt><dd>%d</dd>' % data
.getTotalFiles())
577 f
.write('<dt>Total lines</dt><dd>%d</dd>' % data
.getTotalLOC())
578 f
.write('<dt>Average file size</dt><dd>%.2f bytes</dd>' % ((100.0 * data
.getTotalLOC()) / data
.getTotalFiles()))
581 # Files :: File count by date
582 f
.write(html_header(2, 'File count by date'))
584 fg
= open(path
+ '/files_by_date.dat', 'w')
585 for stamp
in sorted(data
.files_by_stamp
.keys()):
586 fg
.write('%s %d\n' % (datetime
.datetime
.fromtimestamp(stamp
).strftime('%Y-%m-%d'), data
.files_by_stamp
[stamp
]))
589 f
.write('<img src="files_by_date.png" alt="Files by Date" />')
591 #f.write('<h2>Average file size by date</h2>')
593 # Files :: Extensions
594 f
.write(html_header(2, 'Extensions'))
595 f
.write('<table><tr><th>Extension</th><th>Files (%)</th><th>Lines (%)</th><th>Lines/file</th></tr>')
596 for ext
in sorted(data
.extensions
.keys()):
597 files
= data
.extensions
[ext
]['files']
598 lines
= data
.extensions
[ext
]['lines']
599 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
))
602 f
.write('</body></html>')
607 f
= open(path
+ '/lines.html', 'w')
609 f
.write('<h1>Lines</h1>')
613 f
.write('<dt>Total lines</dt><dd>%d</dd>' % data
.getTotalLOC())
616 f
.write(html_header(2, 'Lines of Code'))
617 f
.write('<img src="lines_of_code.png" />')
619 fg
= open(path
+ '/lines_of_code.dat', 'w')
620 for stamp
in sorted(data
.changes_by_date
.keys()):
621 fg
.write('%d %d\n' % (stamp
, data
.changes_by_date
[stamp
]['lines']))
624 f
.write('</body></html>')
629 f
= open(path
+ '/tags.html', 'w')
631 f
.write('<h1>Tags</h1>')
635 f
.write('<dt>Total tags</dt><dd>%d</dd>' % len(data
.tags
))
636 if len(data
.tags
) > 0:
637 f
.write('<dt>Average commits per tag</dt><dd>%.2f</dd>' % (data
.getTotalCommits() / len(data
.tags
)))
641 f
.write('<tr><th>Name</th><th>Date</th></tr>')
642 # sort the tags by date desc
643 tags_sorted_by_date_desc
= map(lambda el
: el
[1], reversed(sorted(map(lambda el
: (el
[1]['date'], el
[0]), data
.tags
.items()))))
644 for tag
in tags_sorted_by_date_desc
:
645 f
.write('<tr><td>%s</td><td>%s</td></tr>' % (tag
, data
.tags
[tag
]['date']))
648 f
.write('</body></html>')
651 self
.createGraphs(path
)
654 def createGraphs(self
, path
):
655 print 'Generating graphs...'
658 f
= open(path
+ '/hour_of_day.plot', 'w')
659 f
.write(GNUPLOT_COMMON
)
662 set output 'hour_of_day.png'
664 set xrange [0.5:24.5]
667 plot 'hour_of_day.dat' using 1:2:(0.5) w boxes fs solid
672 f
= open(path
+ '/day_of_week.plot', 'w')
673 f
.write(GNUPLOT_COMMON
)
676 set output 'day_of_week.png'
681 plot 'day_of_week.dat' using 1:2:(0.5) w boxes fs solid
686 f
= open(path
+ '/month_of_year.plot', 'w')
687 f
.write(GNUPLOT_COMMON
)
690 set output 'month_of_year.png'
692 set xrange [0.5:12.5]
695 plot 'month_of_year.dat' using 1:2:(0.5) w boxes fs solid
699 # commits_by_year_month
700 f
= open(path
+ '/commits_by_year_month.plot', 'w')
701 f
.write(GNUPLOT_COMMON
)
704 set output 'commits_by_year_month.png'
709 set xtics rotate by 90 15768000
712 plot 'commits_by_year_month.dat' using 1:2:(0.5) w boxes fs solid
717 f
= open(path
+ '/commits_by_year.plot', 'w')
718 f
.write(GNUPLOT_COMMON
)
721 set output 'commits_by_year.png'
725 plot 'commits_by_year.dat' using 1:2:(0.5) w boxes fs solid
730 f
= open(path
+ '/files_by_date.plot', 'w')
731 f
.write(GNUPLOT_COMMON
)
734 set output 'files_by_date.png'
737 set timefmt "%Y-%m-%d"
738 set format x "%Y-%m-%d"
740 set xtics rotate by 90
742 plot 'files_by_date.dat' using 1:2 smooth csplines
747 f
= open(path
+ '/lines_of_code.plot', 'w')
748 f
.write(GNUPLOT_COMMON
)
751 set output 'lines_of_code.png'
755 set format x "%Y-%m-%d"
757 set xtics rotate by 90
759 plot 'lines_of_code.dat' using 1:2 w lines
764 files
= glob
.glob(path
+ '/*.plot')
766 out
= getoutput('gnuplot %s' % f
)
770 def printHeader(self
, f
, title
= ''):
772 """<?xml version="1.0" encoding="UTF-8"?>
773 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
774 <html xmlns="http://www.w3.org/1999/xhtml">
776 <title>GitStats - %s</title>
777 <link rel="stylesheet" href="gitstats.css" type="text/css" />
778 <meta name="generator" content="GitStats" />
783 def printNav(self
, f
):
787 <li><a href="index.html">General</a></li>
788 <li><a href="activity.html">Activity</a></li>
789 <li><a href="authors.html">Authors</a></li>
790 <li><a href="files.html">Files</a></li>
791 <li><a href="lines.html">Lines</a></li>
792 <li><a href="tags.html">Tags</a></li>
799 Usage: gitstats [options] <gitpath> <outputpath>
804 if len(sys
.argv
) < 3:
808 gitpath
= sys
.argv
[1]
809 outputpath
= os
.path
.abspath(sys
.argv
[2])
813 os
.makedirs(outputpath
)
816 if not os
.path
.isdir(outputpath
):
817 print 'FATAL: Output path is not a directory or does not exist'
820 print 'Git path: %s' % gitpath
821 print 'Output path: %s' % outputpath
825 print 'Collecting data...'
826 data
= GitDataCollector()
827 data
.collect(gitpath
)
831 print 'Generating report...'
832 report
= HTMLReportCreator()
833 report
.create(data
, outputpath
)
835 time_end
= time
.time()
836 exectime_internal
= time_end
- time_start
837 print 'Execution time %.5f secs, %.5f secs (%.2f %%) in external commands)' % (exectime_internal
, exectime_external
, (100.0 * exectime_external
) / exectime_internal
)