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 --- .../templates/dispatch/drivers/detail.html | 36 ++++++++++++++++++++++ app/dispatch/templatetags/dynamic_key.py | 4 +-- app/dispatch/views.py | 20 ++++++++++-- 3 files changed, 55 insertions(+), 5 deletions(-) (limited to 'app/dispatch') diff --git a/app/dispatch/templates/dispatch/drivers/detail.html b/app/dispatch/templates/dispatch/drivers/detail.html index 24afcc1..2c28064 100644 --- a/app/dispatch/templates/dispatch/drivers/detail.html +++ b/app/dispatch/templates/dispatch/drivers/detail.html @@ -10,6 +10,37 @@ +
+
+ + + + + + + + + + + + + +
Number of LoadsTotal Load costAverage Load cost
{{stats.count}}{{stats.sum}}{{stats.average|stringformat:".3f"}}
+
+
+ +{% if stats.incomplete_loads > 0 %} +
+
+

+ + Note: One or more loads has a 0 amount that needs attention + +

+

+
+{% endif %} +
arrow_back Prev @@ -20,6 +51,7 @@
+ {% load dynamic_key %} {% for date in loads %}
@@ -37,7 +69,11 @@ {% for load in loads|keyvalue:date %} {{ load.company.name }} + {% if load.amount == 0 %} + {{ load.amount }} + {% else %} {{ load.amount }} + {% endif %} Edit View diff --git a/app/dispatch/templatetags/dynamic_key.py b/app/dispatch/templatetags/dynamic_key.py index 6a79707..fdd7f10 100644 --- a/app/dispatch/templatetags/dynamic_key.py +++ b/app/dispatch/templatetags/dynamic_key.py @@ -3,5 +3,5 @@ from django import template register = template.Library() @register.filter -def keyvalue(dict, key): - return dict[key] \ No newline at end of file +def keyvalue(dictionary, key): + return dictionary.get(key) 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