Browse Source

feat:添加日志

zhaohaipeng 11 months ago
parent
commit
55c7f636e7

+ 85 - 10
ad-engine-service/src/main/java/com/tzld/piaoquan/ad/engine/service/score/VideoAdThompsonScorerV2.java

@@ -37,7 +37,7 @@ public class VideoAdThompsonScorerV2 {
     private Map<String, Double> exp665Param = new HashMap<>();
     private Map<String, Double> exp665Param = new HashMap<>();
     private Map<String, Double> exp666Param = new HashMap<>();
     private Map<String, Double> exp666Param = new HashMap<>();
     private Map<String, Double> exp669Param = new HashMap<>();
     private Map<String, Double> exp669Param = new HashMap<>();
-    private Map<String, Double> exp670Param = new HashMap<>();
+    private Map<String, String> exp670Param = new HashMap<>();
     private Map<String, String> exp672Param = new HashMap<>();
     private Map<String, String> exp672Param = new HashMap<>();
 
 
     Random random = new Random();
     Random random = new Random();
@@ -406,21 +406,87 @@ public class VideoAdThompsonScorerV2 {
     }
     }
 
 
     public List<AdRankItem> thompsonScorerByExp670(ScoreParam param, List<AdPlatformCreativeDTO> adIdList) {
     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"));
+        double w2 = Double.parseDouble(exp670Param.getOrDefault("w2", "1"));
+        String scoreCalcWay = exp670Param.getOrDefault("scoreCalcWay", "statistic");
+
+        double alpha = Double.parseDouble(exp670Param.getOrDefault("alpha", "0"));
+        double cidBeta = Double.parseDouble(exp670Param.getOrDefault("cidBeta", "0"));
+        double vidCidBeta = Double.parseDouble(exp670Param.getOrDefault("vidCidBeta", "0"));
+
 
 
         List<AdRankItem> result = new ArrayList<>(adIdList.size());
         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 = 0.0, vidCidScore = 0.0;
+
+                if ("thompson".equals(scoreCalcWay)) {
+                    cidScore = this.betaSampler(cidStatistic.parseOrderToDouble() + alpha, cidStatistic.parseExpToDouble() + cidBeta);
+                    vidCidScore = this.betaSampler(vidCidStatistic.parseOrderToDouble() + alpha, vidCidStatistic.parseExpToDouble() + vidCidBeta);
+                } else {
+                    cidScore = this.orderDivideExp(cidStatistic);
+                    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("scoreCalcWay", scoreCalcWay);
+                ext.put("cpa", cpa);
+                ext.put("abCode", 670);
+            } 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;
         return result;
     }
     }
 
 
@@ -502,6 +568,15 @@ public class VideoAdThompsonScorerV2 {
         return resultMap;
         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) {
     private double calcThompsonScore(Map<String, Double> expParam, CreativeStatistic creativeStatistic, Double defaultAlpha, Double defaultBeta) {
         Double alpha = expParam.getOrDefault("alpha", defaultAlpha);
         Double alpha = expParam.getOrDefault("alpha", defaultAlpha);
         Double beta = expParam.getOrDefault("beta", defaultBeta);
         Double beta = expParam.getOrDefault("beta", defaultBeta);