Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Users stats #306

Merged
merged 7 commits into from
Apr 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions stats/templates/users_stats.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{% extends 'c3_base.html' %}

{% block head_title %}Users stats{% endblock %}
{% block panel %}
<h1>Users stats</h1>
<small class="pull-right"><b>Last updated:</b> <span id="update_date"></span></small>
<div class="row">
<div class="col-md-6">
<h3>All</h3>
<div id="users_stats"></div>
<p><b>Users count:</b> <span id="users_count"></span></p>
</div>
</div>
{% endblock %}
{% block c3script %}
<script>
$.getJSON('{% url 'api_users_stats' %}', function (data) {
c3.generate({
bindto: '#users_stats',
data: {
json: data['users'],
type: 'bar',
keys: {
x: 'user_type',
value: ['Users']
},
},

axis: {
x: {
type: 'category'
}
}
});
$('#update_date').html(data['update_time']);
$('#users_count').html(data['users_count']);
})
;

</script>
{% endblock %}
2 changes: 2 additions & 0 deletions stats/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),

]

Expand Down
31 changes: 30 additions & 1 deletion stats/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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'

Expand All @@ -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()