linfan 1 rok temu
rodzic
commit
881b629317
1 zmienionych plików z 25 dodań i 16 usunięć
  1. 25 16
      video_rank.py

+ 25 - 16
video_rank.py

@@ -627,23 +627,38 @@ def video_new_rank2(data, size, top_K, flow_pool_P, ab_code, mid, exp_config=Non
     rov_recall_rank = rec_recall_item_list
     #call rank service
     #flag_call_service = 0
+    redisObj = RedisHelper()
+    vidKeys = []
+    for recall_item in rec_recall_item_list:
+        vid = recall_item.get("videoId", 0)
+        vidKeys.append(pre_str + str(vid))
+    video_scores = redisObj.get_batch_key(vidKeys)
     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)
         score_result = get_tf_serving_sores(feature_dict)
-        if rec_recall_item_list and score_result and len(score_result) > 0 and len(score_result) == len(rec_recall_item_list):
+        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):
             for i in range(len(score_result)):
-                rec_recall_item_list[i]['sort_score'] = score_result[i][0]
+                try:
+                    if video_scores[i] is None:
+                        return_score = 0.000000001
+                        total_score = return_score * score_result[i][0]
+                        rec_recall_item_list[i]['sort_score'] = total_score
+                    else:
+                        video_score_str = json.loads(video_scores[i])
+                        return_score = video_score_str[3]
+                        print("return_score:", return_score, "score:", score_result[i][0])
+                        total_score = return_score * score_result[i][0]
+                        rec_recall_item_list[i]['sort_score'] = total_score
+                except Exception:
+                    return_score = 0.000000001
+                    total_score = return_score * 0.00000001
+                    rec_recall_item_list[i]['sort_score'] = total_score
                 rec_recall_item_list[i]['flag_call_service'] = 1
             rov_recall_rank = sorted(rec_recall_item_list, key=lambda k: k.get('sort_score', 0), reverse=True)
         else:
-            rov_recall_rank = sup_rank(pre_str, rec_recall_item_list)
+            rov_recall_rank = sup_rank(video_scores, rec_recall_item_list)
     else:
-        redisObj = RedisHelper()
-        vidKeys = []
-        for recall_item in rec_recall_item_list:
-            vid = recall_item.get("videoId", 0)
-            vidKeys.append(pre_str + str(vid))
-        video_scores = redisObj.get_batch_key(vidKeys)
         if video_scores and len(rec_recall_item_list) > 0 and len(video_scores)>0:
             for i in range(len(video_scores)):
                 try:
@@ -729,13 +744,7 @@ def video_new_rank2(data, size, top_K, flow_pool_P, ab_code, mid, exp_config=Non
 
 
 # 排序服务兜底
-def sup_rank(pre_str, recall_list):
-    redisObj = RedisHelper()
-    vidKeys = []
-    for recall_item in recall_list:
-        vid = recall_item.get("videoId", 0)
-        vidKeys.append(pre_str + str(vid))
-    video_scores = redisObj.get_batch_key(vidKeys)
+def sup_rank(video_scores, recall_list):
     if video_scores and len(recall_list) > 0:
         for i in range(len(video_scores)):
             try: