Simplify failure rate by building separate query

This commit is contained in:
Pea Tyczynska
2019-12-03 16:18:07 +00:00
parent 53efd87e28
commit cfbb080f57
9 changed files with 77 additions and 37 deletions

View File

@@ -24,8 +24,7 @@ def format_statistics(statistics):
def get_rate_of_permanent_failures_for_service(statistics, threshold=100):
counts = {"permanent_failure": 0, "all_other_statuses": 0}
for row in statistics:
if row.notification_type == 'sms':
_count_if_status_is_permanent_failure_from_row(counts, row)
_count_if_status_is_permanent_failure_from_row(counts, row)
if counts['permanent_failure'] + counts['all_other_statuses'] >= threshold:
rate = counts['permanent_failure'] / (counts['permanent_failure'] + counts['all_other_statuses'])