Skip to content

Instantly share code, notes, and snippets.

@winhamwr
Created Feb 5, 2015
Embed
What would you like to do?
Percentage of active customers using any-site login
from __future__ import division
from django.db.models import Count
system_setting_pks = list(
Customer.objects.annotate(
tenant_count=Count('tenant_set')
).filter(tenant_count__gt=1).values_list('settings__pk', flat=True)
)
num_systems = len(system_setting_pks)
not_enabled_systems = list(
CustomerSettings.objects.filter(
pk__in=system_setting_pks,
enable_login_from_any_site=False,
).select_related('customer')
)
num_enabled_systems = num_systems - len(not_enabled_systems)
print "Enabled ratio: {0}".format(num_enabled_systems/num_systems)
print "Not enabled:"
for cs in not_enabled_systems:
print "{0}".format(cs.customer.name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment