diff --git a/SAS/TMSS/backend/src/tmss/tmssapp/adapters/reports.py b/SAS/TMSS/backend/src/tmss/tmssapp/adapters/reports.py index 378717b21ce21f4853f4998f59f64df7eaf3f6b6..9db6732d774c59fbe4757b32fe1ec5a7916c84e1 100644 --- a/SAS/TMSS/backend/src/tmss/tmssapp/adapters/reports.py +++ b/SAS/TMSS/backend/src/tmss/tmssapp/adapters/reports.py @@ -673,7 +673,6 @@ class FailureReport(): .annotate(count=Count(f'{field_name}__value'), duration_lost_event=Sum(Coalesce(F('stop'), datetime.utcnow()) - F('start')))) - for d in group_aggregates: # determine total duration of affected scheduling units system_events = self.system_events.filter(**{f'{field_name}__value': d[f'{field_name}__value']}) @@ -687,7 +686,17 @@ class FailureReport(): 'percent_of_wall_time_lost_event': 100 * d['duration_lost_event'].total_seconds() / wall_time, 'percent_of_wall_time_lost_on_sky': total_on_sky_duration_lost.total_seconds() / wall_time if total_on_sky_duration_lost else 0}) + total_failure_event_time = sum([d['duration_lost_event'] for d in group_aggregates]) + total_failure_on_sky_time = sum([d['duration_lost_on_sky'] for d in group_aggregates]) + total_failure_count = sum(d['count'] for d in group_aggregates) + + for d in group_aggregates: + d.update({'percent_of_total_failure_time_lost_event': 100 * d['duration_lost_event'] / total_failure_event_time if total_failure_event_time else 0, + 'percent_of_total_failure_time_lost_on_sky': 100 * d['duration_lost_on_sky'] / total_failure_on_sky_time if total_failure_on_sky_time else 0, + 'percent_of_total_failure_count': 100 * d['count'] / total_failure_count if total_failure_count else 0}) + aggregates[f'by_{field_name}'] = group_aggregates + return aggregates def _get_lost_observing_time_histogram(self, ignore_time_range=True) -> {}: