diff --git a/SAS/TMSS/src/tmss/tmssapp/migrations/0002_populate.py b/SAS/TMSS/src/tmss/tmssapp/migrations/0002_populate.py index 91ceea132673e18cc1747f686b7c536c91d7557a..939098dbcdc9894d9f2c90fa76dff95db7442ea9 100644 --- a/SAS/TMSS/src/tmss/tmssapp/migrations/0002_populate.py +++ b/SAS/TMSS/src/tmss/tmssapp/migrations/0002_populate.py @@ -9,8 +9,4 @@ class Migration(migrations.Migration): ('tmssapp', '0001_initial'), ] - # Start SubTask id with 2 000 000 to avoid overlap with 'old' (test/production) OTDB - operations = [ migrations.RunSQL('ALTER SEQUENCE tmssapp_SubTask_id_seq RESTART WITH 2000000;'), - migrations.RunPython(populate_choices), - migrations.RunPython(populate_misc), - migrations.RunPython(populate_lofar_json_schemas) ] + operations = [ migrations.RunPython(populate_choices) ] diff --git a/SAS/TMSS/src/tmss/tmssapp/models/specification.py b/SAS/TMSS/src/tmss/tmssapp/models/specification.py index 86f621bfa1e2cf6e3130c2a83f8c270ac7ab0330..d1ff99e34b7795505d4d69e99a8c7c6393fb533b 100644 --- a/SAS/TMSS/src/tmss/tmssapp/models/specification.py +++ b/SAS/TMSS/src/tmss/tmssapp/models/specification.py @@ -2,7 +2,7 @@ This file contains the database models """ -from django.db.models import Model, CharField, DateTimeField, BooleanField, ForeignKey, CASCADE, IntegerField, SET_NULL, PROTECT, ManyToManyField +from django.db.models import Model, CharField, DateTimeField, BooleanField, ForeignKey, CASCADE, IntegerField, FloatField, SET_NULL, PROTECT, ManyToManyField from django.contrib.postgres.fields import ArrayField, JSONField from django.contrib.postgres.indexes import GinIndex from enum import Enum @@ -125,6 +125,14 @@ class CopyReason(AbstractChoice): TEMPLATE = "template" REPEATED = "repeated" +class ResourceUnit(AbstractChoice): + """Defines the model and predefined list of possible Unit's for Resources. + The items in the Choises class below are automagically populated into the database via a data migration.""" + class Choices(Enum): + GIGABYTE = "Gigabyte" + TERABYTE = "Terabyte" + MINUTES = "Minutes" + HOURS = "Hours" # concrete models @@ -192,7 +200,6 @@ class DefaultWorkRelationSelectionTemplate(BasicCommon): # class Cycle(NamedCommonPK): - start = DateTimeField(help_text='Moment at which the cycle starts, that is, when its projects can run.') stop = DateTimeField(help_text='Moment at which the cycle officially ends.') number = IntegerField(help_text='Cycle number.') @@ -202,7 +209,7 @@ class Cycle(NamedCommonPK): class Project(NamedCommonPK): - # cycle is protected since we hav<e to manually decide to clean up projects with a cycle or keep them without cycle + # cycle is protected since we have to manually decide to clean up projects with a cycle or keep them without cycle cycle = ForeignKey('Cycle', related_name='projects', on_delete=PROTECT, null=True, help_text='Cycle(s) to which this project belongs (NULLable).') priority = IntegerField(default=0, help_text='Priority of this project w.r.t. other projects. Projects can interrupt observations of lower-priority projects.') # todo: define a value for the default priority can_trigger = BooleanField(default=False, help_text='True if this project is allowed to supply observation requests on the fly, possibly interrupting currently running observations (responsive telescope).') @@ -210,6 +217,15 @@ class Project(NamedCommonPK): expert = BooleanField(default=False, help_text='Expert projects put more responsibility on the PI.') filler = BooleanField(default=False, help_text='Use this project to fill up idle telescope time.') +class ProjectQuotum(NamedCommonPK): + project = ForeignKey('Project', related_name="project_quotums", on_delete=PROTECT, help_text='Project to wich this quota belongs.') # protected to avoid accidents + #lta_storage = FloatField(help_text='LTA storage offered for the project') + #observation_hours = IntegerField(help_text='Number of offered hours for observations.') + #processing_hours = IntegerField(help_text='Number of offered hours for processing.') + +class ResourceType(NamedCommonPK): + resource = FloatField(help_text='Resource value') + resource_unit = ForeignKey('ResourceUnit', null=False, on_delete=PROTECT, help_text='Unit of current resource.') class SchedulingSet(NamedCommon): generator_doc = JSONField(null=True, help_text='Parameters for the generator (NULLable).') diff --git a/SAS/TMSS/src/tmss/tmssapp/serializers/specification.py b/SAS/TMSS/src/tmss/tmssapp/serializers/specification.py index e3804396d7e8601705d9adac99cee64fc8dd9f4a..a9c81e2b51fb49860d1708a80c113e2553fc203a 100644 --- a/SAS/TMSS/src/tmss/tmssapp/serializers/specification.py +++ b/SAS/TMSS/src/tmss/tmssapp/serializers/specification.py @@ -112,6 +112,18 @@ class ProjectSerializer(RelationalHyperlinkedModelSerializer): class Meta: model = models.Project fields = '__all__' + extra_fields = ['name','project_quotums'] + +class ProjectQuotumSerializer(RelationalHyperlinkedModelSerializer): + class Meta: + model = models.ProjectQuotum + fields = '__all__' + extra_fields = ['name'] + +class ResourceTypeSerializer(RelationalHyperlinkedModelSerializer): + class Meta: + model = models.ResourceType + fields = '__all__' extra_fields = ['name'] class SchedulingSetSerializer(RelationalHyperlinkedModelSerializer): diff --git a/SAS/TMSS/src/tmss/tmssapp/viewsets/specification.py b/SAS/TMSS/src/tmss/tmssapp/viewsets/specification.py index b9451879335d806cc5cee91068af0e0543e6d0d6..e64fb15978e34a5744a34fce964947dba6fb87a7 100644 --- a/SAS/TMSS/src/tmss/tmssapp/viewsets/specification.py +++ b/SAS/TMSS/src/tmss/tmssapp/viewsets/specification.py @@ -113,6 +113,15 @@ class ProjectViewSet(LOFARViewSet): else: return models.Project.objects.all() +class ProjectQuotumViewSet(LOFARViewSet): + queryset = models.ProjectQuotum.objects.all() + serializer_class = serializers.ProjectQuotumSerializer + + +class ResourceTypeViewSet(LOFARViewSet): + queryset = models.ResourceType.objects.all() + serializer_class = serializers.ResourceTypeSerializer + class SchedulingSetViewSet(LOFARViewSet): queryset = models.SchedulingSet.objects.all() diff --git a/SAS/TMSS/src/tmss/urls.py b/SAS/TMSS/src/tmss/urls.py index c60cd303450774b7c912cd3afc03e0c728b5a218..05653ea403375f485790103ffa4c54fc911dbfa4 100644 --- a/SAS/TMSS/src/tmss/urls.py +++ b/SAS/TMSS/src/tmss/urls.py @@ -85,6 +85,9 @@ router.register(r'default_work_relation_selection_template', viewsets.DefaultWor # instances router.register(r'cycle', viewsets.CycleViewSet) router.register(r'project', viewsets.ProjectViewSet) +router.register(r'project_quotum', viewsets.ProjectQuotumViewSet) +router.register(r'resource_type', viewsets.ResourceTypeViewSet) + router.register(r'scheduling_set', viewsets.SchedulingSetViewSet) router.register(r'scheduling_unit_draft', viewsets.SchedulingUnitDraftViewSet) router.register(r'scheduling_unit_blueprint', viewsets.SchedulingUnitBlueprintViewSet)