Calculate retained member counts for each month
This commit is contained in:
parent
d0402ea388
commit
99c1c53f12
|
@ -24,6 +24,9 @@ class Command(BaseCommand):
|
||||||
count = self.tally_active_members()
|
count = self.tally_active_members()
|
||||||
self.stdout.write('Tallied {} active members'.format(count))
|
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()
|
utils_stats.changed_card()
|
||||||
self.stdout.write('Updated card change time')
|
self.stdout.write('Updated card change time')
|
||||||
|
|
||||||
|
|
|
@ -138,6 +138,8 @@ class StatsMemberCount(models.Model):
|
||||||
class StatsSignupCount(models.Model):
|
class StatsSignupCount(models.Model):
|
||||||
month = models.DateField()
|
month = models.DateField()
|
||||||
signup_count = models.IntegerField()
|
signup_count = models.IntegerField()
|
||||||
|
retain_count = models.IntegerField(default=0)
|
||||||
|
vetted_count = models.IntegerField(default=0)
|
||||||
|
|
||||||
class HistoryIndex(models.Model):
|
class HistoryIndex(models.Model):
|
||||||
content_type = models.ForeignKey(ContentType, null=True, on_delete=models.SET_NULL)
|
content_type = models.ForeignKey(ContentType, null=True, on_delete=models.SET_NULL)
|
||||||
|
|
|
@ -75,6 +75,28 @@ def calc_signup_counts():
|
||||||
|
|
||||||
return num_new_members
|
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():
|
def check_minecraft_server():
|
||||||
if secrets.MINECRAFT:
|
if secrets.MINECRAFT:
|
||||||
url = 'https://api.minetools.eu/ping/' + secrets.MINECRAFT
|
url = 'https://api.minetools.eu/ping/' + secrets.MINECRAFT
|
||||||
|
|
|
@ -393,9 +393,12 @@ class MemberCountViewSet(Base, List):
|
||||||
|
|
||||||
class SignupCountViewSet(Base, List):
|
class SignupCountViewSet(Base, List):
|
||||||
pagination_class = None
|
pagination_class = None
|
||||||
queryset = models.StatsSignupCount.objects.order_by('-month')[:16][::-1]
|
|
||||||
serializer_class = serializers.SignupCountSerializer
|
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):
|
class BackupView(views.APIView):
|
||||||
def get(self, request):
|
def get(self, request):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user