diff --git a/SAS/TMSS/src/tmss/tmssapp/populate.py b/SAS/TMSS/src/tmss/tmssapp/populate.py index 7cf30fe4da753ab5a337c04c9729abeae86a8dd4..e28b1b392faa5f30161bfcecf6fc3c858924049f 100644 --- a/SAS/TMSS/src/tmss/tmssapp/populate.py +++ b/SAS/TMSS/src/tmss/tmssapp/populate.py @@ -80,124 +80,39 @@ def populate_test_data(): # create a Test Scheduling Set UC1 under project TMSS-Commissioning tmss_project = models.Project.objects.get(name="TMSS-Commissioning") - for set_nr in range(1): + for set_nr in range(3): scheduling_set_data = SchedulingSet_test_data(name="Test Scheduling Set UC1 example %s" % (set_nr,), project=tmss_project) scheduling_set = models.SchedulingSet.objects.create(**scheduling_set_data) - scheduling_set.tags = ["TEST"] + scheduling_set.tags = ["TEST", "UC1"] scheduling_set.save() - for unit_nr in range(1): - # construct a scheduling_unit_doc, i.e.: a specification of interrelated tasks which conforms the scheduling unit schema - # by default, this scheduling_unit_doc holds no tasks, so lets setup the UC1 sequence of tasks here, and add it to the scheduling_unit_doc + logger.info('created test scheduling_set: %s', scheduling_set.name) + + for unit_nr in range(2): + strategy_template = models.SchedulingUnitObservingStrategyTemplate.objects.get(name="UC1 observation strategy template") + scheduling_unit_template = models.SchedulingUnitTemplate.objects.get(name="scheduling unit schema") - scheduling_unit_doc = get_default_json_object_for_schema(scheduling_unit_template.schema) - - # create and add a calibrator task spec - scheduling_unit_doc['tasks']["Calibrator Observation 1"] = { - "description": "Calibrator Observation for UC1 HBA scheduling unit", - "specifications_doc": get_default_json_object_for_schema(models.TaskTemplate.objects.get(name="calibrator schema").schema), - "specifications_template": "calibrator schema"} - - # create and add a calibrator preprocessing spec - scheduling_unit_doc['tasks']["Pipeline Calibrator1"] = { - "description": "Preprocessing Pipeline for Calibrator Observation 1", - "specifications_doc": get_default_json_object_for_schema(models.TaskTemplate.objects.get(name="preprocessing schema").schema), - "specifications_template": "preprocessing schema"} - - # create and add a target obs spec - scheduling_unit_doc['tasks']["Target Observation"] = { - "description": "Target Observation for UC1 HBA scheduling unit", - "specifications_doc": get_default_json_object_for_schema(models.TaskTemplate.objects.get(name="observation schema").schema), - "specifications_template": "observation schema"} - - # create and add a target pipeline spec for sap0 - scheduling_unit_doc['tasks']["Preprocessing Pipeline SAP0"] = { - "description": "Preprocessing Pipeline for Target Observation SAP0", - "specifications_doc": get_default_json_object_for_schema(models.TaskTemplate.objects.get(name="preprocessing schema").schema), - "specifications_template": "preprocessing schema"} - - # create and add a target pipeline spec for sap1 - scheduling_unit_doc['tasks']["Preprocessing Pipeline SAP1"] = { - "description": "Preprocessing Pipeline for Target Observation SAP1", - "specifications_doc": get_default_json_object_for_schema(models.TaskTemplate.objects.get(name="preprocessing schema").schema), - "specifications_template": "preprocessing schema"} - - # create and add a calibrator task spec - scheduling_unit_doc['tasks']["Calibrator Observation 2"] = { - "description": "Calibrator Observation for UC1 HBA scheduling unit", - "specifications_doc": get_default_json_object_for_schema(models.TaskTemplate.objects.get(name="calibrator schema").schema), - "specifications_template": "calibrator schema"} - - # create and add a calibrator preprocessing spec - scheduling_unit_doc['tasks']["Pipeline Calibrator2"] = { - "description": "Preprocessing Pipeline for Calibrator Observation 2", - "specifications_doc": get_default_json_object_for_schema(models.TaskTemplate.objects.get(name="preprocessing schema").schema), - "specifications_template": "preprocessing schema"} - - # ----- end of tasks - - # setup task_scheduling_relations between Target and Calibrator observations - scheduling_unit_doc['task_scheduling_relations'].append({"first": "Calibrator Observation 1", - "second": "Target Observation", - "placement": "before", - "time_offset": 60 }) - scheduling_unit_doc['task_scheduling_relations'].append({"first": "Calibrator Observation 2", - "second": "Target Observation", - "placement": "after", - "time_offset": 60 }) - - # ----- end of task_scheduling_relations - - #TODO: check various input/output datatypes and roles for each task_relation - scheduling_unit_doc['task_relations'].append({"producer": "Calibrator Observation 1", - "consumer": "Pipeline Calibrator1", - "tags": [], - "input": { "role": "input", "datatype": "visibilities" }, - "output": { "role": "correlator", "datatype": "visibilities" }, - "dataformat": "MeasurementSet", - "selection_doc": {}, - "selection_template": "All" }) - - scheduling_unit_doc['task_relations'].append({"producer": "Calibrator Observation 2", - "consumer": "Pipeline Calibrator2", - "tags": [], - "input": { "role": "input", "datatype": "visibilities" }, - "output": { "role": "correlator", "datatype": "visibilities" }, - "dataformat": "MeasurementSet", - "selection_doc": {}, - "selection_template": "All" }) - - scheduling_unit_doc['task_relations'].append({"producer": "Target Observation", - "consumer": "Preprocessing Pipeline SAP0", - "tags": [], - "input": { "role": "input", "datatype": "visibilities" }, - "output": { "role": "correlator", "datatype": "visibilities" }, - "dataformat": "MeasurementSet", - "selection_doc": {"sap": [0]}, - "selection_template": "SAP" }) - - scheduling_unit_doc['task_relations'].append({"producer": "Target Observation", - "consumer": "Preprocessing Pipeline SAP1", - "tags": [], - "input": { "role": "input", "datatype": "visibilities" }, - "output": { "role": "correlator", "datatype": "visibilities" }, - "dataformat": "MeasurementSet", - "selection_doc": {"sap": [1]}, - "selection_template": "SAP" }) - - # finally... add the scheduling_unit_doc to a new SchedulingUnitDraft instance, and were ready to use it! - scheduling_unit_data = SchedulingUnitDraft_test_data(name="Test Scheduling Unit UC1 example %s.%s" % (set_nr, unit_nr), scheduling_set=scheduling_set, - template=scheduling_unit_template, requirements_doc=scheduling_unit_doc) + + # the 'schema' in the strategy_template is a predefined json-data blob which validates against the given scheduling_unit_template + scheduling_unit_spec = strategy_template.schema + # a user might 'upload' a partial json-data blob, so add all the known defaults + scheduling_unit_spec = add_defaults_to_json_object_for_schema(scheduling_unit_spec, scheduling_unit_template.schema) + + # add the scheduling_unit_doc to a new SchedulingUnitDraft instance, and were ready to use it! + scheduling_unit_data = SchedulingUnitDraft_test_data(name="UC1 test scheduling unit %s.%s" % (set_nr+1, unit_nr+1), + scheduling_set=scheduling_set, + template=scheduling_unit_template, + requirements_doc=scheduling_unit_spec) scheduling_unit_draft = models.SchedulingUnitDraft.objects.create(**scheduling_unit_data) + scheduling_unit_draft.tags = ["TEST", "UC1"] + scheduling_unit_draft.save() + + logger.info('created test scheduling_unit_draft: %s', scheduling_unit_draft.name) try: - if set_nr==0 and unit_nr==0: - create_task_blueprints_and_subtasks_and_schedule_subtasks_from_scheduling_unit_draft(scheduling_unit_draft) - else: - create_task_blueprints_and_subtasks_from_scheduling_unit_draft(scheduling_unit_draft) + create_task_blueprints_and_subtasks_from_scheduling_unit_draft(scheduling_unit_draft) except TMSSException as e: logger.exception(e) - except ImportError: pass