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

TMSS-770: Add prognosis field in get_completion_level

parent e0fe1386
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.
......@@ -67,7 +67,7 @@ def _get_average_efficiency(cycle: models.Cycle) -> {}:
"""
from lofar.sas.tmss.tmss.workflowapp.models.schedulingunitflow import SchedulingUnitProcess
result = {'target': '0.65'} # TODO: Default efficiency is 65%. Change it properly when it will be implemented.
result = {'target': 0.65} # TODO: Default efficiency is 65%. Change it properly when it will be implemented.
efficiency_per_day = 0
# Get SchedulingUnitBlueprints related to the cycle
......@@ -95,6 +95,8 @@ def _get_average_efficiency(cycle: models.Cycle) -> {}:
result['efficiency'] = efficiency_per_day / i if efficiency_per_day > 0 else None
return result
import logging
logger = logging.getLogger()
def _get_completion_level(cycle: models.Cycle) -> {}:
"""
......@@ -103,22 +105,25 @@ def _get_completion_level(cycle: models.Cycle) -> {}:
from lofar.sas.tmss.tmss.workflowapp.models.schedulingunitflow import SchedulingUnitProcess
# TODO: Change it properly when it will be implemented.
result = {'target': '0.0'}
result = {'target': 0.0}
# Get SchedulingUnitBlueprints related to the cycle
subs = models.SchedulingUnitBlueprint.objects.filter(draft__scheduling_set__project__cycles=cycle.pk)
total = 0
total_succeeded = 0
total, total_succeeded = 0, 0
for sub in subs:
# Aggregate total and successful durations
if sub.observed_duration:
sup = SchedulingUnitProcess.objects.filter(su=sub).first()
total += sub.observed_duration.total_seconds()
total_succeeded += sub.observed_duration.total_seconds() if sup and sup.results_accepted else 0
result['total'], result['succeeded'] = total, total_succeeded
# Calculate prognosis
unschedulable_subtasks = models.Subtask.objects.filter(task_blueprints__scheduling_unit_blueprint__in=subs).filter(state='unschedulable')
unschedulable_duration = sum([uns.specified_duration.total_seconds() for uns in unschedulable_subtasks])
result['prognosis'] = (total - unschedulable_duration) * 100.0 / total if total > 0 and total >= unschedulable_duration else None
return result
......
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