2 # aggregate per-month statistics for people
8 def __init__ (self
, name
, email
, employer
, date
):
11 self
.employer
= employer
12 self
.added
= self
.removed
= self
.changesets
= 0
14 def accumulate (self
, p
):
15 self
.added
= self
.added
+ p
.added
16 self
.removed
= self
.removed
+ p
.removed
19 PeriodCommitHash
= { }
21 def AccumulatePatch (p
, Aggregate
):
22 if (Aggregate
== 'week'):
23 date
= "%.2d-%.2d"%(p
.date
.isocalendar()[0], p
.date
.isocalendar()[1])
24 elif (Aggregate
== 'year'):
25 date
= "%.2d"%(p
.date
.year
)
27 date
= "%.2d-%.2d-01"%(p
.date
.year
, p
.date
.month
)
28 authdatekey
= "%s-%s"%(p
.author
.name
, date
)
29 if authdatekey
not in PeriodCommitHash
:
30 empl
= p
.author
.emailemployer (p
.email
, p
.date
)
31 stat
= CSVStat (p
.author
.name
, p
.email
, empl
, date
)
32 PeriodCommitHash
[authdatekey
] = stat
34 stat
= PeriodCommitHash
[authdatekey
]
40 def store_patch(patch
):
42 employer
= patch
.author
.emailemployer(patch
.email
, patch
.date
)
43 employer
= employer
.name
.replace('"', '.').replace ('\\', '.')
44 author
= patch
.author
.name
.replace ('"', '.').replace ('\\', '.')
45 author
= patch
.author
.name
.replace ("'", '.')
47 domain
= patch
.email
.split('@')[1]
50 ChangeSets
.append([patch
.commit
, str(patch
.date
),
51 patch
.email
, domain
, author
, employer
,
52 patch
.added
, patch
.removed
])
53 for (filetype
, (added
, removed
)) in patch
.filetypes
.items():
54 FileTypes
.append([patch
.commit
, filetype
, added
, removed
])
57 def save_csv (prefix
='data'):
59 if len(ChangeSets
) > 0:
60 fd
= open('%s-changesets.csv' % prefix
, 'w')
61 writer
= csv
.writer (fd
, quoting
=csv
.QUOTE_NONNUMERIC
)
62 writer
.writerow (['Commit', 'Date', 'Domain',
63 'Email', 'Name', 'Affliation',
65 for commit
in ChangeSets
:
66 writer
.writerow(commit
)
69 if len(FileTypes
) > 0:
70 fd
= open('%s-filetypes.csv' % prefix
, 'w')
71 writer
= csv
.writer (fd
, quoting
=csv
.QUOTE_NONNUMERIC
)
73 writer
.writerow (['Commit', 'Type', 'Added', 'Removed'])
74 for commit
in FileTypes
:
75 writer
.writerow(commit
)
82 writer
= csv
.writer (file, quoting
=csv
.QUOTE_NONNUMERIC
)
83 writer
.writerow (['Name', 'Email', 'Affliation', 'Date',
84 'Added', 'Removed', 'Changesets'])
85 for date
, stat
in PeriodCommitHash
.items():
86 # sanitise names " is common and \" sometimes too
87 empl_name
= stat
.employer
.name
.replace ('"', '.').replace ('\\', '.')
88 author_name
= stat
.name
.replace ('"', '.').replace ('\\', '.')
89 writer
.writerow ([author_name
, stat
.email
, empl_name
, stat
.date
,
90 stat
.added
, stat
.removed
, stat
.changesets
])
92 def OutputHackersCSV (file, hlist
):
95 file.write ("Name,Last affiliation,Activity Start,Activity End,Commits,Changed Lines,Lines Removed,Signoffs,Reviews,Test Credits,Test Credits Given,Report Credits,Report Credits Given\n")
97 if len(hacker
.patches
) > 0:
98 file.write ("\"%s\",%s,%s,%s,%d,%d,%d,%d,%d,%d,%d,%d,%d\n" %
100 hacker
.emailemployer (None, hacker
.activity_end
).name
,
101 hacker
.activity_start
, hacker
.activity_end
,
103 hacker
.changed
, hacker
.removed
,
104 len(hacker
.signoffs
),
111 __all__
= [ 'AccumulatePatch', 'OutputCSV', 'OutputHackersCSV', 'store_patch' ]