Add stats endpoint for tracking computer logins

This commit is contained in:
Tanner Collin 2020-07-26 00:04:07 +00:00
parent 1e5250eb70
commit 0f826015f7
2 changed files with 12 additions and 1 deletions

View File

@ -23,6 +23,7 @@ DEFAULTS = {
'bay_110_temp': None, 'bay_110_temp': None,
'minecraft_players': [], 'minecraft_players': [],
'card_scans': 0, 'card_scans': 0,
'track': {},
} }
def changed_card(): def changed_card():

View File

@ -16,7 +16,7 @@ from rest_auth.views import PasswordChangeView, PasswordResetView, PasswordReset
from rest_auth.registration.views import RegisterView from rest_auth.registration.views import RegisterView
from fuzzywuzzy import fuzz, process from fuzzywuzzy import fuzz, process
from collections import OrderedDict from collections import OrderedDict
import datetime import datetime, time
import requests import requests
@ -421,6 +421,16 @@ class StatsViewSet(viewsets.ViewSet, List):
except KeyError: except KeyError:
raise exceptions.ValidationError(dict(data='This field is required.')) raise exceptions.ValidationError(dict(data='This field is required.'))
@action(detail=False, methods=['post'])
def track(self, request):
if 'name' in request.data:
track = cache.get('track', {})
track[request.data['name']] = time.time()
cache.set('track', track)
return Response(200)
else:
raise exceptions.ValidationError(dict(paste='This field is required.'))
class MemberCountViewSet(Base, List): class MemberCountViewSet(Base, List):
pagination_class = None pagination_class = None