|
@@ -121,8 +121,6 @@ class AiView(View):
|
|
|
return self.do_querylist(userID, request_dict, response)
|
|
|
elif operation == 'getUsingPackage': # 获取设备当前使用的ai套餐
|
|
|
return self.getUsingPackage(request_dict, userID, response)
|
|
|
- elif operation == 'updateJpushTime': # 测试ai识别app的推送时间
|
|
|
- return self.update_jpush_time(userID, request_dict, response)
|
|
|
else:
|
|
|
return response.json(414)
|
|
|
|
|
@@ -737,41 +735,38 @@ class AiView(View):
|
|
|
file_post_one = request_dict.get('fileOne', None)
|
|
|
file_post_two = request_dict.get('fileTwo', None)
|
|
|
file_post_three = request_dict.get('fileThree', None)
|
|
|
+ file_post_four = request_dict.get('fileFour', None)
|
|
|
|
|
|
file_post_one = file_post_one.replace(' ', '+')
|
|
|
file_post_two = file_post_two.replace(' ', '+')
|
|
|
file_post_three = file_post_three.replace(' ', '+')
|
|
|
+ file_post_four = file_post_four.replace(' ', '+')
|
|
|
|
|
|
file_post_one = base64.b64decode(file_post_one)
|
|
|
file_post_two = base64.b64decode(file_post_two)
|
|
|
file_post_three = base64.b64decode(file_post_three)
|
|
|
+ file_post_four = base64.b64decode(file_post_four)
|
|
|
|
|
|
- file_list = [file_post_one, file_post_two, file_post_three]
|
|
|
- del file_post_one, file_post_two, file_post_three
|
|
|
+ file_list = [file_post_one, file_post_two, file_post_three, file_post_four]
|
|
|
+ del file_post_one, file_post_two, file_post_three, file_post_four
|
|
|
|
|
|
- dir_path = os.path.join(BASE_DIR, 'static/ai/' + uid + '/' + str(receiveTime))
|
|
|
+ dir_path = os.path.join(BASE_DIR, 'static/ai/' + uid + '/' + str(n_time))
|
|
|
if not os.path.exists(dir_path):
|
|
|
os.makedirs(dir_path)
|
|
|
file_path_list = []
|
|
|
- i = 1
|
|
|
- for index in file_list:
|
|
|
- file_path = dir_path + '/' + str(i) + '.jpg'
|
|
|
+ for i, val in enumerate(file_list):
|
|
|
+ # file_path = dir_path + '/' + str(i) + '.jpg'
|
|
|
+ file_path = "{dir_path}/{n_time}_{i}.jpg".format(dir_path=dir_path, n_time=n_time, i=i)
|
|
|
file_path_list.append(file_path)
|
|
|
with open(file_path, 'wb') as f:
|
|
|
- f.write(index)
|
|
|
+ f.write(val)
|
|
|
f.close()
|
|
|
- i += 1
|
|
|
|
|
|
image_size = 500 # 每张小图片的大小
|
|
|
image_colnum = 1 # 合并成一张图后,一行有几个小图
|
|
|
MergePic.merge_images(dir_path, image_size, image_colnum)
|
|
|
photo = open(dir_path + '.jpg', 'rb') #打开合成图
|
|
|
|
|
|
- cover = dir_path + '/' + str(i-1) + '.jpg'
|
|
|
- desc = dir_path + '.jpg'
|
|
|
- logger.info('----------------cover')
|
|
|
- logger.info(cover)
|
|
|
- logger.info(desc)
|
|
|
# photo = open(r'E:\test---------------\test\snipaste20220121_215952.jpg', 'rb')
|
|
|
#识别合成图片
|
|
|
maxLabels = 50
|
|
@@ -809,20 +804,16 @@ class AiView(View):
|
|
|
logger.info(label_list)
|
|
|
|
|
|
# 上传缩略图到s3
|
|
|
- upload_cover_path = "{uid}/{channel}/cover{n_time}.jpg".format(uid=uid, channel=channel,
|
|
|
- n_time=n_time) # 封面图
|
|
|
- upload_desc_path = "{uid}/{channel}/desc{n_time}.jpg".format(uid=uid, channel=channel,
|
|
|
- n_time=n_time) # 详情内容图
|
|
|
- #多线程上传图片
|
|
|
- thread_cover = threading.Thread(target=self.upload_s3, args=(cover, upload_cover_path))
|
|
|
- thread_desc = threading.Thread(target=self.upload_s3, args=(desc, upload_desc_path))
|
|
|
- thread_cover.start()
|
|
|
- thread_desc.start()
|
|
|
+ for i, val in enumerate(file_path_list):
|
|
|
+ upload_path = "{uid}/{channel}/{n_time}_{i}.jpg".format(uid=uid, channel=channel,
|
|
|
+ n_time=n_time,i=i) # 封面图
|
|
|
+ thread_task = threading.Thread(target=self.upload_s3, args=(val, upload_path))
|
|
|
+ thread_task.start()
|
|
|
#需要删除图片
|
|
|
-
|
|
|
+ # self.del_path(os.path.join(BASE_DIR, 'static/ai/' + uid))
|
|
|
|
|
|
#存储消息以及推送
|
|
|
- is_st = 1 #单图
|
|
|
+ is_st = 3 #多图
|
|
|
# 查询推送数据
|
|
|
uid_push_qs = UidPushModel.objects.filter(uid_set__uid=uid). \
|
|
|
values('token_val', 'app_type', 'appBundleId', 'm_code', 'push_type', 'userID_id',
|
|
@@ -915,24 +906,20 @@ class AiView(View):
|
|
|
}
|
|
|
return response.json(500, data)
|
|
|
|
|
|
- def delfile(self, path):
|
|
|
-
|
|
|
- # read all the files under the folder
|
|
|
- fileNames = glob.glob(path + r'\*')
|
|
|
-
|
|
|
- for fileName in fileNames:
|
|
|
- try:
|
|
|
- # delete file
|
|
|
- os.remove(fileName)
|
|
|
- except:
|
|
|
- try:
|
|
|
- # delete empty folders
|
|
|
- os.rmdir(fileName)
|
|
|
- except:
|
|
|
- # Not empty, delete files under folders
|
|
|
- delfile(fileName)
|
|
|
- # now, folders are empty, delete it
|
|
|
- os.rmdir(fileName)
|
|
|
+ def del_path(self, path):
|
|
|
+ if not os.path.exists(path):
|
|
|
+ return
|
|
|
+ if os.path.isfile(path):
|
|
|
+ os.remove(path)
|
|
|
+ else:
|
|
|
+ items = os.listdir(path)
|
|
|
+ for f in items:
|
|
|
+ c_path = os.path.join(path, f)
|
|
|
+ if os.path.isdir(c_path):
|
|
|
+ self.del_path(c_path)
|
|
|
+ else:
|
|
|
+ os.remove(c_path)
|
|
|
+ os.rmdir(path)
|
|
|
|
|
|
|
|
|
## 检查是否有符合条件的标签
|
|
@@ -1146,6 +1133,18 @@ class AiView(View):
|
|
|
|
|
|
elif p['is_st'] == 2:
|
|
|
pass
|
|
|
+ elif p['is_st'] == 3:
|
|
|
+ # 列表装载回放时间戳标记
|
|
|
+ p['img_list'] = []
|
|
|
+ for i in range(p['is_st']):
|
|
|
+ thumbspng = '{uid}/{channel}/{time}_{st}.jpeg'.format(uid=devUid, channel=p['Channel'], time=eventTime, st=i)
|
|
|
+ response_url = aws_s3_client.generate_presigned_url('get_object',
|
|
|
+ ExpiresIn=300,
|
|
|
+ Params={
|
|
|
+ 'Bucket': 'aipush', 'Key': thumbspng
|
|
|
+ },
|
|
|
+ )
|
|
|
+ p['img_list'].append(response_url)
|
|
|
|
|
|
if devUid in uid_type_dict.keys():
|
|
|
p['uid_type'] = uid_type_dict[devUid]['type']
|