diff --git a/stats/templates/users_stats.html b/stats/templates/users_stats.html new file mode 100644 index 00000000..4222dd6f --- /dev/null +++ b/stats/templates/users_stats.html @@ -0,0 +1,41 @@ +{% extends 'c3_base.html' %} + +{% block head_title %}Users stats{% endblock %} +{% block panel %} +

Users stats

+ Last updated: +
+
+

All

+
+

Users count:

+
+
+{% endblock %} +{% block c3script %} + +{% endblock %} diff --git a/stats/urls.py b/stats/urls.py index ac066db2..c6ba165c 100644 --- a/stats/urls.py +++ b/stats/urls.py @@ -7,7 +7,9 @@ urlpatterns = [ url(r'^api/apps/$', cache_page(5 * 60)(views.app_stats_api), name='api_app_stats'), url(r'^api/reimb/$', cache_page(5 * 60)(views.reimb_stats_api), name='api_reimb_stats'), + url(r'^api/users/$', cache_page(5 * 60)(views.users_stats_api), name='api_users_stats'), url(r'^apps/$', views.AppStats.as_view(), name='app_stats'), + url(r'^users/$', views.UsersStats.as_view(), name='users_stats'), ] diff --git a/stats/views.py b/stats/views.py index 75f9d981..e84b745b 100644 --- a/stats/views.py +++ b/stats/views.py @@ -9,6 +9,7 @@ from applications import models as a_models from applications.models import Application, STATUS, APP_CONFIRMED, GENDERS from user.mixins import is_organizer, IsOrganizerMixin +from user.models import User from collections import defaultdict @@ -17,7 +18,7 @@ def stats_tabs(): - tabs = [('Applications', reverse('app_stats'), False), ] + tabs = [('Applications', reverse('app_stats'), False), ('Users', reverse('users_stats'), False)] if getattr(settings, 'REIMBURSEMENT_ENABLED', False): tabs.append(('Reimbursements', reverse('reimb_stats'), False)) return tabs @@ -164,6 +165,27 @@ def app_stats_api(request): ) +@is_organizer +def users_stats_api(request): + users = list(User.objects.all()) + users_count = defaultdict(int) + for u in users: + users_count["Volunteers"] += u.is_volunteer + users_count["Directors"] += u.is_director + users_count["Organizers"] += u.is_organizer + users_count["Hackers"] += not (u.is_volunteer or u.is_director or u.is_organizer) + + users_count = [{'user_type': x, 'Users': v} for (x, v) in users_count.items()] + + return JsonResponse( + { + 'update_time': timezone.now(), + 'users': users_count, + 'users_count': len(users) + } + ) + + class AppStats(IsOrganizerMixin, TabsView): template_name = 'application_stats.html' @@ -176,3 +198,10 @@ class ReimbStats(IsOrganizerMixin, TabsView): def get_current_tabs(self): return stats_tabs() + + +class UsersStats(IsOrganizerMixin, TabsView): + template_name = 'users_stats.html' + + def get_current_tabs(self): + return stats_tabs()