jp (roster stats): add some extra information
This commit is contained in:
parent
6a680d9ff8
commit
988990f6f5
1 changed files with 23 additions and 22 deletions
|
|
@ -47,17 +47,17 @@ class Purge(base.CommandBase):
|
|||
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 @@ class Purge(base.CommandBase):
|
|||
|
||||
@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 Purge(base.CommandBase):
|
|||
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 @@ class Stats(base.CommandBase):
|
|||
@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 @@ class Stats(base.CommandBase):
|
|||
|
||||
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 "Contacts not assigned to any group: %d" % no_group
|
||||
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
|
||||
self.host.quit()
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue