diff --git a/src/core/pyros_django/misc/fixtures/initial_fixture_dev_TZ.json b/src/core/pyros_django/misc/fixtures/initial_fixture_dev_TZ.json index f34bbc4..12e984e 100644 --- a/src/core/pyros_django/misc/fixtures/initial_fixture_dev_TZ.json +++ b/src/core/pyros_django/misc/fixtures/initial_fixture_dev_TZ.json @@ -287,8 +287,7 @@ "fields": { "name": "Admin", "desc": "", - "priority": 8, - "quota": 9999.0 + "priority": 8 } }, { @@ -297,8 +296,7 @@ "fields": { "name": "Observer", "desc": "", - "priority": 2, - "quota": 9999.0 + "priority": 2 } }, { @@ -307,8 +305,7 @@ "fields": { "name": "TAC", "desc": "", - "priority": 1, - "quota": 9999.0 + "priority": 1 } }, { @@ -317,8 +314,7 @@ "fields": { "name": "Management board member", "desc": "", - "priority": 3, - "quota": 9999.0 + "priority": 3 } }, { @@ -327,8 +323,7 @@ "fields": { "name": "Operator", "desc": "", - "priority": 4, - "quota": 9999.0 + "priority": 4 } }, { @@ -337,8 +332,7 @@ "fields": { "name": "Unit-PI", "desc": "", - "priority": 7, - "quota": 9999.0 + "priority": 7 } }, { @@ -347,8 +341,7 @@ "fields": { "name": "Unit-board", "desc": "", - "priority": 6, - "quota": 9999.0 + "priority": 6 } }, { @@ -357,8 +350,7 @@ "fields": { "name": "Visitor", "desc": "Account without any privilege", - "priority": 0, - "quota": 0.0 + "priority": 0 } }, { @@ -366,7 +358,7 @@ "pk": 2, "fields": { "name": "CNRS", - "quota": 20 + "f_quota": 0.2 } }, { @@ -374,7 +366,7 @@ "pk": 1, "fields": { "name": "CNES", - "quota": 80 + "f_quota": 0.8 } }, { diff --git a/src/core/pyros_django/scp_mgmt/forms.py b/src/core/pyros_django/scp_mgmt/forms.py index 9a1c89b..ffdf6f4 100644 --- a/src/core/pyros_django/scp_mgmt/forms.py +++ b/src/core/pyros_django/scp_mgmt/forms.py @@ -39,13 +39,13 @@ class SP_PeriodForm(forms.ModelForm): fields = ( #"period", "public_visibility", - "quota_minimal", - "quota_nominal", - "quota_allocated", - "over_quota_duration", - "over_quota_duration_allocated", - "token", - "token_allocated", + # "quota_minimal", + # "quota_nominal", + # "quota_allocated", + # "over_quota_duration", + # "over_quota_duration_allocated", + # "token", + # "token_allocated", "vote_referee1", "reason_referee1", "vote_referee2", diff --git a/src/core/pyros_django/scp_mgmt/models.py b/src/core/pyros_django/scp_mgmt/models.py index 4ee48cd..78da615 100644 --- a/src/core/pyros_django/scp_mgmt/models.py +++ b/src/core/pyros_django/scp_mgmt/models.py @@ -1 +1,93 @@ -#from django.db import models +from django.db import models + + +class Quota(models.Model): + id_period = models.BigIntegerField(blank=True, null=True) + night_id = models.CharField(max_length=8, null=True, blank=True, db_index=True) + d_totalq = models.BigIntegerField(default=0, blank=True, null=True) + d_totalx = models.BigIntegerField(default=0, blank=True, null=True) + + d_previousq = models.BigIntegerField(default=0, blank=True, null=True) + d_previousx = models.BigIntegerField(default=0, blank=True, null=True) + + d_currentq = models.BigIntegerField(default=0, blank=True, null=True) + d_currentx = models.BigIntegerField(default=0, blank=True, null=True) + + d_passedq = models.BigIntegerField(default=0, blank=True, null=True) + d_passedx = models.BigIntegerField(default=0, blank=True, null=True) + + d_scheduleq = models.BigIntegerField(default=0, blank=True, null=True) + d_schedulex = models.BigIntegerField(default=0, blank=True, null=True) + + d_nextq = models.BigIntegerField(default=0, blank=True, null=True) + d_nextx = models.BigIntegerField(default=0, blank=True, null=True) + + @property + def d_total(self): + return self.d_totalq + self.d_totalx + + @property + def d_previous(self): + return self.d_previousq + self.d_previousx + + @property + def d_current(self): + return self.d_currentq + self.d_currentx + + @property + def d_passed(self): + return self.d_passedq + self.d_passedx + + @property + def d_schedule(self): + return self.d_scheduleq + self.d_schedulex + + @property + def d_next(self): + return self.d_nextq + self.d_nextx + + def set_attributes_and_save(self, quota_attributes:dict): + + if quota_attributes.get("id_period") != None: + self.id_period = quota_attributes["id_period"] + if quota_attributes.get("night_id") != None: + self.night_id = quota_attributes["night_id"] + if quota_attributes.get("d_totalq") != None: + self.d_totalq = quota_attributes["d_totalq"] + if quota_attributes.get("d_totalx") != None: + self.d_totalx = quota_attributes["d_totalx"] + if quota_attributes.get("d_previousq") != None: + self.d_previousq = quota_attributes["d_previousq"] + if quota_attributes.get("d_previousx") != None: + self.d_previousx = quota_attributes["d_previousx"] + if quota_attributes.get("d_currentq") != None: + self.d_currentq = quota_attributes["d_currentq"] + if quota_attributes.get("d_currentx") != None: + self.d_currentx = quota_attributes["d_currentx"] + if quota_attributes.get("d_scheduleq") != None: + self.d_scheduleq = quota_attributes["d_scheduleq"] + if quota_attributes.get("d_schedulex") != None: + self.d_schedule = quota_attributes["d_schedulex"] + if quota_attributes.get("d_nextq") != None: + self.d_nextq = quota_attributes["d_nextq"] + if quota_attributes.get("d_nextx") != None: + self.d_nextx = quota_attributes["d_nextx"] + self.save() + + def convert_to_quota(self, f_quota): + quota_institute = {} + + quota_institute["d_totalq"] = self.d_totalq * f_quota + quota_institute["d_totalx"] = self.d_totalx * f_quota + quota_institute["d_previousq"] = self.d_previousq * f_quota + quota_institute["d_previousx"] = self.d_previousx * f_quota + quota_institute["d_currentq"] = self.d_currentq * f_quota + quota_institute["d_currentx"] = self.d_currentx * f_quota + quota_institute["d_passedq"] = self.d_passedq * f_quota + quota_institute["d_passedx"] = self.d_passedx * f_quota + quota_institute["d_scheduleq"] = self.d_scheduleq * f_quota + quota_institute["d_schedulex"] = self.d_schedulex * f_quota + quota_institute["d_nextq"] = self.d_nextq * f_quota + quota_institute["d_nextx"] = self.d_nextx * f_quota + + return quota_institute diff --git a/src/core/pyros_django/seq_submit/models.py b/src/core/pyros_django/seq_submit/models.py index 168f5fe..551c27e 100644 --- a/src/core/pyros_django/seq_submit/models.py +++ b/src/core/pyros_django/seq_submit/models.py @@ -34,6 +34,7 @@ from django.db.models import Q # Project imports from user_mgmt.models import PyrosUser, ScientificProgram, Period +from scp_mgmt.models import Quota # DeviceCommand is used by class Command sys.path.append("../../..") from vendor.guitastro.src.guitastro import FileNames, Ima @@ -349,8 +350,9 @@ class Sequence(models.Model): obsolete = models.BooleanField(default=False) processing = models.BooleanField(default=False) flag = models.CharField(max_length=45, blank=True, null=True) - period = models.ForeignKey(Period, on_delete=models.DO_NOTHING, related_name="sequences", blank=True, null=True) + period = models.ForeignKey(Period, on_delete=models.DO_NOTHING, related_name="sequence_period", blank=True, null=True) #period = models.ForeignKey("Period", on_delete=models.DO_NOTHING, related_name="sequences", blank=True, null=True) + quota = models.ForeignKey(Quota, on_delete=models.DO_NOTHING,related_name="sequence_quotas", blank=True, null=True) start_date = models.DateTimeField( blank=True, null=True, default=timezone.now, editable=True) diff --git a/src/core/pyros_django/user_mgmt/models.py b/src/core/pyros_django/user_mgmt/models.py index 0857581..5740262 100644 --- a/src/core/pyros_django/user_mgmt/models.py +++ b/src/core/pyros_django/user_mgmt/models.py @@ -37,6 +37,11 @@ from django.db.models.query import QuerySet from django.utils import timezone +# Pyros import + +from scp_mgmt.models import Quota + + # Project imports @@ -52,7 +57,6 @@ class UserLevel(models.Model): name = models.CharField(max_length=45, blank=True, null=True) desc = models.TextField(blank=True, null=True) priority = models.IntegerField(blank=True, null=True) - quota = models.FloatField(blank=True, null=True) class Meta: managed = True @@ -79,9 +83,11 @@ class Country(models.Model): class Institute(models.Model): name = models.CharField(max_length=100, blank=False, null=False, unique=True) - # quota % - quota = models.IntegerField( - validators=[MinValueValidator(0), MaxValueValidator(100)]) + # fraction quota + f_quota = models.FloatField( + validators=[MinValueValidator(0), MaxValueValidator(1)], blank=True, null=True) + + quota = models.ForeignKey(Quota, on_delete=models.DO_NOTHING,related_name="institute_quotas", blank=True, null=True) #representative_user = models.ForeignKey("PyrosUser", on_delete=models.DO_NOTHING,related_name="institutes",default=1) def __str__(self) -> str: @@ -90,6 +96,8 @@ class Institute(models.Model): class Meta: db_table = "institute" + + class ScienceTheme(models.Model): name = models.CharField(max_length=120, blank=False, null=False, default="", unique=True) def __str__(self) -> str: @@ -367,6 +375,8 @@ class Period(models.Model): data_accessibility_duration = models.PositiveIntegerField( blank=True, null=True, default=365*10, editable=True) + quota = models.ForeignKey(Quota, on_delete=models.DO_NOTHING,related_name="period_quotas", blank=True, null=True) + @property def end_date(self): return self.start_date + relativedelta(days=self.exploitation_duration) @@ -461,11 +471,11 @@ class ScientificProgram(models.Model): description_short = models.TextField(default="", max_length=320) description_long = models.TextField(default="") institute = models.ForeignKey('Institute', on_delete=models.DO_NOTHING, related_name="scientific_programs") - sp_pi = models.ForeignKey('PyrosUser', on_delete=models.DO_NOTHING, related_name="Scientific_Program_Users") + sp_pi = models.ForeignKey('PyrosUser', on_delete=models.DO_NOTHING, related_name="scientific_Program_Users") science_theme = models.ForeignKey(ScienceTheme, on_delete=models.DO_NOTHING, related_name="scientific_program_theme", default=1) is_auto_validated = models.BooleanField(default=False) objects = ScientificProgramManager() - + quota = models.ForeignKey(Quota, on_delete=models.DO_NOTHING,related_name="scientific_program_quotas", blank=True, null=True) class Meta: managed = True db_table = 'scientific_program' @@ -525,14 +535,6 @@ class SP_Period(models.Model): is_valid = models.TextField( choices=IS_VALID, default=IS_VALID_REJECTED, blank=True) status = models.TextField(choices=STATUSES, default=STATUSES_DRAFT) - quota_minimal = models.PositiveIntegerField(default=0) - quota_nominal = models.PositiveIntegerField(default=0) - quota_allocated = models.PositiveIntegerField(default=0, blank=True) - quota_remaining = models.PositiveIntegerField(default=0, blank=True) - over_quota_duration = models.PositiveIntegerField(default=0) - over_quota_duration_allocated = models.PositiveIntegerField( - default=0, blank=True) - over_quota_duration_remaining = models.PositiveIntegerField(default=0) token = models.PositiveIntegerField(default=0) token_allocated = models.PositiveIntegerField(default=0, blank=True) token_remaining = models.PositiveIntegerField(default=0, blank=True) -- libgit2 0.21.2