|
@@ -7,7 +7,7 @@ from config import set_config
|
|
|
from video_recall import PoolRecall
|
|
|
from db_helper import RedisHelper
|
|
|
from utils import FilterVideos, send_msg_to_feishu
|
|
|
-from rank_service import get_featurs, get_tf_serving_sores
|
|
|
+from rank_service import get_featurs, get_tf_serving_sores
|
|
|
|
|
|
log_ = Log()
|
|
|
config_ = set_config()
|
|
@@ -44,12 +44,12 @@ def video_rank(data, size, top_K, flow_pool_P):
|
|
|
|
|
|
# 相对30天天级规则更新数据
|
|
|
day_30_recall = [item for item in data['rov_pool_recall']
|
|
|
- if item.get('pushFrom') == config_.PUSH_FROM['rov_recall_30day']]
|
|
|
+ if item.get('pushFrom') == config_.PUSH_FROM['rov_recall_30day']]
|
|
|
day_30_recall_rank = sorted(day_30_recall, key=lambda k: k.get('rovScore', 0), reverse=True)
|
|
|
|
|
|
# 地域分组小时级规则更新数据
|
|
|
region_h_recall = [item for item in data['rov_pool_recall']
|
|
|
- if item.get('pushFrom') == config_.PUSH_FROM['rov_recall_region_h']]
|
|
|
+ if item.get('pushFrom') == config_.PUSH_FROM['rov_recall_region_h']]
|
|
|
region_h_recall_rank = sorted(region_h_recall, key=lambda k: k.get('rovScore', 0), reverse=True)
|
|
|
# 地域分组小时级更新24h规则更新数据
|
|
|
region_24h_recall = [item for item in data['rov_pool_recall']
|
|
@@ -162,30 +162,30 @@ def video_new_rank(videoIds, fast_flow_set, flow_set, size, top_K, flow_pool_P):
|
|
|
:return: rank_result
|
|
|
"""
|
|
|
add_flow_set = set('')
|
|
|
- if not videoIds or len(videoIds)==0:
|
|
|
+ if not videoIds or len(videoIds) == 0:
|
|
|
return [], add_flow_set
|
|
|
|
|
|
redisObj = RedisHelper()
|
|
|
vidKeys = []
|
|
|
for vid in videoIds:
|
|
|
- vidKeys.append("k_p:"+str(vid))
|
|
|
- #print("vidKeys:", vidKeys)
|
|
|
+ vidKeys.append("k_p:" + str(vid))
|
|
|
+ # print("vidKeys:", vidKeys)
|
|
|
video_scores = redisObj.get_batch_key(vidKeys)
|
|
|
- #print(video_scores)
|
|
|
+ # print(video_scores)
|
|
|
video_items = []
|
|
|
for i in range(len(video_scores)):
|
|
|
try:
|
|
|
- #print(video_scores[i])
|
|
|
+ # print(video_scores[i])
|
|
|
if video_scores[i] is None:
|
|
|
video_items.append((videoIds[i], 0.0))
|
|
|
else:
|
|
|
video_score_str = json.loads(video_scores[i])
|
|
|
- #print("video_score_str:",video_score_str)
|
|
|
+ # print("video_score_str:",video_score_str)
|
|
|
video_items.append((videoIds[i], video_score_str[0]))
|
|
|
except Exception:
|
|
|
video_items.append((videoIds[i], 0.0))
|
|
|
sort_items = sorted(video_items, key=lambda k: k[1], reverse=True)
|
|
|
- #print("sort_items:", sort_items)
|
|
|
+ # print("sort_items:", sort_items)
|
|
|
rov_recall_rank = sort_items
|
|
|
fast_flow_recall_rank = []
|
|
|
flow_recall_rank = []
|
|
@@ -195,7 +195,7 @@ def video_new_rank(videoIds, fast_flow_set, flow_set, size, top_K, flow_pool_P):
|
|
|
elif item[0] in flow_set:
|
|
|
flow_recall_rank.append(item)
|
|
|
# all flow result
|
|
|
- all_flow_recall_rank = fast_flow_recall_rank+flow_recall_rank
|
|
|
+ all_flow_recall_rank = fast_flow_recall_rank + flow_recall_rank
|
|
|
rank_result = []
|
|
|
rank_set = set('')
|
|
|
|
|
@@ -209,19 +209,19 @@ def video_new_rank(videoIds, fast_flow_set, flow_set, size, top_K, flow_pool_P):
|
|
|
|
|
|
for rank_item in rank_result:
|
|
|
rank_set.add(rank_item[0])
|
|
|
- #print("rank_result:", rank_result)
|
|
|
+ # print("rank_result:", rank_result)
|
|
|
# 按概率 p 及score排序获取 size - k 个视频, 第4个位置按概率取流量池
|
|
|
i = 0
|
|
|
left_quato = size - top_K
|
|
|
j = 0
|
|
|
jj = 0
|
|
|
- while i < left_quato and (j<len(all_flow_recall_rank) or jj<len(rov_recall_rank)):
|
|
|
+ while i < left_quato and (j < len(all_flow_recall_rank) or jj < len(rov_recall_rank)):
|
|
|
# 随机生成[0, 1)浮点数
|
|
|
rand = random.random()
|
|
|
# log_.info('rand: {}'.format(rand))
|
|
|
if rand < flow_pool_P:
|
|
|
for flow_item in all_flow_recall_rank:
|
|
|
- j+=1
|
|
|
+ j += 1
|
|
|
if flow_item[0] in rank_set:
|
|
|
continue
|
|
|
else:
|
|
@@ -229,22 +229,22 @@ def video_new_rank(videoIds, fast_flow_set, flow_set, size, top_K, flow_pool_P):
|
|
|
rank_set.add(flow_item[0])
|
|
|
add_flow_set.add(flow_item[0])
|
|
|
i += 1
|
|
|
- if i>= left_quato:
|
|
|
+ if i >= left_quato:
|
|
|
break
|
|
|
-
|
|
|
+
|
|
|
else:
|
|
|
for recall_item in rov_recall_rank:
|
|
|
- jj+=1
|
|
|
+ jj += 1
|
|
|
if recall_item[0] in rank_set:
|
|
|
continue
|
|
|
else:
|
|
|
rank_result.append(recall_item)
|
|
|
rank_set.add(recall_item[0])
|
|
|
i += 1
|
|
|
- if i>= left_quato:
|
|
|
+ if i >= left_quato:
|
|
|
break
|
|
|
- #print("rank_result:", rank_result)
|
|
|
- #print("add_flow_set:", add_flow_set)
|
|
|
+ # print("rank_result:", rank_result)
|
|
|
+ # print("add_flow_set:", add_flow_set)
|
|
|
return rank_result[:size], add_flow_set
|
|
|
|
|
|
|
|
@@ -263,7 +263,7 @@ def refactor_video_rank(rov_recall_rank, fast_flow_set, flow_set, size, top_K, f
|
|
|
flow_recall_rank = []
|
|
|
for item in rov_recall_rank:
|
|
|
vid = item.get('videoId', 0)
|
|
|
- #print(item)
|
|
|
+ # print(item)
|
|
|
if vid in fast_flow_set:
|
|
|
fast_flow_recall_rank.append(item)
|
|
|
elif vid in flow_set:
|
|
@@ -279,7 +279,7 @@ def refactor_video_rank(rov_recall_rank, fast_flow_set, flow_set, size, top_K, f
|
|
|
else:
|
|
|
rank_result.extend(all_flow_recall_rank[:top_K])
|
|
|
all_flow_recall_rank = all_flow_recall_rank[top_K:]
|
|
|
- #已存放了多少VID
|
|
|
+ # 已存放了多少VID
|
|
|
for rank_item in rank_result:
|
|
|
rank_set.add(rank_item.get('videoId', 0))
|
|
|
|
|
@@ -291,7 +291,7 @@ def refactor_video_rank(rov_recall_rank, fast_flow_set, flow_set, size, top_K, f
|
|
|
# log_.info('rand: {}'.format(rand))
|
|
|
if rand < flow_pool_P:
|
|
|
for flow_item in all_flow_recall_rank:
|
|
|
- flow_vid = flow_item.get('videoId', 0)
|
|
|
+ flow_vid = flow_item.get('videoId', 0)
|
|
|
if flow_vid in rank_set:
|
|
|
continue
|
|
|
else:
|
|
@@ -308,6 +308,7 @@ def refactor_video_rank(rov_recall_rank, fast_flow_set, flow_set, size, top_K, f
|
|
|
i += 1
|
|
|
return rank_result[:size]
|
|
|
|
|
|
+
|
|
|
def remove_duplicate(rov_recall, flow_recall, top_K):
|
|
|
"""
|
|
|
对多路召回的视频去重
|
|
@@ -605,13 +606,13 @@ def video_new_rank2(data, size, top_K, flow_pool_P, ab_code, mid, exp_config=Non
|
|
|
if not data['rov_pool_recall'] and not data['flow_pool_recall']:
|
|
|
return [], 0
|
|
|
|
|
|
- #全量的是vlog,票圈精选, 334,60057,
|
|
|
+ # 全量的是vlog,票圈精选, 334,60057,
|
|
|
# 60054: simrecall,
|
|
|
# 60052: 票圈精选,融合排序,60053:空置
|
|
|
# 60055: video_reall, 60065: video_recall2
|
|
|
# 60056: get_U2I_reall
|
|
|
pre_str = "k_p2:"
|
|
|
- if ab_code==60057:
|
|
|
+ if ab_code == 60057:
|
|
|
pre_str = "k_p2:"
|
|
|
elif ab_code == 60052:
|
|
|
pre_str = "k_p5:"
|
|
@@ -623,23 +624,30 @@ def video_new_rank2(data, size, top_K, flow_pool_P, ab_code, mid, exp_config=Non
|
|
|
pre_str = "k_p4:"
|
|
|
elif ab_code == 60056:
|
|
|
pre_str = "k_p7:"
|
|
|
- #print("pre_str:", pre_str)
|
|
|
+ # print("pre_str:", pre_str)
|
|
|
recall_list = []
|
|
|
rov_recall_rank = data['rov_pool_recall']
|
|
|
- #call rank service
|
|
|
- #flag_call_service = 0
|
|
|
+ # call rank service
|
|
|
+ # flag_call_service = 0
|
|
|
if ab_code == 60066:
|
|
|
feature_dict, recall_list = get_featurs(mid, data, size, top_K, flow_pool_P, env_dict)
|
|
|
score_result = get_tf_serving_sores(feature_dict)
|
|
|
if score_result and len(score_result) > 0 and len(score_result) == len(recall_list):
|
|
|
for i in range(len(score_result)):
|
|
|
recall_list[i]['sort_score'] = score_result[i][0]
|
|
|
- #print(score_result[i][0])
|
|
|
+ # print(score_result[i][0])
|
|
|
recall_list[i]['flag_call_service'] = 1
|
|
|
rov_recall_rank = sorted(recall_list, key=lambda k: k.get('sort_score', 0), reverse=True)
|
|
|
else:
|
|
|
redisObj = RedisHelper()
|
|
|
vidKeys = []
|
|
|
+ for recall_item in data['rov_pool_recall']:
|
|
|
+ if len(recall_item) <= 0:
|
|
|
+ continue
|
|
|
+ vid = recall_item.get("videoId", 0)
|
|
|
+ vidKeys.append(pre_str + str(vid))
|
|
|
+ recall_list.append(recall_item)
|
|
|
+ video_scores = redisObj.get_batch_key(vidKeys)
|
|
|
if video_scores and len(recall_list) > 0:
|
|
|
for i in range(len(video_scores)):
|
|
|
try:
|
|
@@ -647,13 +655,15 @@ def video_new_rank2(data, size, top_K, flow_pool_P, ab_code, mid, exp_config=Non
|
|
|
recall_list[i]['sort_score'] = 0.0
|
|
|
else:
|
|
|
video_score_str = json.loads(video_scores[i])
|
|
|
+ # print("video_score_str:", video_score_str)
|
|
|
recall_list[i]['sort_score'] = video_score_str[0]
|
|
|
except Exception:
|
|
|
recall_list[i]['sort_score'] = 0.0
|
|
|
rov_recall_rank = sorted(recall_list, key=lambda k: k.get('sort_score', 0), reverse=True)
|
|
|
+ # print(rov_recall_rank)
|
|
|
flow_recall_rank = sorted(data['flow_pool_recall'], key=lambda k: k.get('rovScore', 0), reverse=True)
|
|
|
rov_recall_rank, flow_recall_rank = remove_duplicate(rov_recall=rov_recall_rank, flow_recall=flow_recall_rank,
|
|
|
- top_K=top_K)
|
|
|
+ top_K=top_K)
|
|
|
rank_result = []
|
|
|
rank_set = set('')
|
|
|
|
|
@@ -721,6 +731,7 @@ def video_new_rank2(data, size, top_K, flow_pool_P, ab_code, mid, exp_config=Non
|
|
|
i += 1
|
|
|
return rank_result[:size], flow_num
|
|
|
|
|
|
+
|
|
|
def video_sanke_rank(data, size, top_K, flow_pool_P, ab_Code='', exp_config=None):
|
|
|
"""
|
|
|
视频分发排序
|
|
@@ -731,13 +742,13 @@ def video_sanke_rank(data, size, top_K, flow_pool_P, ab_Code='', exp_config=None
|
|
|
:return: rank_result
|
|
|
"""
|
|
|
if not data['rov_pool_recall'] and not data['flow_pool_recall'] \
|
|
|
- and len(data['u2i_recall'])==0 and len(data['w2v_recall'])==0 \
|
|
|
- and len(data['sim_recall']) == 0 and len(data['u2u2i_recall']) == 0 :
|
|
|
+ and len(data['u2i_recall']) == 0 and len(data['w2v_recall']) == 0 \
|
|
|
+ and len(data['sim_recall']) == 0 and len(data['u2u2i_recall']) == 0:
|
|
|
return [], 0
|
|
|
# 地域分组小时级规则更新数据
|
|
|
recall_dict = {}
|
|
|
region_h_recall = [item for item in data['rov_pool_recall']
|
|
|
- if item.get('pushFrom') == config_.PUSH_FROM['rov_recall_region_h']]
|
|
|
+ if item.get('pushFrom') == config_.PUSH_FROM['rov_recall_region_h']]
|
|
|
region_h_recall_rank = sorted(region_h_recall, key=lambda k: k.get('rovScore', 0), reverse=True)
|
|
|
recall_dict['rov_recall_region_h'] = region_h_recall_rank
|
|
|
# 地域分组小时级更新24h规则更新数据
|
|
@@ -757,48 +768,49 @@ def video_sanke_rank(data, size, top_K, flow_pool_P, ab_Code='', exp_config=None
|
|
|
rule_24h_dup_recall_rank = sorted(rule_24h_dup_recall, key=lambda k: k.get('rovScore', 0), reverse=True)
|
|
|
recall_dict['rov_recall_24h_dup'] = rule_24h_dup_recall_rank
|
|
|
hot_recall = []
|
|
|
- w2v_recall =[]
|
|
|
+ w2v_recall = []
|
|
|
sim_recall = []
|
|
|
u2u2i_recall = []
|
|
|
- if ab_Code==60058:
|
|
|
- if len(data['u2i_recall'])>0:
|
|
|
+ if ab_Code == 60058:
|
|
|
+ if len(data['u2i_recall']) > 0:
|
|
|
hot_recall = sorted(data['u2i_recall'], key=lambda k: k.get('rovScore', 0), reverse=True)
|
|
|
recall_dict['u2i_recall'] = hot_recall
|
|
|
- elif ab_Code==60059:
|
|
|
- if len(data['w2v_recall'])>0:
|
|
|
+ elif ab_Code == 60059:
|
|
|
+ if len(data['w2v_recall']) > 0:
|
|
|
recall_dict['w2v_recall'] = data['w2v_recall']
|
|
|
else:
|
|
|
recall_dict['w2v_recall'] = w2v_recall
|
|
|
- elif ab_Code==60061 or ab_Code==60063:
|
|
|
- if len(data['sim_recall'])>0:
|
|
|
+ elif ab_Code == 60061 or ab_Code == 60063:
|
|
|
+ if len(data['sim_recall']) > 0:
|
|
|
recall_dict['sim_recall'] = data['sim_recall']
|
|
|
else:
|
|
|
recall_dict['sim_recall'] = sim_recall
|
|
|
- elif ab_Code==60062:
|
|
|
- if len(data['u2u2i_recall'])>0:
|
|
|
+ elif ab_Code == 60062:
|
|
|
+ if len(data['u2u2i_recall']) > 0:
|
|
|
recall_dict['u2u2i_recall'] = data['u2u2i_recall']
|
|
|
else:
|
|
|
recall_dict['u2u2i_recall'] = u2u2i_recall
|
|
|
|
|
|
- recall_list = [('rov_recall_region_h',1, 1),('rov_recall_region_h',0.5, 1),('rov_recall_region_24h',1,1),
|
|
|
- ('u2i_recall',0.5,1), ('w2v_recall',0.5,1),('rov_recall_24h',1,1), ('rov_recall_24h_dup',0.5,1)]
|
|
|
- if exp_config and exp_config['recall_list']:
|
|
|
+ recall_list = [('rov_recall_region_h', 1, 1), ('rov_recall_region_h', 0.5, 1), ('rov_recall_region_24h', 1, 1),
|
|
|
+ ('u2i_recall', 0.5, 1), ('w2v_recall', 0.5, 1), ('rov_recall_24h', 1, 1),
|
|
|
+ ('rov_recall_24h_dup', 0.5, 1)]
|
|
|
+ if exp_config and exp_config['recall_list']:
|
|
|
recall_list = exp_config['recall_list']
|
|
|
- #print("recall_config:", recall_list)
|
|
|
+ # print("recall_config:", recall_list)
|
|
|
rov_recall_rank = []
|
|
|
select_ids = set('')
|
|
|
- for i in range(3):
|
|
|
- if len(rov_recall_rank)>8:
|
|
|
+ for i in range(3):
|
|
|
+ if len(rov_recall_rank) > 8:
|
|
|
break
|
|
|
for per_recall_item in recall_list:
|
|
|
- per_recall_name = per_recall_item[0]
|
|
|
+ per_recall_name = per_recall_item[0]
|
|
|
per_recall_freq = per_recall_item[1]
|
|
|
- per_limt_num = per_recall_item[2]
|
|
|
+ per_limt_num = per_recall_item[2]
|
|
|
rand_num = random.random()
|
|
|
- #print(recall_dict[per_recall_name])
|
|
|
- if rand_num<per_recall_freq and per_recall_name in recall_dict:
|
|
|
+ # print(recall_dict[per_recall_name])
|
|
|
+ if rand_num < per_recall_freq and per_recall_name in recall_dict:
|
|
|
per_recall = recall_dict[per_recall_name]
|
|
|
- #print("per_recall_item:", per_recall_item)
|
|
|
+ # print("per_recall_item:", per_recall_item)
|
|
|
cur_recall_num = 0
|
|
|
for recall_item in per_recall:
|
|
|
vid = recall_item['videoId']
|
|
@@ -806,12 +818,12 @@ def video_sanke_rank(data, size, top_K, flow_pool_P, ab_Code='', exp_config=None
|
|
|
continue
|
|
|
rov_recall_rank.append(recall_item)
|
|
|
select_ids.add(vid)
|
|
|
- cur_recall_num+=1
|
|
|
- if cur_recall_num>=per_limt_num:
|
|
|
+ cur_recall_num += 1
|
|
|
+ if cur_recall_num >= per_limt_num:
|
|
|
break
|
|
|
# print("rov_recall_rank:")
|
|
|
# print(rov_recall_rank)
|
|
|
- #rov_recall_rank = region_h_recall_rank + region_24h_recall_rank + \
|
|
|
+ # rov_recall_rank = region_h_recall_rank + region_24h_recall_rank + \
|
|
|
# rule_24h_recall_rank + rule_24h_dup_recall_rank
|
|
|
# 流量池
|
|
|
flow_recall_rank = sorted(data['flow_pool_recall'], key=lambda k: k.get('rovScore', 0), reverse=True)
|
|
@@ -832,7 +844,7 @@ def video_sanke_rank(data, size, top_K, flow_pool_P, ab_Code='', exp_config=None
|
|
|
rank_result.extend(flow_recall_rank[:top_K])
|
|
|
flow_recall_rank = flow_recall_rank[top_K:]
|
|
|
flow_num = 0
|
|
|
- flowConfig =0
|
|
|
+ flowConfig = 0
|
|
|
if exp_config and exp_config['flowConfig']:
|
|
|
flowConfig = exp_config['flowConfig']
|
|
|
if flowConfig == 1 and len(rov_recall_rank) > 0:
|
|
@@ -887,10 +899,11 @@ def video_sanke_rank(data, size, top_K, flow_pool_P, ab_Code='', exp_config=None
|
|
|
rov_recall_rank.remove(rov_recall_rank[0])
|
|
|
else:
|
|
|
rank_result.extend(flow_recall_rank[:size - top_K - i])
|
|
|
- return rank_result[:size],flow_num
|
|
|
+ return rank_result[:size], flow_num
|
|
|
i += 1
|
|
|
return rank_result[:size], flow_num
|
|
|
|
|
|
+
|
|
|
def video_sank_pos_rank(data, size, top_K, flow_pool_P, ab_Code='', exp_config=None):
|
|
|
"""
|
|
|
视频分发排序
|
|
@@ -901,13 +914,13 @@ def video_sank_pos_rank(data, size, top_K, flow_pool_P, ab_Code='', exp_config=N
|
|
|
:return: rank_result
|
|
|
"""
|
|
|
if not data['rov_pool_recall'] and not data['flow_pool_recall'] \
|
|
|
- and len(data['u2i_recall'])==0 and len(data['w2v_recall'])==0 \
|
|
|
- and len(data['sim_recall']) == 0 and len(data['u2u2i_recall']) == 0 :
|
|
|
+ and len(data['u2i_recall']) == 0 and len(data['w2v_recall']) == 0 \
|
|
|
+ and len(data['sim_recall']) == 0 and len(data['u2u2i_recall']) == 0:
|
|
|
return [], 0
|
|
|
# 地域分组小时级规则更新数据
|
|
|
recall_dict = {}
|
|
|
region_h_recall = [item for item in data['rov_pool_recall']
|
|
|
- if item.get('pushFrom') == config_.PUSH_FROM['rov_recall_region_h']]
|
|
|
+ if item.get('pushFrom') == config_.PUSH_FROM['rov_recall_region_h']]
|
|
|
region_h_recall_rank = sorted(region_h_recall, key=lambda k: k.get('rovScore', 0), reverse=True)
|
|
|
recall_dict['rov_recall_region_h'] = region_h_recall_rank
|
|
|
# 地域分组小时级更新24h规则更新数据
|
|
@@ -928,13 +941,13 @@ def video_sank_pos_rank(data, size, top_K, flow_pool_P, ab_Code='', exp_config=N
|
|
|
recall_dict['rov_recall_24h_dup'] = rule_24h_dup_recall_rank
|
|
|
u2i_recall = []
|
|
|
u2i_play_recall = []
|
|
|
- w2v_recall =[]
|
|
|
+ w2v_recall = []
|
|
|
sim_recall = []
|
|
|
u2u2i_recall = []
|
|
|
return_video_recall = []
|
|
|
- #print("")
|
|
|
- if ab_Code==60058:
|
|
|
- if len(data['u2i_recall'])>0:
|
|
|
+ # print("")
|
|
|
+ if ab_Code == 60058:
|
|
|
+ if len(data['u2i_recall']) > 0:
|
|
|
recall_dict['u2i_recall'] = data['u2i_recall']
|
|
|
else:
|
|
|
recall_dict['u2i_recall'] = u2i_recall
|
|
@@ -942,45 +955,44 @@ def video_sank_pos_rank(data, size, top_K, flow_pool_P, ab_Code='', exp_config=N
|
|
|
recall_dict['u2i_play_recall'] = data['u2i_play_recall']
|
|
|
else:
|
|
|
recall_dict['u2i_play_recall'] = u2i_play_recall
|
|
|
- elif ab_Code==60059:
|
|
|
- if len(data['w2v_recall'])>0:
|
|
|
+ elif ab_Code == 60059:
|
|
|
+ if len(data['w2v_recall']) > 0:
|
|
|
recall_dict['w2v_recall'] = data['w2v_recall']
|
|
|
else:
|
|
|
recall_dict['w2v_recall'] = w2v_recall
|
|
|
- elif ab_Code==60061 or ab_Code==60063:
|
|
|
- if len(data['sim_recall'])>0:
|
|
|
+ elif ab_Code == 60061 or ab_Code == 60063:
|
|
|
+ if len(data['sim_recall']) > 0:
|
|
|
recall_dict['sim_recall'] = data['sim_recall']
|
|
|
else:
|
|
|
recall_dict['sim_recall'] = sim_recall
|
|
|
- elif ab_Code==60062:
|
|
|
- if len(data['u2u2i_recall'])>0:
|
|
|
+ elif ab_Code == 60062:
|
|
|
+ if len(data['u2u2i_recall']) > 0:
|
|
|
recall_dict['u2u2i_recall'] = data['u2u2i_recall']
|
|
|
else:
|
|
|
recall_dict['u2u2i_recall'] = u2u2i_recall
|
|
|
- elif ab_Code==60064:
|
|
|
- if len(data['return_video_recall'])>0:
|
|
|
+ elif ab_Code == 60064:
|
|
|
+ if len(data['return_video_recall']) > 0:
|
|
|
recall_dict['return_video_recall'] = data['return_video_recall']
|
|
|
else:
|
|
|
recall_dict['return_video_recall'] = return_video_recall
|
|
|
|
|
|
- recall_pos1 = [('rov_recall_region_h',0, 0.98),('rov_recall_24h',0.98, 1),('rov_recall_region_24h',0,1),
|
|
|
- ('rov_recall_24h',0,1), ('rov_recall_24h_dup',0,1)]
|
|
|
- recall_pos2 = [('rov_recall_region_h',0,0.98),('rov_recall_24h',0.98,1),('rov_recall_region_24h',0,1),
|
|
|
- ('rov_recall_24h',0,1),('rov_recall_24h_dup',0,1)]
|
|
|
- recall_pos3 = [('rov_recall_region_h', 0,0.98), ('rov_recall_24h', 0.98,1), ('rov_recall_region_24h', 0,1),
|
|
|
- ('rov_recall_24h', 0,1), ('rov_recall_24h_dup', 0,1)]
|
|
|
- recall_pos4 = [('rov_recall_region_h', 0,0.98), ('rov_recall_24h', 0,0.02), ('rov_recall_region_24h', 0,1),
|
|
|
- ('rov_recall_24h', 0,1), ('rov_recall_24h_dup', 0,1)]
|
|
|
- if exp_config and 'recall_pos1' in exp_config \
|
|
|
+ recall_pos1 = [('rov_recall_region_h', 0, 0.98), ('rov_recall_24h', 0.98, 1), ('rov_recall_region_24h', 0, 1),
|
|
|
+ ('rov_recall_24h', 0, 1), ('rov_recall_24h_dup', 0, 1)]
|
|
|
+ recall_pos2 = [('rov_recall_region_h', 0, 0.98), ('rov_recall_24h', 0.98, 1), ('rov_recall_region_24h', 0, 1),
|
|
|
+ ('rov_recall_24h', 0, 1), ('rov_recall_24h_dup', 0, 1)]
|
|
|
+ recall_pos3 = [('rov_recall_region_h', 0, 0.98), ('rov_recall_24h', 0.98, 1), ('rov_recall_region_24h', 0, 1),
|
|
|
+ ('rov_recall_24h', 0, 1), ('rov_recall_24h_dup', 0, 1)]
|
|
|
+ recall_pos4 = [('rov_recall_region_h', 0, 0.98), ('rov_recall_24h', 0, 0.02), ('rov_recall_region_24h', 0, 1),
|
|
|
+ ('rov_recall_24h', 0, 1), ('rov_recall_24h_dup', 0, 1)]
|
|
|
+ if exp_config and 'recall_pos1' in exp_config \
|
|
|
and 'recall_pos2' in exp_config \
|
|
|
and 'recall_pos3' in exp_config \
|
|
|
- and 'recall_pos4' in exp_config :
|
|
|
+ and 'recall_pos4' in exp_config:
|
|
|
recall_pos1 = exp_config['recall_pos1']
|
|
|
recall_pos2 = exp_config['recall_pos2']
|
|
|
recall_pos3 = exp_config['recall_pos3']
|
|
|
recall_pos4 = exp_config['recall_pos4']
|
|
|
- #print("recall_config:", recall_pos1)
|
|
|
- #print("recall_config:", recall_pos2)
|
|
|
+ # print("recall_config:", recall_pos1)
|
|
|
rov_recall_rank = []
|
|
|
recall_list = []
|
|
|
recall_list.append(recall_pos1)
|
|
@@ -992,9 +1004,9 @@ def video_sank_pos_rank(data, size, top_K, flow_pool_P, ab_Code='', exp_config=N
|
|
|
if exp_config and 'recall_num_limit' in exp_config:
|
|
|
recall_num_limit_dict = exp_config['recall_num_limit']
|
|
|
exp_recall_dict = {}
|
|
|
- #index_pos = 0
|
|
|
+ # index_pos = 0
|
|
|
for j in range(3):
|
|
|
- if len(rov_recall_rank)>12:
|
|
|
+ if len(rov_recall_rank) > 12:
|
|
|
break
|
|
|
# choose pos
|
|
|
for recall_pos_config in recall_list:
|
|
@@ -1004,7 +1016,7 @@ def video_sank_pos_rank(data, size, top_K, flow_pool_P, ab_Code='', exp_config=N
|
|
|
for per_recall_item in recall_pos_config:
|
|
|
if index_pos == 1:
|
|
|
break
|
|
|
- if len(per_recall_item)<3:
|
|
|
+ if len(per_recall_item) < 3:
|
|
|
continue
|
|
|
per_recall_name = per_recall_item[0]
|
|
|
per_recall_min = float(per_recall_item[1])
|
|
@@ -1012,7 +1024,7 @@ def video_sank_pos_rank(data, size, top_K, flow_pool_P, ab_Code='', exp_config=N
|
|
|
per_recall_num = exp_recall_dict.get(per_recall_name, 0)
|
|
|
per_recall_total_num = recall_num_limit_dict.get(per_recall_name, 0)
|
|
|
# recall set total num
|
|
|
- if len(recall_num_limit_dict)>0 and per_recall_total_num>0 and per_recall_num>= per_recall_total_num:
|
|
|
+ if len(recall_num_limit_dict) > 0 and per_recall_total_num > 0 and per_recall_num >= per_recall_total_num:
|
|
|
continue
|
|
|
if rand_num >= per_recall_min and rand_num < per_recall_max and per_recall_name in recall_dict:
|
|
|
per_recall = recall_dict[per_recall_name]
|
|
@@ -1024,24 +1036,24 @@ def video_sank_pos_rank(data, size, top_K, flow_pool_P, ab_Code='', exp_config=N
|
|
|
rov_recall_rank.append(recall_item)
|
|
|
select_ids.add(vid)
|
|
|
if per_recall_name in exp_recall_dict:
|
|
|
- exp_recall_dict[per_recall_name] +=1
|
|
|
+ exp_recall_dict[per_recall_name] += 1
|
|
|
else:
|
|
|
exp_recall_dict[per_recall_name] = 1
|
|
|
index_pos = 1
|
|
|
break
|
|
|
- #print("rov_recall_rank:", rov_recall_rank)
|
|
|
- if len(rov_recall_rank)<4:
|
|
|
- rov_doudi_rank = region_h_recall_rank + sim_recall + u2i_recall + u2u2i_recall + w2v_recall +return_video_recall+u2i_play_recall+ region_24h_recall_rank + rule_24h_recall_rank + rule_24h_dup_recall_rank
|
|
|
+ # print("rov_recall_rank:", rov_recall_rank)
|
|
|
+ if len(rov_recall_rank) < 4:
|
|
|
+ rov_doudi_rank = region_h_recall_rank + sim_recall + u2i_recall + u2u2i_recall + w2v_recall + return_video_recall + u2i_play_recall + region_24h_recall_rank + rule_24h_recall_rank + rule_24h_dup_recall_rank
|
|
|
for recall_item in rov_doudi_rank:
|
|
|
vid = recall_item['videoId']
|
|
|
if vid in select_ids:
|
|
|
continue
|
|
|
rov_recall_rank.append(recall_item)
|
|
|
select_ids.add(vid)
|
|
|
- if len(rov_recall_rank)>12:
|
|
|
+ if len(rov_recall_rank) > 12:
|
|
|
break
|
|
|
# print("rov_recall_rank:")
|
|
|
- #print(rov_recall_rank)
|
|
|
+ # print(rov_recall_rank)
|
|
|
# 流量池
|
|
|
flow_recall_rank = sorted(data['flow_pool_recall'], key=lambda k: k.get('rovScore', 0), reverse=True)
|
|
|
# 对各路召回的视频进行去重
|
|
@@ -1061,7 +1073,7 @@ def video_sank_pos_rank(data, size, top_K, flow_pool_P, ab_Code='', exp_config=N
|
|
|
rank_result.extend(flow_recall_rank[:top_K])
|
|
|
flow_recall_rank = flow_recall_rank[top_K:]
|
|
|
flow_num = 0
|
|
|
- flowConfig =0
|
|
|
+ flowConfig = 0
|
|
|
if exp_config and exp_config['flowConfig']:
|
|
|
flowConfig = exp_config['flowConfig']
|
|
|
if flowConfig == 1 and len(rov_recall_rank) > 0:
|
|
@@ -1116,20 +1128,22 @@ def video_sank_pos_rank(data, size, top_K, flow_pool_P, ab_Code='', exp_config=N
|
|
|
rov_recall_rank.remove(rov_recall_rank[0])
|
|
|
else:
|
|
|
rank_result.extend(flow_recall_rank[:size - top_K - i])
|
|
|
- return rank_result[:size],flow_num
|
|
|
+ return rank_result[:size], flow_num
|
|
|
i += 1
|
|
|
return rank_result[:size], flow_num
|
|
|
|
|
|
|
|
|
-
|
|
|
if __name__ == '__main__':
|
|
|
d_test = [{'videoId': 10028734, 'rovScore': 99.977, 'pushFrom': 'recall_pool', 'abCode': 10000},
|
|
|
{'videoId': 1919925, 'rovScore': 99.974, 'pushFrom': 'recall_pool', 'abCode': 10000},
|
|
|
{'videoId': 9968118, 'rovScore': 99.972, 'pushFrom': 'recall_pool', 'abCode': 10000},
|
|
|
{'videoId': 9934863, 'rovScore': 99.971, 'pushFrom': 'recall_pool', 'abCode': 10000},
|
|
|
- {'videoId': 10219869, 'flowPool': '1#1#1#1640830818883', 'rovScore': 82.21929728934731, 'pushFrom': 'flow_pool', 'abCode': 10000},
|
|
|
- {'videoId': 10212814, 'flowPool': '1#1#1#1640759014984', 'rovScore': 81.26694187726412, 'pushFrom': 'flow_pool', 'abCode': 10000},
|
|
|
- {'videoId': 10219437, 'flowPool': '1#1#1#1640827620520', 'rovScore': 81.21634156641908, 'pushFrom': 'flow_pool', 'abCode': 10000},
|
|
|
+ {'videoId': 10219869, 'flowPool': '1#1#1#1640830818883', 'rovScore': 82.21929728934731,
|
|
|
+ 'pushFrom': 'flow_pool', 'abCode': 10000},
|
|
|
+ {'videoId': 10212814, 'flowPool': '1#1#1#1640759014984', 'rovScore': 81.26694187726412,
|
|
|
+ 'pushFrom': 'flow_pool', 'abCode': 10000},
|
|
|
+ {'videoId': 10219437, 'flowPool': '1#1#1#1640827620520', 'rovScore': 81.21634156641908,
|
|
|
+ 'pushFrom': 'flow_pool', 'abCode': 10000},
|
|
|
{'videoId': 1994050, 'rovScore': 99.97, 'pushFrom': 'recall_pool', 'abCode': 10000},
|
|
|
{'videoId': 9894474, 'rovScore': 99.969, 'pushFrom': 'recall_pool', 'abCode': 10000},
|
|
|
{'videoId': 10028081, 'rovScore': 99.966, 'pushFrom': 'recall_pool', 'abCode': 10000}]
|