models.py
5.01 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
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)
# in seconds
index_start = models.BigIntegerField(default=0, blank=True, null=True)
d_total = models.BigIntegerField(default=0, blank=True, null=True)
d_totalq = models.BigIntegerField(default=0, blank=True, null=True)
d_totalx = models.BigIntegerField(default=0, blank=True, null=True)
d_previous = 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_current = 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_passed = 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_schedule = 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_next = 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("index_start") != None:
self.index_start = quota_attributes.get("index_start")
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_passedq") != None:
self.d_passedq = quota_attributes["d_passedq"]
if quota_attributes.get("d_passedx") != None:
self.d_passedx = quota_attributes["d_passedx"]
if quota_attributes.get("d_scheduleq") != None:
self.d_scheduleq = quota_attributes["d_scheduleq"]
if quota_attributes.get("d_schedulex") != None:
self.d_schedulex = quota_attributes["d_schedulex"]
if quota_attributes.get("d_nextx") != None:
self.d_nextq = quota_attributes["d_nextx"]
if quota_attributes.get("d_nextq") != None:
self.d_nextq = quota_attributes["d_nextq"]
if quota_attributes.get("d_total") != None:
self.d_total = quota_attributes["d_total"]
if quota_attributes.get("d_previous") != None:
self.d_previous = quota_attributes["d_previous"]
if quota_attributes.get("d_current") != None:
self.d_current = quota_attributes["d_current"]
if quota_attributes.get("d_passed") != None:
self.d_passed = quota_attributes["d_passed"]
if quota_attributes.get("d_schedule") != None:
self.d_schedule = quota_attributes["d_schedule"]
if quota_attributes.get("d_next") != None:
self.d_next = quota_attributes["d_next"]
self.save()
def convert_to_quota(self, quota_f):
quota_institute = {}
quota_institute["d_total"] = self.d_total * quota_f
quota_institute["d_previous"] = self.d_previous * quota_f
quota_institute["d_current"] = self.d_current * quota_f
quota_institute["d_passed"] = self.d_passed * quota_f
quota_institute["d_schedule"] = self.d_schedule * quota_f
quota_institute["d_next"] = self.d_next * quota_f
return quota_institute