diff --git a/SAS/TMSS/backend/src/tmss/tmssapp/adapters/reports.py b/SAS/TMSS/backend/src/tmss/tmssapp/adapters/reports.py index 48fe4f7c050c1430c923daeaa83dd930851a0a4f..7629829a156dcbdb37b550e1aed44c063d8b213a 100644 --- a/SAS/TMSS/backend/src/tmss/tmssapp/adapters/reports.py +++ b/SAS/TMSS/backend/src/tmss/tmssapp/adapters/reports.py @@ -32,12 +32,13 @@ def _get_telescope_time_distribution(cycle: models.Cycle): """ result = {} - # Consider FILLER as a category - categories = ['FILLER',] + [c for c in models.ProjectCategory.Choices] + # Consider UNASSIGNED and FILLER as categories for the purposes of reporting + categories = ['UNASSIGNED', 'FILLER',] + [c for c in models.ProjectCategory.Choices] for c in categories: total, succeeded, failed = 0, 0, 0 - projects = models.Project.objects.filter(cycles=cycle, project_category=c.value) if c != 'FILLER' \ - else models.Project.objects.filter(cycles=cycle, filler=True) + projects = models.Project.objects.filter(cycles=cycle, project_category=c.value) if (c != 'UNASSIGNED' and c != 'FILLER') \ + else models.Project.objects.filter(cycles=cycle, filler=True) if c == 'FILLER' \ + else models.Project.objects.filter(cycles=cycle, project_category__isnull=True) for p in projects: # Get durations for single project and aggregate to get the totals _, durations = _get_subs_and_durations_from_project(p) @@ -45,14 +46,16 @@ def _get_telescope_time_distribution(cycle: models.Cycle): succeeded += durations['total_succeeded'] failed += durations['total_failed'] idle = total - succeeded - failed - result[c.name if c != 'FILLER' else 'FILLER'] = {'durations': {'total': total, 'succeeded': succeeded, + result[c if c == 'UNASSIGNED' or c == 'FILLER' else c.name] = {'durations': {'total': total, 'succeeded': succeeded, 'failed': failed, 'idle': idle}} return result def _get_average_efficiency(cycle: models.Cycle): - return 0 + result = {'efficiency': '65%'} # TODO: Default efficiency is 65%. Change it properly when it will be implemented. + + return result def _get_completion_level(cycle: models.Cycle): @@ -72,7 +75,7 @@ def _get_observation_hours_per_category(cycle: models.Cycle): subs = models.SchedulingUnitBlueprint.objects.filter(draft__scheduling_set__project__cycles=cycle.pk).filter(priority_queue=prio.value) for sub in subs: result['total_duration_idle'] += sub.duration.total_seconds() - if sub.status == 'finished': + if sub.status == 'finished': # TODO: Use QA workflow flag instead of the finished status result[f'total_duration_{prio.name}'] += sub.duration.total_seconds() if sub.status == 'cancelled': result['total_duration_failed'] += sub.duration.total_seconds()