From a554942c01191d4f85ca93138bd66794d6ef5e1a Mon Sep 17 00:00:00 2001 From: Matthieu Moy Date: Sun, 9 Jan 2011 20:25:12 +0100 Subject: [PATCH] Per-author commit count graph Signed-off-by: Heikki Hokkanen --- gitstats | 66 ++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 55 insertions(+), 11 deletions(-) diff --git a/gitstats b/gitstats index f4bc25f..7eeb225 100755 --- a/gitstats +++ b/gitstats @@ -322,7 +322,6 @@ class GitDataCollector(DataCollector): if 'last_commit_stamp' not in self.authors[author]: self.authors[author]['last_commit_stamp'] = stamp self.authors[author]['first_commit_stamp'] = stamp - self.authors[author]['commits'] = self.authors[author].get('commits', 0) + 1 # author of the month/year yymm = date.strftime('%Y-%m') @@ -472,12 +471,16 @@ class GitDataCollector(DataCollector): try: (stamp, author) = (int(line[:pos]), line[pos+1:]) if author not in self.authors: - self.authors[author] = { 'lines_added' : 0, 'lines_removed' : 0 } + self.authors[author] = { 'lines_added' : 0, 'lines_removed' : 0, 'commits' : 0} + self.authors[author]['commits'] = self.authors[author].get('commits', 0) + 1 self.authors[author]['lines_added'] = self.authors[author].get('lines_added', 0) + inserted self.authors[author]['lines_removed'] = self.authors[author].get('lines_removed', 0) + deleted if stamp not in self.changes_by_date_by_author: self.changes_by_date_by_author[stamp] = {} - self.changes_by_date_by_author[stamp][author] = self.authors[author]['lines_added'] + if author not in self.changes_by_date_by_author[stamp]: + self.changes_by_date_by_author[stamp][author] = {} + self.changes_by_date_by_author[stamp][author]['lines_added'] = self.authors[author]['lines_added'] + self.changes_by_date_by_author[stamp][author]['commits'] = self.authors[author]['commits'] files, inserted, deleted = 0, 0, 0 except ValueError: print 'Warning: unexpected line "%s"' % line @@ -851,10 +854,16 @@ class HTMLReportCreator(ReportCreator): f.write(html_header(2, 'Cumulated Added Lines of Code per Author')) f.write('Lines of code per Author') if len(allauthors) > conf['max_authors']: - rest = allauthors[conf['max_authors']:] - f.write('

These didn\'t make it to the graph: %s

' % ', '.join(rest)) + f.write('

Only top %d authors shown

' % conf['max_authors']) + + f.write(html_header(2, 'Commits per Author')) + f.write('Commits per Author') + if len(allauthors) > conf['max_authors']: + f.write('

Only top %d authors shown

' % conf['max_authors']) + + fgl = open(path + '/lines_of_code_by_author.dat', 'w') + fgc = open(path + '/commits_by_author.dat', 'w') - fg = open(path + '/lines_of_code_by_author.dat', 'w') lines_by_authors = {} # cumulated added lines by # author. to save memory, # changes_by_date_by_author[stamp][author] is defined @@ -864,17 +873,25 @@ class HTMLReportCreator(ReportCreator): # Don't rely on getAuthors to give the same order each # time. Be robust and keep the list in a variable. + commits_by_authors = {} # cumulated added lines by + self.authors_to_plot = data.getAuthors(conf['max_authors']) for author in self.authors_to_plot: lines_by_authors[author] = 0 + commits_by_authors[author] = 0 for stamp in sorted(data.changes_by_date_by_author.keys()): - fg.write('%d' % stamp) + fgl.write('%d' % stamp) + fgc.write('%d' % stamp) for author in self.authors_to_plot: if author in data.changes_by_date_by_author[stamp].keys(): - lines_by_authors[author] = data.changes_by_date_by_author[stamp][author] - fg.write(' %d' % lines_by_authors[author]) - fg.write('\n'); - fg.close() + lines_by_authors[author] = data.changes_by_date_by_author[stamp][author]['lines_added'] + commits_by_authors[author] = data.changes_by_date_by_author[stamp][author]['commits'] + fgl.write(' %d' % lines_by_authors[author]) + fgc.write(' %d' % commits_by_authors[author]) + fgl.write('\n'); + fgc.write('\n'); + fgl.close() + fgc.close() # Authors :: Author of Month f.write(html_header(2, 'Author of Month')) @@ -1180,6 +1197,33 @@ plot """ f.close() + # Commits per author + f = open(path + '/commits_by_author.plot', 'w') + f.write(GNUPLOT_COMMON) + f.write( +""" +set terminal png transparent size 640,480 +set output 'commits_by_author.png' +set key left top +set xdata time +set timefmt "%s" +set format x "%Y-%m-%d" +set grid y +set ylabel "Commits" +set xtics rotate +set bmargin 6 +plot """ +) + i = 1 + plots = [] + for a in self.authors_to_plot: + i = i + 1 + plots.append("""'commits_by_author.dat' using 1:%d title "%s" w lines""" % (i, a.replace("\"", "\\\""))) + f.write(", ".join(plots)) + f.write('\n') + + f.close() + os.chdir(path) files = glob.glob(path + '/*.plot') for f in files: