From fda979a5f2a94626cab54cfcb9895f9bb9187236 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Thu, 9 Jan 2020 15:54:42 +0000 Subject: [PATCH] Refactor again --- app/models/job.py | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/app/models/job.py b/app/models/job.py index 9a7344bf6..3bd314f31 100644 --- a/app/models/job.py +++ b/app/models/job.py @@ -45,28 +45,26 @@ class Job(JSONModel): def scheduled(self): return self.status == 'scheduled' - @property - def notifications_delivered(self): + def _aggregate_statistics(self, *statuses): return sum( outcome['count'] for outcome in self._dict['statistics'] - if outcome['status'] in {'delivered', 'sent'} + if not statuses or outcome['status'] in statuses ) + @property + def notifications_delivered(self): + return self._aggregate_statistics('delivered', 'sent') + @property def notifications_failed(self): - return sum( - outcome['count'] for outcome in self._dict['statistics'] - if outcome['status'] in { - 'failed', 'technical-failure', 'temporary-failure', - 'permanent-failure', 'cancelled', - } + return self._aggregate_statistics( + 'failed', 'technical-failure', 'temporary-failure', + 'permanent-failure', 'cancelled', ) @property def notifications_requested(self): - return sum( - outcome['count'] for outcome in self._dict['statistics'] - ) + return self._aggregate_statistics() @property def notifications_sent(self):