models.py 3.85 KB
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, quota_f):
        quota_institute = {}

        quota_institute["d_totalq"] = self.d_totalq * quota_f
        quota_institute["d_totalx"] = self.d_totalx * quota_f
        quota_institute["d_previousq"] = self.d_previousq * quota_f
        quota_institute["d_previousx"] = self.d_previousx * quota_f
        quota_institute["d_currentq"] = self.d_currentq * quota_f
        quota_institute["d_currentx"] = self.d_currentx * quota_f
        quota_institute["d_passedq"] = self.d_passedq * quota_f
        quota_institute["d_passedx"] = self.d_passedx * quota_f
        quota_institute["d_scheduleq"] = self.d_scheduleq * quota_f
        quota_institute["d_schedulex"] = self.d_schedulex * quota_f
        quota_institute["d_nextq"] = self.d_nextq * quota_f
        quota_institute["d_nextx"] = self.d_nextx * quota_f

        return quota_institute