| 
					
				 | 
			
			
				@@ -2,6 +2,7 @@ package com.tzld.piaoquan.ad.engine.service.predict.model.threshold; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.alibaba.fastjson.JSONObject; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.tzld.piaoquan.ad.engine.commons.redis.AlgorithmRedisHelper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.tzld.piaoquan.ad.engine.commons.util.TimerWatchUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.tzld.piaoquan.ad.engine.service.predict.config.AdOutV1OnlineWeightConfig; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.tzld.piaoquan.ad.engine.service.predict.constant.RuleRedisKeyConst; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.tzld.piaoquan.ad.engine.service.predict.container.ThresholdModelContainer; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -30,13 +31,17 @@ public class ScoreThresholdPredictModel extends ThresholdPredictModel{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     public Map<String, Object> predict(ThresholdPredictModelParam modelParam) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         Map<String, Object> result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        long startTime=System.currentTimeMillis(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        String methodName=initName(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        int step=1; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         String modelKey = (String) modelParam.getAbtestParam().getOrDefault("model_key", "ad_out_v1"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         String userKeyName = RuleRedisKeyConst.KEY_NAME_PREFIX_AD_OUT_MODEL_SCORE_USER + modelKey + ":" + modelParam.getMid(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         String itemKeyName = RuleRedisKeyConst.KEY_NAME_PREFIX_AD_OUT_MODEL_SCORE_ITEM + modelKey + ":" + modelParam.getVideoId(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        TimerWatchUtil.printCost(methodName,step++,startTime); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         String userScore = redisHelper.get(userKeyName); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        TimerWatchUtil.printCost(methodName,step++,startTime); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         String itemScore = redisHelper.get(itemKeyName); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        TimerWatchUtil.printCost(methodName,step++,startTime); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         //加载配置数据 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         String configKeyNamePrefix = RuleRedisKeyConst.KEY_NAME_PREFIX_AD_OUT_MODEL_CONFIG 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -45,6 +50,7 @@ public class ScoreThresholdPredictModel extends ThresholdPredictModel{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 + modelParam.getAbtestParam().get("abtest_config_tag"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         String configKey = configKeyNamePrefix + ":config"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         String configStr = redisHelper.get(configKey); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        TimerWatchUtil.printCost(methodName,step++,startTime); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         Map<String, Object> configMap = new HashMap<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         String hitStrategy="model"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if (configStr != null) { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -65,7 +71,7 @@ public class ScoreThresholdPredictModel extends ThresholdPredictModel{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         boolean useBackup = Boolean.valueOf((String)configMap.getOrDefault("use_backup_key","false")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        TimerWatchUtil.printCost(methodName,step++,startTime); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         //有数据为空且开启兜底策略 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if ( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 (StringUtils.isBlank(userScore) || StringUtils.isBlank(itemScore)) 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -79,7 +85,7 @@ public class ScoreThresholdPredictModel extends ThresholdPredictModel{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             result.put("hit_strategy",hitStrategy); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             return result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        TimerWatchUtil.printCost(methodName,step++,startTime); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         double offlineScore ; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         //处理空值逻辑 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         double threshold=(double)configMap.getOrDefault("threshold",0); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -97,6 +103,7 @@ public class ScoreThresholdPredictModel extends ThresholdPredictModel{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     (double)configMap.getOrDefault("user_threshold", 0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             hitStrategy=isUserScoreBlank?"item":"user"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        TimerWatchUtil.printCost(methodName,step++,startTime); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         //获取计算参数 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         SimpleDateFormat hourFormat = new SimpleDateFormat("HH"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         SimpleDateFormat weekDayFormat = new SimpleDateFormat("u"); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -114,6 +121,7 @@ public class ScoreThresholdPredictModel extends ThresholdPredictModel{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 rankScore = Double.parseDouble(rankScoreStr); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        TimerWatchUtil.printCost(methodName,step++,startTime); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         offlineScore=Double.parseDouble(userScore) + Double.parseDouble(itemScore); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         double onlineScore=getOlineScore(onlineFeatures); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         double rankScoreBias = (double)configMap.getOrDefault("rank_score_bias", 0.0); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -122,7 +130,7 @@ public class ScoreThresholdPredictModel extends ThresholdPredictModel{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         double rankScoreW = (double)configMap.getOrDefault("rank_score_w", 1.0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         double finalScoreW = (double)configMap.getOrDefault("final_score_w", 1.0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         double mergeScore = finalScoreW * finalScore + rankScoreW * (rankScore + rankScoreBias); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        TimerWatchUtil.printCost(methodName,step++,startTime); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         int adPredict; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if (mergeScore < threshold) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             // If final score is below threshold, show the ad 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -131,6 +139,7 @@ public class ScoreThresholdPredictModel extends ThresholdPredictModel{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             // Otherwise, do not show the ad 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             adPredict = 1; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        TimerWatchUtil.printCost(methodName,step++,startTime); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         result=new HashMap<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         result.put("user_score", userScore); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         result.put("item_score", itemScore); 
			 |