Recount when there's a scan, add count to stats

This commit is contained in:
Tanner Collin 2020-06-16 04:22:42 +00:00
parent 9bfd44199b
commit 82316e914a
3 changed files with 12 additions and 6 deletions

View File

@ -11,7 +11,6 @@ class Command(BaseCommand):
utils_stats.calc_next_events()
member_count, green_count = utils_stats.calc_member_counts()
signup_count = utils_stats.calc_signup_counts()
card_scans = utils_stats.calc_card_scans()
# do this hourly in case an admin causes a change
models.StatsMemberCount.objects.update_or_create(
@ -24,10 +23,7 @@ class Command(BaseCommand):
defaults=dict(signup_count=signup_count),
)
models.StatsSpaceActivity.objects.update_or_create(
date=utils.today_alberta_tz(),
defaults=dict(card_scans=card_scans),
)
utils_stats.calc_card_scans()
def handle(self, *args, **options):

View File

@ -22,6 +22,7 @@ DEFAULTS = {
'bay_108_temp': None,
'bay_110_temp': None,
'minecraft_players': [],
'card_scans': 0,
}
def changed_card():
@ -115,4 +116,11 @@ def check_minecraft_server():
def calc_card_scans():
date = today_alberta_tz()
cards = models.Card.objects
return cards.filter(last_seen_at=date).count()
count = cards.filter(last_seen_at=date).count()
cache.set('card_scans', count)
models.StatsSpaceActivity.objects.update_or_create(
date=today_alberta_tz(),
defaults=dict(card_scans=count),
)

View File

@ -354,6 +354,8 @@ class DoorViewSet(viewsets.ViewSet, List):
member = models.Member.objects.get(id=card.member_id)
logger.info('Name: {} {} ({})'.format(member.first_name, member.last_name, member.id))
utils_stats.calc_card_scans()
return Response(200)