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

Adding Checkin stats #307

Merged
merged 22 commits into from
Apr 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
e068c61
users stats
raquelpanapalen Apr 12, 2020
a60468e
Merge pull request #34 from raquelpanapalen/raquelpanapalen-patch-34
raquelpanapalen Apr 12, 2020
6fdeb87
user stats
raquelpanapalen Apr 12, 2020
84f159a
Merge pull request #35 from raquelpanapalen/raquelpanapalen-patch-35
raquelpanapalen Apr 12, 2020
31f2562
checkin stats
raquelpanapalen Apr 14, 2020
652ee62
Merge pull request #36 from raquelpanapalen/raquelpanapalen-patch-36
raquelpanapalen Apr 14, 2020
64bb8d7
updating
raquelpanapalen Apr 14, 2020
eab1c1b
Merge pull request #37 from raquelpanapalen/raquelpanapalen-patch-37
raquelpanapalen Apr 14, 2020
cd50ca1
checkin stats
raquelpanapalen Apr 14, 2020
cbf0758
Merge pull request #38 from raquelpanapalen/raquelpanapalen-patch-38
raquelpanapalen Apr 14, 2020
7de8c58
Update users_stats.html
raquelpanapalen Apr 14, 2020
18d2765
checkin
raquelpanapalen Apr 14, 2020
4667be5
Merge pull request #39 from raquelpanapalen/raquelpanapalen-patch-39
raquelpanapalen Apr 14, 2020
bb47667
Merge branch 'master' into master
casassg Apr 15, 2020
2eafd2c
checkin stats
raquelpanapalen Apr 15, 2020
526989e
Merge pull request #40 from raquelpanapalen/raquelpanapalen-patch-40
raquelpanapalen Apr 15, 2020
7740d49
updating files
raquelpanapalen Apr 15, 2020
2ee227f
Merge pull request #41 from raquelpanapalen/raquelpanapalen-patch-41
raquelpanapalen Apr 15, 2020
b48d48f
instead of datetime.now(), timezone.now()
raquelpanapalen Apr 15, 2020
84ee341
Merge pull request #42 from raquelpanapalen/raquelpanapalen-patch-42
raquelpanapalen Apr 15, 2020
b73866e
updating files
raquelpanapalen Apr 15, 2020
1c81413
Merge pull request #43 from raquelpanapalen/raquelpanapalen-patch-43
raquelpanapalen Apr 15, 2020
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
5 changes: 2 additions & 3 deletions checkin/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

from django.db import models
# Create your models here.
from django.utils.datetime_safe import datetime

from django.utils import timezone
from applications.models import APP_CONFIRMED, APP_ATTENDED
from user.models import User

Expand All @@ -15,7 +14,7 @@ class CheckIn(models.Model):

def save(self, force_insert=False, force_update=False, using=None,
update_fields=None):
self.update_time = datetime.now()
self.update_time = timezone.now()
super(CheckIn, self).save(force_insert, force_update, using,
update_fields)
self.application.status = APP_ATTENDED
Expand Down
49 changes: 49 additions & 0 deletions stats/templates/checkin_stats.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{% extends 'c3_base.html' %}

{% block head_title %}Check-in stats{% endblock %}
{% block panel %}
<h1>Check-in stats</h1>
<small class="pull-right"><b>Last updated:</b> <span id="update_date"></span></small>
<div class="row">
<div class="col-md-12">
<div id="timeseries"></div>
<p><b>Checkin count:</b> <span id="checkin_count"></span></p>
</div>
</div>
{% endblock %}
{% block c3script %}
<script>
$.getJSON('{% url 'api_checkin_stats' %}', function (data) {
var timeseries_dict = []
data['timeseries'].forEach(element => {
timeseries_dict.push({
hours: new Date(element['hour']),
checkins: element['checkins']
});
});
c3.generate({
bindto: '#timeseries',
data: {
json: timeseries_dict,
keys: {
x: 'hours',
xFormat: '%Y-%m-%d %H:%M:%S',
value: ['checkins']
}
},

axis: {
x: {
type: 'timeseries',
tick: {
format: 'Day %d, %Hh'
}
}
}
});
$('#update_date').html(data['update_time']);
$('#checkin_count').html(data['checkin_count']);
});

</script>
{% endblock %}
2 changes: 2 additions & 0 deletions stats/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
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'^api/checkin/$', cache_page(5 * 60)(views.checkin_stats_api), name='api_checkin_stats'),
url(r'^apps/$', views.AppStats.as_view(), name='app_stats'),
url(r'^users/$', views.UsersStats.as_view(), name='users_stats'),
url(r'^checkin/$', views.CheckinStats.as_view(), name='checkin_stats'),

]

Expand Down
30 changes: 27 additions & 3 deletions stats/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.conf import settings
from django.db.models import Count, Sum
from django.db.models.functions import TruncDate
from django.db.models.functions import TruncDate, TruncHour
from django.http import JsonResponse
from django.urls import reverse
from django.utils import timezone
Expand All @@ -10,6 +10,7 @@
from applications.models import Application, STATUS, APP_CONFIRMED, GENDERS
from user.mixins import is_organizer, IsOrganizerMixin
from user.models import User
from checkin.models import CheckIn

from collections import defaultdict

Expand All @@ -18,7 +19,8 @@


def stats_tabs():
tabs = [('Applications', reverse('app_stats'), False), ('Users', reverse('users_stats'), False)]
tabs = [('Applications', reverse('app_stats'), False), ('Users', reverse('users_stats'), False),
('Check-in', reverse('checkin_stats'), False)]
if getattr(settings, 'REIMBURSEMENT_ENABLED', False):
tabs.append(('Reimbursements', reverse('reimb_stats'), False))
return tabs
Expand Down Expand Up @@ -181,7 +183,22 @@ def users_stats_api(request):
{
'update_time': timezone.now(),
'users': users_count,
'users_count': len(users)
'users_count': len(users),
}
)


@is_organizer
def checkin_stats_api(request):
timeseries = CheckIn.objects.all().annotate(hour=TruncHour('update_time')) \
.values('hour').annotate(checkins=Count('hour'))
checkin_count = len(CheckIn.objects.all())

return JsonResponse(
{
'update_time': timezone.now(),
'timeseries': list(timeseries),
'checkin_count': checkin_count
}
)

Expand All @@ -205,3 +222,10 @@ class UsersStats(IsOrganizerMixin, TabsView):

def get_current_tabs(self):
return stats_tabs()


class CheckinStats(IsOrganizerMixin, TabsView):
template_name = 'checkin_stats.html'

def get_current_tabs(self):
return stats_tabs()