Skip to content

Commit

Permalink
* reports.py: avoid division by zero
Browse files Browse the repository at this point in the history
  • Loading branch information
David Lutterkort authored and markmc committed May 9, 2012
1 parent c2cf1e2 commit d90c69e
Showing 1 changed file with 37 additions and 32 deletions.
69 changes: 37 additions & 32 deletions reports.py
Expand Up @@ -34,6 +34,11 @@ def Write (stuff):
Outfile.write (stuff) Outfile.write (stuff)




def Pct(a, b):
if b == 0:
return 0.0
else:
return (a*100.0)/b


# #
# HTML output support stuff. # HTML output support stuff.
Expand Down Expand Up @@ -88,12 +93,12 @@ def ReportByPCount (hlist, cscount):
changed = max(h.added, h.removed) changed = max(h.added, h.removed)
delta = h.added - h.removed delta = h.added - h.removed
if pcount > 0: if pcount > 0:
ReportLine (h.name, pcount, (pcount*100.0)/cscount) ReportLine (h.name, pcount, Pct(pcount, cscount))
reported += pcount reported += pcount
count += 1 count += 1
if count >= ListCount: if count >= ListCount:
break break
EndReport ('Covers %f%% of changesets' % ((reported*100.0)/cscount, )) EndReport ('Covers %f%% of changesets' % (Pct(reported, cscount), ))


def CompareBCount (h1, h2): def CompareBCount (h1, h2):
return len (h2.bugsfixed) - len (h1.bugsfixed) return len (h2.bugsfixed) - len (h1.bugsfixed)
Expand All @@ -105,12 +110,12 @@ def ReportByBCount (hlist, totalbugs):
for h in hlist: for h in hlist:
bcount = len (h.bugsfixed) bcount = len (h.bugsfixed)
if bcount > 0: if bcount > 0:
ReportLine (h.name, bcount, (bcount*100.0)/totalbugs) ReportLine (h.name, bcount, Pct(bcount, totalbugs))
reported += bcount reported += bcount
count += 1 count += 1
if count >= ListCount: if count >= ListCount:
break break
EndReport ('Covers %f%% of bugs' % ((reported*100.0)/totalbugs, )) EndReport ('Covers %f%% of bugs' % Pct(reported, totalbugs))


def CompareLChanged (h1, h2): def CompareLChanged (h1, h2):
return max(h2.added, h2.removed) - max(h1.added, h1.removed) return max(h2.added, h2.removed) - max(h1.added, h1.removed)
Expand All @@ -124,12 +129,12 @@ def ReportByLChanged (hlist, totalchanged):
changed = max(h.added, h.removed) changed = max(h.added, h.removed)
delta = h.added - h.removed delta = h.added - h.removed
if (h.added + h.removed) > 0: if (h.added + h.removed) > 0:
ReportLine (h.name, changed, (changed*100.0)/totalchanged) ReportLine (h.name, changed, Pct(changed, totalchanged))
reported += changed reported += changed
count += 1 count += 1
if count >= ListCount: if count >= ListCount:
break break
EndReport ('Covers %f%% of changes' % ((reported*100.0)/totalchanged, )) EndReport ('Covers %f%% of changes' % (Pct(reported, totalchanged), ))


def CompareLRemoved (h1, h2): def CompareLRemoved (h1, h2):
return (h2.removed - h2.added) - (h1.removed - h1.added) return (h2.removed - h2.added) - (h1.removed - h1.added)
Expand All @@ -143,12 +148,12 @@ def ReportByLRemoved (hlist, totalremoved):
changed = max(h.added, h.removed) changed = max(h.added, h.removed)
delta = h.added - h.removed delta = h.added - h.removed
if delta < 0: if delta < 0:
ReportLine (h.name, -delta, (-delta*100.0)/totalremoved) ReportLine (h.name, -delta, Pct(-delta, totalremoved))
reported += -delta reported += -delta
count += 1 count += 1
if count >= ListCount: if count >= ListCount:
break break
EndReport ('Covers %f%% of changes' % ((reported*100.0)/totalremoved, )) EndReport ('Covers %f%% of changes' % (Pct(reported, totalremoved), ))


def CompareEPCount (e1, e2): def CompareEPCount (e1, e2):
return e2.count - e1.count return e2.count - e1.count
Expand All @@ -159,12 +164,12 @@ def ReportByPCEmpl (elist, cscount):
BeginReport ('Top changeset contributors by employer') BeginReport ('Top changeset contributors by employer')
for e in elist: for e in elist:
if e.count != 0: if e.count != 0:
ReportLine (e.name, e.count, (e.count*100.0)/cscount) ReportLine (e.name, e.count, Pct(e.count, cscount))
total_pcount += e.count total_pcount += e.count
count += 1 count += 1
if count >= ListCount: if count >= ListCount:
break break
EndReport ('Covers %f%% of changesets' % ((total_pcount*100.0)/cscount, )) EndReport ('Covers %f%% of changesets' % (Pct(total_pcount, cscount), ))


