Add function to calculate member signup counts

This commit is contained in:
Tanner Collin 2020-04-26 04:06:15 +00:00
parent d7a529dd94
commit 7d370fe4b2
2 changed files with 22 additions and 8 deletions

View File

@ -1,26 +1,28 @@
from django.core.management.base import BaseCommand, CommandError
from django.utils.timezone import now, pytz
from django.utils.timezone import now
from apiserver.api import models, utils, utils_stats
from datetime import datetime
import time
def today_alberta_tz():
return datetime.now(pytz.timezone('America/Edmonton')).date()
class Command(BaseCommand):
help = 'Tasks to run on the portal hourly.'
def generate_stats(self):
utils_stats.calc_next_events()
member_count, green_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=today_alberta_tz(),
date=utils.today_alberta_tz(),
defaults=dict(member_count=member_count, green_count=green_count),
)
models.StatsSignupCount.objects.update_or_create(
month=utils.today_alberta_tz().replace(day=1),
defaults=dict(signup_count=signup_count),
)
def handle(self, *args, **options):
self.stdout.write('{} - Beginning hourly tasks'.format(str(now())))

View File

@ -2,13 +2,16 @@ import logging
logger = logging.getLogger(__name__)
import time
import datetime
from datetime import date, datetime
import requests
from django.core.cache import cache
from django.utils.timezone import now
from django.utils.timezone import now, pytz
from apiserver.api import models
from apiserver import secrets
def today_alberta_tz():
return datetime.now(pytz.timezone('America/Edmonton')).date()
DEFAULTS = {
'last_card_change': time.time(),
'next_meeting': None,
@ -63,6 +66,15 @@ def calc_member_counts():
return member_count, green_count
def calc_signup_counts():
month_beginning = today_alberta_tz().replace(day=1)
members = models.Member.objects
new_members = members.filter(application_date__gte=month_beginning)
num_new_members = new_members.count()
return num_new_members
def check_minecraft_server():
if secrets.MINECRAFT:
url = 'https://api.minetools.eu/ping/' + secrets.MINECRAFT