Browse Source

update rank

linfan 1 year ago
parent
commit
eb45f3e446
3 changed files with 58 additions and 41 deletions
  1. 1 4
      rank_service.py
  2. 42 31
      recommend.py
  3. 15 6
      video_rank.py

+ 1 - 4
rank_service.py

@@ -8,7 +8,7 @@ log_ = Log()
 
 
 
 
 config_ = set_config()
 config_ = set_config()
-def get_featurs(mid, data, size, top_K, flow_pool_P, env_dict=None):
+def get_featurs(mid, data, size, top_K, flow_pool_P, env_dict=None, video_static_info=None, video_hour_static_info=None, ):
     feature_dict = {}
     feature_dict = {}
     # defult value
     # defult value
     apptype = 4
     apptype = 4
@@ -91,9 +91,6 @@ def get_featurs(mid, data, size, top_K, flow_pool_P, env_dict=None):
             city_list.append(city_code)
             city_list.append(city_code)
             province_list.append(province_code)
             province_list.append(province_code)
             relevant_video_list.append(relevant_video_id)
             relevant_video_list.append(relevant_video_id)
-    video_static_info = env_dict.get('vid_day_fea_list', [])
-    video_hour_static_info = env_dict.get('vid_hour_fea_list', [])
-    #print("video_static_info:",video_static_info)
     if video_static_info and len(video_static_info)>0:
     if video_static_info and len(video_static_info)>0:
         for i in range(len(video_static_info)):
         for i in range(len(video_static_info)):
             try:
             try:

+ 42 - 31
recommend.py

@@ -624,29 +624,22 @@ def video_old_recommend(request_id, mid, uid, size, top_K, flow_pool_P, app_type
                 'flow_pool_recall': recall_result_list[2]
                 'flow_pool_recall': recall_result_list[2]
             }
             }
     # 3. 特征回流
     # 3. 特征回流
-    rec_recall_list = []
-    vidKeys = []
-    hour_vidKeys = []
-    pre_str = "v_ctr:"
-    pre_hour_str = "v_hour_ctr:"
-    rec_recall_item_list = []
-    for recall_item in data['rov_pool_recall']:
-        if len(recall_item) <= 0:
-            continue
-        vid = recall_item.get("videoId", 0)
-        rec_recall_list.append(vid)
-        vidKeys.append(pre_str + str(vid))
-        hour_vidKeys.append(pre_hour_str + str(vid))
-        rec_recall_item_list.append(recall_item)
-    redisObj = RedisHelper()
-    video_static_info = redisObj.get_batch_key(vidKeys)
-    video_hour_static_info = redisObj.get_batch_key(hour_vidKeys)
-    vid_day_fea_list = []
-    vid_hour_fea_list = []
-    if video_static_info:
-        vid_day_fea_list = video_static_info
-    if video_hour_static_info:
-        vid_hour_fea_list = video_hour_static_info
+    #
+    # for recall_item in data['rov_pool_recall']:
+    #     if len(recall_item) <= 0:
+    #         continue
+    #     vid = recall_item.get("videoId", 0)
+    #     rec_recall_list.append(vid)
+    #     rec_recall_item_list.append(recall_item)
+    # redisObj = RedisHelper()
+    # video_static_info = redisObj.get_batch_key(vidKeys)
+    # video_hour_static_info = redisObj.get_batch_key(hour_vidKeys)
+    # vid_day_fea_list = []
+    # vid_hour_fea_list = []
+    # if video_static_info:
+    #     vid_day_fea_list = video_static_info
+    # if video_hour_static_info:
+    #     vid_hour_fea_list = video_hour_static_info
     if env_dict:
     if env_dict:
         province_code = client_info.get('provinceCode', -1)
         province_code = client_info.get('provinceCode', -1)
         if province_code and province_code == "":
         if province_code and province_code == "":
