diff --git a/SAS/TMSS/backend/services/scheduling/lib/constraints/template_constraints_v1.py b/SAS/TMSS/backend/services/scheduling/lib/constraints/template_constraints_v1.py index ea361a875c1302775001e06007ab4df072020072..2910479840438657cdb95721de0552f941a583b8 100644 --- a/SAS/TMSS/backend/services/scheduling/lib/constraints/template_constraints_v1.py +++ b/SAS/TMSS/backend/services/scheduling/lib/constraints/template_constraints_v1.py @@ -242,16 +242,17 @@ def can_run_within_timewindow_with_sky_constraints(scheduling_unit: models.Sched Checks whether it is possible to run the scheduling unit /somewhere/ in the given time window, considering the duration of the involved observation. :return: True if there is at least one possibility to place the scheduling unit in a way that all sky constraints are met over the runtime of the observation, else False. """ - for task in scheduling_unit.specifications_doc['tasks'].values(): - if 'specifications_doc' in task: - if 'duration' in task['specifications_doc']: - duration = timedelta(seconds=task['specifications_doc']['duration']) - window_lower_bound = lower_bound - while window_lower_bound + duration <= upper_bound: - window_upper_bound = window_lower_bound + duration - if can_run_anywhere_within_timewindow_with_sky_constraints(scheduling_unit, window_lower_bound, window_upper_bound): - return True - window_lower_bound += min(timedelta(hours=1), upper_bound - window_lower_bound) + main_observation_task_name = get_longest_observation_task_name_from_specifications_doc(scheduling_unit) + main_obs_task_spec = scheduling_unit.specifications_doc['tasks'][main_observation_task_name]['specifications_doc'] + duration = timedelta(seconds=main_obs_task_spec.get('duration', main_obs_task_spec.get('target',{}).get('duration',0))) + + window_lower_bound = lower_bound + while window_lower_bound + duration <= upper_bound: + window_upper_bound = window_lower_bound + duration + if can_run_anywhere_within_timewindow_with_sky_constraints(scheduling_unit, window_lower_bound, window_upper_bound): + return True + window_lower_bound += min(timedelta(hours=1), upper_bound - window_lower_bound) + return False diff --git a/SAS/TMSS/backend/src/tmss/tmssapp/models/specification.py b/SAS/TMSS/backend/src/tmss/tmssapp/models/specification.py index e32d0f3195f95777ca72b97e7893d6bb0b09bbd4..ff90f461d833b828f18f6a94439fae65ca31b6a4 100644 --- a/SAS/TMSS/backend/src/tmss/tmssapp/models/specification.py +++ b/SAS/TMSS/backend/src/tmss/tmssapp/models/specification.py @@ -1212,8 +1212,8 @@ class TaskBlueprint(ProjectPropertyMixin, TemplateSchemaMixin, NamedCommon): ''' # todo: when it was added, check if subtask.specifications_template.type.value == TaskType.Choices.OBSERVATION.value: try: - duration = self.specifications_doc["duration"] - return self.relative_start_time + datetime.timedelta(seconds=duration) + duration = datetime.timedelta(seconds=self.specifications_doc.get('duration', self.specifications_doc.get('target', {}).get('duration', 0))) + return self.relative_start_time + duration except: pass return self.relative_start_time