From fee90fd966e97e01c571fbaa07761cf54f37f952 Mon Sep 17 00:00:00 2001 From: Mitch Riedstra Date: Tue, 10 Oct 2017 23:30:41 -0400 Subject: Additional statistics added to the driver summary page --- app/dispatch/views.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'app/dispatch/views.py') diff --git a/app/dispatch/views.py b/app/dispatch/views.py index ea03355..106d20b 100644 --- a/app/dispatch/views.py +++ b/app/dispatch/views.py @@ -103,11 +103,25 @@ class DriverDetail(LoadDateSort): # Shit gets fucky with super() really fast, but this seems to work context = super(DriverDetail, self).get_context_data(**kwargs) + stats = {}; + stats['count'], stats['average'], stats['sum'] = (0,0,0) + stats['incomplete_loads'] = 0 + loads_by_date = context['loads'] for d in loads_by_date: - print(d) - for l in d: - print(l) + # Iterate over the array for the given date + for l in loads_by_date[d]: + stats['count'] += 1 + stats['sum'] += l.amount + if l.amount == 0: + stats['incomplete_loads'] += 1 + + if stats['sum'] is not 0 and stats['count'] is not 0: + stats['average'] = stats['sum']/stats['count'] + + + # Add our stats to the context so we can use it in the template + context['stats'] = stats return context -- cgit v1.2.3