|
@@ -20,9 +20,10 @@ log_ = Log()
|
|
|
config_ = set_config()
|
|
|
|
|
|
|
|
|
-def relevant_video_top_recommend(app_type, mid, uid, head_vid, videos, size):
|
|
|
+def relevant_video_top_recommend(request_id, app_type, mid, uid, head_vid, videos, size):
|
|
|
"""
|
|
|
相关推荐强插 运营给定置顶相关性视频
|
|
|
+ :param request_id: request_id
|
|
|
:param app_type: 产品标识 type-int
|
|
|
:param mid: mid
|
|
|
:param uid: uid
|
|
@@ -44,7 +45,7 @@ def relevant_video_top_recommend(app_type, mid, uid, head_vid, videos, size):
|
|
|
|
|
|
# 过滤
|
|
|
relevant_video_ids = [int(item['recommend_vid']) for item in relevant_videos_sorted]
|
|
|
- filter_helper = FilterVideos(app_type=app_type, video_ids=relevant_video_ids, mid=mid, uid=uid)
|
|
|
+ filter_helper = FilterVideos(request_id=request_id, app_type=app_type, video_ids=relevant_video_ids, mid=mid, uid=uid)
|
|
|
filtered_ids = filter_helper.filter_videos()
|
|
|
if filtered_ids is None:
|
|
|
return videos
|
|
@@ -81,7 +82,7 @@ def relevant_video_top_recommend(app_type, mid, uid, head_vid, videos, size):
|
|
|
return rank_result[:size]
|
|
|
|
|
|
|
|
|
-def video_position_recommend(mid, uid, app_type, videos):
|
|
|
+def video_position_recommend(request_id, mid, uid, app_type, videos):
|
|
|
# videos = video_recommend(mid=mid, uid=uid, size=size, app_type=app_type,
|
|
|
# algo_type=algo_type, client_info=client_info)
|
|
|
redis_helper = RedisHelper()
|
|
@@ -98,8 +99,8 @@ def video_position_recommend(mid, uid, app_type, videos):
|
|
|
pos1_vids = [int(i) for i in pos1_vids]
|
|
|
pos2_vids = [int(i) for i in pos2_vids]
|
|
|
|
|
|
- filter_1 = FilterVideos(app_type=app_type, video_ids=pos1_vids, mid=mid, uid=uid)
|
|
|
- filter_2 = FilterVideos(app_type=app_type, video_ids=pos2_vids, mid=mid, uid=uid)
|
|
|
+ filter_1 = FilterVideos(request_id=request_id, app_type=app_type, video_ids=pos1_vids, mid=mid, uid=uid)
|
|
|
+ filter_2 = FilterVideos(request_id=request_id, app_type=app_type, video_ids=pos2_vids, mid=mid, uid=uid)
|
|
|
t = [gevent.spawn(filter_1.filter_videos), gevent.spawn(filter_2.filter_videos)]
|
|
|
gevent.joinall(t)
|
|
|
filted_list = [i.get() for i in t]
|
|
@@ -135,10 +136,11 @@ def positon_duplicate(pos1_vids, pos2_vids, videos):
|
|
|
return l
|
|
|
|
|
|
|
|
|
-def video_recommend(mid, uid, size, top_K, flow_pool_P, app_type, algo_type, client_info, expire_time=24*3600,
|
|
|
+def video_recommend(request_id, mid, uid, size, top_K, flow_pool_P, app_type, algo_type, client_info, expire_time=24*3600,
|
|
|
ab_code=config_.AB_CODE['initial'], rule_key='', no_op_flag=False, old_video_index=-1, video_id=None):
|
|
|
"""
|
|
|
首页线上推荐逻辑
|
|
|
+ :param request_id: request_id
|
|
|
:param mid: mid type-string
|
|
|
:param uid: uid type-string
|
|
|
:param size: 请求视频数量 type-int
|
|
@@ -171,7 +173,8 @@ def video_recommend(mid, uid, size, top_K, flow_pool_P, app_type, algo_type, cli
|
|
|
pool.join()
|
|
|
'''
|
|
|
recall_result_list = []
|
|
|
- pool_recall = PoolRecall(app_type=app_type, mid=mid, uid=uid, ab_code=ab_code,
|
|
|
+ pool_recall = PoolRecall(request_id=request_id,
|
|
|
+ app_type=app_type, mid=mid, uid=uid, ab_code=ab_code,
|
|
|
client_info=client_info, rule_key=rule_key, no_op_flag=no_op_flag)
|
|
|
_, last_rov_recall_key, _ = pool_recall.get_video_last_idx()
|
|
|
# 小时级实验
|
|
@@ -213,8 +216,13 @@ def video_recommend(mid, uid, size, top_K, flow_pool_P, app_type, algo_type, cli
|
|
|
recall_result_list = [i.get() for i in t]
|
|
|
|
|
|
end_recall = time.time()
|
|
|
- log_.info('mid: {}, uid: {}, recall: {}, execute time = {}ms'.format(
|
|
|
- mid, uid, recall_result_list, (end_recall - start_recall) * 1000))
|
|
|
+ log_.info({'request_id': request_id,
|
|
|
+ 'mid': mid,
|
|
|
+ 'uid': uid,
|
|
|
+ 'operation': 'recall',
|
|
|
+ 'recall_result': recall_result_list,
|
|
|
+ 'executeTime': (end_recall - start_recall) * 1000})
|
|
|
+
|
|
|
|
|
|
# ####### 排序
|
|
|
start_rank = time.time()
|
|
@@ -247,8 +255,12 @@ def video_recommend(mid, uid, size, top_K, flow_pool_P, app_type, algo_type, cli
|
|
|
# size=size, top_K=top_K, old_video_index=old_video_index)
|
|
|
|
|
|
end_rank = time.time()
|
|
|
- log_.info('mid: {}, uid: {}, rank_result: {}, execute time = {}ms'.format(
|
|
|
- mid, uid, rank_result, (end_rank - start_rank) * 1000))
|
|
|
+ log_.info({'request_id': request_id,
|
|
|
+ 'mid': mid,
|
|
|
+ 'uid': uid,
|
|
|
+ 'operation': 'rank',
|
|
|
+ 'rank_result': rank_result,
|
|
|
+ 'executeTime': (end_rank - start_rank) * 1000})
|
|
|
|
|
|
if not rank_result:
|
|
|
# 兜底策略
|
|
@@ -256,8 +268,12 @@ def video_recommend(mid, uid, size, top_K, flow_pool_P, app_type, algo_type, cli
|
|
|
start_bottom = time.time()
|
|
|
rank_result = bottom_strategy(size=size, app_type=app_type, ab_code=ab_code)
|
|
|
end_bottom = time.time()
|
|
|
- log_.info('mid: {}, uid: {}, bottom strategy result: {}, execute time = {}ms'.format(
|
|
|
- mid, uid, rank_result, (end_bottom - start_bottom) * 1000))
|
|
|
+ log_.info({'request_id': request_id,
|
|
|
+ 'mid': mid,
|
|
|
+ 'uid': uid,
|
|
|
+ 'operation': 'bottom',
|
|
|
+ 'bottom_result': rank_result,
|
|
|
+ 'executeTime': (end_bottom - start_bottom) * 1000})
|
|
|
|
|
|
return rank_result, last_rov_recall_key
|
|
|
|
|
@@ -325,7 +341,7 @@ def update_redis_data(result, app_type, mid, last_rov_recall_key, top_K, expire_
|
|
|
if preview_video_ids:
|
|
|
# log_.error('key_name = {} \n values = {}'.format(preview_key_name, tuple(preview_video_ids)))
|
|
|
redis_helper.add_data_with_set(key_name=preview_key_name, values=tuple(preview_video_ids), expire_time=30 * 60)
|
|
|
- log_.info('preview redis update success!')
|
|
|
+ # log_.info('preview redis update success!')
|
|
|
|
|
|
# 将此次获取的ROV召回池top_K末位视频id同步刷新到Redis中,方便下次快速定位到召回位置,过期时间为1天
|
|
|
rov_recall_video = [item['videoId'] for item in result[:top_K]
|
|
@@ -338,14 +354,14 @@ def update_redis_data(result, app_type, mid, last_rov_recall_key, top_K, expire_
|
|
|
if not redis_helper.get_score_with_value(key_name=key_name, value=rov_recall_video[-1]):
|
|
|
redis_helper.set_data_to_redis(key_name=last_rov_recall_key, value=rov_recall_video[-1],
|
|
|
expire_time=expire_time)
|
|
|
- log_.info('last video redis update success!')
|
|
|
+ # log_.info('last video redis update success!')
|
|
|
|
|
|
# 将此次分发的流量池视频,对 本地分发数-1 进行记录
|
|
|
if app_type not in [config_.APP_TYPE['LAO_HAO_KAN_VIDEO'], config_.APP_TYPE['ZUI_JING_QI']]:
|
|
|
flow_recall_video = [item for item in result if item['pushFrom'] == config_.PUSH_FROM['flow_recall']]
|
|
|
if flow_recall_video:
|
|
|
update_local_distribute_count(flow_recall_video)
|
|
|
- log_.info('update local distribute count success!')
|
|
|
+ # log_.info('update local distribute count success!')
|
|
|
|
|
|
except Exception as e:
|
|
|
log_.error("update redis data fail!")
|
|
@@ -548,9 +564,10 @@ def get_recommend_params(ab_exp_info, page_type=0):
|
|
|
return top_K, flow_pool_P, ab_code, rule_key, expire_time, no_op_flag, old_video_index
|
|
|
|
|
|
|
|
|
-def video_homepage_recommend(mid, uid, size, app_type, algo_type, client_info, ab_exp_info):
|
|
|
+def video_homepage_recommend(request_id, mid, uid, size, app_type, algo_type, client_info, ab_exp_info):
|
|
|
"""
|
|
|
首页线上推荐逻辑
|
|
|
+ :param request_id: request_id
|
|
|
:param mid: mid type-string
|
|
|
:param uid: uid type-string
|
|
|
:param size: 请求视频数量 type-int
|
|
@@ -583,7 +600,8 @@ def video_homepage_recommend(mid, uid, size, app_type, algo_type, client_info, a
|
|
|
top_K = config_.K
|
|
|
flow_pool_P = config_.P
|
|
|
# 简单召回 - 排序 - 兜底
|
|
|
- rank_result, last_rov_recall_key = video_recommend(mid=mid, uid=uid, app_type=app_type,
|
|
|
+ rank_result, last_rov_recall_key = video_recommend(request_id=request_id,
|
|
|
+ mid=mid, uid=uid, app_type=app_type,
|
|
|
size=size, top_K=top_K, flow_pool_P=flow_pool_P,
|
|
|
algo_type=algo_type, client_info=client_info,
|
|
|
expire_time=12 * 3600)
|
|
@@ -596,30 +614,54 @@ def video_homepage_recommend(mid, uid, size, app_type, algo_type, client_info, a
|
|
|
top_K=top_K, expire_time=12 * 3600)
|
|
|
|
|
|
else:
|
|
|
+ param_st = time.time()
|
|
|
top_K, flow_pool_P, ab_code, rule_key, expire_time, no_op_flag, old_video_index = \
|
|
|
get_recommend_params(ab_exp_info=ab_exp_info)
|
|
|
+ log_.info({'request_id': request_id,
|
|
|
+ 'app_type': app_type,
|
|
|
+ 'mid': mid,
|
|
|
+ 'uid': uid,
|
|
|
+ 'operation': 'get_recommend_params',
|
|
|
+ 'executeTime': (time.time() - param_st) * 1000})
|
|
|
|
|
|
# 简单召回 - 排序 - 兜底
|
|
|
- rank_result, last_rov_recall_key = video_recommend(mid=mid, uid=uid, app_type=app_type,
|
|
|
+ get_result_st = time.time()
|
|
|
+ rank_result, last_rov_recall_key = video_recommend(request_id=request_id,
|
|
|
+ mid=mid, uid=uid, app_type=app_type,
|
|
|
size=size, top_K=top_K, flow_pool_P=flow_pool_P,
|
|
|
algo_type=algo_type, client_info=client_info,
|
|
|
ab_code=ab_code, expire_time=expire_time,
|
|
|
rule_key=rule_key, no_op_flag=no_op_flag,
|
|
|
old_video_index=old_video_index)
|
|
|
+ log_.info({'request_id': request_id,
|
|
|
+ 'app_type': app_type,
|
|
|
+ 'mid': mid,
|
|
|
+ 'uid': uid,
|
|
|
+ 'operation': 'get_recommend_result',
|
|
|
+ 'executeTime': (time.time() - get_result_st) * 1000})
|
|
|
+
|
|
|
# ab-test
|
|
|
# result = ab_test_op(rank_result=rank_result,
|
|
|
# ab_code_list=[config_.AB_CODE['position_insert']],
|
|
|
# app_type=app_type, mid=mid, uid=uid)
|
|
|
# redis数据刷新
|
|
|
+ update_redis_st = time.time()
|
|
|
update_redis_data(result=rank_result, app_type=app_type, mid=mid, last_rov_recall_key=last_rov_recall_key,
|
|
|
top_K=top_K)
|
|
|
+ log_.info({'request_id': request_id,
|
|
|
+ 'app_type': app_type,
|
|
|
+ 'mid': mid,
|
|
|
+ 'uid': uid,
|
|
|
+ 'operation': 'update_redis_data',
|
|
|
+ 'executeTime': (time.time() - update_redis_st) * 1000})
|
|
|
|
|
|
return rank_result
|
|
|
|
|
|
|
|
|
-def video_relevant_recommend(video_id, mid, uid, size, app_type, ab_exp_info, client_info, page_type):
|
|
|
+def video_relevant_recommend(request_id, video_id, mid, uid, size, app_type, ab_exp_info, client_info, page_type):
|
|
|
"""
|
|
|
相关推荐逻辑
|
|
|
+ :param request_id: request_id
|
|
|
:param video_id: 相关推荐的头部视频id
|
|
|
:param mid: mid type-string
|
|
|
:param uid: uid type-string
|
|
@@ -630,23 +672,46 @@ def video_relevant_recommend(video_id, mid, uid, size, app_type, ab_exp_info, cl
|
|
|
:param page_type: 页面区分参数 1:详情页;2:分享页
|
|
|
:return: videos type-list
|
|
|
"""
|
|
|
+ param_st = time.time()
|
|
|
top_K, flow_pool_P, ab_code, rule_key, expire_time, no_op_flag, old_video_index = \
|
|
|
get_recommend_params(ab_exp_info=ab_exp_info, page_type=page_type)
|
|
|
+ log_.info({'request_id': request_id,
|
|
|
+ 'app_type': app_type,
|
|
|
+ 'mid': mid,
|
|
|
+ 'uid': uid,
|
|
|
+ 'operation': 'get_recommend_params',
|
|
|
+ 'executeTime': (time.time() - param_st) * 1000})
|
|
|
|
|
|
# 简单召回 - 排序 - 兜底
|
|
|
- rank_result, last_rov_recall_key = video_recommend(mid=mid, uid=uid, app_type=app_type,
|
|
|
+ get_result_st = time.time()
|
|
|
+ rank_result, last_rov_recall_key = video_recommend(request_id=request_id,
|
|
|
+ mid=mid, uid=uid, app_type=app_type,
|
|
|
size=size, top_K=top_K, flow_pool_P=flow_pool_P,
|
|
|
algo_type='', client_info=client_info,
|
|
|
ab_code=ab_code, expire_time=expire_time,
|
|
|
rule_key=rule_key, no_op_flag=no_op_flag,
|
|
|
old_video_index=old_video_index, video_id=video_id)
|
|
|
+ log_.info({'request_id': request_id,
|
|
|
+ 'app_type': app_type,
|
|
|
+ 'mid': mid,
|
|
|
+ 'uid': uid,
|
|
|
+ 'operation': 'get_recommend_result',
|
|
|
+ 'executeTime': (time.time() - get_result_st) * 1000})
|
|
|
# ab-test
|
|
|
# result = ab_test_op(rank_result=rank_result,
|
|
|
# ab_code_list=[config_.AB_CODE['position_insert'], config_.AB_CODE['relevant_video_op']],
|
|
|
# app_type=app_type, mid=mid, uid=uid, head_vid=video_id, size=size)
|
|
|
+
|
|
|
# redis数据刷新
|
|
|
+ update_redis_st = time.time()
|
|
|
update_redis_data(result=rank_result, app_type=app_type, mid=mid, last_rov_recall_key=last_rov_recall_key,
|
|
|
top_K=top_K)
|
|
|
+ log_.info({'request_id': request_id,
|
|
|
+ 'app_type': app_type,
|
|
|
+ 'mid': mid,
|
|
|
+ 'uid': uid,
|
|
|
+ 'operation': 'update_redis_data',
|
|
|
+ 'executeTime': (time.time() - update_redis_st) * 1000})
|
|
|
|
|
|
return rank_result
|
|
|
|