Made the CSV file aggregating data by weeks or months

When using -w option together with the -x file option, the data exported
in the CSV file are aggregated by weeks instead of months (the default).
This is useful to extract meaningful stats on short periods.
This commit is contained in:
Cédric Bosdonnat 2011-04-19 10:50:19 +02:00 committed by Jonathan Corbet
parent c1f096042b
commit 92726d0df5
3 changed files with 15 additions and 4 deletions

5
README
View File

@ -55,6 +55,11 @@ be:
-u Group all unknown developers under the "(Unknown)"
employer.
-x file Export raw statistics as CSV.
-w Aggregate the data by weeks instead of months in the
CSV file when -x is used.
-z Dump out the hacker database to "database.dump".
A typical command line used to generate the "who write 2.6.x" LWN articles

4
csv.py
View File

@ -15,8 +15,10 @@ class CSVStat:
PeriodCommitHash = { }
def AccumulatePatch (p):
def AccumulatePatch (p, Aggregate):
date = "%.2d-%.2d-01"%(p.date.year, p.date.month)
if (Aggregate == 'week'):
date = "%.2d-%.2d"%(p.date.isocalendar()[0], p.date.isocalendar()[1])
authdatekey = "%s-%s"%(p.author.name, date)
if authdatekey not in PeriodCommitHash:
empl = p.author.emailemployer (p.email, p.date)

10
gitdm
View File

@ -36,6 +36,7 @@ AkpmOverLt = 0
DumpDB = 0
CFName = 'gitdm.config'
DirName = ''
Aggregate = 'month'
#
# Options:
@ -52,14 +53,15 @@ DirName = ''
# -s Ignore author SOB lines
# -u Map unknown employers to '(Unknown)'
# -x file.csv Export raw statistics as CSV
# -w Aggregrate the raw statistics by weeks instead of months
# -z Dump out the hacker database at completion
def ParseOpts ():
global MapUnknown, DevReports
global DateStats, AuthorSOBs, FileFilter, AkpmOverLt, DumpDB
global CFName, CSVFile, DirName
global CFName, CSVFile, DirName, Aggregate
opts, rest = getopt.getopt (sys.argv[1:], 'ab:dc:Dh:l:o:r:sux:z')
opts, rest = getopt.getopt (sys.argv[1:], 'a:b:dc:Dh:l:o:r:suwx:z')
for opt in opts:
if opt[0] == '-a':
AkpmOverLt = 1
@ -87,6 +89,8 @@ def ParseOpts ():
elif opt[0] == '-x':
CSVFile = open (opt[1], 'w')
print "open output file " + opt[1] + "\n"
elif opt [0] == '-w':
Aggregate = 'week'
elif opt[0] == '-z':
DumpDB = 1
@ -370,7 +374,7 @@ while (1):
for hacker in p.reports:
hacker.addreport (p)
CSCount += 1
csv.AccumulatePatch (p)
csv.AccumulatePatch (p, Aggregate)
print >> sys.stderr, 'Grabbing changesets...done '
if DumpDB: