| 
					
				 | 
			
			
				@@ -134,7 +134,8 @@ def positon_duplicate(pos1_vids, pos2_vids, videos): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     return l 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-def video_recommend(mid, uid, size, app_type, algo_type, client_info): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+def video_recommend(mid, uid, size, app_type, algo_type, client_info, expire_time=24*3600, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    ab_code=config_.AB_CODE['initial']): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     """ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     首页线上推荐逻辑 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     :param mid: mid type-string 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -143,9 +144,10 @@ def video_recommend(mid, uid, size, app_type, algo_type, client_info): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     :param app_type: 产品标识  type-int 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     :param algo_type: 算法类型  type-string 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     :param client_info: 用户位置信息 {"country": "国家",  "province": "省份",  "city": "城市"} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    :param expire_time: 末位视频记录redis过期时间 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    :param ab_code: AB实验code 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     :return: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     """ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    ab_code = config_.AB_CODE['initial'] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     # ####### 多进程召回 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     start_recall = time.time() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     # log_.info('====== recall') 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -165,9 +167,10 @@ def video_recommend(mid, uid, size, app_type, algo_type, client_info): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     pool.join() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     ''' 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     recall_result_list = [] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    pool_recall = PoolRecall(app_type=app_type, mid=mid, uid=uid, ab_code=ab_code, client_info=client_info) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    pool_recall = PoolRecall(app_type=app_type, mid=mid, uid=uid, ab_code=ab_code, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                             client_info=client_info) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     _, last_rov_recall_key, _ = pool_recall.get_video_last_idx() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    t = [gevent.spawn(pool_recall.rov_pool_recall, size), gevent.spawn(pool_recall.flow_pool_recall, size)] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    t = [gevent.spawn(pool_recall.rov_pool_recall, size, expire_time), gevent.spawn(pool_recall.flow_pool_recall, size)] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     gevent.joinall(t) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     recall_result_list = [i.get() for i in t] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -239,13 +242,14 @@ def ab_test_op(rank_result, ab_code_list, app_type, mid, uid, **kwargs): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     return rank_result 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-def update_redis_data(result, app_type, mid, last_rov_recall_key): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+def update_redis_data(result, app_type, mid, last_rov_recall_key, expire_time=24*3600): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     """ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     根据最终的排序结果更新相关redis数据 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     :param result: 排序结果 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     :param app_type: 产品标识 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     :param mid: mid 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     :param last_rov_recall_key: 用户上一次在rov召回池对应的位置 redis key 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    :param expire_time: 末位视频记录redis过期时间 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     :return: None 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     """ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     # ####### redis数据刷新 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -269,7 +273,8 @@ def update_redis_data(result, app_type, mid, last_rov_recall_key): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             else: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 key_name = config_.UPDATE_ROV_KEY_NAME 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             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]) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                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!') 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         # 将此次分发的流量池视频,对 本地分发数-1 进行记录 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -320,15 +325,34 @@ def video_homepage_recommend(mid, uid, size, app_type, algo_type, client_info): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     :param client_info: 用户位置信息 {"country": "国家",  "province": "省份",  "city": "城市"} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     :return: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     """ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    # 简单召回 - 排序 - 兜底 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    rank_result, last_rov_recall_key = video_recommend(mid=mid, uid=uid, size=size, app_type=app_type, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                                                       algo_type=algo_type, client_info=client_info) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    # 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=result, app_type=app_type, mid=mid, last_rov_recall_key=last_rov_recall_key) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    # 对 vlog 切换10%的流量做实验 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    # 对mid进行哈希 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    print(hash(mid)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    print(abs(hash(mid)) % 10) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    if app_type in config_.AB_TEST['rank_by_h'] and abs(hash(mid)) % 10 in [0, 1, 7, 8, 4, ]: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        print('in') 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        # 简单召回 - 排序 - 兜底 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        rank_result, last_rov_recall_key = video_recommend(mid=mid, uid=uid, size=size, app_type=app_type, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                                           algo_type=algo_type, client_info=client_info, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                                           expire_time=3600, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                                           ab_code=config_.AB_CODE['rank_by_h']) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        # 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=result, app_type=app_type, mid=mid, last_rov_recall_key=last_rov_recall_key, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                          expire_time=3600) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    else: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        # 简单召回 - 排序 - 兜底 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        rank_result, last_rov_recall_key = video_recommend(mid=mid, uid=uid, size=size, app_type=app_type, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                                           algo_type=algo_type, client_info=client_info) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        # 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=result, app_type=app_type, mid=mid, last_rov_recall_key=last_rov_recall_key) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     return result 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 |