diff --git a/SAS/TMSS/backend/services/scheduling/test/t_scheduling_constraints.py b/SAS/TMSS/backend/services/scheduling/test/t_scheduling_constraints.py index 242835fea90f0fb26ecedc838cae37170fc3d451..0f3b1f7d4e5b2a158247d1bd5d57175ed859566c 100755 --- a/SAS/TMSS/backend/services/scheduling/test/t_scheduling_constraints.py +++ b/SAS/TMSS/backend/services/scheduling/test/t_scheduling_constraints.py @@ -101,10 +101,6 @@ class BaseSchedulingConstraintsTestCase(unittest.TestCase): constraint_version: int=8) -> models.SchedulingUnitDraft: constraints_template = models.SchedulingConstraintsTemplate.get_version_or_latest(name="constraints", version=constraint_version) - if constraints is None: - # by default, apply no constraints, and let the caller be specific on the constraints needed - constraints = {'scheduler': 'dynamic'} - # we're testing at scheduling unit level here. # so, use a simple template with just one observation. strategy_template = models.SchedulingUnitObservingStrategyTemplate.get_version_or_latest(name="Simple Observation") @@ -119,8 +115,16 @@ class BaseSchedulingConstraintsTestCase(unittest.TestCase): scheduling_unit_spec['tasks']['Observation']['specifications_doc']['QA']['file_conversion']['enabled'] = False scheduling_unit_spec['tasks']['Observation']['specifications_doc']['QA']['plots']['enabled'] = False + if constraints is None: + # by default, apply no constraints, and let the caller be specific on the constraints needed + constraints = {'scheduler': 'dynamic'} + + if scheduling_unit_spec['scheduling_constraints_template']['version'] != constraints_template.version: + scheduling_unit_spec['scheduling_constraints_template']['version'] = constraints_template.version + scheduling_unit_spec['scheduling_constraints_doc'] = constraints + if scheduling_set is None: - scheduling_set = models.SchedulingSet.objects.create(**SchedulingSet_test_data(project=self.project)) + scheduling_set = models.SchedulingSet.objects.create(**SchedulingSet_test_data(project=BaseSchedulingConstraintsTestCase.project)) # add the scheduling_unit_doc to a new SchedulingUnitDraft instance, and were ready to use it! scheduling_unit_draft = models.SchedulingUnitDraft.objects.create(name=name[:models.SchedulingUnitDraft.name.field.max_length], @@ -536,6 +540,55 @@ class TestSkyConstraints(BaseSchedulingConstraintsTestCase): self.scheduling_unit_blueprint.save() self.assertFalse(can_run_within_timewindow_with_constraints(self.scheduling_unit_blueprint, timestamp, timestamp + self.scheduling_unit_blueprint.specified_main_observation_duration)) + def test_sky_min_distance_constraints_with_calibrator_and_target(self): + '''Check the new constraints template version >= 9 with both calibrator and target min_distance constraints + ''' + constraints_template = models.SchedulingConstraintsTemplate.get_version_or_latest(name="constraints", version=9) + strategy_template = models.SchedulingUnitObservingStrategyTemplate.get_version_or_latest(name="IM HBA - 1 Beam") + scheduling_unit_spec = strategy_template.template_doc_complete_with_defaults + scheduling_unit_spec['scheduling_constraints_doc'] = constraints_template.get_default_json_document_for_schema() + scheduling_unit_spec['scheduling_constraints_template'] = { 'name': constraints_template.name, 'version': constraints_template.version } + # scheduling_unit_spec['tasks']['Target Observation']['specifications_doc']['station_configuration']['SAPs'][0]['digital_pointing'] + + # add the scheduling_unit_doc to a new SchedulingUnitDraft instance, and were ready to use it! + scheduling_unit_draft = models.SchedulingUnitDraft.objects.create(name="test_sky_min_distance_constraints_with_calibrator_and_target", + scheduling_set=self.scheduling_set, + specifications_template=strategy_template.scheduling_unit_template, + observation_strategy_template=strategy_template, + scheduling_constraints_template=constraints_template) + scheduling_unit_draft = update_task_graph_from_specifications_doc(scheduling_unit_draft, scheduling_unit_spec) + + scheduling_unit_blueprint = create_scheduling_unit_blueprint_and_tasks_and_subtasks_from_scheduling_unit_draft(scheduling_unit_draft) + scheduling_unit_blueprint.scheduling_constraints_doc = {'sky': {}, 'scheduler': 'dynamic'} + scheduling_unit_blueprint.save() + + timestamp = datetime(2020, 1, 1, 19, 0, 0) + + small_distances_to_bodies = {'sun': 0.01, 'moon': 0.01, 'jupiter': 0.01} + too_large_distances_to_bodies = {'sun': 3.14, 'moon': 3.14, 'jupiter': 3.14} + + scheduling_unit_blueprint.scheduling_constraints_doc['sky'] = {'min_distance': {}} + scheduling_unit_blueprint.scheduling_constraints_doc['sky']['min_distance'] = {'target': small_distances_to_bodies} + scheduling_unit_blueprint.save() + self.assertTrue(can_run_within_timewindow_with_constraints(scheduling_unit_blueprint, timestamp, timestamp + scheduling_unit_blueprint.specified_observation_duration)) + + wipe_evaluate_constraints_caches() + scheduling_unit_blueprint.scheduling_constraints_doc['sky']['min_distance'] = {'target': too_large_distances_to_bodies} + scheduling_unit_blueprint.save() + self.assertFalse(can_run_within_timewindow_with_constraints(scheduling_unit_blueprint, timestamp, timestamp + scheduling_unit_blueprint.specified_observation_duration)) + + wipe_evaluate_constraints_caches() + scheduling_unit_blueprint.scheduling_constraints_doc['sky']['min_distance'] = {'calibrator': small_distances_to_bodies, 'target': small_distances_to_bodies} + scheduling_unit_blueprint.save() + self.assertTrue(can_run_within_timewindow_with_constraints(scheduling_unit_blueprint, timestamp, timestamp + scheduling_unit_blueprint.specified_observation_duration)) + + wipe_evaluate_constraints_caches() + scheduling_unit_blueprint.scheduling_constraints_doc['sky']['min_distance'] = {'calibrator': too_large_distances_to_bodies, 'target': small_distances_to_bodies} + scheduling_unit_blueprint.save() + self.assertFalse(can_run_within_timewindow_with_constraints(scheduling_unit_blueprint, timestamp, timestamp + scheduling_unit_blueprint.specified_observation_duration)) + + + # min_target_elevation