models.py
3.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
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