Blame view

src/common/models.py 34.7 KB
ddf59dd4   haribo   Remaniement :
1
2
from __future__ import unicode_literals

53787d30   Jeremy   Alert now inherit...
3
from django.contrib.auth.models import AbstractUser
3df2d31a   haribo   #3430 : dates are...
4
from django.db import models
bb697c31   Unknown   Auto stash before...
5
from enum import Enum
3df2d31a   haribo   #3430 : dates are...
6

a5f1e984   Etienne Pallier   cleanup common/mo...
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

''' 
NOT USED - to be removed
class PyrosState(Enum):
    START = 'Starting'
    PA = 'Passive'
    INI = "INIT"
    STAND = "Standby"
    SCHED_START = 'Scheduler startup'
    SCHED = 'Scheduler'
    SCHED_CLOSE = 'Scheduler closing'
'''


"""
------------------------
   BASE MODEL CLASSES
------------------------
"""

class Device(models.Model):
ddf59dd4   haribo   Remaniement :
28
29
30
31
    name = models.CharField(max_length=45, blank=True, null=True)
    desc = models.TextField(blank=True, null=True)
    created = models.DateTimeField(blank=True, null=True, auto_now_add=True)
    updated = models.DateTimeField(blank=True, null=True, auto_now=True)
a5f1e984   Etienne Pallier   cleanup common/mo...
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
    is_online = models.BooleanField(default=False)
    status = models.CharField(max_length=11, blank=True, null=True)
    maintenance_date = models.DateTimeField(blank=True, null=True)

    class Meta:
        abstract = True

    def __str__(self):
        return (str(self.name))


class Request(models.Model):
    pyros_user = models.ForeignKey(
        'PyrosUser', on_delete=models.DO_NOTHING, related_name="requests")
    scientific_program = models.ForeignKey(
        'ScientificProgram', on_delete=models.DO_NOTHING, related_name="requests", blank=True, null=True)
    name = models.CharField(max_length=45, blank=True, null=True)
    desc = models.TextField(blank=True, null=True)
    created = models.DateTimeField(blank=True, null=True, auto_now_add=True)
    updated = models.DateTimeField(blank=True, null=True, auto_now=True)
    is_alert = models.BooleanField(default=False)
    target_type = models.CharField(max_length=8, blank=True, null=True)
    status = models.CharField(max_length=10, blank=True, null=True)
    autodeposit = models.BooleanField(default=False)
    checkpoint = models.CharField(max_length=45, blank=True, null=True)
    flag = models.CharField(max_length=45, blank=True, null=True)
ddf59dd4   haribo   Remaniement :
58
    complete = models.BooleanField(default=False)
a5f1e984   Etienne Pallier   cleanup common/mo...
59
    submitted = models.BooleanField(default=False)
ddf59dd4   haribo   Remaniement :
60
61
62

    class Meta:
        managed = True
a5f1e984   Etienne Pallier   cleanup common/mo...
63
        db_table = 'request'
ddf59dd4   haribo   Remaniement :
64
65
66
67
68

    def __str__(self):
        return (str(self.name))


a5f1e984   Etienne Pallier   cleanup common/mo...
69
70
71
72
73
74
75
76
77
78
79
80
81

"""
------------------------
   OTHER MODEL CLASSES
------------------------
"""

# TODO:
"""
A chaque tour de boucle, remplir champ "iamalive" avec timestamp + durée validité (> temps iteration,  n minutes par défaut) 
+ nom agent dans table agents_survey (nom agent + mode + status + updated timestamp)
"""
class AgentsSurvey(models.Model):
ddf59dd4   haribo   Remaniement :
82
83
    name = models.CharField(max_length=45, blank=True, null=True)
    desc = models.TextField(blank=True, null=True)
a5f1e984   Etienne Pallier   cleanup common/mo...
84
85
    created = models.DateTimeField(blank=True, null=True, auto_now_add=True)
    updated = models.DateTimeField(blank=True, null=True, auto_now=True)
ddf59dd4   haribo   Remaniement :
86
87
88

    class Meta:
        managed = True
a5f1e984   Etienne Pallier   cleanup common/mo...
89
        db_table = 'agents_survey'
ddf59dd4   haribo   Remaniement :
90
91
92
93

    def __str__(self):
        return (str(self.name))

ce470283   Jeremy   Plc simulator fin...
94

a5f1e984   Etienne Pallier   cleanup common/mo...
95
96
97
98
99
class Album(models.Model):
    sequence = models.ForeignKey(
        'Sequence', on_delete=models.CASCADE, related_name="albums")
    detector = models.ForeignKey(
        'Detector', models.DO_NOTHING, related_name="albums", blank=True, null=True)
abfb02e2   Jeremy   Device Model is n...
100
101
102
103
    name = models.CharField(max_length=45, blank=True, null=True)
    desc = models.TextField(blank=True, null=True)
    created = models.DateTimeField(blank=True, null=True, auto_now_add=True)
    updated = models.DateTimeField(blank=True, null=True, auto_now=True)
a5f1e984   Etienne Pallier   cleanup common/mo...
104
    complete = models.BooleanField(default=False)
abfb02e2   Jeremy   Device Model is n...
105
106

    class Meta:
a5f1e984   Etienne Pallier   cleanup common/mo...
107
108
        managed = True
        db_table = 'album'
abfb02e2   Jeremy   Device Model is n...
109
110
111
112

    def __str__(self):
        return (str(self.name))

a5f1e984   Etienne Pallier   cleanup common/mo...
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131

class Alert(Request):
    request = models.OneToOneField('Request', on_delete=models.CASCADE, default='', parent_link=True)
    strategyobs = models.ForeignKey(
        'StrategyObs', models.DO_NOTHING, related_name="alerts", blank=True, null=True)
    voevent_file = models.CharField(max_length=45, blank=True, null=True)
    author = models.CharField(max_length=45, blank=True, null=True)
    burst_jd = models.DecimalField(max_digits=15, decimal_places=8, blank=True, null=True)
    burst_ra = models.FloatField(max_length=45, blank=True, null=True)
    burst_dec = models.FloatField(max_length=45, blank=True, null=True)
    astro_coord_system = models.CharField(max_length=45, blank=True, null=True)
    jd_send = models.DecimalField(max_digits=15, decimal_places=8, blank=True, null=True)
    jd_received = models.DecimalField(max_digits=15, decimal_places=8, blank=True, null=True)
    trig_id = models.IntegerField(blank=True, null=True)
    error_radius = models.FloatField(max_length=45, blank=True, null=True)
    defly_not_grb = models.BooleanField(default=False)
    editor = models.CharField(max_length=45, blank=True, null=True)
    soln_status = models.CharField(max_length=45, blank=True, null=True)
    pkt_ser_num = models.IntegerField(blank=True, null=True)
6c2793c2   jeremy   Update
132
133
134

    class Meta:
        managed = True
a5f1e984   Etienne Pallier   cleanup common/mo...
135
        db_table = 'alert'
6c2793c2   jeremy   Update
136
137

    def __str__(self):
a5f1e984   Etienne Pallier   cleanup common/mo...
138
        return str(self.trig_id)
6c2793c2   jeremy   Update
139

a5f1e984   Etienne Pallier   cleanup common/mo...
140
141
    def request_name(self):
        return self.__str__()
fe5613f5   jeremy   Update plc protocol
142

a5f1e984   Etienne Pallier   cleanup common/mo...
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
    request_name.short_description = "Name"



class Config(models.Model):
    PYROS_STATE = ["Starting", "Passive", "Standby", "Remote", "Startup", "Scheduler", "Closing" ]

    id = models.IntegerField(default='1', primary_key=True)
    latitude = models.FloatField(default=1)
    local_time_zone = models.FloatField(default=1)
    longitude = models.FloatField(default=1)
    altitude = models.FloatField(default=1)
    horizon_line = models.FloatField(default=1)
    row_data_save_frequency = models.IntegerField(default='300')
    request_frequency = models.IntegerField(default='300')
    analysed_data_save = models.IntegerField(default='300')
    telescope_ip_address = models.CharField(max_length=45, default="127.0.0.1")
    camera_ip_address = models.CharField(max_length=45, default="127.0.0.1")
    plc_ip_address = models.CharField(max_length=45, default="127.0.0.1")
6973f7df   Quentin Durand   PLC STATE + MODE
162

a5f1e984   Etienne Pallier   cleanup common/mo...
163
164
165
166
167
168
169
170
171
172
173
174
175
    # TODO: changer ça, c'est pas clair du tout...
    # True = mode Scheduler-standby, False = mode Remote !!!!
    global_mode = models.BooleanField(default='True')

    ack = models.BooleanField(default='False')
    bypass = models.BooleanField(default='True')
    lock = models.BooleanField(default='False')
    pyros_state = models.CharField(max_length=25, default=PYROS_STATE[0])
    force_passive_mode = models.BooleanField(default='False')
    plc_timeout_seconds = models.PositiveIntegerField(default=60)
    majordome_state = models.CharField(max_length=25, default="")
    ntc = models.BooleanField(default='False')
    majordome_restarted = models.BooleanField(default='False')
6c2793c2   jeremy   Update
176
177
178

    class Meta:
        managed = True
a5f1e984   Etienne Pallier   cleanup common/mo...
179
180
        db_table = 'config'
        verbose_name_plural = "Config"
6c2793c2   jeremy   Update
181
182

    def __str__(self):
a5f1e984   Etienne Pallier   cleanup common/mo...
183
        return (str(self.__dict__))
6c2793c2   jeremy   Update
184
185


a5f1e984   Etienne Pallier   cleanup common/mo...
186
187
188
189
190
191
192
193
194
195
196
197
198

class Country(models.Model):
    name = models.CharField(max_length=45, blank=True, null=True)
    desc = models.TextField(blank=True, null=True)
    quota = models.FloatField(blank=True, null=True)

    class Meta:
        managed = True
        db_table = 'country'
        verbose_name_plural = "Countries"

    def __str__(self):
        return (str(self.name))
6c2793c2   jeremy   Update
199

abfb02e2   Jeremy   Device Model is n...
200
201
202
203

class Detector(Device):
    VIS = "Visible camera"
    NIR = "Cagire"
ddf59dd4   haribo   Remaniement :
204

ddf59dd4   haribo   Remaniement :
205
206
    telescope = models.ForeignKey(
        'Telescope', models.DO_NOTHING, related_name="detectors")
ddf59dd4   haribo   Remaniement :
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
    nb_photo_x = models.IntegerField(blank=True, null=True)
    nb_photo_y = models.IntegerField(blank=True, null=True)
    photo_size_x = models.IntegerField(blank=True, null=True)
    photo_size_y = models.IntegerField(blank=True, null=True)
    has_shutter = models.BooleanField(default=False)
    equivalent_foc_len = models.CharField(max_length=45, blank=True, null=True)
    acq_start = models.DateTimeField(blank=True, null=True)
    acq_stop = models.DateTimeField(blank=True, null=True)
    check_temp = models.FloatField(blank=True, null=True)
    gain = models.FloatField(blank=True, null=True)
    readout_noise = models.FloatField(blank=True, null=True)
    readout_time = models.FloatField(blank=True, null=True)
    idcam_readout_mode = models.IntegerField(blank=True, null=True)

    class Meta:
        managed = True
        db_table = 'detector'

    def __str__(self):
f7dd3df1   Jeremy   Update simulators...
226
        return str(self.name)
ddf59dd4   haribo   Remaniement :
227
228
229
230
231
232

    def device_name(self):
        return self.__str__()
    device_name.short_description = "Name"


a5f1e984   Etienne Pallier   cleanup common/mo...
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
class Dome(Device):
    DOME = "Dome"

    open = models.BooleanField(default=False, blank=True)

    class Meta:
        managed = True
        db_table = 'dome'

    def __str__(self):
        return str(self.name)

    def device_name(self):
        return self.__str__()
    device_name.short_description = "Name"



abfb02e2   Jeremy   Device Model is n...
251
class Filter(Device):
ddf59dd4   haribo   Remaniement :
252
253
254
255
256
    VIS_FILTER_1 = "First visible filter"
    VIS_FILTER_2 = "Second visible filter"
    NIR_FILTER_1 = "First infrared filter"
    NIR_FILTER_2 = "Second infrared filter"

ddf59dd4   haribo   Remaniement :
257
258
259
260
261
262
263
264
265
266
267
    filter_wheel = models.ForeignKey(
        "FilterWheel", models.DO_NOTHING, related_name="filters", blank=True, null=True)
    category = models.CharField(max_length=1, blank=True, null=True)
    transmission_curve_doc = models.CharField(
        max_length=45, blank=True, null=True)

    class Meta:
        managed = True
        db_table = 'filter'

    def __str__(self):
f7dd3df1   Jeremy   Update simulators...
268
        return (str(self.name))
ddf59dd4   haribo   Remaniement :
269
270
271
272
273
274

    def device_name(self):
        return self.__str__()
    device_name.short_description = "Name"


abfb02e2   Jeremy   Device Model is n...
275
class FilterWheel(Device):
ce470283   Jeremy   Plc simulator fin...
276
277
    detector = models.OneToOneField(Detector, on_delete=models.CASCADE,
                                    related_name="filter_wheel", blank=True, null=True)
ddf59dd4   haribo   Remaniement :
278
279
280
281
282
283

    class Meta:
        managed = True
        db_table = 'filter_wheel'

    def __str__(self):
f7dd3df1   Jeremy   Update simulators...
284
        return (str(self.name))
ddf59dd4   haribo   Remaniement :
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331

    def device_name(self):
        return self.__str__()
    device_name.short_description = "Name"


class Image(models.Model):
    plan = models.ForeignKey('Plan', on_delete=models.CASCADE, related_name="images")
    nrtanalysis = models.ForeignKey(
        'NrtAnalysis', models.DO_NOTHING, blank=True, null=True, related_name="images")
    name = models.CharField(max_length=45, blank=True, null=True)
    desc = models.TextField(blank=True, null=True)
    created = models.DateTimeField(blank=True, null=True, auto_now_add=True)
    updated = models.DateTimeField(blank=True, null=True, auto_now=True)
    date_from_gps = models.CharField(max_length=45, blank=True, null=True)
    level = models.IntegerField(blank=True, null=True)
    type = models.CharField(max_length=5, blank=True, null=True)
    quality = models.CharField(max_length=45, blank=True, null=True)
    flaggps = models.CharField(max_length=45, blank=True, null=True)
    exposure = models.CharField(max_length=45, blank=True, null=True)
    tempext = models.CharField(max_length=45, blank=True, null=True)
    pressure = models.CharField(max_length=45, blank=True, null=True)
    humidext = models.CharField(max_length=45, blank=True, null=True)
    wind = models.CharField(max_length=45, blank=True, null=True)
    wind_dir = models.CharField(max_length=45, blank=True, null=True)
    dwnimg = models.CharField(max_length=45, blank=True, null=True)
    dwncata = models.CharField(max_length=45, blank=True, null=True)
    dwn = models.CharField(max_length=45, blank=True, null=True)
    level0_fits_name = models.CharField(max_length=45, blank=True, null=True)
    level1a_fits_name = models.CharField(max_length=45, blank=True, null=True)
    level1b_fits_name = models.CharField(max_length=45, blank=True, null=True)

    class Meta:
        managed = True
        db_table = 'image'

    def __str__(self):
        return (str(self.name))


class Log(models.Model):
    agent = models.CharField(max_length=45, blank=True, null=True)
    created = models.DateTimeField(blank=True, null=True, auto_now_add=True)
    message = models.TextField(blank=True, null=True)

    class Meta:
        managed = True
a5f1e984   Etienne Pallier   cleanup common/mo...
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
        db_table = 'log'

    def __str__(self):
        return (str(self.agent))


class NrtAnalysis(models.Model):
    name = models.CharField(max_length=45, blank=True, null=True)
    desc = models.TextField(blank=True, null=True)
    created = models.DateTimeField(blank=True, null=True, auto_now_add=True)
    updated = models.DateTimeField(blank=True, null=True, auto_now=True)
    analysis = models.TextField(blank=True, null=True)

    class Meta:
        managed = True
        db_table = 'nrtanalysis'
        verbose_name_plural = "Nrt analyzes"

    def __str__(self):
        return (str(self.name))


class Plan(models.Model):
    album = models.ForeignKey(Album, on_delete=models.CASCADE, related_name="plans")
    filter = models.ForeignKey(Filter, models.DO_NOTHING, related_name="plans", blank=True, null=True)
    name = models.CharField(max_length=45, blank=True, null=True)
    desc = models.CharField(max_length=45, blank=True, null=True)
    created = models.DateTimeField(blank=True, null=True, auto_now_add=True)
    updated = models.DateTimeField(blank=True, null=True, auto_now=True)
    duration = models.FloatField(default=0, blank=True, null=True)
    position = models.CharField(max_length=45, blank=True, null=True)
    exposure_time = models.FloatField(blank=True, null=True)
    nb_images = models.IntegerField(blank=True, null=True)
    dithering = models.BooleanField(default=False)
    complete = models.BooleanField(default=False)

    class Meta:
        managed = True
        db_table = 'plan'

    def __str__(self):
        return (str(self.name))




class PlcDeviceStatus(models.Model):
    device = models.ForeignKey('PlcDevice', on_delete=models.CASCADE, related_name='current_status')
    created = models.DateTimeField(auto_now_add=True, editable=False, blank=True)
    outside_temp = models.DecimalField(max_digits=15, decimal_places=8, blank=True, null=True)
    outside_temp_unit = models.CharField(max_length=45, blank=True, null=True)
    outside_humidity = models.DecimalField(max_digits=15, decimal_places=8, blank=True, null=True)
    outside_humidity_unit = models.CharField(max_length=45, blank=True, null=True)
    pressure = models.DecimalField(max_digits=15, decimal_places=8, blank=True, null=True)
    pressure_unit = models.CharField(max_length=45, blank=True, null=True)
    rain_rate = models.DecimalField(max_digits=15, decimal_places=8, blank=True, null=True)
    rain_rate_unit = models.CharField(max_length=45, blank=True, null=True)
    wind_speed = models.DecimalField(max_digits=15, decimal_places=8, blank=True, null=True)
    wind_speed_unit = models.CharField(max_length=45, blank=True, null=True)
    wind_dir = models.DecimalField(max_digits=15, decimal_places=8, blank=True, null=True)
    wind_dir_unit = models.CharField(max_length=45, blank=True, null=True)
    dew_point = models.DecimalField(max_digits=15, decimal_places=8, blank=True, null=True)
    dew_point_unit = models.CharField(max_length=45, blank=True, null=True)
    analog = models.DecimalField(max_digits=15, decimal_places=8, blank=True, null=True)
    analog_unit = models.CharField(max_length=45, blank=True, null=True)
    digital = models.DecimalField(max_digits=15, decimal_places=8, blank=True, null=True)
    digital_unit = models.CharField(max_length=45, blank=True, null=True)
    inside_temp = models.DecimalField(max_digits=15, decimal_places=8, blank=True, null=True)
    inside_temp_unit = models.CharField(max_length=45, blank=True, null=True)
    inside_humidity = models.DecimalField(max_digits=15, decimal_places=8, blank=True, null=True)
    inside_humidity_unit = models.CharField(max_length=45, blank=True, null=True)
    wind_dir_cardinal = models.CharField(max_length=45, blank=True, null=True)
    wind_dir_cardinal_unit = models.CharField(max_length=45, blank=True, null=True)
    sensor_temperature = models.DecimalField(max_digits=15, decimal_places=8, blank=True, null=True)
    sensor_temperature_unit = models.CharField(max_length=45, blank=True, null=True)
    sky_temperature = models.DecimalField(max_digits=15, decimal_places=8, blank=True, null=True)
    sky_temperature_unit = models.CharField(max_length=45,  blank=True, null=True)
    status = models.CharField(max_length=45, blank=True, null=True)
    current = models.DecimalField(max_digits=15, decimal_places=8, blank=True, null=True)
    current_unit = models.CharField(max_length=45, blank=True, null=True)
    is_safe = models.BooleanField(default=True)
    plc_mode = models.CharField(max_length=4, null=True)
    lights = models.CharField(max_length=3, null=True)
    shutters = models.CharField(max_length=5, null=True)

    class Meta:
        managed = True
        db_table = 'plc_devices_status'
ddf59dd4   haribo   Remaniement :
420
421

    def __str__(self):
a5f1e984   Etienne Pallier   cleanup common/mo...
422
        return (str(self.__dict__))
ddf59dd4   haribo   Remaniement :
423

a5f1e984   Etienne Pallier   cleanup common/mo...
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
    '''
        TODO : This function is Ugly,
        we should change this with a function pointer array
        and setters getters for each attribute
    '''
    def setValue(self, key, value, unit=""):
        if key == "OutsideTemp":
            self.outside_temp = value
            self.outside_temp_unit = unit
        elif key == "OutsideHumidity":
            self.outside_humidity = value
            self.outside_humidity_unit = unit
        elif key == "Pressure":
            self.pressure = value
            self.pressure_unit = unit
        elif key == "RainRate":
            self.rain_rate = value
            self.rain_rate_unit = unit
        elif key == "WindSpeed":
            self.wind_speed = value
            self.wind_speed_unit = unit
        elif key == "WindDir":
            self.wind_dir = value
            self.wind_dir_unit = unit
        elif key == "DewPoint":
            self.dew_point = value
            self.dew_point_unit = unit
        elif key == "analog":
            self.analog = value
            self.analog_unit = unit
        elif key == "digital":
            self.digital = value
            self.digital_unit = unit
        elif key == "InsideTemp":
            self.inside_temp = value
            self.inside_temp_unit = unit
        elif key == "InsideHumidity":
            self.inside_humidity = value
            self.inside_humidity_unit = unit
        elif key == "WindDirCardinal":
            self.wind_dir_cardinal = value
            self.wind_dir_cardinal_unit = unit
        elif key == "SensorTemperature":
            self.sensor_temperature = value
            self.sensor_temperature_unit = unit
        elif key == "SkyTemperature":
            self.sky_temperature = value
            self.sky_temperature_unit = unit
        elif key == "status":
            self.status = value
        elif key == "current":
            self.current = value
            self.current_unit = unit
        elif key == "mode":
            self.plc_mode = value
        elif key == "is_safe":
            self.is_safe = value
        elif key == "LIGHTS":
            self.lights = value
        elif key == "SHUTTERS":
            self.shutters = value
        else:
            raise KeyError("Key " + str(key) + " unrecognized")
ddf59dd4   haribo   Remaniement :
487

a5f1e984   Etienne Pallier   cleanup common/mo...
488
489
class PlcDevice(Device):
    #device = models.ForeignKey('Plc', on_delete=models.CASCADE, related_name='plc_devices')
ddf59dd4   haribo   Remaniement :
490
491
492
493
    name = models.CharField(max_length=45, blank=True, null=True)
    desc = models.TextField(blank=True, null=True)
    created = models.DateTimeField(blank=True, null=True, auto_now_add=True)
    updated = models.DateTimeField(blank=True, null=True, auto_now=True)
a5f1e984   Etienne Pallier   cleanup common/mo...
494

ddf59dd4   haribo   Remaniement :
495
496
497

    class Meta:
        managed = True
a5f1e984   Etienne Pallier   cleanup common/mo...
498
        db_table = 'plc_devices'
ddf59dd4   haribo   Remaniement :
499
500

    def __str__(self):
a5f1e984   Etienne Pallier   cleanup common/mo...
501
        return str(self.name)
ddf59dd4   haribo   Remaniement :
502

ddf59dd4   haribo   Remaniement :
503

a5f1e984   Etienne Pallier   cleanup common/mo...
504
505
506
507
508
509
#class Plc(Device):
 #   last_update_status = models.DateTimeField(blank=True, null=True)
#    i
 #   class Meta:
  #      managed = True
   #     db_table = 'plc'
ddf59dd4   haribo   Remaniement :
510

ddf59dd4   haribo   Remaniement :
511
512


53787d30   Jeremy   Alert now inherit...
513
class PyrosUser(AbstractUser):
2c61f856   theopuhl   Url change to pat...
514
    username = models.CharField(max_length=255, blank=False, null=False, unique=True)
c5ae1cae   theopuhl   Add send mail + v...
515
516
    is_active = models.BooleanField(default='False')
    first_time = models.BooleanField(default='False')
ddf59dd4   haribo   Remaniement :
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
    country = models.ForeignKey(
        Country, on_delete=models.DO_NOTHING, related_name="pyros_users")
    user_level = models.ForeignKey(
        'UserLevel', on_delete=models.DO_NOTHING, related_name="pyros_users")
    desc = models.TextField(blank=True, null=True)
    created = models.DateTimeField(blank=True, null=True, auto_now_add=True)
    updated = models.DateTimeField(blank=True, null=True, auto_now=True)
    tel = models.CharField(max_length=45, blank=True, null=True)
    address = models.TextField(max_length=100, blank=True, null=True)
    laboratory = models.CharField(max_length=45, blank=True, null=True)
    last_connect = models.DateTimeField(blank=True, null=True)
    cur_connect = models.DateTimeField(blank=True, null=True)
    putvalid_beg = models.DateTimeField(blank=True, null=True)
    putvalid_end = models.DateTimeField(blank=True, null=True)
    acqvalid_beg = models.CharField(max_length=45, blank=True, null=True)
    acqvalid_end = models.CharField(max_length=45, blank=True, null=True)
    quota = models.FloatField(blank=True, null=True)
    quota_rea = models.FloatField(blank=True, null=True)
    u_priority = models.IntegerField(blank=True, null=True)
    p_priority = models.IntegerField(blank=True, null=True)
    dir_level = models.IntegerField(blank=True, null=True)
    can_del_void_req = models.BooleanField(default=False)

    class Meta:
        managed = True
        db_table = 'pyros_user'

    def __str__(self):
53787d30   Jeremy   Alert now inherit...
545
        return (str(self.get_username()))
ddf59dd4   haribo   Remaniement :
546
547
548
549
550
551

    def user_username(self):
        return self.__str__()
    user_username.short_description = "Username"


53787d30   Jeremy   Alert now inherit...
552

53787d30   Jeremy   Alert now inherit...
553

53787d30   Jeremy   Alert now inherit...
554

ddf59dd4   haribo   Remaniement :
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615

# class Schedule(models.Model):
#     created = models.DateTimeField(blank=True, null=True, auto_now_add=True)
#     plan_start = models.DecimalField(
#         default=0.0, max_digits=15, decimal_places=8)
#     plan_end = models.DecimalField(
#         default=0.0, max_digits=15, decimal_places=8)
#     flag = models.CharField(max_length=45, blank=True, null=True)
#
#     class Meta:
#         managed = True
#         db_table = 'schedule'
#
#     def __str__(self):
#         return (str(self.created))


class Schedule(models.Model):
    sequences = models.ManyToManyField(
        'Sequence', through='ScheduleHasSequences', related_name='schedules')
    created = models.DateTimeField(blank=True, null=True, auto_now_add=True)
    plan_night_start = models.DecimalField(
        default=0.0, max_digits=15, decimal_places=8)
    plan_end = models.DecimalField(
        default=0.0, max_digits=15, decimal_places=8)
    plan_start = models.DecimalField(
        default=0.0, max_digits=15, decimal_places=8)
    flag = models.CharField(max_length=45, blank=True, null=True)

    class Meta:
        managed = True
        db_table = 'schedule'
        verbose_name_plural = "Schedules"

    def __str__(self):
        return (str(self.created))


class ScientificProgram(models.Model):
    pyros_users = models.ManyToManyField(
        'PyrosUser', related_name="scientific_programs")
    name = models.CharField(max_length=45, blank=True, null=True)
    desc = models.TextField(blank=True, null=True)
    quota = models.FloatField(blank=True, null=True)
    priority = models.IntegerField(blank=True, null=True)

    class Meta:
        managed = True
        db_table = 'scientific_program'

    def __str__(self):
        return (str(self.name))


class Sequence(models.Model):

    """ Definition of Status enum values """

    INCOMPLETE = "INCPL"
    COMPLETE = "CPL"
    TOBEPLANNED = "TBP"
ff448d43   Jeremy   Update
616
    PLANNED = "PLND"
ddf59dd4   haribo   Remaniement :
617
    PENDING = "PNDG"
ddf59dd4   haribo   Remaniement :
618
    EXECUTING = "EXING"
ff448d43   Jeremy   Update
619
    EXECUTED = "EXD"
ddf59dd4   haribo   Remaniement :
620
    REJECTED = "RJTD"
ddf59dd4   haribo   Remaniement :
621
    INVALID = "INVL"
ff448d43   Jeremy   Update
622
623
    CANCELLED = "CNCLD"
    UNPLANNABLE = "UNPLN"
ddf59dd4   haribo   Remaniement :
624
625
626
627
    STATUS_CHOICES = (
        (INCOMPLETE, "Incomplete"),
        (COMPLETE, "Complete"),
        (TOBEPLANNED, "To be planned"),
ff448d43   Jeremy   Update
628
        (PLANNED, "Planned"),
ddf59dd4   haribo   Remaniement :
629
630
631
632
633
634
635
        (UNPLANNABLE, "Unplannable"),
        (PENDING, "Pending"),
        (EXECUTED, "Executed"),
        (EXECUTING, "Executing"),
        (REJECTED, "Rejected"),
        (CANCELLED, "Cancelled"),
        (INVALID, "Invalid"),
ddf59dd4   haribo   Remaniement :
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
    )

    request = models.ForeignKey(
        Request, on_delete=models.CASCADE, related_name="sequences")
    name = models.CharField(max_length=45, blank=True, null=True)
    desc = models.TextField(blank=True, null=True)
    created = models.DateTimeField(blank=True, null=True, auto_now_add=True)
    updated = models.DateTimeField(blank=True, null=True, auto_now=True)
    is_alert = models.BooleanField(default=False)
    status = models.CharField(
        max_length=11, blank=True, null=True, choices=STATUS_CHOICES)
    target_coords = models.CharField(max_length=100, blank=True, null=True)
    with_drift = models.BooleanField(default=False)
    priority = models.IntegerField(blank=True, null=True)
    analysis_method = models.CharField(max_length=45, blank=True, null=True)
    moon_min = models.IntegerField(blank=True, null=True)
    alt_min = models.IntegerField(blank=True, null=True)
    type = models.CharField(max_length=6, blank=True, null=True)
    img_current = models.CharField(max_length=45, blank=True, null=True)
    img_total = models.CharField(max_length=45, blank=True, null=True)
    not_obs = models.BooleanField(default=False)
    obsolete = models.BooleanField(default=False)
    processing = models.BooleanField(default=False)
    flag = models.CharField(max_length=45, blank=True, null=True)
    jd1 = models.DecimalField(default=0.0, max_digits=15, decimal_places=8)
    jd2 = models.DecimalField(default=0.0, max_digits=15, decimal_places=8)
    t_prefered = models.DecimalField(
        default=-1.0, max_digits=15, decimal_places=8)
    duration = models.DecimalField(
        default=-1.0, max_digits=15, decimal_places=8)
    overhead = models.DecimalField(default=0, max_digits=15, decimal_places=8)

    ra = models.FloatField(blank=True, null=True)
    dec = models.FloatField(blank=True, null=True)

    class Meta:
        managed = True
        db_table = 'sequence'

    def __str__(self):
        return (str(self.name))


class ScheduleHasSequences(models.Model):
05bdcc44   Etienne Pallier   BIG DEMO tests (s...
680
    # (EP) TODO: C'est pas un pb d'utiliser 2 fois le meme nom "shs" pour 2 choses differentes ???!!!
ddf59dd4   haribo   Remaniement :
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
    schedule = models.ForeignKey(
        'Schedule', on_delete=models.CASCADE, related_name="shs")
    sequence = models.ForeignKey(
        'Sequence', on_delete=models.CASCADE, related_name="shs")

    status = models.CharField(
        max_length=11, blank=True, null=True, choices=Sequence.STATUS_CHOICES)
    desc = models.CharField(max_length=45, blank=True, null=True)
    tsp = models.DecimalField(default=-1.0, max_digits=15, decimal_places=8)
    tep = models.DecimalField(default=-1.0, max_digits=15, decimal_places=8)
    deltaTL = models.DecimalField(
        default=-1.0, max_digits=15, decimal_places=8)
    deltaTR = models.DecimalField(
        default=-1.0, max_digits=15, decimal_places=8)

    class Meta:
        managed = True
        db_table = 'schedule_has_sequences'


class SiteWatch(models.Model):
c53a13e0   Jeremy   Updating a lot of...
702
703
704
705
706
    OPEN = "OPEN"
    CLOSE = "CLOSE"
    ON = "ON"
    OFF = "OFF"

ce470283   Jeremy   Plc simulator fin...
707
    global_status = models.CharField(max_length=255, blank=True, null=True)
ddf59dd4   haribo   Remaniement :
708
709
710
711
712
    updated = models.DateTimeField(blank=True, null=True, auto_now=True)
    lights = models.CharField(max_length=45, blank=True, null=True)
    dome = models.CharField(max_length=45, blank=True, null=True)
    doors = models.CharField(max_length=45, blank=True, null=True)
    temperature = models.FloatField(blank=True, null=True)
ce470283   Jeremy   Plc simulator fin...
713
714
    shutter = models.FloatField(blank=True, null=True)
    pressure = models.FloatField(blank=True, null=True)
fe5613f5   jeremy   Update plc protocol
715
    humidity = models.FloatField(blank=True, null=True)
ddf59dd4   haribo   Remaniement :
716
717
718
719
720
721
722

    class Meta:
        managed = True
        db_table = 'sitewatch'
        verbose_name_plural = "Site watches"

    def __str__(self):
678838ed   Jeremy   Weather ans insid...
723
        return (str(self.__dict__))
ddf59dd4   haribo   Remaniement :
724

ce470283   Jeremy   Plc simulator fin...
725
726
727
    # TODO
    def setGlobalStatus(self):
        self.global_status = ""
678838ed   Jeremy   Weather ans insid...
728
        if self.doors and self.doors.find("open") != -1:
ce470283   Jeremy   Plc simulator fin...
729
730
731
            self.global_status += "DOOR_OPEN "
        if self.lights and self.lights == "on":
            self.global_status += "LIGHTS_ON "
678838ed   Jeremy   Weather ans insid...
732
        if self.temperature and float(self.temperature) > 40:
ce470283   Jeremy   Plc simulator fin...
733
            self.global_status += "TOO_HOT "
678838ed   Jeremy   Weather ans insid...
734
        if self.humidity and float(self.humidity) > 80:
ce470283   Jeremy   Plc simulator fin...
735
736
737
738
739
            self.global_status += "HUMIDITY_TOO_HIGH "
        if self.global_status == "":
            self.global_status = "OK"
        return 0

fe5613f5   jeremy   Update plc protocol
740
    # TODO HANDLE FLAT LAMPS ...
ce470283   Jeremy   Plc simulator fin...
741
    def setAttribute(self, key, value):
678838ed   Jeremy   Weather ans insid...
742
        self.doors = ""
fe5613f5   jeremy   Update plc protocol
743
        if key == "InsideHumidity":
ce470283   Jeremy   Plc simulator fin...
744
            self.humidity = value
fe5613f5   jeremy   Update plc protocol
745
        elif key == "Pressure":
ce470283   Jeremy   Plc simulator fin...
746
            self.pressure = value
d66e0d93   Quentin Durand   observatory statu...
747
748
        elif key == "InsideTemp":
            self.temperature = value
ce470283   Jeremy   Plc simulator fin...
749
750
751
752
        else:
            return 1
        return 0

ddf59dd4   haribo   Remaniement :
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777

class SiteWatchHistory(models.Model):
    id = models.IntegerField(primary_key=True)

    class Meta:
        managed = True
        db_table = 'sitewatchhistory'
        verbose_name_plural = "Site watch histories"


class StrategyObs(models.Model):
    name = models.CharField(max_length=45, blank=True, null=True)
    desc = models.TextField(blank=True, null=True)
    xml_file = models.CharField(max_length=45, blank=True, null=True)
    is_default = models.BooleanField(default=False)

    class Meta:
        managed = True
        db_table = 'strategyobs'
        verbose_name_plural = "Strategy obs"

    def __str__(self):
        return (str(self.name))


5e45ba9f   Etienne Pallier   Bye Bye Celery (f...
778
#TODO: à virer car utilisé pour Celery (ou bien à utiliser pour les agents)
ddf59dd4   haribo   Remaniement :
779
780
781
782
783
784
785
786
787
788
789
790
class TaskId(models.Model):
    task = models.CharField(max_length=45, blank=True, null=True)
    created = models.DateTimeField(blank=True, null=True, auto_now_add=True)
    task_id = models.CharField(max_length=45, blank=True, null=True)

    class Meta:
        managed = True
        db_table = 'task_id'

    def __str__(self):
        return (str(self.task) + " - " + str(self.task_id))

cfc9d09c   Jeremy   Added dome simula...
791

ddf59dd4   haribo   Remaniement :
792

abfb02e2   Jeremy   Device Model is n...
793
794
795
class Telescope(Device):
    TELESCOPE = "Telescope"

ddf59dd4   haribo   Remaniement :
796
797
    mount_type = models.CharField(max_length=9, blank=True, null=True)
    diameter = models.FloatField(blank=True, null=True)
ddf59dd4   haribo   Remaniement :
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
    latitude = models.FloatField(blank=True, null=True)
    longitude = models.FloatField(blank=True, null=True)
    sens = models.CharField(max_length=1, blank=True, null=True)
    altitude = models.FloatField(blank=True, null=True)
    readout_time = models.IntegerField(blank=True, null=True)
    slew_time = models.IntegerField(blank=True, null=True)
    slew_dead = models.IntegerField(blank=True, null=True)
    slew_rate_max = models.FloatField(blank=True, null=True)
    horizon_type = models.CharField(max_length=45, blank=True, null=True)
    horizon_def = models.FloatField(blank=True, null=True)
    lim_dec_max = models.FloatField(blank=True, null=True)
    lim_dec_min = models.FloatField(blank=True, null=True)
    lim_ha_rise = models.FloatField(blank=True, null=True)
    lim_ha_set = models.FloatField(blank=True, null=True)
    address = models.CharField(max_length=45, blank=True, null=True)
    night_elev_sun = models.FloatField(blank=True, null=True)
    mpc_code = models.CharField(max_length=45, blank=True, null=True)
ddf59dd4   haribo   Remaniement :
815
816
817
818
819
    class Meta:
        managed = True
        db_table = 'telescope'

    def __str__(self):
f7dd3df1   Jeremy   Update simulators...
820
        return (self.name)
ddf59dd4   haribo   Remaniement :
821
822


a5f1e984   Etienne Pallier   cleanup common/mo...
823
824
825
826
827
828
829
830
831
832
833
834
835
class TelescopeCommand(models.Model):
    created = models.DateTimeField(blank=True, null=True, auto_now_add=True)
    answered = models.DateTimeField(blank=True, null=True)
    request = models.CharField(blank=False, null=False, max_length=255)
    answer = models.TextField(null=True, blank=True)
    class Meta:
        managed = True
        db_table = "telescopecommand"

    def __str__(self):
        return str(self.request) + str(self.created)


ddf59dd4   haribo   Remaniement :
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
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
        db_table = 'user_level'

    def __str__(self):
        return (str(self.name))


class Version(models.Model):
    module_name = models.CharField(max_length=45, blank=True, null=True)
    version = models.CharField(max_length=15, blank=True, null=True)
    created = models.DateTimeField(blank=True, null=True, auto_now_add=True)
    updated = models.DateTimeField(blank=True, null=True, auto_now=True)

    class Meta:
        managed = True
        db_table = 'version'

    def __str__(self):
        return (str(self.module_name) + " - " + str(self.version))

ce470283   Jeremy   Plc simulator fin...
863

ddf59dd4   haribo   Remaniement :
864
class WeatherWatch(models.Model):
c53a13e0   Jeremy   Updating a lot of...
865
866
867
    WIND_LIMIT = 100
    RAIN_LIMIT = 5

ce470283   Jeremy   Plc simulator fin...
868
869
870
    global_status = models.CharField(max_length=255, blank=True, null=True)
    updated = models.DateTimeField(blank=True, null=True, auto_now=True)
    humidity = models.FloatField(blank=True, null=True)
ddf59dd4   haribo   Remaniement :
871
    wind = models.FloatField(blank=True, null=True)
fe5613f5   jeremy   Update plc protocol
872
    wind_dir = models.CharField(max_length=45, blank=True, null=True)
ce470283   Jeremy   Plc simulator fin...
873
    temperature = models.FloatField(blank=True, null=True)
ddf59dd4   haribo   Remaniement :
874
875
    pressure = models.FloatField(blank=True, null=True)
    rain = models.FloatField(blank=True, null=True)
ce470283   Jeremy   Plc simulator fin...
876
    cloud = models.FloatField(blank=True, null=True)
ddf59dd4   haribo   Remaniement :
877
878
879
880
881
882
883

    class Meta:
        managed = True
        db_table = 'weatherwatch'
        verbose_name_plural = "Weather watches"

    def __str__(self):
678838ed   Jeremy   Weather ans insid...
884
        return (str(self.__dict__))
ddf59dd4   haribo   Remaniement :
885

ce470283   Jeremy   Plc simulator fin...
886
887
    # TODO
    def setGlobalStatus(self):
fac9194f   Patrick Maeght   get_sensor set d...
888
        #print(self.rain)
ce470283   Jeremy   Plc simulator fin...
889
        self.global_status = ""
e15030dc   Patrick Maeght   penelope work part 2
890
        if self.rain and float(self.rain) > 0:
ce470283   Jeremy   Plc simulator fin...
891
            self.global_status += "RAINING "
678838ed   Jeremy   Weather ans insid...
892
        if self.wind and float(self.wind) > 80:
ce470283   Jeremy   Plc simulator fin...
893
            self.global_status += "WIND_TOO_STRONG "
678838ed   Jeremy   Weather ans insid...
894
        if self.humidity and float(self.humidity) > 80:
ce470283   Jeremy   Plc simulator fin...
895
            self.global_status += "HUMIDITY_TOO_HIGH "
678838ed   Jeremy   Weather ans insid...
896
        if self.cloud and float(self.cloud) > 10:
ce470283   Jeremy   Plc simulator fin...
897
898
899
900
901
902
            self.global_status += "TOO_MUCH_CLOUDY "
        if self.global_status == "":
            self.global_status = "OK"
        return 0

    def setAttribute(self, key, value):
e15030dc   Patrick Maeght   penelope work part 2
903
        if key == "Rain_boolean":
ce470283   Jeremy   Plc simulator fin...
904
            self.rain = value
e15030dc   Patrick Maeght   penelope work part 2
905
        elif key == "_CloudRate":
ce470283   Jeremy   Plc simulator fin...
906
            self.cloud = value
e15030dc   Patrick Maeght   penelope work part 2
907
        elif key == "Wind_speed":
ce470283   Jeremy   Plc simulator fin...
908
            self.wind = value
e15030dc   Patrick Maeght   penelope work part 2
909
        elif key == "Wind_direction":
ce470283   Jeremy   Plc simulator fin...
910
            self.wind_dir = value
e15030dc   Patrick Maeght   penelope work part 2
911
        elif key == "Temperature_outside":
ce470283   Jeremy   Plc simulator fin...
912
            self.temperature = value
e15030dc   Patrick Maeght   penelope work part 2
913
        elif key == "Humidity_outside":
ce470283   Jeremy   Plc simulator fin...
914
            self.humidity = value
e15030dc   Patrick Maeght   penelope work part 2
915
        elif key == "_Pressure":
ce470283   Jeremy   Plc simulator fin...
916
917
918
919
920
            self.pressure = value
        else:
            return 1
        return 0

ddf59dd4   haribo   Remaniement :
921
922
923

class WeatherWatchHistory(models.Model):
    datetime = models.DateTimeField(blank=True, null=True, auto_now_add=True)
e31b2208   theophile.puhl@epitech.eu   Severals Changes ...
924
    humid_int = models.FloatField(blank=True, null=True)
ddf59dd4   haribo   Remaniement :
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
    humid_ext = models.CharField(max_length=45, blank=True, null=True)
    wind = models.CharField(max_length=45, blank=True, null=True)
    wind_dir = models.CharField(max_length=45, blank=True, null=True)
    temp_int = models.CharField(max_length=45, blank=True, null=True)
    temp_ext = models.CharField(max_length=45, blank=True, null=True)
    pressure = models.CharField(max_length=45, blank=True, null=True)
    rain = models.CharField(max_length=45, blank=True, null=True)
    dwn = models.CharField(max_length=45, blank=True, null=True)

    class Meta:
        managed = True
        db_table = 'weatherwatchhistory'
        verbose_name_plural = "Weather watch histories"

    def __str__(self):
        return (str(self.datetime))
e31b2208   theophile.puhl@epitech.eu   Severals Changes ...

e31b2208   theophile.puhl@epitech.eu   Severals Changes ...

e6eb923f   Quentin Durand   Prototype agent t...

e6eb923f   Quentin Durand   Prototype agent t...