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

Add stats (Origin stats) #295

Merged
merged 10 commits into from
Mar 22, 2020
48 changes: 48 additions & 0 deletions stats/templates/application_stats.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ <h3>Gender</h3>
<div id="gender_stats"></div>
</div>
</div>
<h2>Origin</h2>

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

<div class="row">
Expand Down Expand Up @@ -189,6 +201,42 @@ <h3>Confirmed only</h3>
}
}
});
c3.generate({
bindto: '#origin_stats',
data: {
json: data['origin'],
keys: {
x: 'origin',
value: ['applications']
},
type: 'bar'

},

axis: {
x: {
type: 'category'
}
}
});
c3.generate({
bindto: '#origin_stats_confirmed',
data: {
json: data['origin_confirmed'],
keys: {
x: 'origin',
value: ['applications']
},
type: 'bar'

},

axis: {
x: {
type: 'category'
}
}
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accepting, but this may get difficult to read when there are a lot of people from diverse origins.

A suggestion would be to show top 5-10 in the graph + the rest as a table (hidden by default, toggle to see it).

$('#other_diet').html(data['other_diet']);
$('#update_date').html(data['update_time']);
$('#app_count').html(data['app_count']);
Expand Down
10 changes: 10 additions & 0 deletions stats/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ def app_stats_api(request):
gender_count = Application.objects.all().values('gender') \
.annotate(applications=Count('gender'))
gender_count = map(lambda x: dict(gender_name=GENDER_DICT[x['gender']], **x), gender_count)

origin_count = Application.objects.all().values('origin') \
.annotate(applications=Count('origin')) \
.order_by('applications')[:10]
origin_count_confirmed = Application.objects.filter(status=APP_CONFIRMED).values('origin') \
.annotate(applications=Count('origin')) \
.order_by('applications')[:10]

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 @@ -87,6 +95,8 @@ def app_stats_api(request):
'shirt_count_confirmed': list(shirt_count_confirmed),
'timeseries': list(timeseries),
'gender': list(gender_count),
'origin': list(origin_count),
'origin_confirmed': list(origin_count_confirmed),
'diet': list(diet_count),
'diet_confirmed': list(diet_count_confirmed),
'other_diet': '<br>'.join([el['other_diet'] for el in other_diets if el['other_diet']])
Expand Down