Skip to content
Snippets Groups Projects
Commit a3c11ae6 authored by Mario Raciti's avatar Mario Raciti
Browse files

TMSS-770: Update get_subs_and_durations_from_project by splitting SUBs in Prio...

TMSS-770: Update get_subs_and_durations_from_project by splitting SUBs in Prio A,B and switching to observed_durations
parent 57e37936
No related branches found
No related tags found
3 merge requests!634WIP: COBALT commissioning delta,!522Resolve TMSS-770,!481Draft: SW-971 SW-973 SW-975: Various fixes to build LOFAR correctly.
...@@ -128,11 +128,12 @@ def _get_observation_hours_per_category(cycle: models.Cycle) -> {}: ...@@ -128,11 +128,12 @@ def _get_observation_hours_per_category(cycle: models.Cycle) -> {}:
result = {'total_duration_failed': 0, 'total_duration_idle': 0} result = {'total_duration_failed': 0, 'total_duration_idle': 0}
cycle_subs = models.SchedulingUnitBlueprint.objects.filter(draft__scheduling_set__project__cycles=cycle.pk)
# TODO: Filter also according to "DDT Com Rep", and "System Unavailability". # TODO: Filter also according to "DDT Com Rep", and "System Unavailability".
# Filter durations for each prio basing on SUBs states # Filter durations for each prio basing on SUBs states
for prio in models.PriorityQueueType.Choices: for prio in models.PriorityQueueType.Choices:
result[f'total_duration_{prio.name}'] = 0 result[f'total_duration_{prio.name}'] = 0
subs = models.SchedulingUnitBlueprint.objects.filter(draft__scheduling_set__project__cycles=cycle.pk).filter(priority_queue=prio.value) subs = cycle_subs.filter(priority_queue=prio.value)
for sub in subs: for sub in subs:
result['total_duration_idle'] += sub.observed_duration.total_seconds() if sub.observed_duration else 0 result['total_duration_idle'] += sub.observed_duration.total_seconds() if sub.observed_duration else 0
if sub.observed_duration: if sub.observed_duration:
...@@ -325,30 +326,30 @@ def _get_subs_and_durations_from_project(project_pk: int) -> ({}, {}): ...@@ -325,30 +326,30 @@ def _get_subs_and_durations_from_project(project_pk: int) -> ({}, {}):
""" """
from lofar.sas.tmss.tmss.workflowapp.models.schedulingunitflow import SchedulingUnitProcess from lofar.sas.tmss.tmss.workflowapp.models.schedulingunitflow import SchedulingUnitProcess
durations = {'total': 0, 'total_succeeded': 0, 'total_not_cancelled': 0, 'total_failed': 0}
# Get SUBs related to the project # Get SUBs related to the project
scheduling_unit_blueprints = models.SchedulingUnitBlueprint.objects.filter(draft__scheduling_set__project__pk=project_pk) project_subs = models.SchedulingUnitBlueprint.objects.filter(draft__scheduling_set__project__pk=project_pk)
# TODO: Split into total, prio A, prio B. See TMSS-592.
total_duration, total_succeeded_duration, total_failed_duration, total_not_cancelled = timedelta(), timedelta(), timedelta(), timedelta()
subs_succeeded, subs_failed = [], [] subs_succeeded, subs_failed = [], []
for prio in models.PriorityQueueType.Choices:
durations[f'total_succeeded_{prio.name}'] = 0
subs = project_subs.filter(priority_queue=prio.value)
for sub in subs:
# TODO: Maybe also add generic durations.
if sub.observed_duration:
durations['total'] += sub.observed_duration.total_seconds()
sup = SchedulingUnitProcess.objects.filter(su=sub).first()
if sup and sup.results_accepted: # Succeeded SUBs
durations[f'total_succeeded_{prio.name}'] += sub.observed_duration.total_seconds()
subs_succeeded.append({'id': sub.pk, 'name': sub.name, 'observed_duration': sub.duration.total_seconds()})
elif sup and sup.results_accepted is False: # Failed SUBs
durations['total_duration_failed'] += sub.observed_duration.total_seconds()
subs_failed.append({'id': sub.pk, 'name': sub.name, 'observed_duration': sub.duration.total_seconds()})
if sub.status != 'cancelled': # Not cancelled SUBs
durations['total_not_cancelled'] += sub.observed_duration.total_seconds()
durations['total_succeeded'] += durations[f'total_succeeded_{prio.name}']
# NOTE: This might be optimised later with the use of Django's ORM as done for LTA dataproducts.
for sub in scheduling_unit_blueprints: # Distinguish between succeeded and failed observations
# TODO: Clarify if this info should be related only to obs or all SUBs in general. The latter are considered for now.
# We can filter observations by considering observed_duration in the SUB, for now. See TMSS-610 comments.
sup = SchedulingUnitProcess.objects.filter(su=sub).first()
if sup and sup.results_accepted: # Succeeded SUBs
total_succeeded_duration += sub.duration
subs_succeeded.append({'id': sub.pk, 'name': sub.name, 'duration': sub.duration.total_seconds()})
elif sup and sup.results_accepted is False: # Failed SUBs
total_failed_duration += sub.duration
subs_failed.append({'id': sub.pk, 'name': sub.name, 'duration': sub.duration.total_seconds()})
# Total duration without considering the status of the SUBs.
total_duration += sub.duration
if sub.status != 'cancelled': # Calculate not_cancelled duration
total_not_cancelled += sub.duration
durations = {'total': total_duration.total_seconds(), 'total_succeeded': total_succeeded_duration.total_seconds(),
'total_not_cancelled': total_not_cancelled.total_seconds(), 'total_failed': total_failed_duration.total_seconds()}
subs = {'finished': subs_succeeded, 'failed': subs_failed} subs = {'finished': subs_succeeded, 'failed': subs_failed}
return subs, durations return subs, durations
......
...@@ -617,6 +617,7 @@ class ProjectReportTest(unittest.TestCase): ...@@ -617,6 +617,7 @@ class ProjectReportTest(unittest.TestCase):
# Assert durations are well calculated # Assert durations are well calculated
# NOTE: The four SUBs (successful, failed, cancelled and not cancelled) have a duration of 600s each. # NOTE: The four SUBs (successful, failed, cancelled and not cancelled) have a duration of 600s each.
# TODO: Now the APIs consider the observed_duration. Set up these values properly and asserts them.
self.assertAlmostEqual(result['durations']['total'], 2400, places=4) self.assertAlmostEqual(result['durations']['total'], 2400, places=4)
self.assertAlmostEqual(result['durations']['total_succeeded'], 600, places=4) self.assertAlmostEqual(result['durations']['total_succeeded'], 600, places=4)
self.assertAlmostEqual(result['durations']['total_not_cancelled'], 1800, places=4) self.assertAlmostEqual(result['durations']['total_not_cancelled'], 1800, places=4)
......
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