Skip to content
Snippets Groups Projects
Commit 65714d50 authored by Reinder Kraaij's avatar Reinder Kraaij :eye:
Browse files

Merge branch 'TMSS-662' into 'master'

TMSS-662: fix aggregation issue when SU has no on_sky_duration

Closes TMSS-662

See merge request !1248
parents 0a4ebcbe 288f5777
No related branches found
No related tags found
1 merge request!1248TMSS-662: fix aggregation issue when SU has no on_sky_duration
...@@ -687,13 +687,13 @@ class FailureReport(): ...@@ -687,13 +687,13 @@ class FailureReport():
system_events = self.system_events.filter(**{f'{field_name}__value': d[f'{field_name}__value']}) system_events = self.system_events.filter(**{f'{field_name}__value': d[f'{field_name}__value']})
affected_tasks = models.TaskBlueprint.objects.filter(system_events__in=system_events) affected_tasks = models.TaskBlueprint.objects.filter(system_events__in=system_events)
affected_units = (models.SchedulingUnitBlueprint.objects.filter(task_blueprints__in=affected_tasks)) affected_units = (models.SchedulingUnitBlueprint.objects.filter(task_blueprints__in=affected_tasks))
total_on_sky_duration_lost = affected_units.aggregate(Sum(F('on_sky_duration')))['on_sky_duration__sum'] total_on_sky_duration_lost = affected_units.aggregate(on_sky_duration__sum=Sum(Coalesce(F('on_sky_duration'), timedelta(0))))['on_sky_duration__sum']
# convert durations to seconds and add derived values # convert durations to seconds and add derived values
d.update({'duration_lost_event': d['duration_lost_event'].total_seconds(), d.update({'duration_lost_event': d['duration_lost_event'].total_seconds(),
'duration_lost_on_sky': total_on_sky_duration_lost.total_seconds() if total_on_sky_duration_lost else 0, 'duration_lost_on_sky': total_on_sky_duration_lost.total_seconds() if total_on_sky_duration_lost else 0,
'percent_of_wall_time_lost_event': 100 * d['duration_lost_event'].total_seconds() / wall_time, '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}) 'percent_of_wall_time_lost_on_sky': total_on_sky_duration_lost.total_seconds() / wall_time if total_on_sky_duration_lost else 0})
aggregates[f'by_{field_name}'] = group_aggregates aggregates[f'by_{field_name}'] = group_aggregates
return aggregates return aggregates
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment