diff --git a/apiserver/apiserver/api/management/commands/run_hourly.py b/apiserver/apiserver/api/management/commands/run_hourly.py index 7a85b47..f204690 100644 --- a/apiserver/apiserver/api/management/commands/run_hourly.py +++ b/apiserver/apiserver/api/management/commands/run_hourly.py @@ -9,17 +9,18 @@ class Command(BaseCommand): def generate_stats(self): utils_stats.calc_next_events() - member_count, green_count, six_month_plus_count, vetted_count = utils_stats.calc_member_counts() + counts = 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, - six_month_plus_count=six_month_plus_count, - vetted_count=vetted_count, + member_count=counts['member_count'], + green_count=counts['green_count'], + six_month_plus_count=counts['six_month_plus_count'], + vetted_count=counts['vetted_count'], + subscriber_count=counts['subscriber_count'], ), ) diff --git a/apiserver/apiserver/api/models.py b/apiserver/apiserver/api/models.py index f31e6d9..7b9b20e 100644 --- a/apiserver/apiserver/api/models.py +++ b/apiserver/apiserver/api/models.py @@ -152,6 +152,7 @@ class StatsMemberCount(models.Model): green_count = models.IntegerField() six_month_plus_count = models.IntegerField() vetted_count = models.IntegerField() + subscriber_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 199869f..7088ece 100644 --- a/apiserver/apiserver/api/utils_stats.py +++ b/apiserver/apiserver/api/utils_stats.py @@ -4,6 +4,7 @@ logger = logging.getLogger(__name__) import time from datetime import date, datetime, timedelta import requests +from django.db.models import Prefetch from django.core.cache import cache from django.utils.timezone import now, pytz from apiserver.api import models @@ -73,11 +74,33 @@ def calc_member_counts(): vetted_count = not_paused.filter(vetted_date__isnull=False).count() + related_membership_tx = Prefetch( + 'user__transactions', + queryset=models.Transaction.objects.exclude( + number_of_membership_months=0, + ).exclude( + number_of_membership_months__isnull=True, + ), + ) + + subscriber_count = 0 + for member in not_paused.prefetch_related(related_membership_tx): + if not member.user.transactions.count(): + continue + if member.user.transactions.latest('date').paypal_txn_type == 'subscr_payment': + subscriber_count += 1 + cache.set('member_count', member_count) cache.set('paused_count', paused_count) cache.set('green_count', green_count) - return member_count, green_count, six_month_plus_count, vetted_count + return dict( + member_count=member_count, + green_count=green_count, + six_month_plus_count=six_month_plus_count, + vetted_count=vetted_count, + subscriber_count=subscriber_count, + ) def calc_signup_counts(): month_beginning = today_alberta_tz().replace(day=1) diff --git a/apiserver/import_subs_counts.py b/apiserver/import_subs_counts.py new file mode 100755 index 0000000..f1d27bc --- /dev/null +++ b/apiserver/import_subs_counts.py @@ -0,0 +1,711 @@ +import django, sys, os +os.environ['DJANGO_SETTINGS_MODULE'] = 'apiserver.settings' +django.setup() + +from apiserver.api import models + +data = ''' +2020-03-02,74 +2020-03-03,77 +2020-03-04,79 +2020-03-05,83 +2020-03-06,87 +2020-03-07,93 +2020-03-08,98 +2020-03-09,103 +2020-03-10,109 +2020-03-11,115 +2020-03-12,118 +2020-03-13,120 +2020-03-14,124 +2020-03-15,125 +2020-03-16,127 +2020-03-17,128 +2020-03-18,127 +2020-03-19,127 +2020-03-20,126 +2020-03-21,127 +2020-03-22,127 +2020-03-23,127 +2020-03-24,127 +2020-03-25,127 +2020-03-26,129 +2020-03-27,128 +2020-03-28,129 +2020-03-29,129 +2020-03-30,129 +2020-03-31,129 +2020-04-01,127 +2020-04-02,127 +2020-04-03,127 +2020-04-04,127 +2020-04-05,127 +2020-04-06,127 +2020-04-07,129 +2020-04-08,129 +2020-04-09,129 +2020-04-10,128 +2020-04-11,127 +2020-04-12,127 +2020-04-13,128 +2020-04-14,128 +2020-04-15,129 +2020-04-16,129 +2020-04-17,129 +2020-04-18,129 +2020-04-19,130 +2020-04-20,130 +2020-04-21,130 +2020-04-22,130 +2020-04-23,130 +2020-04-24,130 +2020-04-25,131 +2020-04-26,132 +2020-04-27,133 +2020-04-28,133 +2020-04-29,133 +2020-04-30,133 +2020-05-01,133 +2020-05-02,133 +2020-05-03,133 +2020-05-04,133 +2020-05-05,132 +2020-05-06,132 +2020-05-07,132 +2020-05-08,132 +2020-05-09,132 +2020-05-10,132 +2020-05-11,131 +2020-05-12,131 +2020-05-13,129 +2020-05-14,129 +2020-05-15,127 +2020-05-16,127 +2020-05-17,127 +2020-05-18,127 +2020-05-19,127 +2020-05-20,127 +2020-05-21,127 +2020-05-22,128 +2020-05-23,127 +2020-05-24,127 +2020-05-25,127 +2020-05-26,127 +2020-05-27,127 +2020-05-28,127 +2020-05-29,127 +2020-05-30,127 +2020-05-31,127 +2020-06-01,126 +2020-06-02,125 +2020-06-03,126 +2020-06-04,126 +2020-06-05,126 +2020-06-06,126 +2020-06-07,126 +2020-06-08,126 +2020-06-09,126 +2020-06-10,126 +2020-06-11,126 +2020-06-12,126 +2020-06-13,127 +2020-06-14,127 +2020-06-15,128 +2020-06-16,128 +2020-06-17,128 +2020-06-18,128 +2020-06-19,128 +2020-06-20,128 +2020-06-21,128 +2020-06-22,128 +2020-06-23,128 +2020-06-24,129 +2020-06-25,129 +2020-06-26,130 +2020-06-27,129 +2020-06-28,128 +2020-06-29,128 +2020-06-30,128 +2020-07-01,127 +2020-07-02,128 +2020-07-03,129 +2020-07-04,129 +2020-07-05,129 +2020-07-06,129 +2020-07-07,130 +2020-07-08,131 +2020-07-09,131 +2020-07-10,130 +2020-07-11,130 +2020-07-12,129 +2020-07-13,129 +2020-07-14,129 +2020-07-15,130 +2020-07-16,131 +2020-07-17,131 +2020-07-18,131 +2020-07-19,131 +2020-07-20,131 +2020-07-21,131 +2020-07-22,130 +2020-07-23,130 +2020-07-24,130 +2020-07-25,130 +2020-07-26,130 +2020-07-27,129 +2020-07-28,129 +2020-07-29,129 +2020-07-30,131 +2020-07-31,131 +2020-08-01,131 +2020-08-02,131 +2020-08-03,131 +2020-08-04,131 +2020-08-05,131 +2020-08-06,130 +2020-08-07,130 +2020-08-08,129 +2020-08-09,128 +2020-08-10,128 +2020-08-11,127 +2020-08-12,127 +2020-08-13,127 +2020-08-14,127 +2020-08-15,126 +2020-08-16,126 +2020-08-17,126 +2020-08-18,126 +2020-08-19,125 +2020-08-20,125 +2020-08-21,125 +2020-08-22,125 +2020-08-23,125 +2020-08-24,124 +2020-08-25,124 +2020-08-26,124 +2020-08-27,124 +2020-08-28,124 +2020-08-29,124 +2020-08-30,123 +2020-08-31,123 +2020-09-01,123 +2020-09-02,123 +2020-09-03,123 +2020-09-04,123 +2020-09-05,124 +2020-09-06,124 +2020-09-07,124 +2020-09-08,124 +2020-09-09,123 +2020-09-10,123 +2020-09-11,122 +2020-09-12,122 +2020-09-13,122 +2020-09-14,122 +2020-09-15,122 +2020-09-16,122 +2020-09-17,122 +2020-09-18,122 +2020-09-19,122 +2020-09-20,122 +2020-09-21,122 +2020-09-22,122 +2020-09-23,124 +2020-09-24,124 +2020-09-25,124 +2020-09-26,126 +2020-09-27,129 +2020-09-28,129 +2020-09-29,129 +2020-09-30,129 +2020-10-01,128 +2020-10-02,128 +2020-10-03,128 +2020-10-04,128 +2020-10-05,128 +2020-10-06,129 +2020-10-07,128 +2020-10-08,129 +2020-10-09,129 +2020-10-10,128 +2020-10-11,129 +2020-10-12,129 +2020-10-13,129 +2020-10-14,129 +2020-10-15,129 +2020-10-16,130 +2020-10-17,129 +2020-10-18,129 +2020-10-19,129 +2020-10-20,128 +2020-10-21,128 +2020-10-22,128 +2020-10-23,128 +2020-10-24,128 +2020-10-25,128 +2020-10-26,128 +2020-10-27,128 +2020-10-28,128 +2020-10-29,129 +2020-10-30,129 +2020-10-31,129 +2020-11-01,129 +2020-11-02,130 +2020-11-03,130 +2020-11-04,131 +2020-11-05,132 +2020-11-06,133 +2020-11-07,133 +2020-11-08,133 +2020-11-09,133 +2020-11-10,133 +2020-11-11,133 +2020-11-12,133 +2020-11-13,134 +2020-11-14,134 +2020-11-15,134 +2020-11-16,133 +2020-11-17,133 +2020-11-18,132 +2020-11-19,132 +2020-11-20,132 +2020-11-21,132 +2020-11-22,132 +2020-11-23,132 +2020-11-24,133 +2020-11-25,133 +2020-11-26,132 +2020-11-27,132 +2020-11-28,132 +2020-11-29,132 +2020-11-30,132 +2020-12-01,131 +2020-12-02,131 +2020-12-03,132 +2020-12-04,132 +2020-12-05,132 +2020-12-06,132 +2020-12-07,131 +2020-12-08,130 +2020-12-09,130 +2020-12-10,130 +2020-12-11,130 +2020-12-12,130 +2020-12-13,130 +2020-12-14,129 +2020-12-15,129 +2020-12-16,129 +2020-12-17,128 +2020-12-18,127 +2020-12-19,127 +2020-12-20,127 +2020-12-21,127 +2020-12-22,127 +2020-12-23,126 +2020-12-24,126 +2020-12-25,126 +2020-12-26,125 +2020-12-27,125 +2020-12-28,125 +2020-12-29,125 +2020-12-30,125 +2020-12-31,125 +2021-01-01,125 +2021-01-02,125 +2021-01-03,125 +2021-01-04,125 +2021-01-05,125 +2021-01-06,125 +2021-01-07,125 +2021-01-08,125 +2021-01-09,125 +2021-01-10,124 +2021-01-11,124 +2021-01-12,123 +2021-01-13,123 +2021-01-14,123 +2021-01-15,123 +2021-01-16,123 +2021-01-17,123 +2021-01-18,123 +2021-01-19,123 +2021-01-20,123 +2021-01-21,122 +2021-01-22,122 +2021-01-23,122 +2021-01-24,122 +2021-01-25,121 +2021-01-26,119 +2021-01-27,119 +2021-01-28,118 +2021-01-29,118 +2021-01-30,118 +2021-01-31,118 +2021-02-01,118 +2021-02-02,117 +2021-02-03,117 +2021-02-04,117 +2021-02-05,118 +2021-02-06,118 +2021-02-07,118 +2021-02-08,118 +2021-02-09,118 +2021-02-10,118 +2021-02-11,116 +2021-02-12,116 +2021-02-13,115 +2021-02-14,115 +2021-02-15,115 +2021-02-16,115 +2021-02-17,115 +2021-02-18,115 +2021-02-19,115 +2021-02-20,114 +2021-02-21,114 +2021-02-22,114 +2021-02-23,114 +2021-02-24,114 +2021-02-25,114 +2021-02-26,114 +2021-02-27,114 +2021-02-28,115 +2021-03-01,115 +2021-03-02,115 +2021-03-03,115 +2021-03-04,113 +2021-03-05,113 +2021-03-06,113 +2021-03-07,112 +2021-03-08,112 +2021-03-09,113 +2021-03-10,113 +2021-03-11,113 +2021-03-12,113 +2021-03-13,113 +2021-03-14,113 +2021-03-15,113 +2021-03-16,112 +2021-03-17,111 +2021-03-18,111 +2021-03-19,111 +2021-03-20,111 +2021-03-21,111 +2021-03-22,112 +2021-03-23,112 +2021-03-24,112 +2021-03-25,111 +2021-03-26,111 +2021-03-27,111 +2021-03-28,111 +2021-03-29,111 +2021-03-30,111 +2021-03-31,111 +2021-04-01,111 +2021-04-02,112 +2021-04-03,112 +2021-04-04,112 +2021-04-05,112 +2021-04-06,112 +2021-04-07,112 +2021-04-08,112 +2021-04-09,111 +2021-04-10,111 +2021-04-11,111 +2021-04-12,111 +2021-04-13,111 +2021-04-14,110 +2021-04-15,110 +2021-04-16,110 +2021-04-17,110 +2021-04-18,110 +2021-04-19,110 +2021-04-20,110 +2021-04-21,110 +2021-04-22,110 +2021-04-23,110 +2021-04-24,110 +2021-04-25,110 +2021-04-26,109 +2021-04-27,109 +2021-04-28,109 +2021-04-29,109 +2021-04-30,109 +2021-05-01,109 +2021-05-02,109 +2021-05-03,109 +2021-05-04,109 +2021-05-05,109 +2021-05-06,109 +2021-05-07,109 +2021-05-08,109 +2021-05-09,109 +2021-05-10,109 +2021-05-11,109 +2021-05-12,109 +2021-05-13,109 +2021-05-14,109 +2021-05-15,108 +2021-05-16,108 +2021-05-17,108 +2021-05-18,109 +2021-05-19,109 +2021-05-20,109 +2021-05-21,109 +2021-05-22,109 +2021-05-23,109 +2021-05-24,109 +2021-05-25,110 +2021-05-26,110 +2021-05-27,110 +2021-05-28,111 +2021-05-29,111 +2021-05-30,112 +2021-05-31,112 +2021-06-01,112 +2021-06-02,112 +2021-06-03,112 +2021-06-04,111 +2021-06-05,111 +2021-06-06,111 +2021-06-07,111 +2021-06-08,111 +2021-06-09,111 +2021-06-10,111 +2021-06-11,111 +2021-06-12,111 +2021-06-13,111 +2021-06-14,111 +2021-06-15,111 +2021-06-16,111 +2021-06-17,111 +2021-06-18,113 +2021-06-19,112 +2021-06-20,112 +2021-06-21,112 +2021-06-22,114 +2021-06-23,114 +2021-06-24,113 +2021-06-25,113 +2021-06-26,113 +2021-06-27,113 +2021-06-28,113 +2021-06-29,113 +2021-06-30,113 +2021-07-01,111 +2021-07-02,111 +2021-07-03,110 +2021-07-04,111 +2021-07-05,111 +2021-07-06,111 +2021-07-07,111 +2021-07-08,111 +2021-07-09,111 +2021-07-10,111 +2021-07-11,111 +2021-07-12,111 +2021-07-13,111 +2021-07-14,111 +2021-07-15,110 +2021-07-16,110 +2021-07-17,110 +2021-07-18,110 +2021-07-19,111 +2021-07-20,111 +2021-07-21,111 +2021-07-22,111 +2021-07-23,111 +2021-07-24,111 +2021-07-25,111 +2021-07-26,111 +2021-07-27,111 +2021-07-28,112 +2021-07-29,112 +2021-07-30,112 +2021-07-31,112 +2021-08-01,112 +2021-08-02,112 +2021-08-03,112 +2021-08-04,112 +2021-08-05,112 +2021-08-06,112 +2021-08-07,112 +2021-08-08,112 +2021-08-09,112 +2021-08-10,112 +2021-08-11,112 +2021-08-12,112 +2021-08-13,112 +2021-08-14,113 +2021-08-15,113 +2021-08-16,113 +2021-08-17,113 +2021-08-18,113 +2021-08-19,114 +2021-08-20,114 +2021-08-21,114 +2021-08-22,114 +2021-08-23,114 +2021-08-24,114 +2021-08-25,114 +2021-08-26,114 +2021-08-27,114 +2021-08-28,114 +2021-08-29,114 +2021-08-30,113 +2021-08-31,113 +2021-09-01,115 +2021-09-02,115 +2021-09-03,115 +2021-09-04,115 +2021-09-05,115 +2021-09-06,115 +2021-09-07,115 +2021-09-08,115 +2021-09-09,115 +2021-09-10,115 +2021-09-11,115 +2021-09-12,115 +2021-09-13,115 +2021-09-14,115 +2021-09-15,119 +2021-09-16,119 +2021-09-17,119 +2021-09-18,119 +2021-09-19,119 +2021-09-20,119 +2021-09-21,119 +2021-09-22,121 +2021-09-23,118 +2021-09-24,118 +2021-09-25,118 +2021-09-26,118 +2021-09-27,118 +2021-09-28,118 +2021-09-29,118 +2021-09-30,119 +2021-10-01,119 +2021-10-02,119 +2021-10-03,119 +2021-10-04,119 +2021-10-05,120 +2021-10-06,121 +2021-10-07,121 +2021-10-08,121 +2021-10-09,121 +2021-10-10,121 +2021-10-11,121 +2021-10-12,121 +2021-10-13,123 +2021-10-14,124 +2021-10-15,124 +2021-10-16,124 +2021-10-17,124 +2021-10-18,124 +2021-10-19,124 +2021-10-20,124 +2021-10-21,124 +2021-10-22,124 +2021-10-23,124 +2021-10-24,124 +2021-10-25,124 +2021-10-26,125 +2021-10-27,126 +2021-10-28,126 +2021-10-29,126 +2021-10-30,125 +2021-10-31,125 +2021-11-01,125 +2021-11-02,125 +2021-11-03,125 +2021-11-04,125 +2021-11-05,124 +2021-11-06,125 +2021-11-07,125 +2021-11-08,124 +2021-11-09,124 +2021-11-10,124 +2021-11-11,123 +2021-11-12,123 +2021-11-13,122 +2021-11-14,122 +2021-11-15,122 +2021-11-16,123 +2021-11-17,123 +2021-11-18,123 +2021-11-19,123 +2021-11-20,123 +2021-11-21,124 +2021-11-22,124 +2021-11-23,123 +2021-11-24,125 +2021-11-25,126 +2021-11-26,126 +2021-11-27,126 +2021-11-28,127 +2021-11-29,127 +2021-11-30,127 +2021-12-01,129 +2021-12-02,129 +2021-12-03,129 +2021-12-04,130 +2021-12-05,130 +2021-12-06,130 +2021-12-07,129 +2021-12-08,129 +2021-12-09,129 +2021-12-10,129 +2021-12-11,129 +2021-12-12,129 +2021-12-13,129 +2021-12-14,129 +2021-12-15,129 +2021-12-16,129 +2021-12-17,129 +2021-12-18,129 +2021-12-19,129 +2021-12-20,129 +2021-12-21,129 +2021-12-22,129 +2021-12-23,129 +2021-12-24,129 +2021-12-25,129 +2021-12-26,129 +2021-12-27,129 +2021-12-28,129 +2021-12-29,131 +2021-12-30,131 +2021-12-31,131 +2022-01-01,131 +2022-01-02,131 +2022-01-03,131 +2022-01-04,131 +2022-01-05,132 +2022-01-06,132 +2022-01-07,131 +2022-01-08,131 +2022-01-09,131 +2022-01-10,130 +2022-01-11,130 +2022-01-12,130 +2022-01-13,130 +2022-01-14,129 +2022-01-15,129 +2022-01-16,129 +2022-01-17,129 +2022-01-18,129 +2022-01-19,131 +2022-01-20,131 +2022-01-21,131 +2022-01-22,131 +''' + +for row in data.split(): + date, count = row.split(',') + print('Adding', date, count) + + models.StatsMemberCount.objects.update_or_create( + date=date, + defaults=dict(subscriber_count=count), + ) + +print('Done.') diff --git a/webclient/src/Charts.js b/webclient/src/Charts.js index d709cf1..60c45ef 100644 --- a/webclient/src/Charts.js +++ b/webclient/src/Charts.js @@ -219,6 +219,43 @@ export function Charts(props) {
Vetted Count: number of active vetted members.
+
+ {memberCount &&
+
Member Count: same as above.
+ +PayPal Subscriber Count: number of members with a PayPal subscription.
+