changeset 1798:c5d58387d031

jp (roster stats): add some extra information
author souliane <souliane@mailoo.org>
date Wed, 13 Jan 2016 19:46:43 +0100
parents 40cda0c08727
children f1f4775f8cc0
files frontends/src/jp/cmd_roster.py
diffstat 1 files changed, 23 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/frontends/src/jp/cmd_roster.py	Wed Jan 13 19:26:09 2016 +0100
+++ b/frontends/src/jp/cmd_roster.py	Wed Jan 13 19:46:43 2016 +0100
@@ -47,17 +47,17 @@
         print (_("Error while retrieving the contacts [%s]") % failure)
         self.host.quit(1)
 
-    def ask_confirmation(self, none, no_from, no_to):
+    def ask_confirmation(self, no_sub, no_from, no_to):
         """Ask the confirmation before removing contacts.
 
-        @param none (list[unicode]): list of contacts with no subscription
+        @param no_sub (list[unicode]): list of contacts with no subscription
         @param no_from (list[unicode]): list of contacts with no 'from' subscription
         @param no_to (list[unicode]): list of contacts with no 'to' subscription
         @return bool
         """
-        if none:
+        if no_sub:
             print "There's no subscription between profile [%s] and the following contacts:" % self.host.profile
-            print "    " + "\n    ".join(none)
+            print "    " + "\n    ".join(no_sub)
         if no_from:
             print "There's no 'from' subscription between profile [%s] and the following contacts:" % self.host.profile
             print "    " + "\n    ".join(no_from)
@@ -77,20 +77,20 @@
 
         @param contacts(list[tuple]): list of contacts with their attributes and groups
         """
-        none, no_from, no_to = [], [], []
+        no_sub, no_from, no_to = [], [], []
         for contact, attrs, groups in contacts:
             from_, to = C.bool(attrs["from"]), C.bool(attrs["to"])
             if not from_:
                 if not to:
-                    none.append(contact)
+                    no_sub.append(contact)
                 elif self.args.no_from:
                     no_from.append(contact)
             elif not to and self.args.no_to:
                 no_to.append(contact)
-        if not none and not no_from and not no_to:
+        if not no_sub and not no_from and not no_to:
             print "Nothing to do - there's a from and/or to subscription(s) between profile [%s] and each of its contacts" % self.host.profile
-        elif self.ask_confirmation(none, no_from, no_to):
-            for contact in none + no_from + no_to:
+        elif self.ask_confirmation(no_sub, no_from, no_to):
+            for contact in no_sub + no_from + no_to:
                 self.host.bridge.delContact(contact, profile_key=self.host.profile, callback=lambda dummy: None, errback=lambda failure: None)
         self.host.quit()
 
@@ -98,7 +98,7 @@
 class Stats(base.CommandBase):
 
     def __init__(self, host):
-        super(Stats, self).__init__(host, 'stats', help=_('Display show statistics about a roster'))
+        super(Stats, self).__init__(host, 'stats', help=_('Show statistics about a roster'))
 
     def add_parser_options(self):
         pass
@@ -118,24 +118,22 @@
         @param contacts(list[tuple]): list of contacts with their attributes and groups
         """
         hosts = {}
-        no_subscription = 0
-        no_from_subscription = 0
-        no_to_subscription = 0
-        no_group = 0
-        total_group_subscription = 0
+        unique_groups = set()
+        no_sub, no_from, no_to, no_group, total_group_subscription = 0, 0, 0, 0, 0
         for contact, attrs, groups in contacts:
             from_, to = C.bool(attrs["from"]), C.bool(attrs["to"])
             if not from_:
                 if not to:
-                    no_subscription += 1
+                    no_sub += 1
                 else:
-                    no_from_subscription += 1
+                    no_from += 1
             elif not to:
-                no_to_subscription += 1
+                no_to += 1
             host = jid.JID(contact).host
             hosts.setdefault(host, 0)
             hosts[host] += 1
             if groups:
+                unique_groups.update(groups)
                 total_group_subscription += len(groups)
             if not groups:
                 no_group += 1
@@ -143,16 +141,19 @@
 
         print
         print "Total number of contacts: %d" % len(contacts)
+        print "Number of different hosts: %d" % len(hosts)
         print
         for host, count in hosts.iteritems():
             print "Contacts on {host}: {count} ({rate:.1f}%)".format(host=host, count=count, rate=100 * float(count) / len(contacts))
         print
-        print "Contacts with no 'from' subscription: %d" % no_from_subscription
-        print "Contacts with no 'to' subscription: %d" % no_to_subscription
-        print "Contacts with no subscription at all: %d" % no_subscription
+        print "Contacts with no 'from' subscription: %d" % no_from
+        print "Contacts with no 'to' subscription: %d" % no_to
+        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))
         print "Contacts not assigned to any group: %d" % no_group
-        print "Average groups' subscriptions per contact: %.1f" % (float(total_group_subscription) / len(contacts))
         self.host.quit()