| 
					
				 | 
			
			
				@@ -1,10 +1,12 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 package com.tzld.piaoquan.ad.engine.service.score.strategy; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.alibaba.fastjson.JSONObject; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.ctrip.framework.apollo.spring.annotation.ApolloJsonValue; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.tzld.piaoquan.ad.engine.commons.score.ScoreParam; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.tzld.piaoquan.ad.engine.commons.score.ScorerUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.tzld.piaoquan.ad.engine.commons.thread.ThreadPoolFactory; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.tzld.piaoquan.ad.engine.commons.util.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.tzld.piaoquan.ad.engine.service.entity.GuaranteeView; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.tzld.piaoquan.ad.engine.service.feature.Feature; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.tzld.piaoquan.ad.engine.commons.dto.AdPlatformCreativeDTO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.tzld.piaoquan.ad.engine.commons.param.RankRecommendRequestParam; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -42,6 +44,9 @@ public class RankStrategyBy688 extends RankStrategyBasic { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Value("${word2vec.exp:694}") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private String word2vecExp; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @Value("${guarantee.exp:742}") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private String guaranteeExp; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     // FIXME(zhoutian): 可能需要独立配置 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @ApolloJsonValue("${rank.score.weight.680:{}}") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private Map<String, Double> weightMap; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -49,6 +54,9 @@ public class RankStrategyBy688 extends RankStrategyBasic { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @ApolloJsonValue("${rank.score.neg_sample_rate:0.01}") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     Double negSampleRate; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @ApolloJsonValue("${alpha:1.0}") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    Double alpha; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     Set<String> sparseFeatureSet; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @PostConstruct 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -150,6 +158,17 @@ public class RankStrategyBy688 extends RankStrategyBasic { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 userFeatureMap.put("root_source_channel", rootSourceChannel); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<String> adVerIdList = request.getAdIdList().stream().map(AdPlatformCreativeDTO::getAdVerId).distinct().collect(Collectors.toList()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<String> values = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Map<String, GuaranteeView> map = new HashMap<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        for (int i = 0; i < adVerIdList.size(); i++) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            String value = values.get(i); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (value != null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                GuaranteeView guaranteeView = JSONObject.parseObject(value, GuaranteeView.class); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                map.put(adVerIdList.get(i), guaranteeView); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         Map<String, String> sceneFeatureMap = this.handleSceneFeature(ts); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         long time1 = System.currentTimeMillis(); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -176,8 +195,12 @@ public class RankStrategyBy688 extends RankStrategyBasic { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                         adRankItem.getExt().put("isApi", "1"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    GuaranteeView guaranteeView = map.get(dto.getAdVerId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    double guaranteeWeight = getGuaranteeWeight(guaranteeView); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     adRankItem.getExt().put("recallsources", dto.getRecallSources()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    adRankItem.getExt().put("alpha", alpha); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    adRankItem.getExt().put("guaranteeView", guaranteeView.toString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    adRankItem.getExt().put("guaranteeWeight", guaranteeWeight); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     String cidStr = dto.getCreativeId().toString(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     Map<String, String> cidFeatureMap = adRankItem.getFeatureMap(); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -290,8 +313,18 @@ public class RankStrategyBy688 extends RankStrategyBasic { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         for (AdRankItem item : result) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             double scoreCoefficient = creativeScoreCoefficient.getOrDefault(item.getAdId(), 1d); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            item.setScore(item.getLrScore() * scoreCoefficient * item.getCpa()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (scoreParam.getExpCodeSet().contains(guaranteeExp)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                double guaranteeScoreCoefficient; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if (item.getExt().get("guaranteeWeight") == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    guaranteeScoreCoefficient = 1.0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    guaranteeScoreCoefficient = Math.pow((double) item.getExt().get("guaranteeWeight"), alpha); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                item.setScore(item.getLrScore() * scoreCoefficient * item.getCpa() * guaranteeScoreCoefficient); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                item.getScoreMap().put("guaranteeScoreCoefficient", guaranteeScoreCoefficient); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                item.setScore(item.getLrScore() * scoreCoefficient * item.getCpa()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             item.getScoreMap().put("cpa", item.getCpa()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             item.getScoreMap().put("cpm", item.getCpm()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             item.getScoreMap().put("cpmCoefficient", cpmCoefficient); 
			 |