|
@@ -110,7 +110,11 @@ class AiView(View):
|
|
|
for k, val in enumerate(file_list):
|
|
|
if not val:
|
|
|
return response.json(444, '缺少第{k}张图'.format(k=k + 1))
|
|
|
-
|
|
|
+ redis_obj = RedisObject(db=6)
|
|
|
+ ai_key = f'PUSH:AI:{uid}:{channel}'
|
|
|
+ ai_data = redis_obj.get_data(ai_key)
|
|
|
+ if ai_data:
|
|
|
+ return response.json(0, {'msg': 'Push again in one minute'})
|
|
|
# 查询推送数据
|
|
|
uid_push_qs = UidPushModel.objects.filter(uid_set__uid=uid). \
|
|
|
values('token_val', 'app_type', 'appBundleId', 'm_code', 'push_type', 'userID_id',
|
|
@@ -129,31 +133,42 @@ class AiView(View):
|
|
|
if (now_time - add_time) <= (3600 * 24 * 3):
|
|
|
ai_server = 'rekognition'
|
|
|
|
|
|
- redis_obj = RedisObject(db=6)
|
|
|
- app_msg_key = f'ASJ:NOTIFY:PUSH:{uid}:{channel}' # 推送间隔缓存KEY
|
|
|
- push_cache_data = redis_obj.get_data(app_msg_key)
|
|
|
+ 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
|
|
|
- params = {
|
|
|
- 'ai_server': ai_server,
|
|
|
- 'uid': uid,
|
|
|
- 'file_list': file_list,
|
|
|
- 'channel': channel,
|
|
|
- 'n_time': n_time,
|
|
|
- 'uid_push_qs': uid_push_qs,
|
|
|
- 'notify': notify,
|
|
|
- 'app_msg_key': app_msg_key,
|
|
|
- 'redis_obj': redis_obj,
|
|
|
- 'push_cache_data': push_cache_data,
|
|
|
- 'detect_group': detect_group
|
|
|
- }
|
|
|
|
|
|
- msg_detection = threading.Thread(target=self.ai_table_detection, kwargs=params)
|
|
|
- msg_detection.start()
|
|
|
+ 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'])
|
|
|
+ redis_obj.set_data(ai_key, uid, 60)
|
|
|
+ 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,
|
|
|
+ 'uid_push_qs': uid_push_qs,
|
|
|
+ 'channel': channel})
|
|
|
+ push_thread.start() # AI识别异步存表&推送
|
|
|
+ redis_obj.set_data(ai_key, uid, 60)
|
|
|
return response.json(0)
|
|
|
except Exception as e:
|
|
|
print(e)
|
|
@@ -164,37 +179,6 @@ class AiView(View):
|
|
|
TIME_LOGGER.info(f'rekognition识别errMsg={data}')
|
|
|
return response.json(48, data)
|
|
|
|
|
|
- def ai_table_detection(self, ai_server, uid, file_list, channel, n_time, uid_push_qs, notify,
|
|
|
- app_msg_key, redis_obj, push_cache_data, detect_group):
|
|
|
- """
|
|
|
- AI标签检测(移动侦测图片)
|
|
|
- """
|
|
|
- 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
|
|
|
- res = sage_maker.get_table_name(uid, ai_result, detect_group)
|
|
|
- if not res: # 当前识别结果未匹配
|
|
|
- return
|
|
|
- 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_msg_key, redis_obj, push_cache_data,
|
|
|
- uid_push_qs[0]['uid_set__new_detect_interval'])
|
|
|
- return
|
|
|
- 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,
|
|
|
- 'uid_push_qs': uid_push_qs,
|
|
|
- 'channel': channel})
|
|
|
- push_thread.start() # AI识别异步存表&推送
|
|
|
-
|
|
|
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)
|