A quick and dirty treeplot utility
[git-dm.git] / reports.py
blob08805b8256cee1393bc314e4e84bee4781e01312
2 # A new home for the reporting code.
5 import sys
7 Outfile = sys.stdout
8 HTMLfile = None
9 ListCount = 999999
12 def SetOutput (file):
13 global Outfile
14 Outfile = file
16 def SetHTMLOutput (file):
17 global HTMLfile
18 HTMLfile = file
20 def SetMaxList (max):
21 global ListCount
22 ListCount = max
25 def Write (stuff):
26 Outfile.write (stuff)
31 # HTML output support stuff.
33 HTMLclass = 0
34 HClasses = ['Even', 'Odd']
36 THead = '''<p>
37 <table cellspacing=3>
38 <tr><th colspan=3>%s</th></tr>
39 '''
41 def BeginReport (title):
42 global HTMLclass
44 Outfile.write ('\n%s\n' % title)
45 if HTMLfile:
46 HTMLfile.write (THead % title)
47 HTMLclass = 0
49 TRow = ''' <tr class="%s">
50 <td>%s</td><td align="right">%d</td><td align="right">%.1f%%</td></tr>
51 '''
53 def ReportLine (text, count, pct):
54 global HTMLclass
55 if count == 0:
56 return
57 Outfile.write ('%-25s %4d (%.1f%%)\n' % (text, count, pct))
58 if HTMLfile:
59 HTMLfile.write (TRow % (HClasses[HTMLclass], text, count, pct))
60 HTMLclass ^= 1
62 def EndReport ():
63 if HTMLfile:
64 HTMLfile.write ('</table>\n\n')
67 # Comparison and report generation functions.
69 def ComparePCount (h1, h2):
70 return len (h2.patches) - len (h1.patches)
72 def ReportByPCount (hlist, cscount):
73 hlist.sort (ComparePCount)
74 count = 0
75 BeginReport ('Developers with the most changesets')
76 for h in hlist:
77 pcount = len (h.patches)
78 changed = max(h.added, h.removed)
79 delta = h.added - h.removed
80 if pcount > 0:
81 ReportLine (h.name, pcount, (pcount*100.0)/cscount)
82 count += 1
83 if count >= ListCount:
84 break
85 EndReport ()
87 def CompareLChanged (h1, h2):
88 return max(h2.added, h2.removed) - max(h1.added, h1.removed)
90 def ReportByLChanged (hlist, totalchanged):
91 hlist.sort (CompareLChanged)
92 count = 0
93 BeginReport ('Developers with the most changed lines')
94 for h in hlist:
95 pcount = len (h.patches)
96 changed = max(h.added, h.removed)
97 delta = h.added - h.removed
98 if (h.added + h.removed) > 0:
99 ReportLine (h.name, changed, (changed*100.0)/totalchanged)
100 count += 1
101 if count >= ListCount:
102 break
103 EndReport ()
105 def CompareLRemoved (h1, h2):
106 return (h2.removed - h2.added) - (h1.removed - h1.added)
108 def ReportByLRemoved (hlist, totalremoved):
109 hlist.sort (CompareLRemoved)
110 count = 0
111 BeginReport ('Developers with the most lines removed')
112 for h in hlist:
113 pcount = len (h.patches)
114 changed = max(h.added, h.removed)
115 delta = h.added - h.removed
116 if delta < 0:
117 ReportLine (h.name, -delta, (-delta*100.0)/totalremoved)
118 count += 1
119 if count >= ListCount:
120 break
121 EndReport ()
123 def CompareEPCount (e1, e2):
124 return e2.count - e1.count
126 def ReportByPCEmpl (elist, cscount):
127 elist.sort (CompareEPCount)
128 count = 0
129 BeginReport ('Top changeset contributors by employer')
130 for e in elist:
131 if e.count != 0:
132 ReportLine (e.name, e.count, (e.count*100.0)/cscount)
133 count += 1
134 if count >= ListCount:
135 break
136 EndReport ()
140 def CompareELChanged (e1, e2):
141 return e2.changed - e1.changed
143 def ReportByELChanged (elist, totalchanged):
144 elist.sort (CompareELChanged)
145 count = 0
146 BeginReport ('Top lines changed by employer')
147 for e in elist:
148 if e.changed != 0:
149 ReportLine (e.name, e.changed, (e.changed*100.0)/totalchanged)
150 count += 1
151 if count >= ListCount:
152 break
153 EndReport ()
157 def CompareSOBs (h1, h2):
158 return len (h2.signoffs) - len (h1.signoffs)
160 def ReportBySOBs (hlist):
161 hlist.sort (CompareSOBs)
162 totalsobs = 0
163 for h in hlist:
164 totalsobs += len (h.signoffs)
165 count = 0
166 BeginReport ('Developers with the most signoffs (total %d)' % totalsobs)
167 for h in hlist:
168 scount = len (h.signoffs)
169 if scount > 0:
170 ReportLine (h.name, scount, (scount*100.0)/totalsobs)
171 count += 1
172 if count >= ListCount:
173 break
174 EndReport ()
177 # Reviewer reporting.
179 def CompareRevs (h1, h2):
180 return len (h2.reviews) - len (h1.reviews)
182 def ReportByRevs (hlist):
183 hlist.sort (CompareRevs)
184 totalrevs = 0
185 for h in hlist:
186 totalrevs += len (h.reviews)
187 count = 0
188 BeginReport ('Developers with the most reviews (total %d)' % totalrevs)
189 for h in hlist:
190 scount = len (h.reviews)
191 if scount > 0:
192 ReportLine (h.name, scount, (scount*100.0)/totalrevs)
193 count += 1
194 if count >= ListCount:
195 break
196 EndReport ()
199 # tester reporting.
201 def CompareTests (h1, h2):
202 return len (h2.tested) - len (h1.tested)
204 def ReportByTests (hlist):
205 hlist.sort (CompareTests)
206 totaltests = 0
207 for h in hlist:
208 totaltests += len (h.tested)
209 count = 0
210 BeginReport ('Developers with the most test credits (total %d)' % totaltests)
211 for h in hlist:
212 scount = len (h.tested)
213 if scount > 0:
214 ReportLine (h.name, scount, (scount*100.0)/totaltests)
215 count += 1
216 if count >= ListCount:
217 break
218 EndReport ()
220 def CompareTestCred (h1, h2):
221 return h2.testcred - h1.testcred
223 def ReportByTestCreds (hlist):
224 hlist.sort (CompareTestCred)
225 totaltests = 0
226 for h in hlist:
227 totaltests += h.testcred
228 count = 0
229 BeginReport ('Developers who gave the most tested-by credits (total %d)' % totaltests)
230 for h in hlist:
231 if h.testcred > 0:
232 ReportLine (h.name, h.testcred, (h.testcred*100.0)/totaltests)
233 count += 1
234 if count >= ListCount:
235 break
236 EndReport ()
241 # Reporter reporting.
243 def CompareReports (h1, h2):
244 return len (h2.reports) - len (h1.reports)
246 def ReportByReports (hlist):
247 hlist.sort (CompareReports)
248 totalreps = 0
249 for h in hlist:
250 totalreps += len (h.reports)
251 count = 0
252 BeginReport ('Developers with the most report credits (total %d)' % totalreps)
253 for h in hlist:
254 scount = len (h.reports)
255 if scount > 0:
256 ReportLine (h.name, scount, (scount*100.0)/totalreps)
257 count += 1
258 if count >= ListCount:
259 break
260 EndReport ()
262 def CompareRepCred (h1, h2):
263 return h2.repcred - h1.repcred
265 def ReportByRepCreds (hlist):
266 hlist.sort (CompareRepCred)
267 totalreps = 0
268 for h in hlist:
269 totalreps += h.repcred
270 count = 0
271 BeginReport ('Developers who gave the most report credits (total %d)' % totalreps)
272 for h in hlist:
273 if h.repcred > 0:
274 ReportLine (h.name, h.repcred, (h.repcred*100.0)/totalreps)
275 count += 1
276 if count >= ListCount:
277 break
278 EndReport ()
282 def CompareESOBs (e1, e2):
283 return e2.sobs - e1.sobs
285 def ReportByESOBs (elist):
286 elist.sort (CompareESOBs)
287 totalsobs = 0
288 for e in elist:
289 totalsobs += e.sobs
290 count = 0
291 BeginReport ('Employers with the most signoffs (total %d)' % totalsobs)
292 for e in elist:
293 if e.sobs > 0:
294 ReportLine (e.name, e.sobs, (e.sobs*100.0)/totalsobs)
295 count += 1
296 if count >= ListCount:
297 break
298 EndReport ()
301 def DevReports (hlist, totalchanged, cscount, totalremoved):
302 ReportByPCount (hlist, cscount)
303 ReportByLChanged (hlist, totalchanged)
304 ReportByLRemoved (hlist, totalremoved)
305 ReportBySOBs (hlist)
306 ReportByRevs (hlist)
307 ReportByTests (hlist)
308 ReportByTestCreds (hlist)
309 ReportByReports (hlist)
310 ReportByRepCreds (hlist)
312 def EmplReports (elist, totalchanged, cscount):
313 ReportByPCEmpl (elist, cscount)
314 ReportByELChanged (elist, totalchanged)
315 ReportByESOBs (elist)