Skip to content

Commit

Permalink
Merge pull request #302 from raquelpanapalen/master
Browse files Browse the repository at this point in the history
Adding graduation year stats
  • Loading branch information
Casassarnau authored Mar 24, 2020
2 parents cce08ff + 9e28a71 commit c844b5b
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
55 changes: 55 additions & 0 deletions stats/templates/application_stats.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,19 @@ <h3>Confirmed only</h3>
<div id="university_stats_confirmed"></div>
</div>
</div>
</div>
<h2>Graduation year</h2>

<div class="row">
<div class="col-md-6">
<h3>All</h3>
<div id="graduation_year_stats"></div>
</div>
<div class="col-md-6">
<h3>Confirmed only</h3>
<div id="graduation_year_stats_confirmed"></div>
</div>
</div>
<h2>T-Shirts sizes</h2>

<div class="row">
Expand Down Expand Up @@ -285,6 +298,48 @@ <h3>Confirmed only</h3>
}
}
});
var grad_year_data = {};
var grad_years = [];
$(data['graduation_year']).each(function (c, e) {
grad_years.push(e.graduation_year);
grad_year_data[e.graduation_year] = e.applications;
});
c3.generate({
bindto: '#graduation_year_stats',
data: {
json: grad_year_data,
type: 'donut'

},
donut: {
label: {
format: function (value, ratio, id) {
return value;
}
}
}
});
var grad_year_confirmed_data = {};
var grad_years_confirmed = [];
$(data['graduation_year_confirmed']).each(function (c, e) {
grad_years_confirmed.push(e.graduation_year);
grad_year_confirmed_data[e.graduation_year] = e.applications;
});
c3.generate({
bindto: '#graduation_year_stats_confirmed',
data: {
json: grad_year_confirmed_data,
type: 'donut'

},
donut: {
label: {
format: function (value, ratio, id) {
return value;
}
}
}
});
$('#other_diet').html(data['other_diet']);
$('#update_date').html(data['update_time']);
$('#app_count').html(data['app_count']);
Expand Down
7 changes: 7 additions & 0 deletions stats/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ def app_stats_api(request):
.annotate(applications=Count('university')) \
.order_by('-applications')[:10]

grad_year_count = Application.objects.all().values('graduation_year') \
.annotate(applications=Count('graduation_year'))
grad_year_count_confirmed = Application.objects.filter(status=APP_CONFIRMED).values('graduation_year') \
.annotate(applications=Count('graduation_year'))

tshirt_dict = dict(a_models.TSHIRT_SIZES)
shirt_count = map(
lambda x: {'tshirt_size': tshirt_dict.get(x['tshirt_size'], 'Unknown'), 'applications': x['applications']},
Expand Down Expand Up @@ -104,6 +109,8 @@ def app_stats_api(request):
'gender': list(gender_count),
'university': list(university_count),
'university_confirmed': list(university_count_confirmed),
'graduation_year': list(grad_year_count),
'graduation_year_confirmed': list(grad_year_count_confirmed),
'origin': list(origin_count),
'origin_confirmed': list(origin_count_confirmed),
'diet': list(diet_count),
Expand Down

0 comments on commit c844b5b

Please sign in to comment.