From 8293f6e37e643fbc0bbb9e98bad6053702e8d741 Mon Sep 17 00:00:00 2001 From: Heikki Hokkanen Date: Tue, 31 Jul 2007 16:47:39 +0300 Subject: [PATCH] Some initial statistics. --- TODO.txt | 29 +++++++++++++++++++++-- statgit | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 105 insertions(+), 7 deletions(-) diff --git a/TODO.txt b/TODO.txt index 2ae2e87..ea89ff1 100644 --- a/TODO.txt +++ b/TODO.txt @@ -5,7 +5,10 @@ - perl or python? - make git data collection part separate so that portage to other DVCS's is easier + - DataCollector + - make output thingies modular as well (HTML first, plain text later etc) + - ReportCreator [Information] - git-log @@ -28,11 +31,25 @@ - Authors - Authors - - Total number of authors - - List of names + - List of authors - (T): author, commits (%), LOC?, first commit, last commit - (T): Developer of the Month: month, author, commits, LOC? +- Tags + - (T): Name, Date, LOC?, Developers + +- Author page for each author + - Name, mail + - Total commits (%) + - LOC (%) + - Last commit: date + - First commit: date + - Activity by Clock Time + - (G) Hour of Day + - (G) Day of Week + - (T) Activity in Directories: Directory, Changes, LOC, LOC/change + - (Most Recent Commits?) + [Stats in StatSVN] - General - Report Period (first/last date of commits) @@ -74,3 +91,11 @@ [Graphics] - Use gnuplot, graphviz etc ? +[Usage] +- $ statgit [-o html] /path/to/git /output/dir + +[name] +- statgit or gitstats (no google hits for either) + +[Misc] +- use sortable.js ? diff --git a/statgit b/statgit index 6ea74c9..d6be9a1 100755 --- a/statgit +++ b/statgit @@ -1,6 +1,8 @@ #!/usr/bin/python # Copyright (c) 2007 Heikki Hokkanen # GPLv2 +import commands +import datetime import os import re import sys @@ -11,8 +13,50 @@ class DataCollector: def collect(self, dir): self.dir = dir + + ## + # TODO: get a dictionary of author + def getAuthorInfo(self, author): + return None + + ## + # Get a list of authors + def getAuthors(self): + return [] + + def getTotalAuthors(self): + return -1 + + def getTotalCommits(self): + return -1 + + def getTotalFiles(self): + return -1 + + def getTotalLOC(self): + return -1 class GitDataCollector(DataCollector): + def collect(self, dir): + DataCollector.collect(self, dir) + + def getAuthorInfo(self, author): + res = { 'commits' : -1, 'commits_frac' : 1.5, 'date_first' : '0000-00-00', 'date_last' : '0000-00-00' } + return res + + def getAuthors(self): + lines = commands.getoutput('git-rev-list --all --pretty=format:%an |grep -v ^commit |sort |uniq') + return lines.split('\n') + + def getTotalAuthors(self): + return int(commands.getoutput('git-log |git-shortlog -s |wc -l')) + + def getTotalCommits(self): + return int(commands.getoutput('git-rev-list --all |wc -l')) + + def getTotalFiles(self): + files = commands.getoutput('git-ls-files |wc -l') + return int(files) pass class ReportCreator: @@ -23,13 +67,40 @@ class ReportCreator: self.data = data self.path = path -class ConsoleReportCreator(ReportCreator): +class HTMLReportCreator(ReportCreator): def create(self, data, path): - ReportCreator.create(data, path) + ReportCreator.create(self, data, path) - pass + f = open(path + "/index.html", 'w') + f.write(""" + + StatGit + + +""") -class HTMLReportCreator(ReportCreator): + f.write('

StatGit

') + + f.write('
'); + f.write('
Generated
%s
' % datetime.datetime.now().strftime('%Y-%m-%d %H:%m:%S')); + f.write('
Report Period
%s to %s
' % ('0000-00-00', '0000-00-00')) + f.write('
Total Files
%s
' % data.getTotalFiles()) + f.write('
Total Lines of Code
%s
' % data.getTotalLOC()) + f.write('
Total Commits
%s
' % data.getTotalCommits()) + f.write('
Authors
%s
' % data.getTotalAuthors()) + f.write('
'); + + f.write('

Authors

') + + f.write('') + f.write('') + for author in data.getAuthors(): + info = data.getAuthorInfo(author) + f.write('' % (author, info['commits'], info['commits_frac'], info['date_first'], info['date_last'])) + f.write('
AuthorCommits (%)First commitLast commit
%s%d (%.2f)%s%s
') + + f.write('\n'); + f.close() pass usage = """ @@ -49,10 +120,12 @@ outputpath = sys.argv[2] print 'Git path: %s' % gitpath print 'Output path: %s' % outputpath +os.chdir(gitpath) + data = GitDataCollector() data.collect(gitpath) -report = ConsoleReportCreator() +report = HTMLReportCreator() report.create(data, outputpath) -- 2.11.4.GIT