Skip to content

Instantly share code, notes, and snippets.

@winhamwr
Created February 5, 2015 16:19
Show Gist options
  • Save winhamwr/43382b6e1e00a43321a1 to your computer and use it in GitHub Desktop.
Save winhamwr/43382b6e1e00a43321a1 to your computer and use it in GitHub Desktop.
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