Aucune description

models.py 6.3KB

    # -*- coding: utf-8 -*- from django.db import models from django.utils.translation import ugettext_lazy as _ from django_models_ext import BaseModelMixin, SexModelMixin from jsonfield import JSONField from shortuuidfield import ShortUUIDField from TimeConvert import TimeConvert as tc class IsolationPointInfo(BaseModelMixin): point_id = ShortUUIDField(_('point_id'), max_length=32, blank=True, null=True, help_text='隔离点唯一标识', db_index=True, unique=True) point_name = models.CharField(_('point_name'), max_length=255, blank=True, null=True, help_text='隔离点名称') # [{"start": "8:00", "end": "9:00"}, {"start": "12:00", "end": "14:00"}] point_measure_window = JSONField(_('point_measure_window'), default=[], blank=True, null=True, help_text='隔离点测温时间段') class Meta: verbose_name = _('隔离点信息') verbose_name_plural = _('隔离点信息') def __unicode__(self): return '%d' % self.pk @property def data(self): return { 'point_id': self.point_id, 'point_name': self.point_name, 'point_measure_window': self.point_measure_window, } @property def current_measure_window(self): current_ymd = tc.local_string(format='%Y-%m-%d') current_dt = tc.utc_datetime() for window in self.point_measure_window: start_t, end_t = window.get('start'), window.get('end') start_dt = tc.string_to_utc_datetime(f'{current_ymd} {start_t}:00') end_dt = tc.string_to_utc_datetime(f'{current_ymd} {end_t}:00') if start_dt < current_dt < end_dt: return f'{start_t}-{end_t}' return '' class ThermometerEquipmentInfo(BaseModelMixin): ONLINE = 1 OFFLINE = 0 ACTIVE_STATUE_TUPLE = ( (ONLINE, '已激活'), (OFFLINE, '已离线'), ) eqpt_id = ShortUUIDField(_('eqpt_id'), max_length=32, blank=True, null=True, help_text='设备唯一标识', db_index=True, unique=True) point_id = models.CharField(_('point_id'), max_length=32, blank=True, null=True, help_text='隔离点唯一标识', db_index=True) macid = models.CharField(_('macid'), max_length=255, blank=True, null=True, help_text='设备号') sn = models.CharField(_('sn'), max_length=255, blank=True, null=True, help_text='序列号') active_status = models.IntegerField(_('active_status'), choices=ACTIVE_STATUE_TUPLE, default=OFFLINE, help_text='激活状态') active_at = models.DateTimeField(_('active_at'), blank=True, null=True, help_text=_('激活时间')) # 用户基本信息 name = models.CharField(_('name'), max_length=255, blank=True, null=True, help_text='用户姓名') sex = models.IntegerField(_('sex'), choices=SexModelMixin.SEX_TUPLE, default=SexModelMixin.UNKNOWN, help_text='用户性别') age = models.IntegerField(_('age'), default=0, help_text='用户年龄') phone = models.CharField(_('phone'), max_length=11, blank=True, null=True, help_text='用户电话', db_index=True) remark = models.CharField(_('remark'), max_length=255, blank=True, null=True, help_text='备注') last_submit_at = models.DateTimeField(_('last_submit_at'), blank=True, null=True, help_text=_('上一次上报时间')) class Meta: verbose_name = _('测温设备信息') verbose_name_plural = _('测温设备信息') def __unicode__(self): return '%d' % self.pk @property def data(self): return { 'eqpt_id': self.eqpt_id, 'point_id': self.point_id, 'macid': self.macid, 'sn': self.sn, 'active_status': self.active_status, 'active_status_str': dict(self.ACTIVE_STATUE_TUPLE).get(self.active_status, ''), 'active_at': tc.local_string(utc_dt=self.active_at), 'name': self.name or '', 'sex': self.sex, 'sex_str': dict(SexModelMixin.SEX_TUPLE).get(self.sex, ''), 'age': self.age or '', 'phone': self.phone or '', 'remark': self.remark or '', 'last_submit_at': tc.local_string(utc_dt=self.last_submit_at), 'created_at': tc.local_string(utc_dt=self.created_at), } class ThermometerMeasureInfo(BaseModelMixin): point_id = models.CharField(_('point_id'), max_length=32, blank=True, null=True, help_text='隔离点唯一标识', db_index=True) point_measure_ymd = models.CharField(_('point_measure_ymd'), max_length=10, blank=True, null=True, help_text='隔离点测温日期', db_index=True) point_measure_window = models.CharField(_('point_measure_window'), max_length=16, blank=True, null=True, help_text='隔离点测温时间段', db_index=True) macid = models.CharField(_('macid'), max_length=255, blank=True, null=True, help_text='设备号') sn = models.CharField(_('sn'), max_length=255, blank=True, null=True, help_text='序列号') temperature = models.FloatField(_('temperature'), default=0, help_text='用户体温') class Meta: verbose_name = _('测温信息') verbose_name_plural = _('测温信息') unique_together = ( ('point_id', 'point_measure_ymd', 'point_measure_window', 'macid') ) def __unicode__(self): return '%d' % self.pk @property def data(self): return { 'point_id': self.point_id, 'point_measure_window': self.point_measure_window, 'macid': self.macid, 'sn': self.sn, 'temperature': self.temperature, } class ThermometerMeasureLogInfo(BaseModelMixin): point_id = models.CharField(_('point_id'), max_length=32, blank=True, null=True, help_text='隔离点唯一标识', db_index=True) macid = models.CharField(_('macid'), max_length=255, blank=True, null=True, help_text='设备号') sn = models.CharField(_('sn'), max_length=255, blank=True, null=True, help_text='序列号') temperature = models.FloatField(_('temperature'), default=0, help_text='用户体温') class Meta: verbose_name = _('测温记录信息') verbose_name_plural = _('测温记录信息') def __unicode__(self): return '%d' % self.pk @property def data(self): return { 'point_id': self.point_id, 'macid': self.macid, 'sn': self.sn, 'temperature': self.temperature, }