2013-10-18 17:40:16 +02:00
|
|
|
from __future__ import absolute_import
|
2015-11-01 17:11:06 +01:00
|
|
|
from __future__ import print_function
|
2013-10-18 17:40:16 +02:00
|
|
|
|
|
|
|
import datetime
|
|
|
|
import pytz
|
|
|
|
|
|
|
|
from optparse import make_option
|
2016-06-04 16:52:18 +02:00
|
|
|
from typing import Any
|
2017-02-26 03:07:49 +01:00
|
|
|
|
2016-11-03 10:22:19 +01:00
|
|
|
from django.core.management.base import BaseCommand, CommandParser
|
2017-02-26 03:07:49 +01:00
|
|
|
from django.utils import timezone
|
2013-10-18 17:40:16 +02:00
|
|
|
from zerver.lib.statistics import activity_averages_during_day
|
|
|
|
|
|
|
|
class Command(BaseCommand):
|
|
|
|
help = "Generate statistics on user activity for a given day."
|
|
|
|
|
2016-11-03 10:22:19 +01:00
|
|
|
def add_arguments(self, parser):
|
|
|
|
# type: (CommandParser) -> None
|
|
|
|
parser.add_argument('--date', default=None, action='store',
|
|
|
|
help="Day to query in format 2013-12-05. Default is yesterday")
|
2013-10-18 17:40:16 +02:00
|
|
|
|
|
|
|
def handle(self, *args, **options):
|
2016-06-04 16:52:18 +02:00
|
|
|
# type: (*Any, **Any) -> None
|
2013-10-18 17:40:16 +02:00
|
|
|
if options["date"] is None:
|
2017-02-26 03:07:49 +01:00
|
|
|
date = timezone.now() - datetime.timedelta(days=1)
|
2013-10-18 17:40:16 +02:00
|
|
|
else:
|
2017-02-26 03:07:49 +01:00
|
|
|
date = datetime.datetime.strptime(options["date"], "%Y-%m-%d").replace(tzinfo=pytz.utc)
|
2015-11-01 17:11:06 +01:00
|
|
|
print("Activity data for", date)
|
|
|
|
print(activity_averages_during_day(date))
|
|
|
|
print("Please note that the total registered user count is a total for today")
|