from django.db import models from apps.utils.models import CommonBModel, BaseModel from apps.mtm.models import Mgroup from apps.em.models import Equipment # Create your models here. class Drain(CommonBModel): DR_TYPE_CHOICES = ( (10, '排放口'), (20, '污染源'), ) DR_LEVLE_CHOICES = ( (10, '主要排放口'), (20, '次要排放口') ) DR_CATE_MTRAN = 'mtrans' DR_CATE_PRODUCT = 'product' DR_CATE_MSTORE = 'mstore' DR_CATE_CHOICES = ( (DR_CATE_PRODUCT, '生产工艺'), (DR_CATE_MTRAN, '物料输送'), (DR_CATE_MSTORE, '物料储存'), ) type = models.PositiveSmallIntegerField( '类型', choices=DR_TYPE_CHOICES, help_text=str(DR_TYPE_CHOICES)) number = models.CharField('编号', max_length=20) name = models.CharField('名称', max_length=20) level = models.PositiveSmallIntegerField( '排口等级', default=20, choices=DR_LEVLE_CHOICES, help_text=str(DR_LEVLE_CHOICES)) cate = models.CharField('分类', max_length=10, choices=DR_CATE_CHOICES, null=True, blank=True, help_text=str(DR_CATE_CHOICES)) height = models.PositiveSmallIntegerField('排气筒高度', default=0) treatment_capacity = models.CharField('处理量', max_length=20, default='') pm_limit = models.FloatField('PM超低排放限值', default=10, help_text='单位:mg/m³') measure = models.CharField('治理措施', max_length=20, default='') # {"x": 1.0, "y": 2.0, "z": 3.0} coordinates = models.JSONField('坐标', default=dict, blank=True) mgroup = models.ForeignKey( Mgroup, verbose_name='所属工段', on_delete=models.CASCADE) equipments = models.ManyToManyField( Equipment, verbose_name='关联设备', through='DrainEquip', related_name='drain_equipments', blank=True) class DrainEquip(BaseModel): """ 排口/设备关系表 """ drain = models.ForeignKey( Drain, verbose_name='排口', related_name='drainequip_drain', on_delete=models.CASCADE) equipment = models.ForeignKey( Equipment, verbose_name='关联设备', related_name='drainequip_equipment', on_delete=models.CASCADE) params_list = models.JSONField('监测参数列表', default=list, blank=True) dust_alarm = models.DecimalField( '颗粒物报警值', max_digits=10, decimal_places=4, null=True, blank=True) pm10_alarm = models.DecimalField( 'PM10报警值', max_digits=10, decimal_places=4, null=True, blank=True) pm25_alarm = models.DecimalField( 'PM2.5报警值', max_digits=10, decimal_places=4, null=True, blank=True) class EnvData(models.Model): """ 环保监测数据 """ RUNING_STATE_CHOICES = ( (10, '运行'), (20, '待机'), (30, '停机'), (40, '故障'), (50, '未知') ) equipment = models.ForeignKey( Equipment, verbose_name='关联设备', on_delete=models.CASCADE) time = models.DateTimeField('采集时间', primary_key=True) is_online = models.PositiveSmallIntegerField('是否在线', default=1) running_state = models.PositiveSmallIntegerField('运行状态', default=10) dust_rtd = models.DecimalField( '颗粒物实测(mg/m3)', max_digits=10, decimal_places=4, null=True, blank=True) dust_zs = models.DecimalField( '颗粒物折算(mg/m3)', max_digits=10, decimal_places=4, null=True, blank=True) temperature = models.DecimalField( '温度(℃)', max_digits=10, decimal_places=4, null=True, blank=True) pressure = models.DecimalField( '压力(kPa)', max_digits=10, decimal_places=4, null=True, blank=True) speed = models.DecimalField( '流速(m/s)', max_digits=10, decimal_places=4, null=True, blank=True) humidity = models.DecimalField( '湿度(%)', max_digits=10, decimal_places=4, null=True, blank=True) flux = models.DecimalField( '流量(m3/h)', max_digits=10, decimal_places=4, null=True, blank=True) pm25 = models.DecimalField( 'PM2.5(ug/m3)', max_digits=10, decimal_places=4, null=True, blank=True) pm10 = models.DecimalField( 'PM10(ug/m3)', max_digits=10, decimal_places=4, null=True, blank=True) tsp = models.DecimalField( 'TSP(ug/m3)', max_digits=10, decimal_places=4, null=True, blank=True) wind_direction = models.PositiveSmallIntegerField( '风向', null=True, blank=True) wind_speed = models.DecimalField( '风速(m/s)', max_digits=10, decimal_places=4, null=True, blank=True) so2_rtd = models.DecimalField( '二氧化硫实测(mg/m3)', max_digits=10, decimal_places=4, null=True, blank=True) so2_zs = models.DecimalField( '二氧化硫折算(mg/m3)', max_digits=10, decimal_places=4, null=True, blank=True) nox_rtd = models.DecimalField( '氮氧化物实测(mg/m3)', max_digits=10, decimal_places=4, null=True, blank=True) nox_zs = models.DecimalField( '氮氧化物折算(mg/m3)', max_digits=10, decimal_places=4, null=True, blank=True) o2 = models.DecimalField('含氧量(%)', max_digits=10, decimal_places=4, null=True, blank=True) class Meta: db_table = 'enp_envdata' managed = False unique_together = (('equipment', 'time'), ) class VehicleAccess(BaseModel): type = models.PositiveSmallIntegerField( '出入类型', default=1, help_text='1: 进厂, 2: 出厂') vehicle_number = models.CharField('车牌号', max_length=10) access_time = models.DateTimeField('出入时间', null=True, blank=True) emission_standard = models.CharField( '排放标准', max_length=10, null=True, blank=True) door_name = models.CharField('门禁名称', max_length=10, null=True, blank=True) class CarWash(BaseModel): station = models.ForeignKey( Equipment, verbose_name='洗车台', on_delete=models.CASCADE) vehicle_number = models.CharField('车牌号', max_length=10, default='') start_time = models.DateTimeField('洗车时间', null=True, blank=True) end_time = models.DateTimeField('洗车完成时间', null=True, blank=True) duration = models.PositiveIntegerField('洗车时长(s)', null=True, blank=True) pressure = models.DecimalField( '洗车压力(Mpa)', max_digits=10, decimal_places=4, null=True, blank=True) flux = models.DecimalField( '洗车流量(L/min)', max_digits=10, decimal_places=4, null=True, blank=True)