Skip to content

Commit

Permalink
cleaned up a few stats pages
Browse files Browse the repository at this point in the history
  • Loading branch information
jsayles committed Mar 31, 2020
1 parent 7a21610 commit 35b052e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
2 changes: 1 addition & 1 deletion staff/templates/staff/stats/monthly.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

{% block content %}

<h4>Stats - Monthly members:</h4>
<h4>Stats - Monthly members: {{ target_date }}</h4>

<div class='titles'>
<strong>Total Monthly Members:</strong> {{ memberships.count }} &nbsp;&nbsp;
Expand Down
3 changes: 2 additions & 1 deletion staff/urls/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
urlpatterns = [
path('daily/', stats.daily, name='daily'),
path('history/', stats.history, name='history'),
path('monthly/', stats.monthly, name='monthly'),
path('monthly/', stats.monthly_today, name='monthly'),
path('monthly/<int:year>/<int:month>/<int:day>/', stats.monthly_date, name='monthly_date'),
path('gender/', stats.gender, name='gender'),
path('neighborhood/', stats.neighborhood, name='neighborhood'),
path('memberships/', stats.memberships, name='memberships'),
Expand Down
28 changes: 20 additions & 8 deletions staff/views/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,27 @@ def history(request):
return render(request, 'staff/stats/history.html', context)


def monthly_today(request):
today = localtime(now()).date()
return HttpResponseRedirect(reverse('staff:stats:monthly_date', args=[], kwargs={'year': today.year, 'month': today.month, 'day': today.day}))


@staff_member_required
def monthly(request):
def monthly_date(request, year, month, day):
target_date = date(year=int(year), month=int(month), day=int(day))

# Pull all the monthly members
memberships = Membership.objects.active_individual_memberships()
memberships = Membership.objects.active_memberships(target_date)
# memberships = Membership.objects.active_individual_memberships)
# memberships = Membership.objects.filter(end_date__isnull=True).order_by('start_date')
total_income = 0
# for membership in memberships:
# total_income = total_income + membership.monthly_rate
context = {'memberships': memberships, 'total_income': total_income}
for membership in memberships:
total_income = total_income + membership.monthly_rate()
context = {
'target_date': target_date,
'memberships': memberships,
'total_income': total_income,
}
return render(request, 'staff/stats/monthly.html', context)


Expand Down Expand Up @@ -313,7 +325,7 @@ def graph_members(days):
member_max = day['value']
if member_min == 0 or day['value'] < member_min:
member_min = day['value']
member_avg = member_total / len(days)
member_avg = round(member_total / len(days), 2)
return (member_min, member_max, member_avg, days)


Expand All @@ -334,7 +346,7 @@ def graph_income(days):
income_min = membership_income
day['membership'] = membership_count
day['value'] = membership_income
income_avg = income_total / len(days)
income_avg = round(income_total / len(days), 2)
return (income_min, income_max, income_avg, days)


Expand All @@ -350,7 +362,7 @@ def graph_amv(days):
member_max = day['value']
if member_min == 0 or day['value'] < member_min:
member_min = day['value']
member_avg = member_total / len(days)
member_avg = round(member_total / len(days), 2)
return (min_v, max_v, avg_v, days)


Expand Down

0 comments on commit 35b052e

Please sign in to comment.