|
@@ -128,6 +128,35 @@ class AiView(View):
|
|
|
if (now_time - add_time) <= (3600 * 24 * 3):
|
|
|
ai_server = 'rekognition'
|
|
|
|
|
|
+ redis_obj = RedisObject(db=6)
|
|
|
+ APP_NOTIFY_KEY = f'ASJ:NOTIFY:PUSH:{uid}:{channel}' # 推送间隔缓存KEY
|
|
|
+ push_cache_data = redis_obj.get_data(APP_NOTIFY_KEY)
|
|
|
+ is_push = False if push_cache_data else True
|
|
|
+
|
|
|
+ notify_data = uid_push_qs[0]['uid_set__msg_notify']
|
|
|
+
|
|
|
+ # APP推送提醒状态
|
|
|
+ notify = self.is_ai_push(uid, notify_data) if is_push else is_push
|
|
|
+
|
|
|
+ if ai_server == 'sageMaker': # 自建模型sageMaker AI
|
|
|
+ sage_maker = SageMakerAiObject()
|
|
|
+ ai_result = sage_maker.sage_maker_ai_server(uid, file_list) # 图片base64识别AI标签
|
|
|
+ if ai_result:
|
|
|
+ if ai_result == 'imageError':
|
|
|
+ return response.json(0)
|
|
|
+ res = sage_maker.get_table_name(uid, ai_result, detect_group)
|
|
|
+ if not res: # 当前识别结果未匹配
|
|
|
+ return response.json(0)
|
|
|
+ push_thread = threading.Thread(
|
|
|
+ target=self.async_message_push,
|
|
|
+ kwargs={'sage_maker': sage_maker, 'uid': uid, 'n_time': n_time, 'uid_push_qs': uid_push_qs,
|
|
|
+ 'channel': channel, 'res': res, 'file_list': file_list, 'notify': notify})
|
|
|
+ push_thread.start() # AI识别异步存表&推送
|
|
|
+ self.add_push_cache(APP_NOTIFY_KEY, redis_obj, push_cache_data,
|
|
|
+ uid_push_qs[0]['uid_set__new_detect_interval'])
|
|
|
+ return response.json(0)
|
|
|
+ TIME_LOGGER.info(f'uid={uid},sagemakerAI识别失败{ai_result}')
|
|
|
+
|
|
|
push_thread = threading.Thread(target=self.image_label_detection,
|
|
|
kwargs={'ai_server': ai_server, 'uid': uid, 'file_list': file_list,
|
|
|
'detect_group': detect_group, 'n_time': n_time,
|
|
@@ -145,6 +174,10 @@ class AiView(View):
|
|
|
TIME_LOGGER.info(f'rekognition识别errMsg={data}')
|
|
|
return response.json(48, data)
|
|
|
|
|
|
+ def async_message_push(self, sage_maker, uid, n_time, uid_push_qs, channel, res, file_list, notify):
|
|
|
+ # 保存推送消息
|
|
|
+ sage_maker.save_push_message(uid, n_time, uid_push_qs, channel, res, file_list, notify)
|
|
|
+
|
|
|
def add_push_cache(self, key, redis_obj, cache_push_data, push_interval):
|
|
|
"""
|
|
|
推送间隔缓存设置
|
|
@@ -184,19 +217,6 @@ class AiView(View):
|
|
|
# APP推送提醒状态
|
|
|
notify = self.is_ai_push(uid, notify_data) if is_push else is_push
|
|
|
|
|
|
- if ai_server == 'sageMaker': # 自建模型sageMaker AI
|
|
|
- sage_maker = SageMakerAiObject()
|
|
|
- ai_result = sage_maker.sage_maker_ai_server(uid, file_list) # 图片base64识别AI标签
|
|
|
- if ai_result:
|
|
|
- res = sage_maker.get_table_name(uid, ai_result, detect_group)
|
|
|
- if not res: # 当前识别结果未匹配
|
|
|
- return False
|
|
|
- # 保存推送消息
|
|
|
- sage_maker.save_push_message(uid, n_time, uid_push_qs, channel, res, file_list, notify)
|
|
|
- self.add_push_cache(APP_NOTIFY_KEY, redis_obj, push_cache_data,
|
|
|
- uid_push_qs[0]['uid_set__new_detect_interval'])
|
|
|
- return True
|
|
|
-
|
|
|
TIME_LOGGER.info(f'*****现执行Reko,uid={uid}识别类型={ai_server}')
|
|
|
dir_path = os.path.join(BASE_DIR, 'static/ai/' + uid + '/' + str(n_time))
|
|
|
if not os.path.exists(dir_path):
|