def CompareEBCount (e1, e2): def CompareEBCount (e1, e2):
return len (e2.bugsfixed) - len (e1.bugsfixed) return len (e2.bugsfixed) - len (e1.bugsfixed)
Expand All @@ -175,12 +180,12 @@ def ReportByBCEmpl (elist, totalbugs):
BeginReport ('Top bugs fixed by employer') BeginReport ('Top bugs fixed by employer')
for e in elist: for e in elist:
if len(e.bugsfixed) != 0: if len(e.bugsfixed) != 0:
ReportLine (e.name, len(e.bugsfixed), (len(e.bugsfixed)*100.0)/totalbugs) ReportLine (e.name, len(e.bugsfixed), Pct(len(e.bugsfixed), totalbugs))
reported += len(e.bugsfixed) reported += len(e.bugsfixed)
count += 1 count += 1
if count >= ListCount: if count >= ListCount:
break break
EndReport ('Covers %f%% of bugs' % ((reported*100.0)/totalbugs, )) EndReport ('Covers %f%% of bugs' % (Pct(reported, totalbugs, )))


def CompareELChanged (e1, e2): def CompareELChanged (e1, e2):
return e2.changed - e1.changed return e2.changed - e1.changed
Expand All @@ -191,12 +196,12 @@ def ReportByELChanged (elist, totalchanged):
BeginReport ('Top lines changed by employer') BeginReport ('Top lines changed by employer')
for e in elist: for e in elist:
if e.changed != 0: if e.changed != 0:
ReportLine (e.name, e.changed, (e.changed*100.0)/totalchanged) ReportLine (e.name, e.changed, Pct(e.changed, totalchanged))
reported += e.changed reported += e.changed
count += 1 count += 1
if count >= ListCount: if count >= ListCount:
break break
EndReport ('Covers %f%% of changes' % ((reported*100.0)/totalchanged, )) EndReport ('Covers %f%% of changes' % (Pct(reported, totalchanged), ))






Expand All @@ -213,12 +218,12 @@ def ReportBySOBs (hlist):
for h in hlist: for h in hlist:
scount = len (h.signoffs) scount = len (h.signoffs)
if scount > 0: if scount > 0:
ReportLine (h.name, scount, (scount*100.0)/totalsobs) ReportLine (h.name, scount, Pct(scount, totalsobs))
reported += scount reported += scount
count += 1 count += 1
if count >= ListCount: if count >= ListCount:
break break
EndReport ('Covers %f%% of signoffs' % ((reported*100.0)/totalsobs, )) EndReport ('Covers %f%% of signoffs' % (Pct(reported, totalsobs), ))


# #
# Reviewer reporting. # Reviewer reporting.
Expand All @@ -236,12 +241,12 @@ def ReportByRevs (hlist):
for h in hlist: for h in hlist:
scount = len (h.reviews) scount = len (h.reviews)
if scount > 0: if scount > 0:
ReportLine (h.name, scount, (scount*100.0)/totalrevs) ReportLine (h.name, scount, Pct(scount, totalrevs))
reported += scount reported += scount
count += 1 count += 1
if count >= ListCount: if count >= ListCount:
break break
EndReport ('Covers %f%% of reviews' % ((reported*100.0)/totalrevs, )) EndReport ('Covers %f%% of reviews' % (Pct(reported, totalrevs), ))


def CompareRevsEmpl (e1, e2): def CompareRevsEmpl (e1, e2):
return len (e2.reviews) - len (e1.reviews) return len (e2.reviews) - len (e1.reviews)
Expand All @@ -256,12 +261,12 @@ def ReportByRevsEmpl (elist):
for e in elist: for e in elist:
scount = len (e.reviews) scount = len (e.reviews)
if scount > 0: if scount > 0:
ReportLine (e.name, scount, (scount*100.0)/totalrevs) ReportLine (e.name, scount, Pct(scount, totalrevs))
reported += scount reported += scount
count += 1 count += 1
if count >= ListCount: if count >= ListCount:
break break
EndReport ('Covers %f%% of reviews' % ((reported*100.0)/totalrevs, )) EndReport ('Covers %f%% of reviews' % (Pct(reported, totalrevs), ))


# #
# tester reporting. # tester reporting.
Expand All @@ -279,12 +284,12 @@ def ReportByTests (hlist):
for h in hlist: for h in hlist:
scount = len (h.tested) scount = len (h.tested)
if scount > 0: if scount > 0:
ReportLine (h.name, scount, (scount*100.0)/totaltests) ReportLine (h.name, scount, Pct(scount, totaltests))
reported += scount reported += scount
count += 1 count += 1
if count >= ListCount: if count >= ListCount:
break break
EndReport ('Covers %f%% of test credits' % ((reported*100.0)/totaltests, )) EndReport ('Covers %f%% of test credits' % (Pct(reported, totaltests), ))


def CompareTestCred (h1, h2): def CompareTestCred (h1, h2):
return h2.testcred - h1.testcred return h2.testcred - h1.testcred
Expand All @@ -298,12 +303,12 @@ def ReportByTestCreds (hlist):
BeginReport ('Developers who gave the most tested-by credits (total %d)' % totaltests) BeginReport ('Developers who gave the most tested-by credits (total %d)' % totaltests)
for h in hlist: for h in hlist:
if h.testcred > 0: if h.testcred > 0:
ReportLine (h.name, h.testcred, (h.testcred*100.0)/totaltests) ReportLine (h.name, h.testcred, Pct(h.testcred, totaltests))
reported += h.testcred reported += h.testcred
count += 1 count += 1
if count >= ListCount: if count >= ListCount:
break break
EndReport ('Covers %f%% of test credits' % ((reported*100.0)/totaltests, )) EndReport ('Covers %f%% of test credits' % (Pct(reported, totaltests), ))






Expand All @@ -323,12 +328,12 @@ def ReportByReports (hlist):
for h in hlist: for h in hlist:
scount = len (h.reports) scount = len (h.reports)
if scount > 0: if scount > 0:
ReportLine (h.name, scount, (scount*100.0)/totalreps) ReportLine (h.name, scount, Pct(scount, totalreps))
report += scount report += scount
count += 1 count += 1
if count >= ListCount: if count >= ListCount:
break break
EndReport ('Covers %f%% of report credits' % ((reported*100.0)/totalreps, )) EndReport ('Covers %f%% of report credits' % (Pct(reported, totalreps), ))


def CompareRepCred (h1, h2): def CompareRepCred (h1, h2):
return h2.repcred - h1.repcred return h2.repcred - h1.repcred
Expand All @@ -342,12 +347,12 @@ def ReportByRepCreds (hlist):
BeginReport ('Developers who gave the most report credits (total %d)' % totalreps) BeginReport ('Developers who gave the most report credits (total %d)' % totalreps)
for h in hlist: for h in hlist:
if h.repcred > 0: if h.repcred > 0:
ReportLine (h.name, h.repcred, (h.repcred*100.0)/totalreps) ReportLine (h.name, h.repcred, Pct(h.repcred, totalreps))
reported += h.repcred reported += h.repcred
count += 1 count += 1
if count >= ListCount: if count >= ListCount:
break break
EndReport ('Covers %f%% of report credits' % ((reported*100.0)/totalreps, )) EndReport ('Covers %f%% of report credits' % (Pct(reported, totalreps), ))






Expand All @@ -363,12 +368,12 @@ def ReportByESOBs (elist):
BeginReport ('Employers with the most signoffs (total %d)' % totalsobs) BeginReport ('Employers with the most signoffs (total %d)' % totalsobs)
for e in elist: for e in elist:
if e.sobs > 0: if e.sobs > 0:
ReportLine (e.name, e.sobs, (e.sobs*100.0)/totalsobs) ReportLine (e.name, e.sobs, Pct(e.sobs, totalsobs))
reported += e.sobs reported += e.sobs
count += 1 count += 1
if count >= ListCount: if count >= ListCount:
break break
EndReport ('Covers %f%% of signoffs' % ((reported*100.0)/totalsobs, )) EndReport ('Covers %f%% of signoffs' % (Pct(reported, totalsobs), ))


def CompareHackers (e1, e2): def CompareHackers (e1, e2):
return len (e2.hackers) - len (e1.hackers) return len (e2.hackers) - len (e1.hackers)
Expand All @@ -383,12 +388,12 @@ def ReportByEHackers (elist):
for e in elist: for e in elist:
nhackers = len (e.hackers) nhackers = len (e.hackers)
if nhackers > 0: if nhackers > 0:
ReportLine (e.name, nhackers, (nhackers*100.0)/totalhackers) ReportLine (e.name, nhackers, Pct(nhackers, totalhackers))
reported += nhackers reported += nhackers
count += 1 count += 1
if count >= ListCount: if count >= ListCount:
break break
EndReport ('Covers %f%% of hackers' % ((reported*100.0)/totalhackers, )) EndReport ('Covers %f%% of hackers' % (Pct(reported, totalhackers), ))




def DevReports (hlist, totalchanged, cscount, totalremoved): def DevReports (hlist, totalchanged, cscount, totalremoved):
Expand Down

0 comments on commit d90c69e

Please sign in to comment.