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

TMSS-610: Fix retrieve of obs durations; cleanup

parent b53c2d88
No related branches found
No related tags found
3 merge requests!634WIP: COBALT commissioning delta,!492Resolve TMSS-610,!481Draft: SW-971 SW-973 SW-975: Various fixes to build LOFAR correctly.
...@@ -57,38 +57,35 @@ def _get_telescope_time_distribution(cycle: models.Cycle): ...@@ -57,38 +57,35 @@ def _get_telescope_time_distribution(cycle: models.Cycle):
def _get_average_efficiency(cycle: models.Cycle): def _get_average_efficiency(cycle: models.Cycle):
""" """
Help function to retrieve the average efficiency with total and total successful durations per day. Help function to retrieve the average efficiency with total and total successful obs durations per day.
""" """
result = {'efficiency': '65%'} # TODO: Default efficiency is 65%. Change it properly when it will be implemented. result = {'efficiency': '65%'} # TODO: Default efficiency is 65%. Change it properly when it will be implemented.
subtasks = [] # Get SchedulingUnitBlueprints related to the cycle
projects = models.Project.objects.filter(cycles=cycle) subs = models.SchedulingUnitBlueprint.objects.filter(draft__scheduling_set__project__cycles=cycle.pk)
for p in projects:
# Get Subtask observations related to the project
subtasks = models.Subtask.objects.filter(task_blueprints__scheduling_unit_blueprint__draft__scheduling_set__project__pk=p.pk)\
.filter(specifications_template__type='observation')
# NOTE: This can be improved, maybe using Django ORM? # NOTE: This can be improved, maybe using Django ORM?
# Get days # Get days
days = [] days = []
for s in subtasks: for sub in subs:
day = s.start_time.date() day = sub.observed_start_time
if day not in days: if day:
days.append(day) days.append(day.date())
day = s.stop_time.date() day = sub.observed_end_time
if day not in days: if day:
days.append(day) days.append(day.date())
days = list(dict.fromkeys(days))
# Calculate the total and total successful durations per day # Calculate the total and total successful durations per day
result['days'] = [] result['days'] = []
for d in days: for d in days:
total_per_day = 0 total_per_day = 0
total_succeeded_per_day = 0 total_succeeded_per_day = 0
for s in subtasks: # TODO: Handle the multiple days situations. for sub in subs: # TODO: Handle the multiple days situations.
total_per_day += s.duration.total_seconds() if s.start_time.date() in days and s.stop_time.date() in days else 0 total_per_day += sub.observed_duration.total_seconds() if sub.observed_duration and sub.observed_start_time.date() in days and sub.observed_end_time.date() in days else 0
# TODO: Use QA workflow flag to get successful or failed SUBs, instead of SUBs' states. # TODO: Use QA workflow flag to get successful or failed SUBs, instead of SUBs' states.
# At the moment just return some 0 placeholder values. # At the moment just return some 0 placeholder values.
# total_succeeded_per_day += s.duration.total_seconds() if s.start_time.date() in days and s.stop_time.date() in days and s.state == 'finished' else 0 # total_succeeded_per_day += sub.observed_duration.total_seconds() if sub.observed_duration and sub.observed_start_time.date() in days and sub.observed_end_time.date() in days and sub.status == 'finished' else 0
result['days'].append({str(d): {'total': total_per_day, 'succeeded': total_succeeded_per_day}}) result['days'].append({str(d): {'total': total_per_day, 'succeeded': total_succeeded_per_day}})
return result return result
...@@ -100,21 +97,16 @@ def _get_completion_level(cycle: models.Cycle): ...@@ -100,21 +97,16 @@ def _get_completion_level(cycle: models.Cycle):
""" """
result = {'target': '0%'} # TODO: Change it properly when it will be implemented. result = {'target': '0%'} # TODO: Change it properly when it will be implemented.
subtasks = [] # Get SchedulingUnitBlueprints related to the cycle
projects = models.Project.objects.filter(cycles=cycle) subs = models.SchedulingUnitBlueprint.objects.filter(draft__scheduling_set__project__cycles=cycle.pk)
for p in projects:
# Get Subtask observations related to the project
subtasks = models.Subtask.objects.filter(
task_blueprints__scheduling_unit_blueprint__draft__scheduling_set__project__pk=p.pk) \
.filter(specifications_template__type='observation')
total = 0 total = 0
total_succeeded = 0 total_succeeded = 0
for s in subtasks: for sub in subs:
total += s.duration.total_seconds() total += sub.observed_duration.total_seconds() if sub.observed_duration else 0
# TODO: Use QA workflow flag to get successful SUBs, instead of SUBs' states. # TODO: Use QA workflow flag to get successful SUBs, instead of SUBs' states.
# At the moment just return some 0 placeholder values. # At the moment just return some 0 placeholder values.
# total_succeeded += s.duration.total_seconds() if s.state == 'finished' else 0 # total_succeeded += sub.observed_duration.total_seconds() if sub.observed_duration and sub.status == 'finished' else 0
result['total'], result['succeeded'] = total, total_succeeded result['total'], result['succeeded'] = total, total_succeeded
return result return result
...@@ -131,13 +123,13 @@ def _get_observation_hours_per_category(cycle: models.Cycle): ...@@ -131,13 +123,13 @@ def _get_observation_hours_per_category(cycle: models.Cycle):
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 = models.SchedulingUnitBlueprint.objects.filter(draft__scheduling_set__project__cycles=cycle.pk).filter(priority_queue=prio.value)
for sub in subs: for sub in subs:
result['total_duration_idle'] += sub.duration.total_seconds() result['total_duration_idle'] += sub.observed_duration.total_seconds() if sub.observed_duration else 0
# TODO: Use QA workflow flag to get successful or failed SUBs, instead of SUBs' states. # TODO: Use QA workflow flag to get successful or failed SUBs, instead of SUBs' states.
# At the moment just return some 0 placeholder values. # At the moment just return some 0 placeholder values.
# if sub.status == 'finished': # if sub.status == 'finished':
# result[f'total_duration_{prio.name}'] += sub.duration.total_seconds() # result[f'total_duration_{prio.name}'] += sub.observed_duration.total_seconds() if sub.observed_duration else 0
# if sub.status == 'error': # if sub.status == 'error':
# result['total_duration_failed'] += sub.duration.total_seconds() # result['total_duration_failed'] += sub.observed_duration.total_seconds() if sub.observed_duration else 0
# Subtract prio states from total to get partial idle # Subtract prio states from total to get partial idle
result['total_duration_idle'] -= result[f'total_duration_{prio.name}'] result['total_duration_idle'] -= result[f'total_duration_{prio.name}']
# Subtract total failed to get total idle eventually # Subtract total failed to get total idle eventually
...@@ -147,10 +139,18 @@ def _get_observation_hours_per_category(cycle: models.Cycle): ...@@ -147,10 +139,18 @@ def _get_observation_hours_per_category(cycle: models.Cycle):
def _get_weekly_efficiency(cycle: models.Cycle): def _get_weekly_efficiency(cycle: models.Cycle):
"""
Help function to retrieve the weekly efficiency with total successful obs durations per week.
"""
# TODO: Use QA workflow flag to get successful or failed SUBs, instead of SUBs' states.
# At the moment just return a 0 placeholder value.
return 0 return 0
def _get_data_ingested_per_site_and_category(cycle: models.Cycle): def _get_data_ingested_per_site_and_category(cycle: models.Cycle):
"""
Help function to retrieve data ingested per site and category info.
"""
return 0 return 0
......
...@@ -592,6 +592,7 @@ class SchedulingUnitBlueprint(RefreshFromDbInvalidatesCachedPropertiesMixin, Tem ...@@ -592,6 +592,7 @@ class SchedulingUnitBlueprint(RefreshFromDbInvalidatesCachedPropertiesMixin, Tem
""" """
return the overall observed duration of all (observation) tasks of this scheduling unit return the overall observed duration of all (observation) tasks of this scheduling unit
""" """
# TODO: Trigger an exception if a task overlaps with another. Just assume that they run subsequently for now.
if self.observed_start_time and self.observed_end_time: if self.observed_start_time and self.observed_end_time:
return self.observed_end_time - self.observed_start_time return self.observed_end_time - self.observed_start_time
else: else:
......
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