A quick and dirty treeplot utility
[git-dm.git] / csv.py
blob34ea10aba6b91f0b0f751707feaccc350b848b6f
2 # aggregate per-month statistics for people
4 import sys, datetime
6 class CSVStat:
7 def __init__ (self, name, employer, date):
8 self.name = name
9 self.employer = employer
10 self.added = self.removed = 0
11 self.date = date
12 def accumulate (self, p):
13 self.added = self.added + p.added
14 self.removed = self.removed + p.removed
16 PeriodCommitHash = { }
18 def AccumulatePatch (p):
19 date = "%.2d-%.2d-01"%(p.date.year, p.date.month)
20 authdatekey = "%s-%s"%(p.author.name, date)
21 if authdatekey not in PeriodCommitHash:
22 empl = p.author.emailemployer (p.email, p.date)
23 stat = CSVStat (p.author.name, empl, date)
24 PeriodCommitHash[authdatekey] = stat
25 else:
26 stat = PeriodCommitHash[authdatekey]
27 stat.accumulate (p)
29 def OutputCSV (file):
30 if file is None:
31 return
32 file.write ("Name\tAffliation\tDate\tAdded\tRemoved\n")
33 for date, stat in PeriodCommitHash.items():
34 # sanitise names " is common and \" sometimes too
35 empl_name = stat.employer.name.replace ("\"", ".").replace ("\\", ".")
36 author_name = stat.name.replace ("\"", ".").replace ("\\", ".")
37 file.write ("\"%s\"\t\"%s\"\t%s\t%d\t%d\n"%(author_name, empl_name, stat.date, \
38 stat.added, stat.removed))