|
@@ -426,10 +426,12 @@ def update_local_distribute_count(videos):
|
|
|
log_.error(traceback.format_exc())
|
|
|
|
|
|
|
|
|
-def get_recommend_params(ab_exp_info, page_type=0):
|
|
|
+def get_recommend_params(recommend_type, ab_exp_info, ab_info_data, page_type=0):
|
|
|
"""
|
|
|
根据实验分组给定对应的推荐参数
|
|
|
+ :param recommend_type: 首页推荐和相关推荐区分参数(0-首页推荐,1-相关推荐)
|
|
|
:param ab_exp_info: AB实验组参数
|
|
|
+ :param ab_info_data: app实验组参数
|
|
|
:param page_type: 页面区分参数,默认:0(首页)
|
|
|
:return:
|
|
|
"""
|
|
@@ -605,10 +607,36 @@ def get_recommend_params(ab_exp_info, page_type=0):
|
|
|
# else:
|
|
|
# old_video_index = -1
|
|
|
|
|
|
+ # APP实验组
|
|
|
+ if ab_info_data:
|
|
|
+ ab_info_app = {}
|
|
|
+ for page_code, item in json.loads(ab_info_data).items():
|
|
|
+ if not item:
|
|
|
+ continue
|
|
|
+ ab_info_code = item.get('eventId', None)
|
|
|
+ if ab_info_code:
|
|
|
+ ab_info_app[page_code] = ab_info_code
|
|
|
+ print(f"======{ab_info_app}")
|
|
|
+ # 首页推荐
|
|
|
+ if recommend_type == 0:
|
|
|
+ if config_.APP_AB_CODE['10003'] == ab_info_app.get('10003', None):
|
|
|
+ ab_code = config_.AB_CODE['region_rank_by_h'].get('region_rule_rank3')
|
|
|
+ expire_time = 3600
|
|
|
+ rule_key = config_.RULE_KEY_REGION['region_rule_rank3']
|
|
|
+ no_op_flag = True
|
|
|
+ # 相关推荐
|
|
|
+ elif recommend_type == 1:
|
|
|
+ if config_.APP_AB_CODE['10037'] == ab_info_app.get('10037', None):
|
|
|
+ ab_code = config_.AB_CODE['region_rank_by_h'].get('region_rule_rank3')
|
|
|
+ expire_time = 3600
|
|
|
+ rule_key = config_.RULE_KEY_REGION['region_rule_rank3']
|
|
|
+ no_op_flag = True
|
|
|
+
|
|
|
return top_K, flow_pool_P, ab_code, rule_key, expire_time, no_op_flag, old_video_index
|
|
|
|
|
|
|
|
|
-def video_homepage_recommend(request_id, mid, uid, size, app_type, algo_type, client_info, ab_exp_info, params):
|
|
|
+def video_homepage_recommend(request_id, mid, uid, size, app_type, algo_type,
|
|
|
+ client_info, ab_exp_info, params, ab_info_data):
|
|
|
"""
|
|
|
首页线上推荐逻辑
|
|
|
:param request_id: request_id
|
|
@@ -620,6 +648,7 @@ def video_homepage_recommend(request_id, mid, uid, size, app_type, algo_type, cl
|
|
|
:param client_info: 用户位置信息 {"country": "国家", "province": "省份", "city": "城市"}
|
|
|
:param ab_exp_info: ab实验分组参数 [{"expItemId":1, "configValue":{"size":4, "K":3, ...}}, ...]
|
|
|
:param params:
|
|
|
+ :param ab_info_data: app实验分组参数
|
|
|
:return:
|
|
|
"""
|
|
|
|
|
@@ -640,86 +669,87 @@ def video_homepage_recommend(request_id, mid, uid, size, app_type, algo_type, cl
|
|
|
# update_redis_data(result=result, app_type=app_type, mid=mid, last_rov_recall_key=last_rov_recall_key,
|
|
|
# expire_time=3600)
|
|
|
|
|
|
- if app_type == config_.APP_TYPE['APP']:
|
|
|
- # 票圈视频APP
|
|
|
- top_K = config_.K
|
|
|
- flow_pool_P = config_.P
|
|
|
- # 简单召回 - 排序 - 兜底
|
|
|
- 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, params=params)
|
|
|
- # 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_data(result=rank_result, app_type=app_type, mid=mid, last_rov_recall_key=last_rov_recall_key,
|
|
|
- top_K=top_K, expire_time=12 * 3600)
|
|
|
+ # if app_type == config_.APP_TYPE['APP']:
|
|
|
+ # # 票圈视频APP
|
|
|
+ # top_K = config_.K
|
|
|
+ # flow_pool_P = config_.P
|
|
|
+ # # 简单召回 - 排序 - 兜底
|
|
|
+ # 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, params=params)
|
|
|
+ # # 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_data(result=rank_result, app_type=app_type, mid=mid, last_rov_recall_key=last_rov_recall_key,
|
|
|
+ # top_K=top_K, expire_time=12 * 3600)
|
|
|
+ #
|
|
|
+ # else:
|
|
|
+ param_st = time.time()
|
|
|
+ # 特殊mid推荐处理
|
|
|
+ if mid in get_special_mid_list() or app_type == config_.APP_TYPE['PIAO_QUAN_VIDEO_PLUS']:
|
|
|
+ rank_result = special_mid_recommend(request_id=request_id, mid=mid, uid=uid, app_type=app_type, size=size)
|
|
|
+ return rank_result
|
|
|
|
|
|
- else:
|
|
|
- param_st = time.time()
|
|
|
- # 特殊mid推荐处理
|
|
|
- if mid in get_special_mid_list() or app_type == config_.APP_TYPE['PIAO_QUAN_VIDEO_PLUS']:
|
|
|
- rank_result = special_mid_recommend(request_id=request_id, mid=mid, uid=uid, app_type=app_type, size=size)
|
|
|
- return rank_result
|
|
|
-
|
|
|
- # 普通mid推荐处理
|
|
|
- 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({
|
|
|
- 'logTimestamp': int(time.time() * 1000),
|
|
|
- 'request_id': request_id,
|
|
|
- 'app_type': app_type,
|
|
|
- 'mid': mid,
|
|
|
- 'uid': uid,
|
|
|
- 'operation': 'get_recommend_params',
|
|
|
- 'executeTime': (time.time() - param_st) * 1000
|
|
|
- })
|
|
|
+ # 普通mid推荐处理
|
|
|
+ top_K, flow_pool_P, ab_code, rule_key, expire_time, no_op_flag, old_video_index = \
|
|
|
+ get_recommend_params(recommend_type=0, ab_exp_info=ab_exp_info, ab_info_data=ab_info_data)
|
|
|
+ log_.info({
|
|
|
+ 'logTimestamp': int(time.time() * 1000),
|
|
|
+ 'request_id': request_id,
|
|
|
+ 'app_type': app_type,
|
|
|
+ 'mid': mid,
|
|
|
+ 'uid': uid,
|
|
|
+ 'operation': 'get_recommend_params',
|
|
|
+ 'executeTime': (time.time() - param_st) * 1000
|
|
|
+ })
|
|
|
|
|
|
- # 简单召回 - 排序 - 兜底
|
|
|
- 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,
|
|
|
- params=params)
|
|
|
- log_.info({
|
|
|
- 'logTimestamp': int(time.time() * 1000),
|
|
|
- 'request_id': request_id,
|
|
|
- 'app_type': app_type,
|
|
|
- 'mid': mid,
|
|
|
- 'uid': uid,
|
|
|
- 'operation': 'get_recommend_result',
|
|
|
- 'executeTime': (time.time() - get_result_st) * 1000
|
|
|
- })
|
|
|
+ # 简单召回 - 排序 - 兜底
|
|
|
+ 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,
|
|
|
+ params=params)
|
|
|
+ log_.info({
|
|
|
+ 'logTimestamp': int(time.time() * 1000),
|
|
|
+ '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({
|
|
|
- 'logTimestamp': int(time.time() * 1000),
|
|
|
- 'request_id': request_id,
|
|
|
- 'app_type': app_type,
|
|
|
- 'mid': mid,
|
|
|
- 'uid': uid,
|
|
|
- 'operation': 'update_redis_data',
|
|
|
- 'executeTime': (time.time() - update_redis_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({
|
|
|
+ 'logTimestamp': int(time.time() * 1000),
|
|
|
+ '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(request_id, video_id, mid, uid, size, app_type, ab_exp_info, client_info, page_type, params):
|
|
|
+def video_relevant_recommend(request_id, video_id, mid, uid, size, app_type, ab_exp_info, client_info,
|
|
|
+ page_type, params, ab_info_data):
|
|
|
"""
|
|
|
相关推荐逻辑
|
|
|
:param request_id: request_id
|
|
@@ -732,6 +762,7 @@ def video_relevant_recommend(request_id, video_id, mid, uid, size, app_type, ab_
|
|
|
:param client_info: 地域参数
|
|
|
:param page_type: 页面区分参数 1:详情页;2:分享页
|
|
|
:param params:
|
|
|
+ :param ab_info_data: app实验分组参数
|
|
|
:return: videos type-list
|
|
|
"""
|
|
|
param_st = time.time()
|
|
@@ -742,7 +773,7 @@ def video_relevant_recommend(request_id, video_id, mid, uid, size, app_type, ab_
|
|
|
|
|
|
# 普通mid推荐处理
|
|
|
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)
|
|
|
+ get_recommend_params(recommend_type=1, ab_exp_info=ab_exp_info, ab_info_data=ab_info_data, page_type=page_type)
|
|
|
log_.info({
|
|
|
'logTimestamp': int(time.time() * 1000),
|
|
|
'request_id': request_id,
|