| 
					
				 | 
			
			
				@@ -6,6 +6,7 @@ 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.util.CommonCollectionUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.tzld.piaoquan.ad.engine.service.predict.container.PredictPidContainer; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.tzld.piaoquan.ad.engine.service.predict.container.RandWContainer; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.tzld.piaoquan.ad.engine.service.predict.container.ThresholdModelContainer; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.tzld.piaoquan.ad.engine.service.predict.param.ThresholdPredictModelParam; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.tzld.piaoquan.ad.engine.service.remote.FeatureRemoteService; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -18,12 +19,16 @@ import org.springframework.beans.factory.annotation.Autowired; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.beans.factory.annotation.Value; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.stereotype.Component; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import javax.annotation.PostConstruct; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import java.time.LocalDateTime; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import java.time.format.DateTimeFormatter; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import java.util.HashMap; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import java.util.List; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import java.util.Map; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import java.util.Random; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.util.concurrent.Executors; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.util.concurrent.ScheduledExecutorService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.util.concurrent.TimeUnit; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import static com.tzld.piaoquan.ad.engine.commons.score.ScorerUtils.BREAK_CONFIG; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import static com.tzld.piaoquan.ad.engine.commons.score.ScorerUtils.SHARE0_CONFIG; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -31,16 +36,13 @@ import static com.tzld.piaoquan.ad.engine.commons.score.ScorerUtils.SHARE0_CONFI 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 @Component 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 public class NoShareUserThresholdPredictModel extends ThresholdPredictModel { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private final static Logger log = LoggerFactory.getLogger(NoShareUserThresholdPredictModel.class); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    private FeatureRemoteService featureRemoteService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    Random random=new Random(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Value("${ad.predict.threshold.share0:0.4}") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private double threshold; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Value("${ad.model.pid.type.share0:-1}") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private double pidType; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     String initName() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return "share0"; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -49,86 +51,13 @@ public class NoShareUserThresholdPredictModel extends ThresholdPredictModel { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     public Map<String, Object> predict(ThresholdPredictModelParam modelParam) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//        UserAdFeature userAdFeature = featureRemoteService.getUserAdFeature(modelParam.getMid()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//        if (userAdFeature == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//            userAdFeature = new UserAdFeature(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//        List<AdRankItem> rankItems = featureRemoteService.getAllAdFeatureList(CommonCollectionUtils.toList(AdConfig.getAdIds(), id -> id.toString())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-// 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//        // scoreParam 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//        AdRequestContext context = new AdRequestContext(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//        context.setApptype(modelParam.getAppType().toString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//        context.setMachineinfoBrand(modelParam.getMachineInfo().getBrand()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//        context.setMachineinfoModel(modelParam.getMachineInfo().getModel()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//        context.setMachineinfoSdkversion(modelParam.getMachineInfo().getSdkVersion()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//        context.setMachineinfoWchatversion(modelParam.getMachineInfo().getWeChatVersion()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//        LocalDateTime date = LocalDateTime.now(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//        context.setHour(date.getHour() + ""); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//        context.setDay(date.format(DateTimeFormatter.ofPattern("yyyyMMdd"))); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//        context.setWeek(date.getDayOfWeek().getValue() + ""); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-// 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//        ScoreParam scoreParam = new ScoreParam(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//        scoreParam.setRequestContext(context); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//        scoreParam.getRequestContext().setRegion(modelParam.getRegion().replace("省", "")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//        scoreParam.getRequestContext().setCity(modelParam.getCity().replace("市", "")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//        scoreParam.setVideoId(modelParam.getVideoId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//        scoreParam.setMid(modelParam.getMid()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//        scoreParam.setUid(""); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//        scoreParam.setProvince(modelParam.getRegion()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//        scoreParam.setCity(modelParam.getCity()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//        scoreParam.setExtraParam(modelParam.getExtraParam()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-// 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//        List<AdRankItem> scoreResult = ScorerUtils 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//                .getScorerPipeline(SHARE0_CONFIG) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//                .scoring(scoreParam, userAdFeature, rankItems); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-// 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//        // 找出ctr*cvr最大的 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-////        double max = -1; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//        AdRankItem maxItem = scoreResult.get(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-////        for (int i = 0; i < scoreResult.size(); i++) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-////            AdRankItem item = scoreResult.get(i); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-////            double ctrCvr = item.getCtr() * item.getCvr(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-////            if (ctrCvr > max) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-////                max = ctrCvr; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-////                maxItem = item; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-////            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-////        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//        double realThreshold=Double.parseDouble( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//                scoreParam.getExtraParam().getOrDefault("Share0Predict_"+modelParam.getAppType(),threshold).toString() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//        ); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//        int adPredict; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//        //加入pid逻辑 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//        if(pidType>1){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//            realThreshold=realThreshold+ PredictPidContainer.getPidLambda( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//                    scoreParam.getExtraParam().getOrDefault("predict_test_id","default")+"_"+modelParam.getAppType()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//        }else if(pidType>=0){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//            realThreshold=PredictPidContainer.getLatestThreshold( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//                    scoreParam.getExtraParam().getOrDefault("predict_test_id","default")+"_"+modelParam.getAppType()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-// 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-// 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//        if (maxItem != null && maxItem.getScore() < realThreshold) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//            // If final score is below threshold, do not show the ad 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//            adPredict = 1; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//        } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//            // Otherwise, show the ad 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//            adPredict = 2; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//        if(maxItem != null){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//            //删除多余打印 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//            maxItem.setItemFeature(null); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//            maxItem.setLrSampleString(null); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//            maxItem.setLrSampleStringOrgin(null); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//            log.info("svc=Share0ThresholdPredictModel_predict modelName=ScoreV2ThresholdPredictModel maxItem={} extraParam={} app_type={} realThreshold={}", 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//                    JSONObject.toJSONString(maxItem), JSONObject.toJSONString(scoreParam.getExtraParam()),modelParam.getAppType(),realThreshold); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        double score=modelParam.getMid().hashCode()%100/100d; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        double score=(modelParam.getMid().hashCode()+ RandWContainer.getRandW())%100/100d; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         score=score<0?-score:score; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         Map<String, Object> result = new HashMap<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 //        result.put("threshold", realThreshold); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 //        result.put("score", maxItem == null ? -1 : maxItem.getScore()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        result.put("ad_predict", score>threshold?2:1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        result.put("ad_predict", score<threshold?2:1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         result.put("score", score); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return result; 
			 |