Skip to content

Commit

Permalink
created api route /hackathon/get/stats to return public hackathon sta…
Browse files Browse the repository at this point in the history
…tisitcs to logged in users
  • Loading branch information
jrdbnntt committed Jan 29, 2017
1 parent 3d94ca4 commit 91460dc
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
1 change: 1 addition & 0 deletions api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
url(r'hackathon/get/schedule_items$', views.hackathon.get.ScheduleItemsView.as_view()),
url(r'hackathon/get/sponsors$', views.hackathon.get.SponsorsView.as_view()),
url(r'hackathon/get/updates$', views.hackathon.get.UpdatesView.as_view()),
url(r'hackathon/get/stats$', views.hackathon.get.StatsView.as_view()),

url(r'user/login$', views.user.LogInView.as_view(), name='user-login'),
url(r'user/register$', views.user.RegisterView.as_view(), name='user-register'),
Expand Down
1 change: 1 addition & 0 deletions api/views/hackathon/get/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
from .schedule_items import ScheduleItemsView
from .sponsors import SponsorsView
from .updates import UpdatesView
from .stats import StatsView
60 changes: 60 additions & 0 deletions api/views/hackathon/get/stats.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
"""
Get public statistics for current hackathon
"""
from django import forms
from django.http.request import HttpRequest
from hackfsu_com.views.generic import ApiView
from hackfsu_com.util import acl
from api.models import Hackathon, HackerInfo, MentorInfo, JudgeInfo, OrganizerInfo, AttendeeStatus


class ResponseForm(forms.Form):
hackathon_name = forms.CharField()
hackathon_start = forms.DateField()
hackathon_end = forms.DateField()
hackers_registered = forms.IntegerField()
hackers_approved = forms.IntegerField()
hackers_checked_in = forms.IntegerField()
mentors_registered = forms.IntegerField()
mentors_approved = forms.IntegerField()
mentors_checked_in = forms.IntegerField()
judges_registered = forms.IntegerField()
judges_approved = forms.IntegerField()
judges_checked_in = forms.IntegerField()
organizers_registered = forms.IntegerField()
organizers_approved = forms.IntegerField()
organizers_checked_in = forms.IntegerField()


class StatsView(ApiView):
response_form_class = ResponseForm
http_method_names = ['get']
access_manager = acl.AccessManager(acl_accept=[acl.group_user])

def work(self, request: HttpRequest, req: dict, res: dict):
ch = Hackathon.objects.current()

res['hackathon_name'] = ch.name
res['hackathon_start'] = ch.start_date
res['hackathon_end'] = ch.end_date

res['hackers_registered'] = HackerInfo.objects.filter(hackathon=ch).count()
res['hackers_approved'] = HackerInfo.objects.filter(hackathon=ch, approved=True).count()
res['hackers_checked_in'] =\
AttendeeStatus.objects.filter(hackathon=ch, checked_in=True, hackerinfo__isnull=False).count()

res['mentors_registered'] = MentorInfo.objects.filter(hackathon=ch).count()
res['mentors_approved'] = MentorInfo.objects.filter(hackathon=ch, approved=True).count()
res['mentors_checked_in'] = \
AttendeeStatus.objects.filter(hackathon=ch, checked_in=True, mentorinfo__isnull=False).count()

res['judges_registered'] = JudgeInfo.objects.filter(hackathon=ch).count()
res['judges_approved'] = JudgeInfo.objects.filter(hackathon=ch, approved=True).count()
res['judges_checked_in'] = \
AttendeeStatus.objects.filter(hackathon=ch, checked_in=True, judgeinfo__isnull=False).count()

res['organizers_registered'] = OrganizerInfo.objects.filter(hackathon=ch).count()
res['organizers_approved'] = OrganizerInfo.objects.filter(hackathon=ch, approved=True).count()
res['organizers_checked_in'] = \
AttendeeStatus.objects.filter(hackathon=ch, checked_in=True, organizerinfo__isnull=False).count()

0 comments on commit 91460dc

Please sign in to comment.