Commit a5f1e9846edce210af58b8c346f01d02b400c683
1 parent
e40cf186
Exists in
dev
cleanup common/models.py (ordre alpha)
Showing
2 changed files
with
340 additions
and
283 deletions
Show diff stats
src/common/models.py
... | ... | @@ -4,186 +4,198 @@ from django.contrib.auth.models import AbstractUser |
4 | 4 | from django.db import models |
5 | 5 | from enum import Enum |
6 | 6 | |
7 | -class Album(models.Model): | |
8 | - sequence = models.ForeignKey( | |
9 | - 'Sequence', on_delete=models.CASCADE, related_name="albums") | |
10 | - detector = models.ForeignKey( | |
11 | - 'Detector', models.DO_NOTHING, related_name="albums", blank=True, null=True) | |
7 | + | |
8 | +''' | |
9 | +NOT USED - to be removed | |
10 | +class PyrosState(Enum): | |
11 | + START = 'Starting' | |
12 | + PA = 'Passive' | |
13 | + INI = "INIT" | |
14 | + STAND = "Standby" | |
15 | + SCHED_START = 'Scheduler startup' | |
16 | + SCHED = 'Scheduler' | |
17 | + SCHED_CLOSE = 'Scheduler closing' | |
18 | +''' | |
19 | + | |
20 | + | |
21 | +""" | |
22 | +------------------------ | |
23 | + BASE MODEL CLASSES | |
24 | +------------------------ | |
25 | +""" | |
26 | + | |
27 | +class Device(models.Model): | |
12 | 28 | name = models.CharField(max_length=45, blank=True, null=True) |
13 | 29 | desc = models.TextField(blank=True, null=True) |
14 | 30 | created = models.DateTimeField(blank=True, null=True, auto_now_add=True) |
15 | 31 | updated = models.DateTimeField(blank=True, null=True, auto_now=True) |
32 | + is_online = models.BooleanField(default=False) | |
33 | + status = models.CharField(max_length=11, blank=True, null=True) | |
34 | + maintenance_date = models.DateTimeField(blank=True, null=True) | |
35 | + | |
36 | + class Meta: | |
37 | + abstract = True | |
38 | + | |
39 | + def __str__(self): | |
40 | + return (str(self.name)) | |
41 | + | |
42 | + | |
43 | +class Request(models.Model): | |
44 | + pyros_user = models.ForeignKey( | |
45 | + 'PyrosUser', on_delete=models.DO_NOTHING, related_name="requests") | |
46 | + scientific_program = models.ForeignKey( | |
47 | + 'ScientificProgram', on_delete=models.DO_NOTHING, related_name="requests", blank=True, null=True) | |
48 | + name = models.CharField(max_length=45, blank=True, null=True) | |
49 | + desc = models.TextField(blank=True, null=True) | |
50 | + created = models.DateTimeField(blank=True, null=True, auto_now_add=True) | |
51 | + updated = models.DateTimeField(blank=True, null=True, auto_now=True) | |
52 | + is_alert = models.BooleanField(default=False) | |
53 | + target_type = models.CharField(max_length=8, blank=True, null=True) | |
54 | + status = models.CharField(max_length=10, blank=True, null=True) | |
55 | + autodeposit = models.BooleanField(default=False) | |
56 | + checkpoint = models.CharField(max_length=45, blank=True, null=True) | |
57 | + flag = models.CharField(max_length=45, blank=True, null=True) | |
16 | 58 | complete = models.BooleanField(default=False) |
59 | + submitted = models.BooleanField(default=False) | |
17 | 60 | |
18 | 61 | class Meta: |
19 | 62 | managed = True |
20 | - db_table = 'album' | |
63 | + db_table = 'request' | |
21 | 64 | |
22 | 65 | def __str__(self): |
23 | 66 | return (str(self.name)) |
24 | 67 | |
25 | 68 | |
26 | -class Country(models.Model): | |
69 | + | |
70 | +""" | |
71 | +------------------------ | |
72 | + OTHER MODEL CLASSES | |
73 | +------------------------ | |
74 | +""" | |
75 | + | |
76 | +# TODO: | |
77 | +""" | |
78 | +A chaque tour de boucle, remplir champ "iamalive" avec timestamp + durée validité (> temps iteration, n minutes par défaut) | |
79 | ++ nom agent dans table agents_survey (nom agent + mode + status + updated timestamp) | |
80 | +""" | |
81 | +class AgentsSurvey(models.Model): | |
27 | 82 | name = models.CharField(max_length=45, blank=True, null=True) |
28 | 83 | desc = models.TextField(blank=True, null=True) |
29 | - quota = models.FloatField(blank=True, null=True) | |
84 | + created = models.DateTimeField(blank=True, null=True, auto_now_add=True) | |
85 | + updated = models.DateTimeField(blank=True, null=True, auto_now=True) | |
30 | 86 | |
31 | 87 | class Meta: |
32 | 88 | managed = True |
33 | - db_table = 'country' | |
34 | - verbose_name_plural = "Countries" | |
89 | + db_table = 'agents_survey' | |
35 | 90 | |
36 | 91 | def __str__(self): |
37 | 92 | return (str(self.name)) |
38 | 93 | |
39 | 94 | |
40 | -class Device(models.Model): | |
95 | +class Album(models.Model): | |
96 | + sequence = models.ForeignKey( | |
97 | + 'Sequence', on_delete=models.CASCADE, related_name="albums") | |
98 | + detector = models.ForeignKey( | |
99 | + 'Detector', models.DO_NOTHING, related_name="albums", blank=True, null=True) | |
41 | 100 | name = models.CharField(max_length=45, blank=True, null=True) |
42 | 101 | desc = models.TextField(blank=True, null=True) |
43 | 102 | created = models.DateTimeField(blank=True, null=True, auto_now_add=True) |
44 | 103 | updated = models.DateTimeField(blank=True, null=True, auto_now=True) |
45 | - is_online = models.BooleanField(default=False) | |
46 | - status = models.CharField(max_length=11, blank=True, null=True) | |
47 | - maintenance_date = models.DateTimeField(blank=True, null=True) | |
104 | + complete = models.BooleanField(default=False) | |
48 | 105 | |
49 | 106 | class Meta: |
50 | - abstract = True | |
107 | + managed = True | |
108 | + db_table = 'album' | |
51 | 109 | |
52 | 110 | def __str__(self): |
53 | 111 | return (str(self.name)) |
54 | 112 | |
55 | -class PlcDeviceStatus(models.Model): | |
56 | - device = models.ForeignKey('PlcDevice', on_delete=models.CASCADE, related_name='current_status') | |
57 | - created = models.DateTimeField(auto_now_add=True, editable=False, blank=True) | |
58 | - outside_temp = models.DecimalField(max_digits=15, decimal_places=8, blank=True, null=True) | |
59 | - outside_temp_unit = models.CharField(max_length=45, blank=True, null=True) | |
60 | - outside_humidity = models.DecimalField(max_digits=15, decimal_places=8, blank=True, null=True) | |
61 | - outside_humidity_unit = models.CharField(max_length=45, blank=True, null=True) | |
62 | - pressure = models.DecimalField(max_digits=15, decimal_places=8, blank=True, null=True) | |
63 | - pressure_unit = models.CharField(max_length=45, blank=True, null=True) | |
64 | - rain_rate = models.DecimalField(max_digits=15, decimal_places=8, blank=True, null=True) | |
65 | - rain_rate_unit = models.CharField(max_length=45, blank=True, null=True) | |
66 | - wind_speed = models.DecimalField(max_digits=15, decimal_places=8, blank=True, null=True) | |
67 | - wind_speed_unit = models.CharField(max_length=45, blank=True, null=True) | |
68 | - wind_dir = models.DecimalField(max_digits=15, decimal_places=8, blank=True, null=True) | |
69 | - wind_dir_unit = models.CharField(max_length=45, blank=True, null=True) | |
70 | - dew_point = models.DecimalField(max_digits=15, decimal_places=8, blank=True, null=True) | |
71 | - dew_point_unit = models.CharField(max_length=45, blank=True, null=True) | |
72 | - analog = models.DecimalField(max_digits=15, decimal_places=8, blank=True, null=True) | |
73 | - analog_unit = models.CharField(max_length=45, blank=True, null=True) | |
74 | - digital = models.DecimalField(max_digits=15, decimal_places=8, blank=True, null=True) | |
75 | - digital_unit = models.CharField(max_length=45, blank=True, null=True) | |
76 | - inside_temp = models.DecimalField(max_digits=15, decimal_places=8, blank=True, null=True) | |
77 | - inside_temp_unit = models.CharField(max_length=45, blank=True, null=True) | |
78 | - inside_humidity = models.DecimalField(max_digits=15, decimal_places=8, blank=True, null=True) | |
79 | - inside_humidity_unit = models.CharField(max_length=45, blank=True, null=True) | |
80 | - wind_dir_cardinal = models.CharField(max_length=45, blank=True, null=True) | |
81 | - wind_dir_cardinal_unit = models.CharField(max_length=45, blank=True, null=True) | |
82 | - sensor_temperature = models.DecimalField(max_digits=15, decimal_places=8, blank=True, null=True) | |
83 | - sensor_temperature_unit = models.CharField(max_length=45, blank=True, null=True) | |
84 | - sky_temperature = models.DecimalField(max_digits=15, decimal_places=8, blank=True, null=True) | |
85 | - sky_temperature_unit = models.CharField(max_length=45, blank=True, null=True) | |
86 | - status = models.CharField(max_length=45, blank=True, null=True) | |
87 | - current = models.DecimalField(max_digits=15, decimal_places=8, blank=True, null=True) | |
88 | - current_unit = models.CharField(max_length=45, blank=True, null=True) | |
89 | - is_safe = models.BooleanField(default=True) | |
90 | - plc_mode = models.CharField(max_length=4, null=True) | |
91 | - lights = models.CharField(max_length=3, null=True) | |
92 | - shutters = models.CharField(max_length=5, null=True) | |
113 | + | |
114 | +class Alert(Request): | |
115 | + request = models.OneToOneField('Request', on_delete=models.CASCADE, default='', parent_link=True) | |
116 | + strategyobs = models.ForeignKey( | |
117 | + 'StrategyObs', models.DO_NOTHING, related_name="alerts", blank=True, null=True) | |
118 | + voevent_file = models.CharField(max_length=45, blank=True, null=True) | |
119 | + author = models.CharField(max_length=45, blank=True, null=True) | |
120 | + burst_jd = models.DecimalField(max_digits=15, decimal_places=8, blank=True, null=True) | |
121 | + burst_ra = models.FloatField(max_length=45, blank=True, null=True) | |
122 | + burst_dec = models.FloatField(max_length=45, blank=True, null=True) | |
123 | + astro_coord_system = models.CharField(max_length=45, blank=True, null=True) | |
124 | + jd_send = models.DecimalField(max_digits=15, decimal_places=8, blank=True, null=True) | |
125 | + jd_received = models.DecimalField(max_digits=15, decimal_places=8, blank=True, null=True) | |
126 | + trig_id = models.IntegerField(blank=True, null=True) | |
127 | + error_radius = models.FloatField(max_length=45, blank=True, null=True) | |
128 | + defly_not_grb = models.BooleanField(default=False) | |
129 | + editor = models.CharField(max_length=45, blank=True, null=True) | |
130 | + soln_status = models.CharField(max_length=45, blank=True, null=True) | |
131 | + pkt_ser_num = models.IntegerField(blank=True, null=True) | |
93 | 132 | |
94 | 133 | class Meta: |
95 | 134 | managed = True |
96 | - db_table = 'plc_devices_status' | |
135 | + db_table = 'alert' | |
97 | 136 | |
98 | 137 | def __str__(self): |
99 | - return (str(self.__dict__)) | |
138 | + return str(self.trig_id) | |
100 | 139 | |
101 | - ''' | |
102 | - TODO : This function is Ugly, | |
103 | - we should change this with a function pointer array | |
104 | - and setters getters for each attribute | |
105 | - ''' | |
106 | - def setValue(self, key, value, unit=""): | |
107 | - if key == "OutsideTemp": | |
108 | - self.outside_temp = value | |
109 | - self.outside_temp_unit = unit | |
110 | - elif key == "OutsideHumidity": | |
111 | - self.outside_humidity = value | |
112 | - self.outside_humidity_unit = unit | |
113 | - elif key == "Pressure": | |
114 | - self.pressure = value | |
115 | - self.pressure_unit = unit | |
116 | - elif key == "RainRate": | |
117 | - self.rain_rate = value | |
118 | - self.rain_rate_unit = unit | |
119 | - elif key == "WindSpeed": | |
120 | - self.wind_speed = value | |
121 | - self.wind_speed_unit = unit | |
122 | - elif key == "WindDir": | |
123 | - self.wind_dir = value | |
124 | - self.wind_dir_unit = unit | |
125 | - elif key == "DewPoint": | |
126 | - self.dew_point = value | |
127 | - self.dew_point_unit = unit | |
128 | - elif key == "analog": | |
129 | - self.analog = value | |
130 | - self.analog_unit = unit | |
131 | - elif key == "digital": | |
132 | - self.digital = value | |
133 | - self.digital_unit = unit | |
134 | - elif key == "InsideTemp": | |
135 | - self.inside_temp = value | |
136 | - self.inside_temp_unit = unit | |
137 | - elif key == "InsideHumidity": | |
138 | - self.inside_humidity = value | |
139 | - self.inside_humidity_unit = unit | |
140 | - elif key == "WindDirCardinal": | |
141 | - self.wind_dir_cardinal = value | |
142 | - self.wind_dir_cardinal_unit = unit | |
143 | - elif key == "SensorTemperature": | |
144 | - self.sensor_temperature = value | |
145 | - self.sensor_temperature_unit = unit | |
146 | - elif key == "SkyTemperature": | |
147 | - self.sky_temperature = value | |
148 | - self.sky_temperature_unit = unit | |
149 | - elif key == "status": | |
150 | - self.status = value | |
151 | - elif key == "current": | |
152 | - self.current = value | |
153 | - self.current_unit = unit | |
154 | - elif key == "mode": | |
155 | - self.plc_mode = value | |
156 | - elif key == "is_safe": | |
157 | - self.is_safe = value | |
158 | - elif key == "LIGHTS": | |
159 | - self.lights = value | |
160 | - elif key == "SHUTTERS": | |
161 | - self.shutters = value | |
162 | - else: | |
163 | - raise KeyError("Key " + str(key) + " unrecognized") | |
140 | + def request_name(self): | |
141 | + return self.__str__() | |
164 | 142 | |
165 | -class PlcDevice(Device): | |
166 | - #device = models.ForeignKey('Plc', on_delete=models.CASCADE, related_name='plc_devices') | |
167 | - name = models.CharField(max_length=45, blank=True, null=True) | |
168 | - desc = models.TextField(blank=True, null=True) | |
169 | - created = models.DateTimeField(blank=True, null=True, auto_now_add=True) | |
170 | - updated = models.DateTimeField(blank=True, null=True, auto_now=True) | |
143 | + request_name.short_description = "Name" | |
144 | + | |
145 | + | |
146 | + | |
147 | +class Config(models.Model): | |
148 | + PYROS_STATE = ["Starting", "Passive", "Standby", "Remote", "Startup", "Scheduler", "Closing" ] | |
149 | + | |
150 | + id = models.IntegerField(default='1', primary_key=True) | |
151 | + latitude = models.FloatField(default=1) | |
152 | + local_time_zone = models.FloatField(default=1) | |
153 | + longitude = models.FloatField(default=1) | |
154 | + altitude = models.FloatField(default=1) | |
155 | + horizon_line = models.FloatField(default=1) | |
156 | + row_data_save_frequency = models.IntegerField(default='300') | |
157 | + request_frequency = models.IntegerField(default='300') | |
158 | + analysed_data_save = models.IntegerField(default='300') | |
159 | + telescope_ip_address = models.CharField(max_length=45, default="127.0.0.1") | |
160 | + camera_ip_address = models.CharField(max_length=45, default="127.0.0.1") | |
161 | + plc_ip_address = models.CharField(max_length=45, default="127.0.0.1") | |
171 | 162 | |
163 | + # TODO: changer ça, c'est pas clair du tout... | |
164 | + # True = mode Scheduler-standby, False = mode Remote !!!! | |
165 | + global_mode = models.BooleanField(default='True') | |
166 | + | |
167 | + ack = models.BooleanField(default='False') | |
168 | + bypass = models.BooleanField(default='True') | |
169 | + lock = models.BooleanField(default='False') | |
170 | + pyros_state = models.CharField(max_length=25, default=PYROS_STATE[0]) | |
171 | + force_passive_mode = models.BooleanField(default='False') | |
172 | + plc_timeout_seconds = models.PositiveIntegerField(default=60) | |
173 | + majordome_state = models.CharField(max_length=25, default="") | |
174 | + ntc = models.BooleanField(default='False') | |
175 | + majordome_restarted = models.BooleanField(default='False') | |
172 | 176 | |
173 | 177 | class Meta: |
174 | 178 | managed = True |
175 | - db_table = 'plc_devices' | |
179 | + db_table = 'config' | |
180 | + verbose_name_plural = "Config" | |
176 | 181 | |
177 | 182 | def __str__(self): |
178 | - return str(self.name) | |
183 | + return (str(self.__dict__)) | |
179 | 184 | |
180 | 185 | |
181 | -#class Plc(Device): | |
182 | - # last_update_status = models.DateTimeField(blank=True, null=True) | |
183 | -# i | |
184 | - # class Meta: | |
185 | - # managed = True | |
186 | - # db_table = 'plc' | |
186 | + | |
187 | +class Country(models.Model): | |
188 | + name = models.CharField(max_length=45, blank=True, null=True) | |
189 | + desc = models.TextField(blank=True, null=True) | |
190 | + quota = models.FloatField(blank=True, null=True) | |
191 | + | |
192 | + class Meta: | |
193 | + managed = True | |
194 | + db_table = 'country' | |
195 | + verbose_name_plural = "Countries" | |
196 | + | |
197 | + def __str__(self): | |
198 | + return (str(self.name)) | |
187 | 199 | |
188 | 200 | |
189 | 201 | class Detector(Device): |
... | ... | @@ -218,6 +230,24 @@ class Detector(Device): |
218 | 230 | device_name.short_description = "Name" |
219 | 231 | |
220 | 232 | |
233 | +class Dome(Device): | |
234 | + DOME = "Dome" | |
235 | + | |
236 | + open = models.BooleanField(default=False, blank=True) | |
237 | + | |
238 | + class Meta: | |
239 | + managed = True | |
240 | + db_table = 'dome' | |
241 | + | |
242 | + def __str__(self): | |
243 | + return str(self.name) | |
244 | + | |
245 | + def device_name(self): | |
246 | + return self.__str__() | |
247 | + device_name.short_description = "Name" | |
248 | + | |
249 | + | |
250 | + | |
221 | 251 | class Filter(Device): |
222 | 252 | VIS_FILTER_1 = "First visible filter" |
223 | 253 | VIS_FILTER_2 = "Second visible filter" |
... | ... | @@ -299,48 +329,185 @@ class Log(models.Model): |
299 | 329 | |
300 | 330 | class Meta: |
301 | 331 | managed = True |
302 | - db_table = 'log' | |
332 | + db_table = 'log' | |
333 | + | |
334 | + def __str__(self): | |
335 | + return (str(self.agent)) | |
336 | + | |
337 | + | |
338 | +class NrtAnalysis(models.Model): | |
339 | + name = models.CharField(max_length=45, blank=True, null=True) | |
340 | + desc = models.TextField(blank=True, null=True) | |
341 | + created = models.DateTimeField(blank=True, null=True, auto_now_add=True) | |
342 | + updated = models.DateTimeField(blank=True, null=True, auto_now=True) | |
343 | + analysis = models.TextField(blank=True, null=True) | |
344 | + | |
345 | + class Meta: | |
346 | + managed = True | |
347 | + db_table = 'nrtanalysis' | |
348 | + verbose_name_plural = "Nrt analyzes" | |
349 | + | |
350 | + def __str__(self): | |
351 | + return (str(self.name)) | |
352 | + | |
353 | + | |
354 | +class Plan(models.Model): | |
355 | + album = models.ForeignKey(Album, on_delete=models.CASCADE, related_name="plans") | |
356 | + filter = models.ForeignKey(Filter, models.DO_NOTHING, related_name="plans", blank=True, null=True) | |
357 | + name = models.CharField(max_length=45, blank=True, null=True) | |
358 | + desc = models.CharField(max_length=45, blank=True, null=True) | |
359 | + created = models.DateTimeField(blank=True, null=True, auto_now_add=True) | |
360 | + updated = models.DateTimeField(blank=True, null=True, auto_now=True) | |
361 | + duration = models.FloatField(default=0, blank=True, null=True) | |
362 | + position = models.CharField(max_length=45, blank=True, null=True) | |
363 | + exposure_time = models.FloatField(blank=True, null=True) | |
364 | + nb_images = models.IntegerField(blank=True, null=True) | |
365 | + dithering = models.BooleanField(default=False) | |
366 | + complete = models.BooleanField(default=False) | |
367 | + | |
368 | + class Meta: | |
369 | + managed = True | |
370 | + db_table = 'plan' | |
371 | + | |
372 | + def __str__(self): | |
373 | + return (str(self.name)) | |
374 | + | |
375 | + | |
376 | + | |
377 | + | |
378 | +class PlcDeviceStatus(models.Model): | |
379 | + device = models.ForeignKey('PlcDevice', on_delete=models.CASCADE, related_name='current_status') | |
380 | + created = models.DateTimeField(auto_now_add=True, editable=False, blank=True) | |
381 | + outside_temp = models.DecimalField(max_digits=15, decimal_places=8, blank=True, null=True) | |
382 | + outside_temp_unit = models.CharField(max_length=45, blank=True, null=True) | |
383 | + outside_humidity = models.DecimalField(max_digits=15, decimal_places=8, blank=True, null=True) | |
384 | + outside_humidity_unit = models.CharField(max_length=45, blank=True, null=True) | |
385 | + pressure = models.DecimalField(max_digits=15, decimal_places=8, blank=True, null=True) | |
386 | + pressure_unit = models.CharField(max_length=45, blank=True, null=True) | |
387 | + rain_rate = models.DecimalField(max_digits=15, decimal_places=8, blank=True, null=True) | |
388 | + rain_rate_unit = models.CharField(max_length=45, blank=True, null=True) | |
389 | + wind_speed = models.DecimalField(max_digits=15, decimal_places=8, blank=True, null=True) | |
390 | + wind_speed_unit = models.CharField(max_length=45, blank=True, null=True) | |
391 | + wind_dir = models.DecimalField(max_digits=15, decimal_places=8, blank=True, null=True) | |
392 | + wind_dir_unit = models.CharField(max_length=45, blank=True, null=True) | |
393 | + dew_point = models.DecimalField(max_digits=15, decimal_places=8, blank=True, null=True) | |
394 | + dew_point_unit = models.CharField(max_length=45, blank=True, null=True) | |
395 | + analog = models.DecimalField(max_digits=15, decimal_places=8, blank=True, null=True) | |
396 | + analog_unit = models.CharField(max_length=45, blank=True, null=True) | |
397 | + digital = models.DecimalField(max_digits=15, decimal_places=8, blank=True, null=True) | |
398 | + digital_unit = models.CharField(max_length=45, blank=True, null=True) | |
399 | + inside_temp = models.DecimalField(max_digits=15, decimal_places=8, blank=True, null=True) | |
400 | + inside_temp_unit = models.CharField(max_length=45, blank=True, null=True) | |
401 | + inside_humidity = models.DecimalField(max_digits=15, decimal_places=8, blank=True, null=True) | |
402 | + inside_humidity_unit = models.CharField(max_length=45, blank=True, null=True) | |
403 | + wind_dir_cardinal = models.CharField(max_length=45, blank=True, null=True) | |
404 | + wind_dir_cardinal_unit = models.CharField(max_length=45, blank=True, null=True) | |
405 | + sensor_temperature = models.DecimalField(max_digits=15, decimal_places=8, blank=True, null=True) | |
406 | + sensor_temperature_unit = models.CharField(max_length=45, blank=True, null=True) | |
407 | + sky_temperature = models.DecimalField(max_digits=15, decimal_places=8, blank=True, null=True) | |
408 | + sky_temperature_unit = models.CharField(max_length=45, blank=True, null=True) | |
409 | + status = models.CharField(max_length=45, blank=True, null=True) | |
410 | + current = models.DecimalField(max_digits=15, decimal_places=8, blank=True, null=True) | |
411 | + current_unit = models.CharField(max_length=45, blank=True, null=True) | |
412 | + is_safe = models.BooleanField(default=True) | |
413 | + plc_mode = models.CharField(max_length=4, null=True) | |
414 | + lights = models.CharField(max_length=3, null=True) | |
415 | + shutters = models.CharField(max_length=5, null=True) | |
416 | + | |
417 | + class Meta: | |
418 | + managed = True | |
419 | + db_table = 'plc_devices_status' | |
303 | 420 | |
304 | 421 | def __str__(self): |
305 | - return (str(self.agent)) | |
422 | + return (str(self.__dict__)) | |
306 | 423 | |
424 | + ''' | |
425 | + TODO : This function is Ugly, | |
426 | + we should change this with a function pointer array | |
427 | + and setters getters for each attribute | |
428 | + ''' | |
429 | + def setValue(self, key, value, unit=""): | |
430 | + if key == "OutsideTemp": | |
431 | + self.outside_temp = value | |
432 | + self.outside_temp_unit = unit | |
433 | + elif key == "OutsideHumidity": | |
434 | + self.outside_humidity = value | |
435 | + self.outside_humidity_unit = unit | |
436 | + elif key == "Pressure": | |
437 | + self.pressure = value | |
438 | + self.pressure_unit = unit | |
439 | + elif key == "RainRate": | |
440 | + self.rain_rate = value | |
441 | + self.rain_rate_unit = unit | |
442 | + elif key == "WindSpeed": | |
443 | + self.wind_speed = value | |
444 | + self.wind_speed_unit = unit | |
445 | + elif key == "WindDir": | |
446 | + self.wind_dir = value | |
447 | + self.wind_dir_unit = unit | |
448 | + elif key == "DewPoint": | |
449 | + self.dew_point = value | |
450 | + self.dew_point_unit = unit | |
451 | + elif key == "analog": | |
452 | + self.analog = value | |
453 | + self.analog_unit = unit | |
454 | + elif key == "digital": | |
455 | + self.digital = value | |
456 | + self.digital_unit = unit | |
457 | + elif key == "InsideTemp": | |
458 | + self.inside_temp = value | |
459 | + self.inside_temp_unit = unit | |
460 | + elif key == "InsideHumidity": | |
461 | + self.inside_humidity = value | |
462 | + self.inside_humidity_unit = unit | |
463 | + elif key == "WindDirCardinal": | |
464 | + self.wind_dir_cardinal = value | |
465 | + self.wind_dir_cardinal_unit = unit | |
466 | + elif key == "SensorTemperature": | |
467 | + self.sensor_temperature = value | |
468 | + self.sensor_temperature_unit = unit | |
469 | + elif key == "SkyTemperature": | |
470 | + self.sky_temperature = value | |
471 | + self.sky_temperature_unit = unit | |
472 | + elif key == "status": | |
473 | + self.status = value | |
474 | + elif key == "current": | |
475 | + self.current = value | |
476 | + self.current_unit = unit | |
477 | + elif key == "mode": | |
478 | + self.plc_mode = value | |
479 | + elif key == "is_safe": | |
480 | + self.is_safe = value | |
481 | + elif key == "LIGHTS": | |
482 | + self.lights = value | |
483 | + elif key == "SHUTTERS": | |
484 | + self.shutters = value | |
485 | + else: | |
486 | + raise KeyError("Key " + str(key) + " unrecognized") | |
307 | 487 | |
308 | -class NrtAnalysis(models.Model): | |
488 | +class PlcDevice(Device): | |
489 | + #device = models.ForeignKey('Plc', on_delete=models.CASCADE, related_name='plc_devices') | |
309 | 490 | name = models.CharField(max_length=45, blank=True, null=True) |
310 | 491 | desc = models.TextField(blank=True, null=True) |
311 | 492 | created = models.DateTimeField(blank=True, null=True, auto_now_add=True) |
312 | 493 | updated = models.DateTimeField(blank=True, null=True, auto_now=True) |
313 | - analysis = models.TextField(blank=True, null=True) | |
494 | + | |
314 | 495 | |
315 | 496 | class Meta: |
316 | 497 | managed = True |
317 | - db_table = 'nrtanalysis' | |
318 | - verbose_name_plural = "Nrt analyzes" | |
498 | + db_table = 'plc_devices' | |
319 | 499 | |
320 | 500 | def __str__(self): |
321 | - return (str(self.name)) | |
322 | - | |
501 | + return str(self.name) | |
323 | 502 | |
324 | -class Plan(models.Model): | |
325 | - album = models.ForeignKey(Album, on_delete=models.CASCADE, related_name="plans") | |
326 | - filter = models.ForeignKey(Filter, models.DO_NOTHING, related_name="plans", blank=True, null=True) | |
327 | - name = models.CharField(max_length=45, blank=True, null=True) | |
328 | - desc = models.CharField(max_length=45, blank=True, null=True) | |
329 | - created = models.DateTimeField(blank=True, null=True, auto_now_add=True) | |
330 | - updated = models.DateTimeField(blank=True, null=True, auto_now=True) | |
331 | - duration = models.FloatField(default=0, blank=True, null=True) | |
332 | - position = models.CharField(max_length=45, blank=True, null=True) | |
333 | - exposure_time = models.FloatField(blank=True, null=True) | |
334 | - nb_images = models.IntegerField(blank=True, null=True) | |
335 | - dithering = models.BooleanField(default=False) | |
336 | - complete = models.BooleanField(default=False) | |
337 | 503 | |
338 | - class Meta: | |
339 | - managed = True | |
340 | - db_table = 'plan' | |
504 | +#class Plc(Device): | |
505 | + # last_update_status = models.DateTimeField(blank=True, null=True) | |
506 | +# i | |
507 | + # class Meta: | |
508 | + # managed = True | |
509 | + # db_table = 'plc' | |
341 | 510 | |
342 | - def __str__(self): | |
343 | - return (str(self.name)) | |
344 | 511 | |
345 | 512 | |
346 | 513 | class PyrosUser(AbstractUser): |
... | ... | @@ -382,62 +549,9 @@ class PyrosUser(AbstractUser): |
382 | 549 | user_username.short_description = "Username" |
383 | 550 | |
384 | 551 | |
385 | -class Request(models.Model): | |
386 | - pyros_user = models.ForeignKey( | |
387 | - 'PyrosUser', on_delete=models.DO_NOTHING, related_name="requests") | |
388 | - scientific_program = models.ForeignKey( | |
389 | - 'ScientificProgram', on_delete=models.DO_NOTHING, related_name="requests", blank=True, null=True) | |
390 | - name = models.CharField(max_length=45, blank=True, null=True) | |
391 | - desc = models.TextField(blank=True, null=True) | |
392 | - created = models.DateTimeField(blank=True, null=True, auto_now_add=True) | |
393 | - updated = models.DateTimeField(blank=True, null=True, auto_now=True) | |
394 | - is_alert = models.BooleanField(default=False) | |
395 | - target_type = models.CharField(max_length=8, blank=True, null=True) | |
396 | - status = models.CharField(max_length=10, blank=True, null=True) | |
397 | - autodeposit = models.BooleanField(default=False) | |
398 | - checkpoint = models.CharField(max_length=45, blank=True, null=True) | |
399 | - flag = models.CharField(max_length=45, blank=True, null=True) | |
400 | - complete = models.BooleanField(default=False) | |
401 | - submitted = models.BooleanField(default=False) | |
402 | - | |
403 | - class Meta: | |
404 | - managed = True | |
405 | - db_table = 'request' | |
406 | - | |
407 | - def __str__(self): | |
408 | - return (str(self.name)) | |
409 | - | |
410 | - | |
411 | -class Alert(Request): | |
412 | - request = models.OneToOneField('Request', on_delete=models.CASCADE, default='', parent_link=True) | |
413 | - strategyobs = models.ForeignKey( | |
414 | - 'StrategyObs', models.DO_NOTHING, related_name="alerts", blank=True, null=True) | |
415 | - voevent_file = models.CharField(max_length=45, blank=True, null=True) | |
416 | - author = models.CharField(max_length=45, blank=True, null=True) | |
417 | - burst_jd = models.DecimalField(max_digits=15, decimal_places=8, blank=True, null=True) | |
418 | - burst_ra = models.FloatField(max_length=45, blank=True, null=True) | |
419 | - burst_dec = models.FloatField(max_length=45, blank=True, null=True) | |
420 | - astro_coord_system = models.CharField(max_length=45, blank=True, null=True) | |
421 | - jd_send = models.DecimalField(max_digits=15, decimal_places=8, blank=True, null=True) | |
422 | - jd_received = models.DecimalField(max_digits=15, decimal_places=8, blank=True, null=True) | |
423 | - trig_id = models.IntegerField(blank=True, null=True) | |
424 | - error_radius = models.FloatField(max_length=45, blank=True, null=True) | |
425 | - defly_not_grb = models.BooleanField(default=False) | |
426 | - editor = models.CharField(max_length=45, blank=True, null=True) | |
427 | - soln_status = models.CharField(max_length=45, blank=True, null=True) | |
428 | - pkt_ser_num = models.IntegerField(blank=True, null=True) | |
429 | - | |
430 | - class Meta: | |
431 | - managed = True | |
432 | - db_table = 'alert' | |
433 | 552 | |
434 | - def __str__(self): | |
435 | - return str(self.trig_id) | |
436 | 553 | |
437 | - def request_name(self): | |
438 | - return self.__str__() | |
439 | 554 | |
440 | - request_name.short_description = "Name" | |
441 | 555 | |
442 | 556 | # class Schedule(models.Model): |
443 | 557 | # created = models.DateTimeField(blank=True, null=True, auto_now_add=True) |
... | ... | @@ -675,22 +789,6 @@ class TaskId(models.Model): |
675 | 789 | return (str(self.task) + " - " + str(self.task_id)) |
676 | 790 | |
677 | 791 | |
678 | -class Dome(Device): | |
679 | - DOME = "Dome" | |
680 | - | |
681 | - open = models.BooleanField(default=False, blank=True) | |
682 | - | |
683 | - class Meta: | |
684 | - managed = True | |
685 | - db_table = 'dome' | |
686 | - | |
687 | - def __str__(self): | |
688 | - return str(self.name) | |
689 | - | |
690 | - def device_name(self): | |
691 | - return self.__str__() | |
692 | - device_name.short_description = "Name" | |
693 | - | |
694 | 792 | |
695 | 793 | class Telescope(Device): |
696 | 794 | TELESCOPE = "Telescope" |
... | ... | @@ -722,6 +820,19 @@ class Telescope(Device): |
722 | 820 | return (self.name) |
723 | 821 | |
724 | 822 | |
823 | +class TelescopeCommand(models.Model): | |
824 | + created = models.DateTimeField(blank=True, null=True, auto_now_add=True) | |
825 | + answered = models.DateTimeField(blank=True, null=True) | |
826 | + request = models.CharField(blank=False, null=False, max_length=255) | |
827 | + answer = models.TextField(null=True, blank=True) | |
828 | + class Meta: | |
829 | + managed = True | |
830 | + db_table = "telescopecommand" | |
831 | + | |
832 | + def __str__(self): | |
833 | + return str(self.request) + str(self.created) | |
834 | + | |
835 | + | |
725 | 836 | class UserLevel(models.Model): |
726 | 837 | name = models.CharField(max_length=45, blank=True, null=True) |
727 | 838 | desc = models.TextField(blank=True, null=True) |
... | ... | @@ -829,63 +940,8 @@ class WeatherWatchHistory(models.Model): |
829 | 940 | return (str(self.datetime)) |
830 | 941 | |
831 | 942 | |
832 | -class PyrosState(Enum): | |
833 | - START = 'Starting' | |
834 | - PA = 'Passive' | |
835 | - INI = "INIT" | |
836 | - STAND = "Standby" | |
837 | - SCHED_START = 'Scheduler startup' | |
838 | - SCHED = 'Scheduler' | |
839 | - SCHED_CLOSE = 'Scheduler closing' | |
840 | - | |
841 | -class Config(models.Model): | |
842 | - PYROS_STATE = ["Starting", "Passive", "Standby", "Remote", "Startup", "Scheduler", "Closing" ] | |
843 | - | |
844 | - id = models.IntegerField(default='1', primary_key=True) | |
845 | - latitude = models.FloatField(default=1) | |
846 | - local_time_zone = models.FloatField(default=1) | |
847 | - longitude = models.FloatField(default=1) | |
848 | - altitude = models.FloatField(default=1) | |
849 | - horizon_line = models.FloatField(default=1) | |
850 | - row_data_save_frequency = models.IntegerField(default='300') | |
851 | - request_frequency = models.IntegerField(default='300') | |
852 | - analysed_data_save = models.IntegerField(default='300') | |
853 | - telescope_ip_address = models.CharField(max_length=45, default="127.0.0.1") | |
854 | - camera_ip_address = models.CharField(max_length=45, default="127.0.0.1") | |
855 | - plc_ip_address = models.CharField(max_length=45, default="127.0.0.1") | |
856 | - | |
857 | - # TODO: changer ça, c'est pas clair du tout... | |
858 | - # True = mode Scheduler-standby, False = mode Remote !!!! | |
859 | - global_mode = models.BooleanField(default='True') | |
860 | - | |
861 | - ack = models.BooleanField(default='False') | |
862 | - bypass = models.BooleanField(default='True') | |
863 | - lock = models.BooleanField(default='False') | |
864 | - pyros_state = models.CharField(max_length=25, default=PYROS_STATE[0]) | |
865 | - force_passive_mode = models.BooleanField(default='False') | |
866 | - plc_timeout_seconds = models.PositiveIntegerField(default=60) | |
867 | - majordome_state = models.CharField(max_length=25, default="") | |
868 | - ntc = models.BooleanField(default='False') | |
869 | - majordome_restarted = models.BooleanField(default='False') | |
870 | - | |
871 | - class Meta: | |
872 | - managed = True | |
873 | - db_table = 'config' | |
874 | - verbose_name_plural = "Config" | |
875 | 943 | |
876 | - def __str__(self): | |
877 | - return (str(self.__dict__)) | |
878 | 944 | |
879 | 945 | |
880 | 946 | |
881 | -class TelescopeCommand(models.Model): | |
882 | - created = models.DateTimeField(blank=True, null=True, auto_now_add=True) | |
883 | - answered = models.DateTimeField(blank=True, null=True) | |
884 | - request = models.CharField(blank=False, null=False, max_length=255) | |
885 | - answer = models.TextField(null=True, blank=True) | |
886 | - class Meta: | |
887 | - managed = True | |
888 | - db_table = "telescopecommand" | |
889 | 947 | |
890 | - def __str__(self): | |
891 | - return str(self.request) + str(self.created) | ... | ... |
src/dashboard/templatetags/tags.py