Remove domain from analytics management commands.

This commit is contained in:
Rishi Gupta
2017-01-08 10:48:22 -08:00
committed by Tim Abbott
parent e14f575979
commit ac29928d91
4 changed files with 10 additions and 10 deletions

View File

@@ -33,10 +33,10 @@ class Command(BaseCommand):
known_active = last_presence.timestamp known_active = last_presence.timestamp
for bucket in hour_buckets: for bucket in hour_buckets:
if bucket not in user_info[last_presence.user_profile.realm.domain]: if bucket not in user_info[last_presence.user_profile.realm.string_id]:
user_info[last_presence.user_profile.realm.domain][bucket] = [] user_info[last_presence.user_profile.realm.string_id][bucket] = []
if datetime.now(known_active.tzinfo) - known_active < timedelta(hours=bucket): if datetime.now(known_active.tzinfo) - known_active < timedelta(hours=bucket):
user_info[last_presence.user_profile.realm.domain][bucket].append(last_presence.user_profile.email) user_info[last_presence.user_profile.realm.string_id][bucket].append(last_presence.user_profile.email)
for realm, buckets in user_info.items(): for realm, buckets in user_info.items():
print("Realm %s" % (realm,)) print("Realm %s" % (realm,))
@@ -49,10 +49,10 @@ class Command(BaseCommand):
user_info = defaultdict(dict) user_info = defaultdict(dict)
for activity in users_reading: for activity in users_reading:
for bucket in hour_buckets: for bucket in hour_buckets:
if bucket not in user_info[activity.user_profile.realm.domain]: if bucket not in user_info[activity.user_profile.realm.string_id]:
user_info[activity.user_profile.realm.domain][bucket] = [] user_info[activity.user_profile.realm.string_id][bucket] = []
if datetime.now(activity.last_visit.tzinfo) - activity.last_visit < timedelta(hours=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) user_info[activity.user_profile.realm.string_id][bucket].append(activity.user_profile.email)
for realm, buckets in user_info.items(): for realm, buckets in user_info.items():
print("Realm %s" % (realm,)) print("Realm %s" % (realm,))
for hr, users in sorted(buckets.items()): for hr, users in sorted(buckets.items()):

View File

@@ -17,7 +17,7 @@ def compute_stats(log_level):
logger.setLevel(log_level) logger.setLevel(log_level)
one_week_ago = timestamp_to_datetime(time.time()) - datetime.timedelta(weeks=1) one_week_ago = timestamp_to_datetime(time.time()) - datetime.timedelta(weeks=1)
mit_query = Message.objects.filter(sender__realm__domain="mit.edu", mit_query = Message.objects.filter(sender__realm__string_id="mit",
recipient__type=Recipient.STREAM, recipient__type=Recipient.STREAM,
pub_date__gt=one_week_ago) pub_date__gt=one_week_ago)
for bot_sender_start in ["imap.", "rcmd.", "sys."]: for bot_sender_start in ["imap.", "rcmd.", "sys."]:

View File

@@ -19,7 +19,7 @@ def analyze_activity(options):
user_profile_query = UserProfile.objects.all() user_profile_query = UserProfile.objects.all()
if options["realm"]: if options["realm"]:
user_profile_query = user_profile_query.filter(realm__domain=options["realm"]) user_profile_query = user_profile_query.filter(realm__string_id=options["realm"])
print("Per-user online duration:\n") print("Per-user online duration:\n")
total_duration = datetime.timedelta(0) total_duration = datetime.timedelta(0)
@@ -47,7 +47,7 @@ It will correctly not count server-initiated reloads in the activity statistics.
The duration flag can be used to control how many days to show usage duration for The duration flag can be used to control how many days to show usage duration for
Usage: ./manage.py analyze_user_activity [--realm=zulip.com] [--date=2013-09-10] [--duration=1] Usage: ./manage.py analyze_user_activity [--realm=zulip] [--date=2013-09-10] [--duration=1]
By default, if no date is selected 2013-09-10 is used. If no realm is provided, information By default, if no date is selected 2013-09-10 is used. If no realm is provided, information
is shown for all realms""" is shown for all realms"""

View File

@@ -76,5 +76,5 @@ Usage examples:
self.compute_activity(UserActivity.objects.filter( self.compute_activity(UserActivity.objects.filter(
user_profile__realm=realm)) user_profile__realm=realm))
except Realm.DoesNotExist: except Realm.DoesNotExist:
print("Unknown user or domain %s" % (arg,)) print("Unknown user or realm %s" % (arg,))
exit(1) exit(1)