diff options
author | Priit Laes <plaes@plaes.org> | 2010-02-28 12:00:47 +0200 |
---|---|---|
committer | Mart Raudsepp <leio@gentoo.org> | 2010-03-16 08:41:48 +0200 |
commit | f23cf23c4fbfa089e947385e42676f538c26547c (patch) | |
tree | 01f120f50838e010e2b615dd0af2070f11aee76a | |
parent | Remove workaround for gdl package. (diff) | |
download | gentoo-bumpchecker-f23cf23c4fbfa089e947385e42676f538c26547c.tar.gz gentoo-bumpchecker-f23cf23c4fbfa089e947385e42676f538c26547c.tar.bz2 gentoo-bumpchecker-f23cf23c4fbfa089e947385e42676f538c26547c.zip |
Clean up the percentage calculation and related HTML output.
-rw-r--r-- | modules/gnome_output.py | 50 |
1 files changed, 22 insertions, 28 deletions
diff --git a/modules/gnome_output.py b/modules/gnome_output.py index 45286dc..f985a85 100644 --- a/modules/gnome_output.py +++ b/modules/gnome_output.py @@ -12,13 +12,17 @@ class Output: self.calculate_stats() def calculate_stats(self): - # variables to hold for stats - total_packs = len(self.packages) - self.update_needed = float(0) - self.compliant = float(0) - self.not_found = float(0) - self.newer = float(0) - + # Variables for holding stats + total_packs = len(self.packages) + self.update_needed = 0 + self.compliant = 0 + self.not_found = 0 + self.newer = 0 + # Percentages + self.update_percent = 0 + self.notfound_percent = 0 + self.compliant_percent = 0 + for package in self.packages: if package.status == package_module.Status.Compliant: self.compliant +=1 @@ -28,24 +32,14 @@ class Output: self.not_found +=1 elif package.status == package_module.Status.NeedUpdate: self.update_needed +=1 - - try: - self.update_percent = float(self.update_needed / total_packs) * 100 - except ZeroDivisionError: - self.update_percent = 0 - try: - self.compliant_percent = float(self.compliant / total_packs) * 100 - except ZeroDivisionError: - self.compliant_percent = 0 - try: - self.notfound_percent = float(self.not_found / total_packs) * 100 - except ZeroDivisionError: - self.notfound_percent = 0 - try: - self.total_percent = float( (self.update_needed + self.not_found ) / total_packs ) * 100 - except ZeroDivisionError: - self.total_percent = 0 - + + if total_packs == 0: + return + + self.update_percent = 100 * self.update_needed / float(total_packs) + self.compliant_percent = 100 * self.compliant / float(total_packs) + self.notfound_percent = 100 * self.not_found / float(total_packs) + def generate_html(self): # now we have all the results in the results list. @@ -72,9 +66,9 @@ class Output: # stats lines.append("<br>") - lines.append("Compliant Packs: " + str('%0.2f' % self.compliant_percent)+ "%" + " Number = " + str(self.compliant) + "<br>") - lines.append("Packs that need to be updated: " + str('%0.2f' % self.update_percent)+ "%" + " Number = " + str(self.update_needed) + "<br>") - lines.append("New Packs that need to be added: " + str('%0.2f' % self.notfound_percent)+ "%" + " Number = " + str(self.not_found) + "<br>") + lines.append("Compliant Packages: %d (%0.2f%%)<br />" % (self.compliant, self.compliant_percent)) + lines.append("Packages requiring update: %d (%0.2f%%)<br />" % (self.update_needed, self.update_percent)) + lines.append("Packages missing from tree: %d (%0.2f%%)<br />" % (self.not_found, self.notfound_percent)) lines.append("<br>") lines.append('<table cellpadding="3">') |