Refactor again

This commit is contained in:
Chris Hill-Scott
2020-01-09 15:54:42 +00:00
parent 2f6a8a5864
commit fda979a5f2

View File

@@ -45,28 +45,26 @@ class Job(JSONModel):
def scheduled(self): def scheduled(self):
return self.status == 'scheduled' return self.status == 'scheduled'
@property def _aggregate_statistics(self, *statuses):
def notifications_delivered(self):
return sum( return sum(
outcome['count'] for outcome in self._dict['statistics'] 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 @property
def notifications_failed(self): def notifications_failed(self):
return sum( return self._aggregate_statistics(
outcome['count'] for outcome in self._dict['statistics'] 'failed', 'technical-failure', 'temporary-failure',
if outcome['status'] in { 'permanent-failure', 'cancelled',
'failed', 'technical-failure', 'temporary-failure',
'permanent-failure', 'cancelled',
}
) )
@property @property
def notifications_requested(self): def notifications_requested(self):
return sum( return self._aggregate_statistics()
outcome['count'] for outcome in self._dict['statistics']
)
@property @property
def notifications_sent(self): def notifications_sent(self):