|
@@ -66,14 +66,10 @@ class AiView(View):
|
|
|
|
|
|
if not all([etk, n_time]):
|
|
if not all([etk, n_time]):
|
|
return response.json(444)
|
|
return response.json(444)
|
|
-
|
|
|
|
# 解密etk并判断uid长度
|
|
# 解密etk并判断uid长度
|
|
eto = ETkObject(etk)
|
|
eto = ETkObject(etk)
|
|
uid = eto.uid
|
|
uid = eto.uid
|
|
-
|
|
|
|
- logger = logging.getLogger('info')
|
|
|
|
- logger.info('---进入ai识别推送接口--- etk:{}, uid:{}'.format(etk, uid))
|
|
|
|
-
|
|
|
|
|
|
+ LOGGING.info('---进入ai识别推送接口--- etk:{}, uid:{}'.format(etk, uid))
|
|
receive_time = int(time.time())
|
|
receive_time = int(time.time())
|
|
file_list = [file_one, file_two, file_three]
|
|
file_list = [file_one, file_two, file_three]
|
|
|
|
|
|
@@ -92,10 +88,7 @@ class AiView(View):
|
|
# 查询设备数据
|
|
# 查询设备数据
|
|
device_info_qs = Device_Info.objects.filter(UID=uid).first()
|
|
device_info_qs = Device_Info.objects.filter(UID=uid).first()
|
|
nickname = uid if device_info_qs is None else device_info_qs.NickName
|
|
nickname = uid if device_info_qs is None else device_info_qs.NickName
|
|
-
|
|
|
|
now_time = int(time.time())
|
|
now_time = int(time.time())
|
|
- detect_group = ai_service_qs[0]['detect_group']
|
|
|
|
-
|
|
|
|
try:
|
|
try:
|
|
dir_path = os.path.join(BASE_DIR, 'static/ai/' + uid + '/' + str(n_time))
|
|
dir_path = os.path.join(BASE_DIR, 'static/ai/' + uid + '/' + str(n_time))
|
|
if not os.path.exists(dir_path):
|
|
if not os.path.exists(dir_path):
|
|
@@ -111,34 +104,13 @@ class AiView(View):
|
|
f.write(val)
|
|
f.write(val)
|
|
f.close()
|
|
f.close()
|
|
ai_view = AiView()
|
|
ai_view = AiView()
|
|
- ai_results = ai_view.image_aI_recognition(file_path_list, 0.45, 0.45, 50)
|
|
|
|
|
|
+ ai_results = ai_view.image_aI_recognition(file_path_list, 0.45, 0.45, 1)
|
|
if not ai_results:
|
|
if not ai_results:
|
|
return response.json(0)
|
|
return response.json(0)
|
|
event_type = ai_view.get_cloud_recognition_tag(ai_results)
|
|
event_type = ai_view.get_cloud_recognition_tag(ai_results)
|
|
if event_type == 0:
|
|
if event_type == 0:
|
|
return response.json(0)
|
|
return response.json(0)
|
|
- # image_size = 0 # 每张小图片的大小,等于0是按原图大小进行合并
|
|
|
|
- # image_row = 1 # 合并成一张图后,一行有几个小图
|
|
|
|
- # image_processing_obj = ImageProcessingObject(dir_path, image_size, image_row)
|
|
|
|
- # image_processing_obj.merge_images()
|
|
|
|
-
|
|
|
|
- # 获取识别结果
|
|
|
|
- # aws_rekognition = AmazonRekognitionUtil()
|
|
|
|
- # with open(dir_path + '.jpg', 'rb') as f:
|
|
|
|
- # rekognition_res = aws_rekognition.detect_labels(f.read())
|
|
|
|
-
|
|
|
|
- # if not rekognition_res:
|
|
|
|
- # return response.json(0)
|
|
|
|
-
|
|
|
|
- # label_dict = image_processing_obj.handle_rekognition_res(detect_group, rekognition_res)
|
|
|
|
- # if not label_dict['label_list']:
|
|
|
|
- # # 需要删除图片
|
|
|
|
- # # photo.close()
|
|
|
|
- # # self.del_path(os.path.join(BASE_DIR, 'static/ai/' + uid))
|
|
|
|
- # return response.json(0)
|
|
|
|
- label_str = '' # ','.join(label_dict['label_list'])
|
|
|
|
- new_bounding_box_dict = '' # label_dict['new_bounding_box_dict']
|
|
|
|
-
|
|
|
|
|
|
+ new_bounding_box_dict = ''
|
|
# 上传缩略图到s3
|
|
# 上传缩略图到s3
|
|
file_dict = {}
|
|
file_dict = {}
|
|
for i, val in enumerate(file_path_list):
|
|
for i, val in enumerate(file_path_list):
|
|
@@ -149,10 +121,11 @@ class AiView(View):
|
|
|
|
|
|
# 存储消息以及推送
|
|
# 存储消息以及推送
|
|
uid_push_list = [uid_push for uid_push in uid_push_qs]
|
|
uid_push_list = [uid_push for uid_push in uid_push_qs]
|
|
-
|
|
|
|
eq_list = []
|
|
eq_list = []
|
|
user_id_list = []
|
|
user_id_list = []
|
|
local_date_time = ''
|
|
local_date_time = ''
|
|
|
|
+ lang = uid_push_list[0]['lang']
|
|
|
|
+ label_str = ai_view.get_tag_message(lang, event_type, channel)
|
|
for up in uid_push_list:
|
|
for up in uid_push_list:
|
|
# 保存推送数据
|
|
# 保存推送数据
|
|
tz = up['tz']
|
|
tz = up['tz']
|
|
@@ -169,7 +142,7 @@ class AiView(View):
|
|
device_uid=uid,
|
|
device_uid=uid,
|
|
device_nick_name=nickname,
|
|
device_nick_name=nickname,
|
|
channel=channel,
|
|
channel=channel,
|
|
- alarm='检查到{} \tChannel:{}'.format(label_str, channel),
|
|
|
|
|
|
+ alarm=label_str,
|
|
is_st=3,
|
|
is_st=3,
|
|
receive_time=receive_time,
|
|
receive_time=receive_time,
|
|
add_time=now_time,
|
|
add_time=now_time,
|
|
@@ -205,9 +178,11 @@ class AiView(View):
|
|
elif push_type == 1: # android gcm
|
|
elif push_type == 1: # android gcm
|
|
PushObject.android_fcm_push(**kwargs)
|
|
PushObject.android_fcm_push(**kwargs)
|
|
elif push_type == 2: # android jpush
|
|
elif push_type == 2: # android jpush
|
|
|
|
+ kwargs.pop('uid')
|
|
|
|
+ kwargs.pop('channel')
|
|
PushObject.android_jpush(**kwargs)
|
|
PushObject.android_jpush(**kwargs)
|
|
except Exception as e:
|
|
except Exception as e:
|
|
- logger.info('ai推送消息异常,errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
|
|
|
+ LOGGING.info('ai推送消息异常,errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
continue
|
|
continue
|
|
AiView.save_cloud_ai_tag(uid, int(n_time), event_type)
|
|
AiView.save_cloud_ai_tag(uid, int(n_time), event_type)
|
|
week = LocalDateTimeUtil.date_to_week(local_date_time)
|
|
week = LocalDateTimeUtil.date_to_week(local_date_time)
|
|
@@ -215,7 +190,7 @@ class AiView(View):
|
|
return response.json(0)
|
|
return response.json(0)
|
|
|
|
|
|
except Exception as e:
|
|
except Exception as e:
|
|
- logger.info('---ai识别推送异常---:{}'.format(repr(e)))
|
|
|
|
|
|
+ LOGGING.info('---ai识别推送异常---:{}'.format(repr(e)))
|
|
data = {
|
|
data = {
|
|
'errLine': e.__traceback__.tb_lineno,
|
|
'errLine': e.__traceback__.tb_lineno,
|
|
'errMsg': repr(e)
|
|
'errMsg': repr(e)
|
|
@@ -286,6 +261,26 @@ class AiView(View):
|
|
else:
|
|
else:
|
|
return 0
|
|
return 0
|
|
|
|
|
|
|
|
+ @staticmethod
|
|
|
|
+ def get_tag_message(lang, event_type, channel):
|
|
|
|
+ event_type = str(event_type)
|
|
|
|
+ types = []
|
|
|
|
+ if len(event_type) > 1:
|
|
|
|
+ for i in range(1, len(event_type) + 1):
|
|
|
|
+ types.append(MessageTypeEnum(int(event_type[i - 1:i])))
|
|
|
|
+ else:
|
|
|
|
+ types.append(int(event_type))
|
|
|
|
+ msg_cn = {1: '人', 2: '动物', 3: '车', 4: '包裹'}
|
|
|
|
+ msg_en = {1: 'person', 2: 'animal', 3: 'vehicle', 4: 'package'}
|
|
|
|
+ msg_text = '检测到'
|
|
|
|
+ for item in types:
|
|
|
|
+ if lang == 'cn':
|
|
|
|
+ msg_text += msg_cn.get(item) + ' '
|
|
|
|
+ else:
|
|
|
|
+ msg_text += msg_en.get(item) + ' '
|
|
|
|
+ msg_text += ' channel:{}'.format(channel)
|
|
|
|
+ return msg_text
|
|
|
|
+
|
|
@classmethod
|
|
@classmethod
|
|
def save_cloud_ai_tag(cls, uid, event_time, types):
|
|
def save_cloud_ai_tag(cls, uid, event_time, types):
|
|
"""
|
|
"""
|