Calculate retained member counts for each month

This commit is contained in:
Tanner Collin 2020-05-17 00:18:08 +00:00
parent d0402ea388
commit 99c1c53f12
4 changed files with 31 additions and 1 deletions

View File

@ -24,6 +24,9 @@ class Command(BaseCommand):
count = self.tally_active_members()
self.stdout.write('Tallied {} active members'.format(count))
count = utils_stats.calc_retain_counts()
self.stdout.write('Tallied {} retained members'.format(count))
utils_stats.changed_card()
self.stdout.write('Updated card change time')

View File

@ -138,6 +138,8 @@ class StatsMemberCount(models.Model):
class StatsSignupCount(models.Model):
month = models.DateField()
signup_count = models.IntegerField()
retain_count = models.IntegerField(default=0)
vetted_count = models.IntegerField(default=0)
class HistoryIndex(models.Model):
content_type = models.ForeignKey(ContentType, null=True, on_delete=models.SET_NULL)

View File

@ -75,6 +75,28 @@ def calc_signup_counts():
return num_new_members
def calc_retain_counts():
signup_counts = models.StatsSignupCount.objects.all()
all_members = models.Member.objects
active_members = all_members.filter(paused_date__isnull=True)
vetted_members = all_members.filter(vetted_date__isnull=False)
for entry in signup_counts:
date = entry.month
active_new_members = active_members.filter(
application_date__month=date.month, application_date__year=date.year
)
vetted_new_members = vetted_members.filter(
application_date__month=date.month, application_date__year=date.year
)
entry.retain_count = active_new_members.count()
entry.vetted_count = vetted_new_members.count()
entry.save()
return active_members.count()
def check_minecraft_server():
if secrets.MINECRAFT:
url = 'https://api.minetools.eu/ping/' + secrets.MINECRAFT

View File

@ -393,9 +393,12 @@ class MemberCountViewSet(Base, List):
class SignupCountViewSet(Base, List):
pagination_class = None
queryset = models.StatsSignupCount.objects.order_by('-month')[:16][::-1]
serializer_class = serializers.SignupCountSerializer
def get_queryset(self):
# have to use method as slicing breaks makemigrations
return models.StatsSignupCount.objects.order_by('-month')[:16][::-1]
class BackupView(views.APIView):
def get(self, request):