Przeglądaj źródła

Merge branch 'feature_20240531_zhaohaipeng_log' into pre-master

zhaohaipeng 1 rok temu
rodzic
commit
0d16612827

+ 1 - 1
ad-engine-service/src/main/java/com/tzld/piaoquan/ad/engine/service/log/LogHubService.java

@@ -9,5 +9,5 @@ import java.util.List;
 
 public interface LogHubService {
 
-    void scoreLogUpload(ScoreParam param, List<AdPlatformCreativeDTO> adIdList, List<AdRankItem> rankItems, RecommendRequestParam requestParam, String scoreStrategy);
+    void scoreLogUpload(ScoreParam param, List<AdPlatformCreativeDTO> adIdList, List<AdRankItem> rankItems, RecommendRequestParam requestParam, String scoreStrategy, String abCode);
 }

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

@@ -14,10 +14,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
 import java.util.concurrent.LinkedBlockingDeque;
 import java.util.concurrent.ThreadPoolExecutor;
 import java.util.concurrent.TimeUnit;
@@ -40,7 +37,7 @@ public class LogHubServiceImpl implements LogHubService {
     private AliyunLogManager aliyunLogManager;
 
     @Override
-    public void scoreLogUpload(ScoreParam param, List<AdPlatformCreativeDTO> adIdList, List<AdRankItem> rankItems, RecommendRequestParam requestParam, String scoreStrategy) {
+    public void scoreLogUpload(ScoreParam param, List<AdPlatformCreativeDTO> adIdList, List<AdRankItem> rankItems, RecommendRequestParam requestParam, String scoreStrategy, String abCode) {
         logUploadThreadPool.execute(new Runnable() {
             @Override
             public void run() {
@@ -48,6 +45,7 @@ public class LogHubServiceImpl implements LogHubService {
                 logMap.put("pqtId", param.getPqtId());
                 logMap.put("mid", param.getMid());
                 logMap.put("videoId", param.getVideoId());
+                logMap.put("abCode", abCode);
                 // 获取AB实验列表
                 Set<String> abExpCode = new HashSet<>();
                 if (CollectionUtils.isNotEmpty(requestParam.getAdAbExpArr())) {
@@ -57,11 +55,24 @@ public class LogHubServiceImpl implements LogHubService {
                         }
                     }
                 }
+                logMap.put("abExpCode", abExpCode);
 
-                logMap.put("scoreResult", JSON.toJSONString(rankItems));
-                logMap.put("creativeList", JSON.toJSONString(adIdList));
+                List<JSONObject> scoreResult = new ArrayList<>();
+                for (AdRankItem rankItem : rankItems) {
+                    JSONObject json = new JSONObject();
+                    json.put("adId", rankItem.getAdId());
+                    json.put("score", rankItem.getScore());
+                    json.put("ext", rankItem.getExt());
+                    scoreResult.add(json);
+                }
+                logMap.put("scoreResult", JSON.toJSONString(scoreResult));
 
-                logMap.put("abExpCode", abExpCode);
+                AdRankItem top1 = rankItems.get(0);
+                logMap.put("top1_adId", top1.getAdId());
+                logMap.put("top1_score", top1.getScore());
+                logMap.put("top1_exp", top1.getExt());
+
+                logMap.put("creativeList", JSON.toJSONString(adIdList));
                 logMap.put("adAbGroup", requestParam.getAdAbGroup());
                 logMap.put("scoreStrategy", scoreStrategy);
                 logMap.put("appType", requestParam.getAppType());

+ 67 - 50
ad-engine-service/src/main/java/com/tzld/piaoquan/ad/engine/service/score/VideoAdThompsonScorerV2.java

@@ -96,34 +96,41 @@ public class VideoAdThompsonScorerV2 {
         double beta = exp663Param.getOrDefault("beta", 0d);
 
         for (AdPlatformCreativeDTO dto : adIdList) {
-            CreativeStatistic cidStatistics = creativeStatisticsMap.getOrDefault(dto.getCreativeId(), new CreativeStatistic());
-
-            double order;
-            double exp;
-            order = cidStatistics.parseOrderToDouble();
-            exp = cidStatistics.parseExpToDouble();
-
-            double s1 = 0.0;
-            double a = order + alpha;
-            double b = exp + beta;
-            if (a != 0 && b != 0) {
-                s1 = a / b;
-            }
-
-            double score = s1 * dto.getCpa() * dto.getBid1() * dto.getBid2();
 
             // 日志上报扩展参数
             Map<String, Object> ext = new HashMap<>();
-            ext.put("a", alpha);
-            ext.put("b", beta);
-            ext.put("order", order);
-            ext.put("exp", exp);
-            ext.put("s1", s1);
-            ext.put("pairOrSingle", "single");
-            ext.put("cidStatistic", JSON.toJSONString(cidStatistics));
-            ext.put("cpa", dto.getCpa());
-            ext.put("abCode", 663);
+            double score = 0.0;
+            try {
+                CreativeStatistic cidStatistics = creativeStatisticsMap.getOrDefault(dto.getCreativeId(), new CreativeStatistic());
+
+                double order;
+                double exp;
+                order = cidStatistics.parseOrderToDouble();
+                exp = cidStatistics.parseExpToDouble();
+
+                double s1 = 0.0;
+                double a = order + alpha;
+                double b = exp + beta;
+                if (a != 0 && b != 0) {
+                    s1 = a / b;
+                }
 
+                score = s1 * dto.getCpa() * dto.getBid1() * dto.getBid2();
+
+                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);
+            } catch (Exception e) {
+                log.error("svc=663exp, error: ", e);
+            }
             AdRankItem item = new AdRankItem();
             item.setCpa(dto.getCpa());
             item.setAdId(dto.getCreativeId());
@@ -131,6 +138,8 @@ public class VideoAdThompsonScorerV2 {
             item.setExt(ext);
             item.setVideoId(param.getVideoId());
             item.setScore_type(663);
+            item.setBid1(dto.getBid1());
+            item.setBid2(dto.getBid2());
             result.add(item);
         }
 
@@ -318,36 +327,43 @@ public class VideoAdThompsonScorerV2 {
             double exp;
             CreativeStatistic vidCidStatistics = videoCreativeStatisticsMap.getOrDefault(cid, new CreativeStatistic());
             CreativeStatistic cidStatistics = creativeStatisticsMap.getOrDefault(cid, new CreativeStatistic());
+            // 日志上报扩展参数
+            Map<String, Object> ext = new HashMap<>();
+            double score = 0.0;
+            try {
 
-            if (vidCidStatistics.parseExpToDouble() >= viewThreshold) {
-                pairOrSingle = "pair";
-                order = vidCidStatistics.parseOrderToDouble();
-                exp = vidCidStatistics.parseExpToDouble();
-            } else {
-                pairOrSingle = "single";
-                order = cidStatistics.parseOrderToDouble();
-                exp = cidStatistics.parseExpToDouble();
-            }
 
-            double s1 = this.betaSampler((alpha + order), ((beta + exp) / betaK));
-            double score = s1 * dto.getCpa() * dto.getBid1() * dto.getBid2();
+                if (vidCidStatistics.parseExpToDouble() >= viewThreshold) {
+                    pairOrSingle = "pair";
+                    order = vidCidStatistics.parseOrderToDouble();
+                    exp = vidCidStatistics.parseExpToDouble();
+                } else {
+                    pairOrSingle = "single";
+                    order = cidStatistics.parseOrderToDouble();
+                    exp = cidStatistics.parseExpToDouble();
+                }
 
+                double s1 = this.betaSampler((alpha + order), ((beta + exp) / betaK));
+                score = s1 * dto.getCpa() * dto.getBid1() * dto.getBid2();
 
-            // 日志上报扩展参数
-            Map<String, Object> ext = new HashMap<>();
-            ext.put("a", alpha);
-            ext.put("b", beta);
-            ext.put("bk", betaK);
-            ext.put("order", order);
-            ext.put("exp", exp);
-            ext.put("s1", s1);
-            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("alpha", alpha);
+                ext.put("beta", beta);
+                ext.put("beta_k", betaK);
+                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);
+            } catch (Exception e) {
+                log.error("svc=666exp, error: ", e);
+            }
             AdRankItem item = new AdRankItem();
             item.setCpa(dto.getCpa());
             item.setAdId(dto.getCreativeId());
@@ -355,7 +371,8 @@ public class VideoAdThompsonScorerV2 {
             item.setExt(ext);
             item.setVideoId(param.getVideoId());
             item.setScore_type(666);
-
+            item.setBid2(dto.getBid2());
+            item.setBid1(dto.getBid1());
             result.add(item);
         }
 

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

@@ -182,7 +182,8 @@ public class RankServiceImpl implements RankService {
                 adRankItem.getExt().put("userAdFeature", JSON.toJSONString(userAdFeature));
             }
             // 日志上报
-            logHubService.scoreLogUpload(param, request.getAdIdList(), rankResult, request, inCvrAdjustingExp ? "cvr_adjusting" : "base_line");
+            logHubService.scoreLogUpload(param, request.getAdIdList(), rankResult, request,
+                    inCvrAdjustingExp ? "cvr_adjusting" : "base_line", "531");
 
             return rankResult.get(0);
         }else {
@@ -252,36 +253,43 @@ public class RankServiceImpl implements RankService {
         ThresholdPredictModelParam modelParam = ThresholdPredictModelParam.builder()
                 .build();
         // 兜底方案
+        String abCode = "";
         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))){
             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))){
             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))){
             rankResult = videoAdThompsonScorerV2.thompsonScorerByExp666(param, request.getAdIdList());
+            abCode = "666";
         } else if (expCodes.contains("669") ||
                 (expCodes.contains(NewExpInfoHelper.flagId) && NewExpInfoHelper.checkInNewExpGroupAndSetParamIfIn(
                         request.getAppType().toString(), request.getNewExpGroup(), "669", modelParam))) {
             rankResult = videoAdThompsonScorerV2.thompsonScorerByExp669(param, request.getAdIdList());
+            abCode = "669";
         } else if (expCodes.contains("670") ||
                 (expCodes.contains(NewExpInfoHelper.flagId) && NewExpInfoHelper.checkInNewExpGroupAndSetParamIfIn(
                         request.getAppType().toString(), request.getNewExpGroup(), "670", modelParam))) {
             rankResult = videoAdThompsonScorerV2.thompsonScorerByExp670(param, request.getAdIdList());
+            abCode = "670";
         }
         log.info("RankServiceImpl.adItemRankWithVideoAdThompson.adIdList: {}, result: {}", JSON.toJSONString(request.getAdIdList()), JSON.toJSONString(rankResult));
 
         // 日志上报
-        logHubService.scoreLogUpload(param, request.getAdIdList(), rankResult, request, "video_ad_thompson");
+        logHubService.scoreLogUpload(param, request.getAdIdList(), rankResult, request, "video_ad_thompson", abCode);
 
         if (!CollectionUtils.isEmpty(rankResult)) {
             JSONObject object=new JSONObject();