diff options
| author | Mitch Riedstra <Mitch@riedstra.us> | 2017-10-10 23:30:41 -0400 |
|---|---|---|
| committer | Mitch Riedstra <Mitch@riedstra.us> | 2017-10-10 23:30:41 -0400 |
| commit | fee90fd966e97e01c571fbaa07761cf54f37f952 (patch) | |
| tree | ebf79990cab9edc49c509d4127c3965abfc570c3 /app/dispatch/views.py | |
| parent | 926acc9648b8d6093caf16a9624fd9e3e25e3e50 (diff) | |
| download | dispatch-tracker-fee90fd966e97e01c571fbaa07761cf54f37f952.tar.gz dispatch-tracker-fee90fd966e97e01c571fbaa07761cf54f37f952.tar.xz | |
Additional statistics added to the driver summary page
Diffstat (limited to 'app/dispatch/views.py')
| -rw-r--r-- | app/dispatch/views.py | 20 |
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 |