@@ -657,21 +650,39 @@ def video_old_recommend(request_id, mid, uid, size, top_K, flow_pool_P, app_type
         env_dict['mid'] = mid
         env_dict['mid'] = mid
         env_dict['province_code'] = province_code
         env_dict['province_code'] = province_code
         env_dict['city_code'] = city_code
         env_dict['city_code'] = city_code
-
-        env_dict['recall_list'] = rec_recall_list
-        env_dict['vid_day_fea_list'] = vid_day_fea_list
-        env_dict['vid_hour_fea_list'] = vid_hour_fea_list
         env_json = env_dict
         env_json = env_dict
     #4.
     #4.
-    rank_result, flow_num  = video_new_rank2(data=data, size=size, top_K=top_K, flow_pool_P=float(flow_pool_P), ab_code=ab_code, mid=mid, exp_config=exp_config, env_dict=env_dict, rec_recall_item_list=rec_recall_item_list)
-    #print(rank_result)
+    rank_result, flow_num  = video_new_rank2(data=data, size=size, top_K=top_K, flow_pool_P=float(flow_pool_P), ab_code=ab_code, mid=mid, exp_config=exp_config, env_dict=env_dict)
+    print(rank_result)
     if rank_result:
     if rank_result:
         result['rank_num'] = len(rank_result)
         result['rank_num'] = len(rank_result)
+        day_vidKeys = []
+        hour_vidKeys = []
+        rec_recall_list = []
+        pre_str = "v_ctr:"
+        pre_hour_str = "v_hour_ctr:"
+        if env_dict and len(rank_result)>0:
+            for rec_item in rank_result:
+                vid = rec_item
+                rec_recall_list.append(vid)
+                day_vidKeys.append(pre_str+str(vid))
+                hour_vidKeys.append(pre_hour_str+str(vid))
+            redisObj = RedisHelper()
+            video_static_info = redisObj.get_batch_key(day_vidKeys)
+            video_hour_static_info = redisObj.get_batch_key(hour_vidKeys)
+            vid_day_fea_list = []
+            vid_hour_fea_list = []
+            if video_static_info:
+                 vid_day_fea_list = video_static_info
+            if video_hour_static_info:
+                 vid_hour_fea_list = video_hour_static_info
+            env_dict['recall_list'] = rec_recall_list
+            env_dict['vid_day_fea_list'] = vid_day_fea_list
+            env_dict['vid_hour_fea_list'] = vid_hour_fea_list
+            env_json = env_dict
     result['rankResult'] = rank_result
     result['rankResult'] = rank_result
     result['flow_num'] = flow_num
     result['flow_num'] = flow_num
     result['rankTime'] = (time.time() - start_rank) * 1000
     result['rankTime'] = (time.time() - start_rank) * 1000
-
-
     return result, env_json
     return result, env_json
     # return rank_result, last_rov_recall_key
     # return rank_result, last_rov_recall_key
 
 

+ 15 - 6
video_rank.py

@@ -593,7 +593,7 @@ def video_rank_with_old_video(rank_result, old_video_recall, size, top_K, old_vi
     return new_rank_result[:size]
     return new_rank_result[:size]
 
 
 
 
-def video_new_rank2(data, size, top_K, flow_pool_P, ab_code, mid, exp_config=None, env_dict=None, rec_recall_item_list=None):
+def video_new_rank2(data, size, top_K, flow_pool_P, ab_code, mid, exp_config=None, env_dict=None):
     """
     """
         视频分发排序
         视频分发排序
         :param data: 各路召回的视频 type-dict {'rov_pool_recall': [], 'flow_pool_recall': []}
         :param data: 各路召回的视频 type-dict {'rov_pool_recall': [], 'flow_pool_recall': []}
@@ -602,14 +602,13 @@ def video_new_rank2(data, size, top_K, flow_pool_P, ab_code, mid, exp_config=Non
         :param flow_pool_P: size-top_K视频为流量池视频的概率 type-float
         :param flow_pool_P: size-top_K视频为流量池视频的概率 type-float
         :return: rank_result
         :return: rank_result
         """
         """
-    if not rec_recall_item_list and not data['flow_pool_recall']:
+    if not data['rov_pool_recall'] and not data['flow_pool_recall']:
         return [], 0
         return [], 0
 
 
     #全量的是vlog,票圈精选, 334,60057,
     #全量的是vlog,票圈精选, 334,60057,
     # 60054: simrecall,
     # 60054: simrecall,
     pre_str = "k_p2:"
     pre_str = "k_p2:"
-    #print("pre_str:", pre_str)
-    rov_recall_rank = rec_recall_item_list
+    rov_recall_rank = data['rov_pool_recall']
     #call rank service
     #call rank service
     #flag_call_service = 0
     #flag_call_service = 0
     sort_index = 0
     sort_index = 0
@@ -618,12 +617,22 @@ def video_new_rank2(data, size, top_K, flow_pool_P, ab_code, mid, exp_config=Non
     #print("sort_index:", sort_index)
     #print("sort_index:", sort_index)
     redisObj = RedisHelper()
     redisObj = RedisHelper()
     vidKeys = []
     vidKeys = []
-    for recall_item in rec_recall_item_list:
+    rec_recall_item_list = []
+    day_vidKeys = []
+    hour_vidKeys = []
+    pre_day_str = "v_ctr:"
+    pre_hour_str = "v_hour_ctr:"
+    for recall_item in data['rov_pool_recall']:
         vid = recall_item.get("videoId", 0)
         vid = recall_item.get("videoId", 0)
+        rec_recall_item_list.append(recall_item)
         vidKeys.append(pre_str + str(vid))
         vidKeys.append(pre_str + str(vid))
+        day_vidKeys.append(pre_day_str+str(vid))
+        hour_vidKeys.append(pre_hour_str+str(vid))
     video_scores = redisObj.get_batch_key(vidKeys)
     video_scores = redisObj.get_batch_key(vidKeys)
     if ab_code == 60066 or ab_code == 60069 or ab_code == 60070 or ab_code == 60071:
     if ab_code == 60066 or ab_code == 60069 or ab_code == 60070 or ab_code == 60071:
-        feature_dict = get_featurs(mid, data, size, top_K, flow_pool_P, env_dict)
+        video_static_info = redisObj.get_batch_key(day_vidKeys)
+        video_hour_static_info = redisObj.get_batch_key(hour_vidKeys)
+        feature_dict = get_featurs(mid, data, size, top_K, flow_pool_P, env_dict, video_static_info, video_hour_static_info)
         score_result = get_tf_serving_sores(feature_dict)
         score_result = get_tf_serving_sores(feature_dict)
         if video_scores and len(video_scores)>0  and rec_recall_item_list and score_result and len(score_result) > 0\
         if video_scores and len(video_scores)>0  and rec_recall_item_list and score_result and len(score_result) > 0\
                 and len(score_result) == len(rec_recall_item_list) and len(video_scores)== len(score_result):
                 and len(score_result) == len(rec_recall_item_list) and len(video_scores)== len(score_result):