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