更新人员表bug

This commit is contained in:
曹前明 2022-09-19 17:26:02 +08:00
parent 6a1f0a9f75
commit b2b25548ae
5 changed files with 21 additions and 9 deletions

View File

@ -7,7 +7,6 @@ myLogger = logging.getLogger('log')
algo_dict = {
"helmet": "apps.ai.client.helmet",
"helmet2": "apps.ai.client.helmet2",
"fire1": "apps.ai.client.fire1"
}
@ -28,8 +27,11 @@ def ai_analyse(codes: list, global_img: str, face_img: str = None):
f = getattr(m, func)
try:
is_happend, res = False, None
if i == 'helmet' and face_img: # 如果是安全帽抠图识别
if i == 'helmet': # 如果是安全帽抠图识别
if face_img:
is_happend, res = f(ip=settings.AI_IP, pic_url=face_img)
else:
is_happend, res = getattr(m, 'helmet2')(ip=settings.AI_IP, pic_url=face_img)
else:
is_happend, res = f(ip=settings.AI_IP, pic_url=global_img)
if is_happend:

View File

@ -22,6 +22,7 @@ class EventCate(CommonAModel):
trigger = models.PositiveSmallIntegerField('触发方式', default=10, choices=EVENT_TRIGGER_CHOICES)
self_algo = models.BooleanField('识别算法', default=False)
speaker_on = models.BooleanField('开启喇叭报警', default=True)
# loop_on = models.BooleanField('开启循环拍照', default=False)
voice_person = models.PositiveSmallIntegerField('声音选择', default=0, help_text='0女声3男声')
voice_num = models.PositiveSmallIntegerField('播放次数', default=2)
speakers = models.ManyToManyField(TDevice, verbose_name='固定喇叭', blank=True, related_name='ec_speakers')

View File

@ -490,7 +490,8 @@ def handle_xx_event(name: str, data: dict):
cate = EventCate.objects.filter(code=name).first()
# 找到最近未处理同一人发生的事件
if cate:
last_event = Event.objects.filter(cates__code=name, employee=blts.employee, handle_user=None).order_by('-create_time').first()
last_event = Event.objects.filter(cates__code=name, employee=blts.employee,
handle_user=None).order_by('-create_time').first()
if last_event and last_event.create_time + timedelta(minutes=5) > timezone.now():
return
event = Event()
@ -631,16 +632,17 @@ def get_area_from_point(x: int, y: int, floorNo: str):
return area_fix, area_temp
def snap_and_analyse(vchannel: TDevice, algo_codes: list, opl: Opl):
def snap_and_analyse(vchannel: TDevice, algo_codes: list, opl: Opl = None):
global_img_o = dhClient.snap(vchannel.code)
happen_time = timezone.now()
ec_codes = ai_analyse(algo_codes, global_img=global_img_o) # 算法处理返回的事件结果
if ec_codes:
# 获取本次所有发生事件种类
ecs = EventCate.objects.filter(code__in=ec_codes.keys())
obj_cate = 'opl'
obj_cate = 'opl' if opl else 'other'
ep = None
if 'helmet' in ec_codes:
if 'helmet' in ec_codes or 'helmet2' in ec_codes and obj_cate == 'other':
obj_cate = 'people'
# 如果存在安全帽事件
# 尝试以图搜图找到当事人
# res = dhClient.face_search(path=global_img_o)
@ -663,3 +665,10 @@ def snap_and_analyse(vchannel: TDevice, algo_codes: list, opl: Opl):
})
if event:
notify_event(event)
def loop_task():
# 轮询拍照进行算法识别
pass
# cates = EventCate.objects.filter(loop_on=True, self_algo=True)
# AlgoChannel.objects.filter(algo__loop_on=True, algo__self_algo=True).values('algo__code', 'vchannel')

View File

@ -86,7 +86,7 @@ def opl_task(vc_codes: list, opl_id: str):
algo_codes = list(EventCate.objects.filter(opl_cates=opl_cate).values_list('code', flat=True))
vchannels = TDevice.objects.filter(code__in=vc_codes)
opl = Opl.objects.get(id=opl_id)
while time.time()-start_time < 14400: # 一次任务不手动关闭最多持续8小时
while time.time()-start_time < 14400: # 一次任务不手动关闭最多持续4小时
for i in vchannels:
Thread(target=snap_and_analyse, args=(i, algo_codes, opl)).start()
time.sleep(10)

View File

@ -386,7 +386,7 @@ class UserPostViewSet(CreateModelMixin, DestroyModelMixin, ListModelMixin, Custo
user.update_by = self.request.user
user.save()
# 更新人员表
ep = Employee.objects.get_queryset(all=True).filter(user=instance).first()
ep = Employee.objects.get_queryset(all=True).filter(user=user).first()
if ep:
ep.belong_dept = user.belong_dept
ep.post = user.post