From 4408147e2d69bd23be210621a6a2886938a35ec5 Mon Sep 17 00:00:00 2001 From: souliane Date: Sun, 17 Apr 2016 13:00:44 +0200 Subject: [PATCH] jp (cmd/roster): fixes division by zero exceptions fix bug 135 --- frontends/src/jp/cmd_roster.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/frontends/src/jp/cmd_roster.py b/frontends/src/jp/cmd_roster.py index 9f31ed70..c0a1dd36 100644 --- a/frontends/src/jp/cmd_roster.py +++ b/frontends/src/jp/cmd_roster.py @@ -149,8 +149,16 @@ class Stats(base.CommandBase): print "Contacts with no subscription at all: %d" % no_sub print print "Total number of groups: %d" % len(unique_groups) - print "Average contacts per group: %.1f" % (float(total_group_subscription) / len(unique_groups)) - print "Average groups' subscriptions per contact: %.1f" % (float(total_group_subscription) / len(contacts)) + try: + contacts_per_group = float(total_group_subscription) / len(unique_groups) + except ZeroDivisionError: + contacts_per_group = 0 + print "Average contacts per group: {:.1f}".format(contacts_per_group) + try: + groups_per_contact = float(total_group_subscription) / len(contacts) + except ZeroDivisionError: + groups_per_contact = 0 + print "Average groups' subscriptions per contact: {:.1f}".format(groups_per_contact) print "Contacts not assigned to any group: %d" % no_group self.host.quit()