diff --git a/SAS/TMSS/src/tmss/tmssapp/models/specification.py b/SAS/TMSS/src/tmss/tmssapp/models/specification.py index 9c91d47b5948c69ce9ba2fd74649dab71b93b6fc..3caf5c6a31395acee91640096b4c8438ca496eaf 100644 --- a/SAS/TMSS/src/tmss/tmssapp/models/specification.py +++ b/SAS/TMSS/src/tmss/tmssapp/models/specification.py @@ -41,7 +41,7 @@ class BasicCommon(Model): class NamedCommon(BasicCommon): name = CharField(max_length=128, help_text='Human-readable name of this object.', null=False) # todo: check if we want to have this primary_key=True - description = CharField(max_length=255, help_text='A longer description of this object.') + description = CharField(max_length=255, help_text='A longer description of this object.', blank=True) def __str__(self): return self.name @@ -553,7 +553,7 @@ class SchedulingUnitDraft(NamedCommon): validate_json_against_schema(self.observation_strategy_template.template, self.requirements_template.schema) if self.scheduling_constraints_doc is not None and self.scheduling_constraints_template_id and self.scheduling_constraints_template.schema is not None: - validate_json_against_schema(self.scheduling_constraints_doc, self.scheduling_constraints_template.schema) + validate_json_against_schema(self.scheduling_constraints_doc, self.scheduling_constraints_template.schema) annotate_validate_add_defaults_to_doc_using_template(self, 'requirements_doc', 'requirements_template') annotate_validate_add_defaults_to_doc_using_template(self, 'scheduling_constraints_doc', 'scheduling_constraints_template') diff --git a/SAS/TMSS/src/tmss/tmssapp/populate.py b/SAS/TMSS/src/tmss/tmssapp/populate.py index d9f964aae6c3d0b9ac70e02c653edcce27eb4c2a..b786248f34773046434364d3ddc887ecd6d59e3a 100644 --- a/SAS/TMSS/src/tmss/tmssapp/populate.py +++ b/SAS/TMSS/src/tmss/tmssapp/populate.py @@ -55,6 +55,12 @@ def populate_test_data(): from lofar.sas.tmss.test.tmss_test_data_django_models import SchedulingSet_test_data, SchedulingUnitDraft_test_data from lofar.sas.tmss.tmss.tmssapp.tasks import create_task_blueprints_and_subtasks_from_scheduling_unit_draft, create_task_blueprints_and_subtasks_and_schedule_subtasks_from_scheduling_unit_draft from lofar.sas.tmss.tmss.tmssapp.subtasks import schedule_subtask + from lofar.common.json_utils import get_default_json_object_for_schema + + constraints_template = models.SchedulingConstraintsTemplate.objects.get(name="constraints") + constraints_spec = get_default_json_object_for_schema(constraints_template.schema) + + strategy_template = models.SchedulingUnitObservingStrategyTemplate.objects.get(name="UC1 CTC+pipelines") # create a Test Scheduling Set UC1 under project TMSS-Commissioning tmss_project = models.Project.objects.get(name="TMSS-Commissioning") @@ -67,8 +73,6 @@ def populate_test_data(): logger.info('created test scheduling_set: %s', scheduling_set.name) for unit_nr in range(5): - strategy_template = models.SchedulingUnitObservingStrategyTemplate.objects.get(name="UC1 CTC+pipelines") - # the 'template' in the strategy_template is a predefined json-data blob which validates against the given scheduling_unit_template # a user might 'upload' a partial json-data blob, so add all the known defaults @@ -79,7 +83,9 @@ def populate_test_data(): scheduling_set=scheduling_set, requirements_template=strategy_template.scheduling_unit_template, requirements_doc=scheduling_unit_spec, - observation_strategy_template=strategy_template) + observation_strategy_template=strategy_template, + scheduling_constraints_doc=constraints_spec, + scheduling_constraints_template=constraints_template) scheduling_unit_draft.tags = ["TEST", "UC1"] scheduling_unit_draft.save() diff --git a/SAS/TMSS/src/tmss/tmssapp/schemas/scheduling_constraints_template-constraints-1.json b/SAS/TMSS/src/tmss/tmssapp/schemas/scheduling_constraints_template-constraints-1.json index 04bb208f0b4deff2d4a7d0491ef4108afe335922..77a916705c8df50c069f5929e11fc03d5586acf7 100644 --- a/SAS/TMSS/src/tmss/tmssapp/schemas/scheduling_constraints_template-constraints-1.json +++ b/SAS/TMSS/src/tmss/tmssapp/schemas/scheduling_constraints_template-constraints-1.json @@ -1,13 +1,32 @@ { + "$id":"http://tmss.lofar.org/api/schemas/schedulingconstraintstemplate/constraints/1#", "$schema": "http://json-schema.org/draft-06/schema#", - "title": "Constraints", - "description": "This schema defines the constraints for a scheduling unit", + "title": "constraints", + "description": "This schema defines the scheduling constraints for a scheduling unit", "version": 1, "definitions": { "timestamp": { + "description": "A timestamp defined in UTC", "type": "string", - "pattern": "\\d{4}-[01]\\d-[0-3]\\dT[0-2]\\d:[0-5]\\d:[0-5]\\d\\.\\d+Z", - "format": "datetime" + "pattern": "\\d{4}-[01]\\d-[0-3]\\dT[0-2]\\d:[0-5]\\d:[0-5]\\d(\\.\\d+)?Z", + "format": "date-time" + }, + "timewindow": { + "type": "object", + "description": "A timewindow interval: [from, to)", + "properties": { + "from": { + "$ref": "#/definitions/timestamp" + }, + "to": { + "$ref": "#/definitions/timestamp" + } + }, + "additionalProperties": false, + "required": [ + "from", + "to" + ] }, "distance_on_sky": { "type": "number", @@ -24,7 +43,7 @@ "properties": { "scheduler": { "name": "Scheduler", - "description": "Which scheduling system wiil schedule this", + "description": "Which scheduling system will schedule this", "type": "string", "enum": [ "manual", @@ -34,6 +53,7 @@ }, "time": { "type": "object", + "default": {}, "properties": { "at": { "description": "Start at this moment", @@ -51,41 +71,28 @@ "description": "Run within one of these time windows", "type": "array", "items": { - "from": { - "$ref": "#/definitions/timestamp" - }, - "to": { - "$ref": "#/definitions/timestamp" - }, - "required": [ - "from", - "to" - ] + "$ref": "#/definitions/timewindow" }, - "additionalItems": false + "minItems":0, + "uniqueItems":true, + "default": [] }, "not_between": { - "description": "NOT run within one of these time windows", + "description": "Do NOT run within any of these time windows", "type": "array", "items": { - "from": { - "$ref": "#/definitions/timestamp" - }, - "to": { - "$ref": "#/definitions/timestamp" - }, - "required": [ - "from", - "to" - ] + "$ref": "#/definitions/timewindow" }, - "additionalItems": false + "minItems":0, + "uniqueItems":true, + "default": [] } }, "additionalProperties": false }, "daily": { "type": "object", + "default": {}, "properties": { "require_night": { "description": "Must run at night", @@ -107,6 +114,7 @@ }, "sky": { "type": "object", + "default": {}, "properties": { "min_calibrator_elevation": { "description": "Minimum elevation for all calibrator sources", @@ -123,14 +131,14 @@ "type": "object", "properties": { "from": { - "type": "integer", - "minimum": -43200, - "maximum": 43200 + "type": "number", + "minimum": -0.20943951, + "maximum": 0.20943951 }, "to": { - "type": "integer", - "minimum": -43200, - "maximum": 43200 + "type": "number", + "minimum": -0.20943951, + "maximum": 0.20943951 } }, "additionalProperties": false @@ -157,7 +165,6 @@ "additionalProperties": false } }, - "additionalProperties": false, "required": [ "scheduler" ] diff --git a/SAS/TMSS/src/tmss/tmssapp/serializers/specification.py b/SAS/TMSS/src/tmss/tmssapp/serializers/specification.py index dc0f28d734c988f0343ccd657564d789ca62e9ee..bf250c5a51a2781970924e9ec30eb415d147b9fe 100644 --- a/SAS/TMSS/src/tmss/tmssapp/serializers/specification.py +++ b/SAS/TMSS/src/tmss/tmssapp/serializers/specification.py @@ -288,6 +288,7 @@ class SchedulingSetSerializer(RelationalHyperlinkedModelSerializer): class SchedulingUnitDraftSerializer(RelationalHyperlinkedModelSerializer): requirements_doc = JSONEditorField(schema_source="requirements_template.schema") + scheduling_constraints_doc = JSONEditorField(schema_source="scheduling_constraints_template.schema") duration = FloatDurationField(read_only=True) class Meta: