from __future__ import unicode_literals from django.contrib.auth.models import AbstractUser from django.db import models 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) 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) complete = models.BooleanField(default=False) class Meta: managed = True db_table = 'album' def __str__(self): return (str(self.name)) 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)) class Device(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) 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 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) class Meta: managed = True db_table = 'plc_devices_status' def __str__(self): return (str(self.__dict__)) ''' 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 else: raise KeyError("Key " + str(key) + " unrecognized") class PlcDevice(Device): #device = models.ForeignKey('Plc', on_delete=models.CASCADE, related_name='plc_devices') 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) class Meta: managed = True db_table = 'plc_devices' def __str__(self): return str(self.name) #class Plc(Device): # last_update_status = models.DateTimeField(blank=True, null=True) # i # class Meta: # managed = True # db_table = 'plc' class Detector(Device): VIS = "Visible camera" NIR = "Cagire" telescope = models.ForeignKey( 'Telescope', models.DO_NOTHING, related_name="detectors") 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): return str(self.name) def device_name(self): return self.__str__() device_name.short_description = "Name" class Filter(Device): VIS_FILTER_1 = "First visible filter" VIS_FILTER_2 = "Second visible filter" NIR_FILTER_1 = "First infrared filter" NIR_FILTER_2 = "Second infrared filter" 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): return (str(self.name)) def device_name(self): return self.__str__() device_name.short_description = "Name" class FilterWheel(Device): detector = models.OneToOneField(Detector, on_delete=models.CASCADE, related_name="filter_wheel", blank=True, null=True) class Meta: managed = True db_table = 'filter_wheel' def __str__(self): return (str(self.name)) 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 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 PyrosUser(AbstractUser): username = models.CharField(max_length=255, blank=False, null=False, unique=True) is_active = models.BooleanField(default='False') first_time = models.BooleanField(default='False') 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): return (str(self.get_username())) def user_username(self): return self.__str__() user_username.short_description = "Username" 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) complete = models.BooleanField(default=False) submitted = models.BooleanField(default=False) class Meta: managed = True db_table = 'request' def __str__(self): return (str(self.name)) 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) class Meta: managed = True db_table = 'alert' def __str__(self): return str(self.trig_id) def request_name(self): return self.__str__() request_name.short_description = "Name" # 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" PLANNED = "PLND" PENDING = "PNDG" EXECUTING = "EXING" EXECUTED = "EXD" REJECTED = "RJTD" INVALID = "INVL" CANCELLED = "CNCLD" UNPLANNABLE = "UNPLN" STATUS_CHOICES = ( (INCOMPLETE, "Incomplete"), (COMPLETE, "Complete"), (TOBEPLANNED, "To be planned"), (PLANNED, "Planned"), (UNPLANNABLE, "Unplannable"), (PENDING, "Pending"), (EXECUTED, "Executed"), (EXECUTING, "Executing"), (REJECTED, "Rejected"), (CANCELLED, "Cancelled"), (INVALID, "Invalid"), ) 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): # (EP) TODO: C'est pas un pb d'utiliser 2 fois le meme nom "shs" pour 2 choses differentes ???!!! 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): OPEN = "OPEN" CLOSE = "CLOSE" ON = "ON" OFF = "OFF" global_status = models.CharField(max_length=255, blank=True, null=True) 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) shutter = models.FloatField(blank=True, null=True) pressure = models.FloatField(blank=True, null=True) humidity = models.FloatField(blank=True, null=True) class Meta: managed = True db_table = 'sitewatch' verbose_name_plural = "Site watches" def __str__(self): return (str(self.__dict__)) # TODO def setGlobalStatus(self): self.global_status = "" if self.doors and self.doors.find("open") != -1: self.global_status += "DOOR_OPEN " if self.lights and self.lights == "on": self.global_status += "LIGHTS_ON " if self.temperature and float(self.temperature) > 40: self.global_status += "TOO_HOT " if self.humidity and float(self.humidity) > 80: self.global_status += "HUMIDITY_TOO_HIGH " if self.global_status == "": self.global_status = "OK" return 0 # TODO HANDLE FLAT LAMPS ... def setAttribute(self, key, value): self.doors = "" if key == "InsideHumidity": self.humidity = value elif key == "Pressure": self.pressure = value else: return 1 return 0 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)) 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)) 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" class Telescope(Device): TELESCOPE = "Telescope" mount_type = models.CharField(max_length=9, blank=True, null=True) diameter = models.FloatField(blank=True, null=True) 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) class Meta: managed = True db_table = 'telescope' def __str__(self): return (self.name) 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)) class WeatherWatch(models.Model): WIND_LIMIT = 100 RAIN_LIMIT = 5 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) wind = models.FloatField(blank=True, null=True) wind_dir = models.CharField(max_length=45, blank=True, null=True) temperature = models.FloatField(blank=True, null=True) pressure = models.FloatField(blank=True, null=True) rain = models.FloatField(blank=True, null=True) cloud = models.FloatField(blank=True, null=True) class Meta: managed = True db_table = 'weatherwatch' verbose_name_plural = "Weather watches" def __str__(self): return (str(self.__dict__)) # TODO def setGlobalStatus(self): self.global_status = "" if self.rain and float(self.rain) > 10: self.global_status += "RAINING " if self.wind and float(self.wind) > 80: self.global_status += "WIND_TOO_STRONG " if self.humidity and float(self.humidity) > 80: self.global_status += "HUMIDITY_TOO_HIGH " if self.cloud and float(self.cloud) > 10: self.global_status += "TOO_MUCH_CLOUDY " if self.global_status == "": self.global_status = "OK" return 0 def setAttribute(self, key, value): if key == "RainRate": self.rain = value elif key == "CloudRate": self.cloud = value elif key == "WindSpeed": self.wind = value elif key == "WindDir": self.wind_dir = value elif key == "SensorTemperature": self.temperature = value elif key == "OutsideHumidity": self.humidity = value elif key == "Pressure": self.pressure = value else: return 1 return 0 class WeatherWatchHistory(models.Model): datetime = models.DateTimeField(blank=True, null=True, auto_now_add=True) humid_int = models.FloatField(blank=True, null=True) 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)) class Config(models.Model): SCHEDULER_STATE = ( ('0', 'init'), ('1', 'sleeping'), ('2', 'startup'), ('3', 'observing'), ('4', 'shutdown'), ) 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") global_mode = models.BooleanField(default='True') ack = models.BooleanField(default='False') bypass = models.BooleanField(default='True') scheduler_state = models.CharField(max_length=1, choices=SCHEDULER_STATE, default=0) force_passive_mode = models.BooleanField(default='False') plc_timeout_seconds = models.PositiveIntegerField(default=60) class Meta: managed = True db_table = 'config' verbose_name_plural = "Config" def __str__(self): return (str(self.__dict__))