Browse Source

feat:添加671实验

zhaohaipeng 1 year ago
parent
commit
442c7c6771

+ 35 - 0
ad-engine-commons/src/main/java/com/tzld/piaoquan/ad/engine/commons/util/JSONUtils.java

@@ -2,14 +2,49 @@ package com.tzld.piaoquan.ad.engine.commons.util;
 
 import com.alibaba.fastjson.JSONObject;
 import com.google.common.reflect.TypeToken;
+import com.google.gson.ExclusionStrategy;
+import com.google.gson.FieldAttributes;
 import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Objects;
+
 public class JSONUtils {
 
     private static final Logger log = LoggerFactory.getLogger(JSONUtils.class);
+
+    public static String toJson(Object obj, Collection<String> ignoreFieldName) {
+        if (Objects.isNull(obj)) {
+            return "";
+        }
+        try {
+
+            ExclusionStrategy strategy = new ExclusionStrategy() {
+                @Override
+                public boolean shouldSkipField(FieldAttributes fieldAttributes) {
+                    return CollectionUtils.isNotEmpty(ignoreFieldName) &&
+                            ignoreFieldName.contains(fieldAttributes.getName());
+                }
+
+                @Override
+                public boolean shouldSkipClass(Class<?> aClass) {
+                    return false;
+                }
+            };
+            return new GsonBuilder().setExclusionStrategies(strategy).create().toJson(obj);
+        } catch (Exception e) {
+            log.error("toJsonIgnoreField exception: ", e);
+            return "";
+        }
+    }
+
     public static String toJson(Object obj) {
         if (obj == null) {
             return "";

+ 10 - 6
ad-engine-server/src/main/java/com/tzld/piaoquan/ad/engine/server/controller/ControllerAspect.java

@@ -1,6 +1,7 @@
 package com.tzld.piaoquan.ad.engine.server.controller;
 
 import com.google.common.base.Stopwatch;
+import com.google.common.collect.Sets;
 import com.tzld.piaoquan.ad.engine.commons.util.JSONUtils;
 import com.tzld.piaoquan.ad.engine.commons.util.TraceUtils;
 import lombok.extern.slf4j.Slf4j;
@@ -12,6 +13,7 @@ import org.aspectj.lang.annotation.Pointcut;
 import org.aspectj.lang.reflect.MethodSignature;
 import org.springframework.stereotype.Component;
 
+import java.util.Collections;
 import java.util.concurrent.TimeUnit;
 
 /**
@@ -23,12 +25,12 @@ import java.util.concurrent.TimeUnit;
 public class ControllerAspect {
 
     @Pointcut("execution(* com.tzld.piaoquan.ad.engine.server.controller.*Controller.*(..))")
-    public void logPointcut(){
+    public void logPointcut() {
 
     }
 
     @Pointcut("execution(* com.tzld.piaoquan.ad.engine.server.controller.HealthController.*(..))")
-    public void excludePointcut(){
+    public void excludePointcut() {
 
     }
 
@@ -39,13 +41,15 @@ public class ControllerAspect {
         String className = pjp.getTarget().getClass().getSimpleName();
         MethodSignature signature = (MethodSignature) pjp.getSignature();
         Stopwatch stopwatch = Stopwatch.createStarted();
-        log.info("request className=[{}], method=[{}], param=[{}]", className, signature.getName(),
-                JSONUtils.toJson(pjp.getArgs()));
+
+        String param = JSONUtils.toJson(pjp.getArgs(), Sets.newHashSet("statisticsLog"));
+
+        log.info("request className=[{}], method=[{}], param=[{}]", className, signature.getName(), param);
         Object result = pjp.proceed();
         if (result != null && result instanceof String) {
-            log.info("request method=[{}]  param=[{}] result=[{}] cost=[{}]", signature.getName(),JSONUtils.toJson(pjp.getArgs()),result, stopwatch.stop().elapsed(TimeUnit.MILLISECONDS));
+            log.info("request method=[{}]  param=[{}] result=[{}] cost=[{}]", signature.getName(), param, result, stopwatch.stop().elapsed(TimeUnit.MILLISECONDS));
         } else {
-            log.info("request method=[{}]  param=[{}] result=[{}] cost=[{}]", signature.getName(),JSONUtils.toJson(pjp.getArgs()), JSONUtils.toJson(result), stopwatch.stop().elapsed(TimeUnit.MILLISECONDS));
+            log.info("request method=[{}]  param=[{}] result=[{}] cost=[{}]", signature.getName(), param, JSONUtils.toJson(result), stopwatch.stop().elapsed(TimeUnit.MILLISECONDS));
         }
         TraceUtils.removeMDC();
         return result;

+ 4 - 0
ad-engine-service/src/main/java/com/tzld/piaoquan/ad/engine/service/log/impl/LogHubServiceImpl.java

@@ -83,6 +83,10 @@ public class LogHubServiceImpl implements LogHubService {
                     logMap.put("earlyAdIds", requestParam.getStatisticsLog().getEarlyAdIds());
                     logMap.put("earlyCidList", requestParam.getStatisticsLog().getEarlyCreativeIds());
                     logMap.put("finalCidList", requestParam.getStatisticsLog().getFinalCreativeIds());
+                    logMap.put("commonFilterAfterAdIds", requestParam.getStatisticsLog().getCommonFilterAfterAdIds());
+                    logMap.put("commonFilterAfterCidList", requestParam.getStatisticsLog().getCommonFilterAfterCreativeIds());
+                    logMap.put("tacticsFilterAfterAdIds", requestParam.getStatisticsLog().getTacticsFilterAfterAdIds());
+                    logMap.put("tacticsFilterAfterCidList", requestParam.getStatisticsLog().getTacticsFilterAfterCreativeIds());
                 }
 
                 aliyunLogManager.sendLog(project, logStore, "", logMap);

+ 127 - 58
ad-engine-service/src/main/java/com/tzld/piaoquan/ad/engine/service/score/VideoAdThompsonScorerV2.java

@@ -37,8 +37,9 @@ public class VideoAdThompsonScorerV2 {
     private Map<String, Double> exp665Param = new HashMap<>();
     private Map<String, Double> exp666Param = new HashMap<>();
     private Map<String, Double> exp669Param = new HashMap<>();
-    private Map<String, Double> exp670Param = new HashMap<>();
-    private Map<String, String> exp672Param = new HashMap<>();
+    private Map<String, Object> exp670Param = new HashMap<>();
+    private Map<String, Object> exp671Param = new HashMap<>();
+    private Map<String, Object> exp672Param = new HashMap<>();
 
     Random random = new Random();
     Gson gson = new Gson();
@@ -101,8 +102,10 @@ public class VideoAdThompsonScorerV2 {
             // 日志上报扩展参数
             Map<String, Object> ext = new HashMap<>();
             double score = 0.0;
+            double cpa = 0.0;
             try {
                 CreativeStatistic cidStatistics = creativeStatisticsMap.getOrDefault(dto.getCreativeId(), new CreativeStatistic());
+                cpa = cidStatistics.parseCpaToDouble();
 
                 double order;
                 double exp;
@@ -116,31 +119,26 @@ public class VideoAdThompsonScorerV2 {
                     s1 = a / b;
                 }
 
-                score = s1 * dto.getCpa() * dto.getBid1() * dto.getBid2();
+                score = s1 * cpa;
 
                 ext.put("alpha", alpha);
                 ext.put("beta", beta);
                 ext.put("order", order);
                 ext.put("exp", exp);
                 ext.put("s1", s1);
-                ext.put("bid1", dto.getBid1());
-                ext.put("bid2", dto.getBid2());
                 ext.put("pairOrSingle", "single");
                 ext.put("cidStatistic", JSON.toJSONString(cidStatistics));
-                ext.put("cpa", dto.getCpa());
-                ext.put("abCode", 663);
+                ext.put("cpa", cpa);
             } catch (Exception e) {
                 log.error("svc=663exp, error: ", e);
             }
             AdRankItem item = new AdRankItem();
-            item.setCpa(dto.getCpa());
+            item.setCpa(cpa);
             item.setAdId(dto.getCreativeId());
             item.setScore(score);
             item.setExt(ext);
             item.setVideoId(param.getVideoId());
             item.setScore_type(663);
-            item.setBid1(dto.getBid1());
-            item.setBid2(dto.getBid2());
             item.setWeight(dto.getWeight());
             item.setCreativeCode(dto.getCreativeCode());
             result.add(item);
@@ -337,6 +335,7 @@ public class VideoAdThompsonScorerV2 {
             // 日志上报扩展参数
             Map<String, Object> ext = new HashMap<>();
             double score = 0.0;
+            double cpa = cidStatistics.parseCpaToDouble();
             try {
 
 
@@ -351,7 +350,7 @@ public class VideoAdThompsonScorerV2 {
                 }
 
                 double s1 = this.betaSampler((alpha + order), ((beta + exp) / betaK));
-                score = s1 * dto.getCpa() * dto.getBid1() * dto.getBid2();
+                score = s1 * cpa;
 
 
                 ext.put("alpha", alpha);
@@ -360,26 +359,21 @@ public class VideoAdThompsonScorerV2 {
                 ext.put("order", order);
                 ext.put("exp", exp);
                 ext.put("s1", s1);
-                ext.put("bid1", dto.getBid1());
-                ext.put("bid2", dto.getBid2());
                 ext.put("viewThreshold", viewThreshold);
                 ext.put("pairOrSingle", pairOrSingle);
                 ext.put("cidStatistic", JSON.toJSONString(cidStatistics));
                 ext.put("vidCidStatistic", JSON.toJSONString(vidCidStatistics));
-                ext.put("cpa", dto.getCpa());
-                ext.put("abCode", 666);
+                ext.put("cpa", cpa);
             } catch (Exception e) {
                 log.error("svc=666exp, error: ", e);
             }
             AdRankItem item = new AdRankItem();
-            item.setCpa(dto.getCpa());
+            item.setCpa(cpa);
             item.setAdId(dto.getCreativeId());
             item.setScore(score);
             item.setExt(ext);
             item.setVideoId(param.getVideoId());
             item.setScore_type(666);
-            item.setBid2(dto.getBid2());
-            item.setBid1(dto.getBid1());
             item.setWeight(dto.getWeight());
             item.setCreativeCode(dto.getCreativeCode());
             result.add(item);
@@ -402,30 +396,85 @@ public class VideoAdThompsonScorerV2 {
         for (AdRankItem adRankItem : result) {
             adRankItem.setVideoId(param.getVideoId());
             adRankItem.setScore_type(699);
-            if (MapUtils.isNotEmpty(adRankItem.getExt())) {
-                adRankItem.getExt().put("abCode", 699);
-            }
         }
 
         return result;
     }
 
     public List<AdRankItem> thompsonScorerByExp670(ScoreParam param, List<AdPlatformCreativeDTO> adIdList) {
-        Map<Long, CreativeStatistic> creativeStatisticsMap = this.batchFindCreativeRedisCache(redisCidActionKeyV1, adIdList);
-        Map<Long, CreativeStatistic> videoCreativeStatisticsMap = this.batchFindCreativeRedisCache(redisCidVidActionKeyV1 + param.getVideoId() + "_", adIdList);
+        Map<Long, CreativeStatistic> cidMap = this.batchFindCreativeRedisCache(redisCidActionKeyV1, adIdList);
+        Map<Long, CreativeStatistic> vidCidMap = this.batchFindCreativeRedisCache(redisCidVidActionKeyV1 + param.getVideoId() + "_", adIdList);
+
+        double w1 = Double.parseDouble(exp670Param.getOrDefault("w1", "1").toString());
+        double w2 = Double.parseDouble(exp670Param.getOrDefault("w2", "1").toString());
+
+        double alpha = Double.parseDouble(exp670Param.getOrDefault("alpha", "0").toString());
+        double cidBeta = Double.parseDouble(exp670Param.getOrDefault("cidBeta", "0").toString());
+        double vidCidBeta = Double.parseDouble(exp670Param.getOrDefault("vidCidBeta", "0").toString());
+
 
         List<AdRankItem> result = new ArrayList<>(adIdList.size());
-        this.calcScore(result, adIdList, 0.0, 0.0, 0.0, creativeStatisticsMap, videoCreativeStatisticsMap, exp670Param);
-        result.sort(equalsRandomComparator());
 
-        for (AdRankItem adRankItem : result) {
-            adRankItem.setVideoId(param.getVideoId());
-            adRankItem.setScore_type(670);
-            if (MapUtils.isNotEmpty(adRankItem.getExt())) {
-                adRankItem.getExt().put("abCode", 670);
+        for (AdPlatformCreativeDTO dto : adIdList) {
+
+            // 日志上报扩展参数
+            Map<String, Object> ext = new HashMap<>();
+            double score = 0;
+            double cpa = 0.0;
+            try {
+
+                CreativeStatistic cidStatistic = cidMap.getOrDefault(dto.getCreativeId(), new CreativeStatistic());
+                CreativeStatistic vidCidStatistic = vidCidMap.getOrDefault(dto.getCreativeId(), new CreativeStatistic());
+
+                cpa = cidStatistic.parseCpaToDouble();
+                double cidExp = cidStatistic.parseExpToDouble();
+                double vidCidExp = vidCidStatistic.parseExpToDouble();
+
+                // double cidScore = this.betaSampler(cidStatistic.parseOrderToDouble() + alpha, cidStatistic.parseExpToDouble() + cidBeta);
+                // double vidCidScore = this.betaSampler(vidCidStatistic.parseOrderToDouble() + alpha, vidCidStatistic.parseExpToDouble() + vidCidBeta);
+                double cidScore = this.orderDivideExp(cidStatistic);
+                double vidCidScore = this.orderDivideExp(vidCidStatistic);
+
+
+                if (w1 != 0 || w2 != 0) {
+                    score = ((w1 * vidCidScore * vidCidExp + w2 * cidScore * cidExp) / (w1 * vidCidExp + w2 * cidExp)) * cpa;
+                }
+
+                ext.put("w1", w1);
+                ext.put("w2", w2);
+                ext.put("cidScore", cidScore);
+                ext.put("vidCidScore", vidCidScore);
+                ext.put("cidA", alpha);
+                ext.put("vidCidA", alpha);
+                ext.put("cidB", cidBeta);
+                ext.put("vidCidB", vidCidBeta);
+                ext.put("cidExp", cidExp);
+                ext.put("vidCidExp", vidCidExp);
+                ext.put("bid1", dto.getBid1());
+                ext.put("bid2", dto.getBid2());
+                ext.put("cidStatistic", JSON.toJSONString(cidStatistic));
+                ext.put("vidCidStatistic", JSON.toJSONString(vidCidStatistic));
+                ext.put("cpa", cpa);
+            } catch (Exception e) {
+                log.error("svc=670exp, error: ", e);
             }
+
+            AdRankItem item = new AdRankItem();
+            item.setCpa(cpa);
+            item.setAdId(dto.getCreativeId());
+            item.setWeight(dto.getWeight());
+            item.setScore(score);
+            item.setExt(ext);
+            item.setBid1(dto.getBid1());
+            item.setBid2(dto.getBid2());
+            item.setCreativeCode(dto.getCreativeCode());
+            item.setScore_type(670);
+            item.setVideoId(param.getVideoId());
+            result.add(item);
+
         }
 
+        result.sort(equalsRandomComparator());
         return result;
     }
 
@@ -444,9 +493,11 @@ public class VideoAdThompsonScorerV2 {
             double w1 = expParam.getOrDefault("w1", 1d);
             double w2 = expParam.getOrDefault("w2", 1d);
 
+            double cpa = cidStatistic.parseCpaToDouble();
+
             double score = 0;
             if (w1 != 0 || w2 != 0) {
-                score = ((w1 * vidCidScore * vidCidExp + w2 * cidScore * cidExp) / (w1 + w2)) * dto.getCpa();
+                score = ((w1 * vidCidScore * vidCidExp + w2 * cidScore * cidExp) / (w1 * vidCidExp + w2 * cidExp)) * cpa;
             }
 
 
@@ -466,13 +517,13 @@ public class VideoAdThompsonScorerV2 {
             ext.put("bid2", dto.getBid2());
             ext.put("cidStatistic", JSON.toJSONString(cidStatistic));
             ext.put("vidCidStatistic", JSON.toJSONString(vidCidStatistic));
-            ext.put("cpa", dto.getCpa());
+            ext.put("cpa", cpa);
 
             log.info("svc=699And670Score, score: {}, param: {}", score, JSON.toJSONString(ext));
 
 
             AdRankItem item = new AdRankItem();
-            item.setCpa(dto.getCpa());
+            item.setCpa(cpa);
             item.setAdId(dto.getCreativeId());
             item.setWeight(dto.getWeight());
             item.setScore(score);
@@ -482,6 +533,7 @@ public class VideoAdThompsonScorerV2 {
             item.setCreativeCode(dto.getCreativeCode());
 
             result.add(item);
+
         }
     }
 
@@ -504,6 +556,15 @@ public class VideoAdThompsonScorerV2 {
         return resultMap;
     }
 
+    private double orderDivideExp(CreativeStatistic statistic) {
+        double order = statistic.parseOrderToDouble();
+        double exp = statistic.parseExpToDouble();
+        if (exp != 0) {
+            return order / exp;
+        }
+        return 0.0;
+    }
+
     private double calcThompsonScore(Map<String, Double> expParam, CreativeStatistic creativeStatistic, Double defaultAlpha, Double defaultBeta) {
         Double alpha = expParam.getOrDefault("alpha", defaultAlpha);
         Double beta = expParam.getOrDefault("beta", defaultBeta);
@@ -540,7 +601,6 @@ public class VideoAdThompsonScorerV2 {
 
     private Map<String, Object> extMap(CreativeStatistic statistic, String abCode, Double cpa, Double viewThreshold, Double alpha, Double beta, Double beta_k) {
         Map<String, Object> map = new HashMap<>();
-        map.put("abCode", abCode);
         if (Objects.nonNull(viewThreshold)) {
             map.put("viewThreshold", viewThreshold);
         }
@@ -557,37 +617,41 @@ public class VideoAdThompsonScorerV2 {
     }
 
     public List<AdRankItem> thompsonScorerByExp672(ScoreParam param, List<AdPlatformCreativeDTO> adIdList) {
-        String cidRedisKey = exp672Param.getOrDefault("cidActionRedisKey", redisCidActionKeyV1);
-        String vidCidRedisKey = exp672Param.getOrDefault("vidCidActionRedisKey", redisCidVidActionKeyV1);
-
-
-        Map<Long, CreativeStatistic> paramCidRedisCache = this.batchFindCreativeRedisCache(cidRedisKey, adIdList);
-        Map<Long, CreativeStatistic> paramVidCidRedisCache = this.batchFindCreativeRedisCache(vidCidRedisKey, adIdList);
+        return statisticsScore(param, adIdList, exp672Param, 672);
+    }
 
-        // 兜底逻辑
-        if (MapUtils.isEmpty(paramCidRedisCache) && MapUtils.isEmpty(paramVidCidRedisCache)) {
+    public List<AdRankItem> thompsonScorerByExp671(ScoreParam param, List<AdPlatformCreativeDTO> adIdList) {
+        return statisticsScore(param, adIdList, exp671Param, 671);
+    }
 
-            Map<Long, CreativeStatistic> defaultCidCache = this.batchFindCreativeRedisCache(redisCidActionKeyV1, adIdList);
-            Map<Long, CreativeStatistic> defaultVidCidCache = this.batchFindCreativeRedisCache(redisCidVidActionKeyV1, adIdList);
+    private List<AdRankItem> statisticsScore(ScoreParam param, List<AdPlatformCreativeDTO> adIdList, Map<String, Object> expParam, int scoreType){
+        String cidRedisKey = expParam.getOrDefault("cidActionRedisKey", redisCreativeStatisticsPrefix).toString();
+        String vidCidRedisKey = expParam.getOrDefault("vidCidActionRedisKey", redisVideoCreativeStatisticsPrefix).toString();
+        double viewThreshold = Double.parseDouble(expParam.getOrDefault("viewThreshold", "7000").toString());
 
-            for (AdPlatformCreativeDTO dto : adIdList) {
-                Long cid = dto.getCreativeId();
-                paramCidRedisCache.putIfAbsent(cid, defaultCidCache.getOrDefault(cid, new CreativeStatistic()));
-                paramVidCidRedisCache.putIfAbsent(cid, defaultVidCidCache.getOrDefault(cid, new CreativeStatistic()));
-            }
+        // RedisKey前缀判断
+        if (!StringUtils.equals(redisCidActionKeyV1, cidRedisKey) && !StringUtils.equals(redisCreativeStatisticsPrefix, cidRedisKey)) {
+            cidRedisKey = redisCreativeStatisticsPrefix;
+        }
+        if (!StringUtils.equals(redisCidVidActionKeyV1, vidCidRedisKey) && !StringUtils.equals(redisVideoCreativeStatisticsPrefix, vidCidRedisKey)) {
+            vidCidRedisKey = redisVideoCreativeStatisticsPrefix;
         }
 
-        double viewThreshold = Double.parseDouble(exp672Param.getOrDefault("viewThreshold", "7000"));
+        Map<Long, CreativeStatistic> paramCidRedisCache = this.batchFindCreativeRedisCache(cidRedisKey, adIdList);
+        Map<Long, CreativeStatistic> paramVidCidRedisCache = this.batchFindCreativeRedisCache(vidCidRedisKey + param.getVideoId() + "_", adIdList);
+
         List<AdRankItem> result = new ArrayList<>(adIdList.size());
         for (AdPlatformCreativeDTO dto : adIdList) {
             Map<String, Object> ext = new HashMap<>();
             double score = 0.0;
-            double cpa = dto.getCpa();
+            double cpa = 0.0;
             Long cid = dto.getCreativeId();
             try {
                 String pairOrSingle = "pair";
-                CreativeStatistic vidCidStatistic = paramVidCidRedisCache.get(cid);
-                CreativeStatistic cidStatistic = paramCidRedisCache.get(cid);
+                CreativeStatistic vidCidStatistic = paramVidCidRedisCache.getOrDefault(cid, new CreativeStatistic());
+                CreativeStatistic cidStatistic = paramCidRedisCache.getOrDefault(cid, new CreativeStatistic());
+
+                cpa = cidStatistic.parseCpaToDouble();
 
                 double order = vidCidStatistic.parseOrderToDouble();
                 double exp = vidCidStatistic.parseExpToDouble();
@@ -598,7 +662,7 @@ public class VideoAdThompsonScorerV2 {
                     exp = cidStatistic.parseExpToDouble();
                 }
 
-                if (exp > 0 && order > 0 && cpa > 0) {
+                if (exp != 0) {
                     score = (order / exp) * cpa;
                 }
 
@@ -609,9 +673,8 @@ public class VideoAdThompsonScorerV2 {
                 ext.put("cidStatistic", JSON.toJSONString(cidStatistic));
                 ext.put("vidCidStatistic", JSON.toJSONString(vidCidStatistic));
                 ext.put("cpa", cpa);
-                ext.put("abCode", 672);
             } catch (Exception e) {
-                log.error("svc=666exp, error: ", e);
+                log.error("svc=statisticsScore, error: ", e);
             }
 
             AdRankItem item = new AdRankItem();
@@ -620,7 +683,7 @@ public class VideoAdThompsonScorerV2 {
             item.setScore(score);
             item.setExt(ext);
             item.setVideoId(param.getVideoId());
-            item.setScore_type(672);
+            item.setScore_type(scoreType);
             item.setWeight(dto.getWeight());
             item.setCreativeCode(dto.getCreativeCode());
             result.add(item);
@@ -630,6 +693,7 @@ public class VideoAdThompsonScorerV2 {
         return result;
     }
 
+
     class CreativeStatistic {
 
         private String exp;
@@ -751,7 +815,12 @@ public class VideoAdThompsonScorerV2 {
         this.exp670Param = gson.fromJson(str, Map.class);
     }
 
-    @Value("${ad.engine.new.thompson.exp.V2.672{}}")
+    @Value("${ad.engine.new.thompson.exp.V2.671:{}}")
+    public void setExp671Param(String str) {
+        this.exp671Param = gson.fromJson(str, Map.class);
+    }
+
+    @Value("${ad.engine.new.thompson.exp.V2.672:{}}")
     public void setExp672Param(String str) {
         this.exp672Param = gson.fromJson(str, Map.class);
     }

+ 233 - 268
ad-engine-service/src/main/java/com/tzld/piaoquan/ad/engine/service/score/impl/RankServiceImpl.java

@@ -2,26 +2,26 @@ package com.tzld.piaoquan.ad.engine.service.score.impl;
 
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
+import com.tzld.piaoquan.ad.engine.commons.score.ScoreParam;
+import com.tzld.piaoquan.ad.engine.commons.score.ScorerUtils;
+import com.tzld.piaoquan.ad.engine.service.log.LogHubService;
 import com.tzld.piaoquan.ad.engine.service.predict.helper.NewExpInfoHelper;
 import com.tzld.piaoquan.ad.engine.service.predict.param.ThresholdPredictModelParam;
-import com.tzld.piaoquan.ad.engine.service.log.LogHubService;
+import com.tzld.piaoquan.ad.engine.service.remote.FeatureRemoteService;
+import com.tzld.piaoquan.ad.engine.service.score.RankService;
 import com.tzld.piaoquan.ad.engine.service.score.VideoAdThompsonScorerV2;
 import com.tzld.piaoquan.ad.engine.service.score.container.AdCreativeFeatureContainer;
 import com.tzld.piaoquan.ad.engine.service.score.container.PidLambdaContainer;
 import com.tzld.piaoquan.ad.engine.service.score.container.PidLambdaForCpcContainer;
 import com.tzld.piaoquan.ad.engine.service.score.container.PidLambdaV2Container;
+import com.tzld.piaoquan.ad.engine.service.score.convert.RequestConvert;
 import com.tzld.piaoquan.ad.engine.service.score.dto.AdPlatformCreativeDTO;
 import com.tzld.piaoquan.ad.engine.service.score.param.BidRankRecommendRequestParam;
+import com.tzld.piaoquan.ad.engine.service.score.param.RankRecommendRequestParam;
 import com.tzld.piaoquan.ad.engine.service.score.param.UnionRankRecommendRequestParam;
 import com.tzld.piaoquan.recommend.feature.domain.ad.base.AdItemFeature;
 import com.tzld.piaoquan.recommend.feature.domain.ad.base.AdRankItem;
 import com.tzld.piaoquan.recommend.feature.domain.ad.base.UserAdFeature;
-import com.tzld.piaoquan.ad.engine.commons.score.ScoreParam;
-import com.tzld.piaoquan.ad.engine.commons.score.ScorerUtils;
-import com.tzld.piaoquan.ad.engine.service.remote.FeatureRemoteService;
-import com.tzld.piaoquan.ad.engine.service.score.RankService;
-import com.tzld.piaoquan.ad.engine.service.score.convert.RequestConvert;
-import com.tzld.piaoquan.ad.engine.service.score.param.RankRecommendRequestParam;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.BeanUtils;
@@ -53,52 +53,52 @@ public class RankServiceImpl implements RankService {
     @Autowired
     AdCreativeFeatureContainer adCreativeFeatureContainer;
     @Value("${ad.model.cpm.max:200}")
-    Double cpmMax=200d;
+    Double cpmMax = 200d;
     @Value("${ad.model.cpm.min:30}")
-    Double cpmMin=30d;
+    Double cpmMin = 30d;
     @Value("${ad.pid.cpc.exp:30}")
     private String cpcPidExpCode;
     @Value("${ad.cvr.adjusting.exp:652}")
     private String cvrAdjustingExpCode;
 
-    public AdRankItem adItemRank(RankRecommendRequestParam request){
-        ScoreParam param= RequestConvert.requestConvert(request);
+    public AdRankItem adItemRank(RankRecommendRequestParam request) {
+        ScoreParam param = RequestConvert.requestConvert(request);
         LocalDateTime currentTime = LocalDateTime.now();
         int currentHour = currentTime.getHour();
         int dayOfWeek = currentTime.getDayOfWeek().getValue();
-        param.getRequestContext().setHour(currentHour+"");
-        param.getRequestContext().setWeek(dayOfWeek+"");
-        param.getRequestContext().setRegion(request.getRegion().replace("省",""));
-        param.getRequestContext().setCity(request.getCity().replace("市",""));
+        param.getRequestContext().setHour(currentHour + "");
+        param.getRequestContext().setWeek(dayOfWeek + "");
+        param.getRequestContext().setRegion(request.getRegion().replace("省", ""));
+        param.getRequestContext().setCity(request.getCity().replace("市", ""));
         param.getRequestContext().setDay(currentTime.format(dateFormatter));
 
-        UserAdFeature userAdFeature=featureRemoteService.getUserAdFeature(request.getMid());
-        if(userAdFeature==null){
-            userAdFeature=new UserAdFeature();
+        UserAdFeature userAdFeature = featureRemoteService.getUserAdFeature(request.getMid());
+        if (userAdFeature == null) {
+            userAdFeature = new UserAdFeature();
         }
-        Map<Long,List<AdPlatformCreativeDTO>> groupMap=request
+        Map<Long, List<AdPlatformCreativeDTO>> groupMap = request
                 .getAdIdList()
                 .stream()
                 .collect(Collectors.groupingBy(creativeDTO -> creativeDTO.getCreativeId()));
-        Map<Long, AdRankItem> cache=adCreativeFeatureContainer.getAll(new ArrayList<>(groupMap.keySet()));
-        List<AdRankItem> rankItems=Collections.emptyList();
-        if(!cache.isEmpty()){
-            rankItems=new LinkedList<>(cache.values());
+        Map<Long, AdRankItem> cache = adCreativeFeatureContainer.getAll(new ArrayList<>(groupMap.keySet()));
+        List<AdRankItem> rankItems = Collections.emptyList();
+        if (!cache.isEmpty()) {
+            rankItems = new LinkedList<>(cache.values());
         }
-        //避免recommend-feature出问题
-        if(rankItems==null|| rankItems.size()==0){
-            rankItems=new LinkedList<>();
-            for(Long adId:groupMap.keySet()){
-                AdRankItem item=new AdRankItem();
+        // 避免recommend-feature出问题
+        if (rankItems == null || rankItems.size() == 0) {
+            rankItems = new LinkedList<>();
+            for (Long adId : groupMap.keySet()) {
+                AdRankItem item = new AdRankItem();
                 item.setAdId(adId);
                 item.setItemFeature(new AdItemFeature());
                 rankItems.add(item);
             }
         }
-        boolean inCpcPidExp=false;
-        boolean inCvrAdjustingExp=false;
+        boolean inCpcPidExp = false;
+        boolean inCvrAdjustingExp = false;
         if (request.getAdAbExpArr() != null && request.getAdAbExpArr().size() != 0) {
-            for (Map<String, Object> map : request.getAdAbExpArr() ) {
+            for (Map<String, Object> map : request.getAdAbExpArr()) {
                 if (map.getOrDefault("abExpCode", "").equals(cpcPidExpCode)) {
                     inCpcPidExp = true;
                 }
@@ -107,39 +107,39 @@ public class RankServiceImpl implements RankService {
                 }
             }
         }
-        double lambda=-1d;
-        if(inCpcPidExp){
-            for(AdRankItem item:rankItems){
+        double lambda = -1d;
+        if (inCpcPidExp) {
+            for (AdRankItem item : rankItems) {
                 try {
-                    AdPlatformCreativeDTO dto=groupMap.get(item.getAdId()).get(0);
+                    AdPlatformCreativeDTO dto = groupMap.get(item.getAdId()).get(0);
                     item.setBid1(dto.getBid1());
                     item.setBid2(dto.getBid2());
-                    lambda= PidLambdaForCpcContainer.getPidLambda(item.getAdId());
-                    if(lambda<0){
+                    lambda = PidLambdaForCpcContainer.getPidLambda(item.getAdId());
+                    if (lambda < 0) {
                         item.setCpa(dto.getCpa());
                         item.setPidLambda(1);
-                    }else {
-                        if(dto.getCpa()>1&&lambda<=1){
-                            lambda=2d;
+                    } else {
+                        if (dto.getCpa() > 1 && lambda <= 1) {
+                            lambda = 2d;
                         }
                         item.setCpa(lambda);
                         item.setPidLambda(1d);
                     }
-                }catch (Exception e){
-                    log.error("rankItems info error itemId={}",item.getAdId());
+                } catch (Exception e) {
+                    log.error("rankItems info error itemId={}", item.getAdId());
                     e.printStackTrace();
                 }
             }
-        }else {
-            for(AdRankItem item:rankItems){
+        } else {
+            for (AdRankItem item : rankItems) {
                 try {
-                    AdPlatformCreativeDTO dto=groupMap.get(item.getAdId()).get(0);
+                    AdPlatformCreativeDTO dto = groupMap.get(item.getAdId()).get(0);
                     item.setBid1(dto.getBid1());
                     item.setBid2(dto.getBid2());
                     item.setCpa(dto.getCpa());
                     item.setPidLambda(1d);
-                }catch (Exception e){
-                    log.error("rankItems info error itemId={}",item.getAdId());
+                } catch (Exception e) {
+                    log.error("rankItems info error itemId={}", item.getAdId());
                     e.printStackTrace();
                 }
             }
@@ -154,28 +154,28 @@ public class RankServiceImpl implements RankService {
         }
 
         if (!CollectionUtils.isEmpty(rankResult)) {
-            JSONObject object=new JSONObject();
-            object.put("mid",request.getMid());
-            object.put("adid",rankResult.get(0).getAdId());
-            object.put("type",rankResult.get(0).getScore_type());
-            object.put("pctr",rankResult.get(0).getCtr());
-            object.put("pcvr",rankResult.get(0).getCvr());
-            object.put("score",rankResult.get(0).getScore());
-            object.put("pidLambda",rankResult.get(0).getPidLambda());
-            object.put("lrsamples",rankResult.get(0).getLrSampleString());
-            object.put("dataTime",currentTime.format(timeFormatter));
-            object.put("creativeId",rankResult.get(0).getAdId());
+            JSONObject object = new JSONObject();
+            object.put("mid", request.getMid());
+            object.put("adid", rankResult.get(0).getAdId());
+            object.put("type", rankResult.get(0).getScore_type());
+            object.put("pctr", rankResult.get(0).getCtr());
+            object.put("pcvr", rankResult.get(0).getCvr());
+            object.put("score", rankResult.get(0).getScore());
+            object.put("pidLambda", rankResult.get(0).getPidLambda());
+            object.put("lrsamples", rankResult.get(0).getLrSampleString());
+            object.put("dataTime", currentTime.format(timeFormatter));
+            object.put("creativeId", rankResult.get(0).getAdId());
             object.put("videoId", request.getVideoId());
             object.put("pqtId", request.getPqtId());
             log.info("svc=adItemRank {}", JSONObject.toJSONString(object));
             object.remove("lrsamples");
-            if(inCpcPidExp){
-                AdPlatformCreativeDTO dto=groupMap.get(rankResult.get(0).getAdId()).get(0);
-                object.put("cpa",dto.getCpa()*dto.getBid1());
-                object.put("oCpa",dto.getCpa());
-                object.put("realECpm",rankResult.get(0).getEcpm1());
+            if (inCpcPidExp) {
+                AdPlatformCreativeDTO dto = groupMap.get(rankResult.get(0).getAdId()).get(0);
+                object.put("cpa", dto.getCpa() * dto.getBid1());
+                object.put("oCpa", dto.getCpa());
+                object.put("realECpm", rankResult.get(0).getEcpm1());
                 log.info("svc=cpc_pid obj={}", JSONObject.toJSONString(object));
-            }else {
+            } else {
                 log.info("svc=pid_log obj={}", JSONObject.toJSONString(object));
             }
 
@@ -187,67 +187,27 @@ public class RankServiceImpl implements RankService {
                     inCvrAdjustingExp ? "cvr_adjusting" : "base_line", "531");
 
             return rankResult.get(0);
-        }else {
-            //空返回值
+        } else {
+            // 空返回值
             return new AdRankItem();
         }
     }
 
-    public AdRankItem adItemRankWithVideoAdThompson(RankRecommendRequestParam request){
-        ScoreParam param= RequestConvert.requestConvert(request);
+    public AdRankItem adItemRankWithVideoAdThompson(RankRecommendRequestParam request) {
+        ScoreParam param = RequestConvert.requestConvert(request);
         LocalDateTime currentTime = LocalDateTime.now();
         int currentHour = currentTime.getHour();
         int dayOfWeek = currentTime.getDayOfWeek().getValue();
-        param.getRequestContext().setHour(currentHour+"");
-        param.getRequestContext().setWeek(dayOfWeek+"");
-        param.getRequestContext().setRegion(request.getRegion().replace("省",""));
-        param.getRequestContext().setCity(request.getCity().replace("市",""));
+        param.getRequestContext().setHour(currentHour + "");
+        param.getRequestContext().setWeek(dayOfWeek + "");
+        param.getRequestContext().setRegion(request.getRegion().replace("省", ""));
+        param.getRequestContext().setCity(request.getCity().replace("市", ""));
         param.getRequestContext().setDay(currentTime.format(dateFormatter));
 
-//        UserAdFeature userAdFeature=featureRemoteService.getUserAdFeature(request.getMid());
-//        if(userAdFeature==null){
-//            userAdFeature=new UserAdFeature();
-//        }
-//        Map<Long,List<AdPlatformCreativeDTO>> groupMap=request
-//                .getAdIdList()
-//                .stream()
-//                .collect(Collectors.groupingBy(creativeDTO -> creativeDTO.getCreativeId()));
-//        Map<Long, AdRankItem> cache=adCreativeFeatureContainer.getAll(new ArrayList<>(groupMap.keySet()));
-//        List<AdRankItem> rankItems=Collections.emptyList();
-//        if(!cache.isEmpty()){
-//            rankItems=new LinkedList<>();
-//            for (AdRankItem value : cache.values()) {
-//                value.setVideoId(request.getVideoId());
-//                rankItems.add(value);
-//            }
-//        }
-//        //避免recommend-feature出问题
-//        if(rankItems==null|| rankItems.size()==0){
-//            rankItems=new LinkedList<>();
-//            for(Long adId:groupMap.keySet()){
-//                AdRankItem item=new AdRankItem();
-//                item.setAdId(adId);
-//                item.setItemFeature(new AdItemFeature());
-//                item.setVideoId(request.getVideoId());
-//                rankItems.add(item);
-//            }
-//        }
-//        for(AdRankItem item:rankItems){
-//            try {
-//                AdPlatformCreativeDTO dto=groupMap.get(item.getAdId()).get(0);
-//                item.setBid1(dto.getBid1());
-//                item.setBid2(dto.getBid2());
-//                item.setCpa(dto.getCpa());
-//                item.setPidLambda(1d);
-//            }catch (Exception e){
-//                log.error("rankItems info error itemId={}",item.getAdId());
-//                e.printStackTrace();
-//            }
-//        }
-        Set<String> expCodes=new HashSet<>();
+        Set<String> expCodes = new HashSet<>();
         if (request.getAdAbExpArr() != null && request.getAdAbExpArr().size() != 0) {
-            for (Map<String, Object> map : request.getAdAbExpArr() ) {
-                String expCode=map.getOrDefault("abExpCode","").toString();
+            for (Map<String, Object> map : request.getAdAbExpArr()) {
+                String expCode = map.getOrDefault("abExpCode", "").toString();
                 expCodes.add(expCode);
             }
         }
@@ -255,25 +215,25 @@ public class RankServiceImpl implements RankService {
                 .build();
         // 兜底方案
         String abCode = "";
-        List<AdRankItem> rankResult=null;
-        if(expCodes.contains("663")||
-                (expCodes.contains(NewExpInfoHelper.flagId)&&NewExpInfoHelper.checkInNewExpGroupAndSetParamIfIn(
-                        request.getAppType().toString(),request.getNewExpGroup(),"663",modelParam))){
+        List<AdRankItem> rankResult = null;
+        if (expCodes.contains("663") ||
+                (expCodes.contains(NewExpInfoHelper.flagId) && NewExpInfoHelper.checkInNewExpGroupAndSetParamIfIn(
+                        request.getAppType().toString(), request.getNewExpGroup(), "663", modelParam))) {
             rankResult = videoAdThompsonScorerV2.thompsonScorerByExp663(param, request.getAdIdList());
             abCode = "663";
-        }else if(expCodes.contains("664")||
-                (expCodes.contains(NewExpInfoHelper.flagId)&&NewExpInfoHelper.checkInNewExpGroupAndSetParamIfIn(
-                        request.getAppType().toString(),request.getNewExpGroup(),"664",modelParam))){
+        } else if (expCodes.contains("664") ||
+                (expCodes.contains(NewExpInfoHelper.flagId) && NewExpInfoHelper.checkInNewExpGroupAndSetParamIfIn(
+                        request.getAppType().toString(), request.getNewExpGroup(), "664", modelParam))) {
             rankResult = videoAdThompsonScorerV2.thompsonScorerByExp664(param, request.getAdIdList());
             abCode = "664";
-        }else if(expCodes.contains("665")||
-                (expCodes.contains(NewExpInfoHelper.flagId)&&NewExpInfoHelper.checkInNewExpGroupAndSetParamIfIn(
-                        request.getAppType().toString(),request.getNewExpGroup(),"665",modelParam))){
+        } else if (expCodes.contains("665") ||
+                (expCodes.contains(NewExpInfoHelper.flagId) && NewExpInfoHelper.checkInNewExpGroupAndSetParamIfIn(
+                        request.getAppType().toString(), request.getNewExpGroup(), "665", modelParam))) {
             rankResult = videoAdThompsonScorerV2.thompsonScorerByExp665(param, request.getAdIdList());
             abCode = "665";
-        }else if(expCodes.contains("666")||
-                (expCodes.contains(NewExpInfoHelper.flagId)&&NewExpInfoHelper.checkInNewExpGroupAndSetParamIfIn(
-                        request.getAppType().toString(),request.getNewExpGroup(),"666",modelParam))){
+        } else if (expCodes.contains("666") ||
+                (expCodes.contains(NewExpInfoHelper.flagId) && NewExpInfoHelper.checkInNewExpGroupAndSetParamIfIn(
+                        request.getAppType().toString(), request.getNewExpGroup(), "666", modelParam))) {
             rankResult = videoAdThompsonScorerV2.thompsonScorerByExp666(param, request.getAdIdList());
             abCode = "666";
         } else if (expCodes.contains("669") ||
@@ -286,9 +246,14 @@ public class RankServiceImpl implements RankService {
                         request.getAppType().toString(), request.getNewExpGroup(), "670", modelParam))) {
             rankResult = videoAdThompsonScorerV2.thompsonScorerByExp670(param, request.getAdIdList());
             abCode = "670";
-        }else if (expCodes.contains("672") ||
+        } else if (expCodes.contains("671") ||
+                (expCodes.contains(NewExpInfoHelper.flagId) && NewExpInfoHelper.checkInNewExpGroupAndSetParamIfIn(
+                        request.getAppType().toString(), request.getNewExpGroup(), "671", modelParam))) {
+            rankResult = videoAdThompsonScorerV2.thompsonScorerByExp671(param, request.getAdIdList());
+            abCode = "672";
+        } else if (expCodes.contains("672") ||
                 (expCodes.contains(NewExpInfoHelper.flagId) && NewExpInfoHelper.checkInNewExpGroupAndSetParamIfIn(
-                        request.getAppType().toString(), request.getNewExpGroup(), "670", modelParam))){
+                        request.getAppType().toString(), request.getNewExpGroup(), "672", modelParam))) {
             rankResult = videoAdThompsonScorerV2.thompsonScorerByExp672(param, request.getAdIdList());
             abCode = "672";
         }
@@ -298,26 +263,26 @@ public class RankServiceImpl implements RankService {
         logHubService.scoreLogUpload(param, request.getAdIdList(), rankResult, request, "video_ad_thompson", abCode);
 
         if (!CollectionUtils.isEmpty(rankResult)) {
-            JSONObject object=new JSONObject();
-            object.put("mid",request.getMid());
-            object.put("adid",rankResult.get(0).getAdId());
-            object.put("type",rankResult.get(0).getScore_type());
-            object.put("pctr",rankResult.get(0).getCtr());
-            object.put("pcvr",rankResult.get(0).getCvr());
-            object.put("score",rankResult.get(0).getScore());
-            object.put("pidLambda",rankResult.get(0).getPidLambda());
-            object.put("lrsamples",rankResult.get(0).getLrSampleString());
-            object.put("dataTime",currentTime.format(timeFormatter));
-            object.put("creativeId",rankResult.get(0).getAdId());
+            JSONObject object = new JSONObject();
+            object.put("mid", request.getMid());
+            object.put("adid", rankResult.get(0).getAdId());
+            object.put("type", rankResult.get(0).getScore_type());
+            object.put("pctr", rankResult.get(0).getCtr());
+            object.put("pcvr", rankResult.get(0).getCvr());
+            object.put("score", rankResult.get(0).getScore());
+            object.put("pidLambda", rankResult.get(0).getPidLambda());
+            object.put("lrsamples", rankResult.get(0).getLrSampleString());
+            object.put("dataTime", currentTime.format(timeFormatter));
+            object.put("creativeId", rankResult.get(0).getAdId());
             object.put("videoId", rankResult.get(0).getVideoId());
             object.put("pqtId", request.getPqtId());
             log.info("svc=videoAdThompsonRank_lr_log {}", JSONObject.toJSONString(object));
             object.remove("lrsamples");
-            object.put("score_500",rankResult.get(0).getTf_ctr());
-            object.put("score_1000",rankResult.get(0).getTf_cvr());
+            object.put("score_500", rankResult.get(0).getTf_ctr());
+            object.put("score_1000", rankResult.get(0).getTf_cvr());
             log.info("svc=videoAdThompsonRank_log obj={}", JSONObject.toJSONString(object));
             return rankResult.get(0);
-        }else {
+        } else {
             return new AdRankItem();
         }
     }
@@ -325,124 +290,124 @@ public class RankServiceImpl implements RankService {
     @Override
     public AdPlatformCreativeDTO adBidRank(BidRankRecommendRequestParam request) {
 
-        ScoreParam param= RequestConvert.requestConvert(request);
+        ScoreParam param = RequestConvert.requestConvert(request);
 
         LocalDateTime currentTime = LocalDateTime.now();
         int currentHour = currentTime.getHour();
         int dayOfWeek = currentTime.getDayOfWeek().getValue();
-        param.getRequestContext().setHour(currentHour+"");
-        param.getRequestContext().setWeek(dayOfWeek+"");
-        param.getRequestContext().setRegion(request.getRegion().replace("省",""));
-        param.getRequestContext().setCity(request.getCity().replace("市",""));
+        param.getRequestContext().setHour(currentHour + "");
+        param.getRequestContext().setWeek(dayOfWeek + "");
+        param.getRequestContext().setRegion(request.getRegion().replace("省", ""));
+        param.getRequestContext().setCity(request.getCity().replace("市", ""));
         param.getRequestContext().setDay(currentTime.format(dateFormatter));
 
-        UserAdFeature userAdFeature=featureRemoteService.getUserAdFeature(request.getMid());
-        if(userAdFeature==null){
-            userAdFeature=new UserAdFeature();
+        UserAdFeature userAdFeature = featureRemoteService.getUserAdFeature(request.getMid());
+        if (userAdFeature == null) {
+            userAdFeature = new UserAdFeature();
         }
-        Map<Long,List<AdPlatformCreativeDTO>> groupMap=request
+        Map<Long, List<AdPlatformCreativeDTO>> groupMap = request
                 .getCreativeList()
                 .stream()
                 .collect(Collectors.groupingBy(creativeDTO -> creativeDTO.getCreativeId()));
 
 
-        Map<Long, AdRankItem> cache=adCreativeFeatureContainer.getAll(new ArrayList<>(groupMap.keySet()));
-        List<AdRankItem> rankItems=Collections.emptyList();
-        if(!cache.isEmpty()){
-            rankItems=new LinkedList<>(cache.values());
+        Map<Long, AdRankItem> cache = adCreativeFeatureContainer.getAll(new ArrayList<>(groupMap.keySet()));
+        List<AdRankItem> rankItems = Collections.emptyList();
+        if (!cache.isEmpty()) {
+            rankItems = new LinkedList<>(cache.values());
         }
-        double lambda=-1d;
-        for(AdRankItem item:rankItems){
+        double lambda = -1d;
+        for (AdRankItem item : rankItems) {
             try {
-                AdPlatformCreativeDTO dto=groupMap.get(item.getAdId()).get(0);
+                AdPlatformCreativeDTO dto = groupMap.get(item.getAdId()).get(0);
                 item.setBid1(dto.getBid1());
                 item.setBid2(dto.getBid2());
-                lambda=PidLambdaContainer.getPidLambda(item.getAdId());
-                if(lambda<0){
+                lambda = PidLambdaContainer.getPidLambda(item.getAdId());
+                if (lambda < 0) {
                     item.setCpa(dto.getCpa());
                     item.setPidLambda(0.6);
-                }else {
-                    if(dto.getCpa()>1&&lambda<=1){
-                        lambda=2d;
+                } else {
+                    if (dto.getCpa() > 1 && lambda <= 1) {
+                        lambda = 2d;
                     }
                     item.setCpa(lambda);
                     item.setPidLambda(1d);
                 }
 
-            }catch (Exception e){
-                log.error("rankItems info error itemId={}",item.getAdId());
+            } catch (Exception e) {
+                log.error("rankItems info error itemId={}", item.getAdId());
                 e.printStackTrace();
             }
         }
         List<AdRankItem> rankResult;
-        if(rankItems==null|| rankItems.size()==0){
-            rankItems=new LinkedList<>();
-            for(AdPlatformCreativeDTO dto:request.getCreativeList()){
-                AdRankItem item=new AdRankItem();
+        if (rankItems == null || rankItems.size() == 0) {
+            rankItems = new LinkedList<>();
+            for (AdPlatformCreativeDTO dto : request.getCreativeList()) {
+                AdRankItem item = new AdRankItem();
                 item.setBid1(dto.getBid1());
                 item.setBid2(dto.getBid2());
                 item.setAdId(dto.getCreativeId());
                 item.setItemFeature(new AdItemFeature());
-                lambda=PidLambdaContainer.getPidLambda(item.getAdId());
-                if(lambda<0){
+                lambda = PidLambdaContainer.getPidLambda(item.getAdId());
+                if (lambda < 0) {
                     item.setCpa(dto.getCpa());
                     item.setPidLambda(0.6);
-                }else {
-                    if(dto.getCpa()>1&&lambda<=1){
-                        lambda=2d;
+                } else {
+                    if (dto.getCpa() > 1 && lambda <= 1) {
+                        lambda = 2d;
                     }
                     item.setCpa(lambda);
                     item.setPidLambda(1d);
                 }
                 rankItems.add(item);
             }
-            rankResult=rankServiceThompson.rank(param, userAdFeature, rankItems,null);
-        }else {
-            rankResult=rank(param, userAdFeature, rankItems,ScorerUtils.BASE_CONF);
+            rankResult = rankServiceThompson.rank(param, userAdFeature, rankItems, null);
+        } else {
+            rankResult = rank(param, userAdFeature, rankItems, ScorerUtils.BASE_CONF);
         }
 
-        AdRankItem topItem=rankResult.get(0);
+        AdRankItem topItem = rankResult.get(0);
 
-        AdPlatformCreativeDTO result= AdPlatformCreativeDTO
+        AdPlatformCreativeDTO result = AdPlatformCreativeDTO
                 .builder()
                 .build();
-        BeanUtils.copyProperties(topItem,result);
+        BeanUtils.copyProperties(topItem, result);
         result.setCreativeId(topItem.getAdId());
         result.setPctr(topItem.getCtr());
         result.setPcvr(topItem.getCvr());
 //        result.setCreativeCode(groupMap.get(topItem.getAdId()+"").get(0).getCreativeCode());
         result.setCreativeCode(groupMap.get(topItem.getAdId()).get(0).getCreativeCode());
-        double realECpm=0d;
-            //经验值 待定
+        double realECpm = 0d;
+        // 经验值 待定
 //        realECpm=topItem.getEcpm1();
-        realECpm=topItem.getEcpm2();
+        realECpm = topItem.getEcpm2();
 
-        if(realECpm>cpmMax/1000d){
-            realECpm=cpmMax/1000d;
+        if (realECpm > cpmMax / 1000d) {
+            realECpm = cpmMax / 1000d;
         }
-        if(realECpm<cpmMin/1000d){
-            realECpm=cpmMin/1000d;
+        if (realECpm < cpmMin / 1000d) {
+            realECpm = cpmMin / 1000d;
         }
         result.setEcpm2(realECpm);
-        AdPlatformCreativeDTO dto=groupMap.get(topItem.getAdId()).get(0);
-        JSONObject object=new JSONObject();
-        object.put("mid",request.getMid());
-        object.put("adid",result.getCreativeId());
-        object.put("creativeCode",result.getCreativeCode());
-        object.put("type",topItem.getScore_type());
-        object.put("pctr",topItem.getCtr());
-        object.put("pcvr",topItem.getCvr());
-        object.put("lrsamples",topItem.getLrSampleString());
-        object.put("pidLambda",topItem.getPidLambda());
+        AdPlatformCreativeDTO dto = groupMap.get(topItem.getAdId()).get(0);
+        JSONObject object = new JSONObject();
+        object.put("mid", request.getMid());
+        object.put("adid", result.getCreativeId());
+        object.put("creativeCode", result.getCreativeCode());
+        object.put("type", topItem.getScore_type());
+        object.put("pctr", topItem.getCtr());
+        object.put("pcvr", topItem.getCvr());
+        object.put("lrsamples", topItem.getLrSampleString());
+        object.put("pidLambda", topItem.getPidLambda());
         object.put("videoId", request.getVideoId());
 
-        //临时加入供pid v2使用
-        object.put("realECpm",realECpm);
-        object.put("creativeId",result.getCreativeId());
-        //CPA还原
-        object.put("cpa",dto.getCpa()*dto.getBid1());
-        object.put("oCpa",dto.getCpa());
-        object.put("dataTime",currentTime.format(timeFormatter));
+        // 临时加入供pid v2使用
+        object.put("realECpm", realECpm);
+        object.put("creativeId", result.getCreativeId());
+        // CPA还原
+        object.put("cpa", dto.getCpa() * dto.getBid1());
+        object.put("oCpa", dto.getCpa());
+        object.put("dataTime", currentTime.format(timeFormatter));
         object.put("pqtId", request.getPqtId());
         log.info("svc=adBidRank {}", JSONObject.toJSONString(object));
         object.remove("lrsamples");
@@ -453,121 +418,121 @@ public class RankServiceImpl implements RankService {
     @Override
     public AdPlatformCreativeDTO adBidRankNewPid(BidRankRecommendRequestParam request) {
 
-        ScoreParam param= RequestConvert.requestConvert(request);
+        ScoreParam param = RequestConvert.requestConvert(request);
         LocalDateTime currentTime = LocalDateTime.now();
         int currentHour = currentTime.getHour();
         int dayOfWeek = currentTime.getDayOfWeek().getValue();
-        param.getRequestContext().setHour(currentHour+"");
-        param.getRequestContext().setWeek(dayOfWeek+"");
-        param.getRequestContext().setRegion(request.getRegion().replace("省",""));
-        param.getRequestContext().setCity(request.getCity().replace("市",""));
+        param.getRequestContext().setHour(currentHour + "");
+        param.getRequestContext().setWeek(dayOfWeek + "");
+        param.getRequestContext().setRegion(request.getRegion().replace("省", ""));
+        param.getRequestContext().setCity(request.getCity().replace("市", ""));
         param.getRequestContext().setDay(currentTime.format(dateFormatter));
 
-        UserAdFeature userAdFeature=featureRemoteService.getUserAdFeature(request.getMid());
-        if(userAdFeature==null){
-            userAdFeature=new UserAdFeature();
+        UserAdFeature userAdFeature = featureRemoteService.getUserAdFeature(request.getMid());
+        if (userAdFeature == null) {
+            userAdFeature = new UserAdFeature();
         }
-        Map<Long,List<AdPlatformCreativeDTO>> groupMap=request
+        Map<Long, List<AdPlatformCreativeDTO>> groupMap = request
                 .getCreativeList()
                 .stream()
                 .collect(Collectors.groupingBy(creativeDTO -> creativeDTO.getCreativeId()));
 
 
-        Map<Long, AdRankItem> cache=adCreativeFeatureContainer.getAll(new ArrayList<>(groupMap.keySet()));
-        List<AdRankItem> rankItems=Collections.emptyList();
-        if(!cache.isEmpty()){
-            rankItems=new LinkedList<>(cache.values());
+        Map<Long, AdRankItem> cache = adCreativeFeatureContainer.getAll(new ArrayList<>(groupMap.keySet()));
+        List<AdRankItem> rankItems = Collections.emptyList();
+        if (!cache.isEmpty()) {
+            rankItems = new LinkedList<>(cache.values());
         }
-        double lambda=-1d;
-        for(AdRankItem item:rankItems){
+        double lambda = -1d;
+        for (AdRankItem item : rankItems) {
             try {
 
-                AdPlatformCreativeDTO dto=groupMap.get(item.getAdId()).get(0);
+                AdPlatformCreativeDTO dto = groupMap.get(item.getAdId()).get(0);
                 item.setBid1(dto.getBid1());
                 item.setBid2(dto.getBid2());
-                lambda=PidLambdaV2Container.getPidLambda(item.getAdId());
-                if(lambda<0){
+                lambda = PidLambdaV2Container.getPidLambda(item.getAdId());
+                if (lambda < 0) {
                     item.setCpa(dto.getCpa());
-                    item.setPidLambda(dto.getCpa()*0.6);
-                }else {
-                    if(dto.getCpa()>1&&lambda<=1){
-                        lambda=2d;
+                    item.setPidLambda(dto.getCpa() * 0.6);
+                } else {
+                    if (dto.getCpa() > 1 && lambda <= 1) {
+                        lambda = 2d;
                     }
                     item.setCpa(dto.getCpa());
                     item.setPidLambda(lambda);
                 }
 
-            }catch (Exception e){
-                log.error("rankItems info error itemId={}",item.getAdId());
+            } catch (Exception e) {
+                log.error("rankItems info error itemId={}", item.getAdId());
                 e.printStackTrace();
             }
         }
         List<AdRankItem> rankResult;
-        if(rankItems==null|| rankItems.size()==0){
-            rankItems=new LinkedList<>();
-            for(AdPlatformCreativeDTO dto:request.getCreativeList()){
-                AdRankItem item=new AdRankItem();
+        if (rankItems == null || rankItems.size() == 0) {
+            rankItems = new LinkedList<>();
+            for (AdPlatformCreativeDTO dto : request.getCreativeList()) {
+                AdRankItem item = new AdRankItem();
                 item.setBid1(dto.getBid1());
                 item.setBid2(dto.getBid2());
                 item.setAdId(dto.getCreativeId());
                 item.setItemFeature(new AdItemFeature());
-                lambda=PidLambdaV2Container.getPidLambda(item.getAdId());
+                lambda = PidLambdaV2Container.getPidLambda(item.getAdId());
 
-                if(lambda<0){
+                if (lambda < 0) {
                     item.setCpa(dto.getCpa());
-                    item.setPidLambda(dto.getCpa()*0.6);
-                }else {
-                    if(dto.getCpa()>1&&lambda<=1){
-                        lambda=2d;
+                    item.setPidLambda(dto.getCpa() * 0.6);
+                } else {
+                    if (dto.getCpa() > 1 && lambda <= 1) {
+                        lambda = 2d;
                     }
                     item.setCpa(dto.getCpa());
                     item.setPidLambda(lambda);
                 }
                 rankItems.add(item);
             }
-            rankResult=rankServiceThompson.rank(param, userAdFeature, rankItems,null);
-        }else {
-            rankResult=rank(param, userAdFeature, rankItems,ScorerUtils.BASE_CONF);
+            rankResult = rankServiceThompson.rank(param, userAdFeature, rankItems, null);
+        } else {
+            rankResult = rank(param, userAdFeature, rankItems, ScorerUtils.BASE_CONF);
         }
 
-        AdRankItem topItem=rankResult.get(0);
+        AdRankItem topItem = rankResult.get(0);
 
-        AdPlatformCreativeDTO result= AdPlatformCreativeDTO
+        AdPlatformCreativeDTO result = AdPlatformCreativeDTO
                 .builder()
                 .build();
-        BeanUtils.copyProperties(topItem,result);
+        BeanUtils.copyProperties(topItem, result);
         result.setCreativeId(topItem.getAdId());
         result.setPctr(topItem.getCtr());
         result.setPcvr(topItem.getCvr());
         result.setCreativeCode(groupMap.get(topItem.getAdId()).get(0).getCreativeCode());
-        double realECpm=0d;
-        realECpm=topItem.getEcpm2();
+        double realECpm = 0d;
+        realECpm = topItem.getEcpm2();
 
-        if(realECpm>cpmMax/1000d){
-            realECpm=cpmMax/1000d;
+        if (realECpm > cpmMax / 1000d) {
+            realECpm = cpmMax / 1000d;
         }
-        if(realECpm<cpmMin/1000d){
-            realECpm=cpmMin/1000d;
+        if (realECpm < cpmMin / 1000d) {
+            realECpm = cpmMin / 1000d;
         }
         result.setEcpm2(realECpm);
-        AdPlatformCreativeDTO dto=groupMap.get(topItem.getAdId()).get(0);
-        JSONObject object=new JSONObject();
-        object.put("mid",request.getMid());
-        object.put("adid",result.getCreativeId());
-        object.put("creativeCode",result.getCreativeCode());
-        object.put("type",topItem.getScore_type());
-        object.put("pctr",topItem.getCtr());
-        object.put("pcvr",topItem.getCvr());
-        object.put("lrsamples",topItem.getLrSampleString());
-        object.put("pidLambda",topItem.getPidLambda());
-        object.put("realECpm",realECpm);
-        object.put("creativeId",result.getCreativeId());
+        AdPlatformCreativeDTO dto = groupMap.get(topItem.getAdId()).get(0);
+        JSONObject object = new JSONObject();
+        object.put("mid", request.getMid());
+        object.put("adid", result.getCreativeId());
+        object.put("creativeCode", result.getCreativeCode());
+        object.put("type", topItem.getScore_type());
+        object.put("pctr", topItem.getCtr());
+        object.put("pcvr", topItem.getCvr());
+        object.put("lrsamples", topItem.getLrSampleString());
+        object.put("pidLambda", topItem.getPidLambda());
+        object.put("realECpm", realECpm);
+        object.put("creativeId", result.getCreativeId());
         object.put("videoId", request.getVideoId());
-        //CPA还原
-        object.put("cpa",dto.getCpa()*dto.getBid1());
-        object.put("oCpa",dto.getCpa());
+        // CPA还原
+        object.put("cpa", dto.getCpa() * dto.getBid1());
+        object.put("oCpa", dto.getCpa());
         object.put("pqtId", request.getPqtId());
-        object.put("dataTime",currentTime.format(timeFormatter));
+        object.put("dataTime", currentTime.format(timeFormatter));
         log.info("svc=adBidRankNewPid {}", JSONObject.toJSONString(object));
         object.remove("lrsamples");
         log.info("svc=pid_v2_log obj={}", JSONObject.toJSONString(object));

+ 7 - 0
ad-engine-service/src/main/java/com/tzld/piaoquan/ad/engine/service/score/param/StatisticsLogParam.java

@@ -16,4 +16,11 @@ public class StatisticsLogParam {
 
     private List<Long> finalCreativeIds;
 
+    private List<Long> commonFilterAfterAdIds;
+
+    private List<Long> commonFilterAfterCreativeIds;
+
+    private List<Long> tacticsFilterAfterAdIds;
+
+    private List<Long> tacticsFilterAfterCreativeIds;
 }