diff --git a/zephyr/management/commands/active_user_stats.py b/zephyr/management/commands/active_user_stats.py index 8fcf9d7368..bd4cba49c3 100644 --- a/zephyr/management/commands/active_user_stats.py +++ b/zephyr/management/commands/active_user_stats.py @@ -3,7 +3,7 @@ from __future__ import absolute_import from django.core.management.base import BaseCommand from django.conf import settings -from zephyr.models import UserProfile, UserPresence +from zephyr.models import UserProfile, UserPresence, UserActivity from zephyr.lib.utils import statsd, statsd_key from datetime import datetime, timedelta @@ -43,3 +43,17 @@ class Command(BaseCommand): print("\tUsers for %s: %s" % (hr, len(users))) statsd.gauge("users.active.%s.%shr" % (statsd_key(realm, True), statsd_key(hr, True)), len(users)) + # Also do stats for how many users have been reading the app. + users_reading = UserActivity.objects.select_related().filter(query="/json/update_message_flags") + user_info = {} + for activity in users_reading: + for bucket in hour_buckets: + if not bucket in user_info[activity.user_profile.realm.domain]: + user_info[activity.user_profile.realm.domain][bucket] = [] + if datetime.now(activity.last_visit.tzinfo) - activity.last_visit < timedelta(hours=bucket): + user_info[activity.user_profile.realm.domain][bucket].append(activity.user_profile.email) + for realm, buckets in user_info.items(): + print("Realm %s" % realm) + for hr, users in sorted(buckets.items()): + print("\tUsers reading for %s: %s" % (hr, len(users))) + statsd.gauge("users.reading.%s.%shr" % (statsd_key(realm, True), statsd_key(hr, True)), len(users))