diff --git a/apiserver/apiserver/api/management/commands/run_hourly.py b/apiserver/apiserver/api/management/commands/run_hourly.py index 443bb34..57ad634 100644 --- a/apiserver/apiserver/api/management/commands/run_hourly.py +++ b/apiserver/apiserver/api/management/commands/run_hourly.py @@ -9,13 +9,17 @@ class Command(BaseCommand): def generate_stats(self): utils_stats.calc_next_events() - member_count, green_count = utils_stats.calc_member_counts() + member_count, green_count, six_month_plus_count = utils_stats.calc_member_counts() signup_count = utils_stats.calc_signup_counts() # do this hourly in case an admin causes a change models.StatsMemberCount.objects.update_or_create( date=utils.today_alberta_tz(), - defaults=dict(member_count=member_count, green_count=green_count), + defaults=dict( + member_count=member_count, + green_count=green_count, + six_month_plus_count=six_month_plus_count, + ), ) models.StatsSignupCount.objects.update_or_create( diff --git a/apiserver/apiserver/api/models.py b/apiserver/apiserver/api/models.py index faf6459..70c437c 100644 --- a/apiserver/apiserver/api/models.py +++ b/apiserver/apiserver/api/models.py @@ -142,6 +142,7 @@ class StatsMemberCount(models.Model): date = models.DateField(default=today_alberta_tz) member_count = models.IntegerField() green_count = models.IntegerField() + six_month_plus_count = models.IntegerField() class StatsSignupCount(models.Model): month = models.DateField() diff --git a/apiserver/apiserver/api/utils_stats.py b/apiserver/apiserver/api/utils_stats.py index e81eeec..ddfd37d 100644 --- a/apiserver/apiserver/api/utils_stats.py +++ b/apiserver/apiserver/api/utils_stats.py @@ -2,7 +2,7 @@ import logging logger = logging.getLogger(__name__) import time -from datetime import date, datetime +from datetime import date, datetime, timedelta import requests from django.core.cache import cache from django.utils.timezone import now, pytz @@ -64,11 +64,14 @@ def calc_member_counts(): paused_count = members.count() - member_count green_count = num_current + num_prepaid + six_months_ago = today_alberta_tz() - timedelta(days=183) + six_month_plus_count = not_paused.filter(application_date__lte=six_months_ago).count() + cache.set('member_count', member_count) cache.set('paused_count', paused_count) cache.set('green_count', green_count) - return member_count, green_count + return member_count, green_count, six_month_plus_count def calc_signup_counts(): month_beginning = today_alberta_tz().replace(day=1)