aboutsummaryrefslogtreecommitdiff
path: root/app/dispatch/views.py
diff options
context:
space:
mode:
Diffstat (limited to 'app/dispatch/views.py')
-rw-r--r--app/dispatch/views.py20
1 files changed, 17 insertions, 3 deletions
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