Skip to content

Commit

Permalink
better email stats display
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Oppenheimer authored and Aaron Oppenheimer committed Jun 9, 2024
1 parent 41cdcf2 commit 60896ac
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 15 deletions.
2 changes: 1 addition & 1 deletion static/js/band_stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function initStats(container) {
}
Highcharts.chart(container, {
title: {
text: 'Gigs Over Time'
text: 'Scheduled Gigs'
},
xAxis: {
title: {
Expand Down
22 changes: 15 additions & 7 deletions stats/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,25 @@ def get_emails_for_date(date=None, band=None):
args['created'] = date

if band:
args['band'] = band
args['metric__band'] = band

val = Stat.objects.filter(**args).aggregate(Sum('value'))['value__sum']

return val if val else 0

def get_emails_for_all_bands(maxnum=None):
x = Stat.objects.filter(metric__name='Number of Emails Sent').values('metric__band').annotate(emails=Sum('value'))
the_list = [[Band.objects.get(id=s['metric__band']),s['emails']] for s in x]
the_list.sort(key = lambda d: -d[1])
""" returns list of [band, all-time-emails-sent, today-emails-sent]"""

x = Stat.objects.filter(metric__name='Number of Emails Sent').values('metric__band').annotate(emails=Sum('value')).order_by('-emails')
if maxnum:
return the_list[:maxnum]
else:
return the_list
x = x[:maxnum]

the_list = []
today = datetime.now().date()
for s in x:
""" get emails for today for the band """
band = Band.objects.get(id=s['metric__band'])
now = get_emails_for_date(date=today, band=band)
the_list.append([band, s['emails'], now])

return the_list
6 changes: 3 additions & 3 deletions stats/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ def get_context_data(self, **kwargs):
context['gigs_over_time_data'] = json.dumps(get_all_gigs_over_time_stats(), default=dateconverter)

# get the email totals for all bands
data = get_emails_for_all_bands()
y = [[x[0].name, x[1]] for x in data]
context['emails_all_bands'] = y
data = get_emails_for_all_bands(10)
y = [[x[0].name, x[1],x[2]] for x in data]
context['top_email_bands'] = y

return context
19 changes: 15 additions & 4 deletions templates/stats/stats.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,25 @@
<div>
<div class="mx-auto col-lg-8 col-md-10 col-sm-12">
<div class="row">
Top email senders:<br>
<div class="col-4">
{% trans "Top email senders" %}
</div>
<div class="col-4">
{% trans "All Time" %}
</div>
<div class="col-4">
{% trans "Today" %}
</div>
</div>
{% for stat in emails_all_bands %}
{% for stat in top_email_bands %}
<div class="row" style="padding-top: 5px; {% cycle '' 'background:#f5f5f5;' %}">
<div class="col-3">
<div class="col-4">
{{ stat.0 }}
</div>
<div class="col-3">
<div class="col-4">
{{ stat.2 }}
</div>
<div class="col-4">
{{ stat.1 }}
</div>
</div>
Expand Down

0 comments on commit 60896ac

Please sign in to comment.