mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-06 16:48:24 -04:00
Refactor stats calcualtions
This commit is contained in:
@@ -1,4 +1,3 @@
|
|||||||
from collections import defaultdict
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
from notifications_utils.letter_timings import (
|
from notifications_utils.letter_timings import (
|
||||||
@@ -46,33 +45,28 @@ class Job(JSONModel):
|
|||||||
def scheduled(self):
|
def scheduled(self):
|
||||||
return self.status == 'scheduled'
|
return self.status == 'scheduled'
|
||||||
|
|
||||||
@cached_property
|
|
||||||
def statistics(self):
|
|
||||||
results = defaultdict(int)
|
|
||||||
for outcome in self._dict['statistics']:
|
|
||||||
if outcome['status'] in [
|
|
||||||
'failed', 'technical-failure', 'temporary-failure',
|
|
||||||
'permanent-failure', 'cancelled'
|
|
||||||
]:
|
|
||||||
results['failed'] += outcome['count']
|
|
||||||
if outcome['status'] in ['sending', 'pending', 'created']:
|
|
||||||
results['sending'] += outcome['count']
|
|
||||||
if outcome['status'] in ['delivered', 'sent']:
|
|
||||||
results['delivered'] += outcome['count']
|
|
||||||
results['requested'] += outcome['count']
|
|
||||||
return results
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def notifications_delivered(self):
|
def notifications_delivered(self):
|
||||||
return self.statistics['delivered']
|
return sum(
|
||||||
|
outcome['count'] for outcome in self._dict['statistics']
|
||||||
|
if outcome['status'] in {'delivered', 'sent'}
|
||||||
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def notifications_failed(self):
|
def notifications_failed(self):
|
||||||
return self.statistics['failed']
|
return sum(
|
||||||
|
outcome['count'] for outcome in self._dict['statistics']
|
||||||
|
if outcome['status'] in {
|
||||||
|
'failed', 'technical-failure', 'temporary-failure',
|
||||||
|
'permanent-failure', 'cancelled',
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def notifications_requested(self):
|
def notifications_requested(self):
|
||||||
return self.statistics['requested']
|
return sum(
|
||||||
|
outcome['count'] for outcome in self._dict['statistics']
|
||||||
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def notifications_sent(self):
|
def notifications_sent(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user