| 
					
				 | 
			
			
				@@ -2,8 +2,12 @@ package com.tzld.piaoquan.ad.engine.service.predict.container; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.tdunning.math.stats.Centroid; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.tdunning.math.stats.MergingDigest; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.tzld.piaoquan.ad.engine.service.predict.model.threshold.ScoreV2ThresholdPredictModel; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.tzld.piaoquan.ad.engine.service.predict.model.threshold.ThresholdPredictModel; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.slf4j.Logger; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.slf4j.LoggerFactory; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.beans.factory.annotation.Autowired; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.springframework.beans.factory.annotation.Value; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.context.ApplicationContext; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.stereotype.Component; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -11,22 +15,41 @@ import org.springframework.stereotype.Component; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import javax.annotation.PostConstruct; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import java.util.HashMap; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import java.util.Map; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.util.concurrent.Executors; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.util.concurrent.ScheduledExecutorService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.util.concurrent.TimeUnit; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 @Component 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 public class ThresholdModelContainer { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private final static Logger log = LoggerFactory.getLogger(ScoreV2ThresholdPredictModel.class); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private ApplicationContext applicationContext; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @Value("${ad.predict.t-digest.position:0.52}") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private double position; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     public static Map<String,ThresholdPredictModel> modelMap=new HashMap<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     public static MergingDigest mergingDigest = new MergingDigest(1000); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private static final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @PostConstruct 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     public void init() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         Map<String,ThresholdPredictModel> beanMap= applicationContext.getBeansOfType(ThresholdPredictModel.class); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         beanMap.forEach((s,model)->{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             modelMap.put(model.getName(), model); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        final Runnable task = new Runnable() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            public void run() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    printDigestThreshold(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                }catch (Exception e){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    e.printStackTrace(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        scheduler.scheduleAtFixedRate(task, 0, 1, TimeUnit.MINUTES); // 10分钟 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     public static ThresholdPredictModel getThresholdPredictModel(String modelName){ 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -45,6 +68,15 @@ public class ThresholdModelContainer { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return mergingDigest.quantile(sortPosition); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public void printDigestThreshold(){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            log.info("svc=predict modelName=modelV2 mergingDigestThreshold={}", ThresholdModelContainer.getThresholdByTDigest(position)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        }catch (Exception e){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            e.printStackTrace(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 //    public static void main(String[] args){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 //        MergingDigest mergingDigest = new MergingDigest(100); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 //        for(long i=0;i<1000;i++){ 
			 |