浏览代码

修改保量判断方式

xueyiming 4 天之前
父节点
当前提交
5326f73135

+ 8 - 3
ad-engine-server/src/main/java/com/tzld/piaoquan/ad/engine/server/controller/AdRecommendController.java

@@ -1,6 +1,7 @@
 package com.tzld.piaoquan.ad.engine.server.controller;
 
 import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.TypeReference;
 import com.tzld.piaoquan.ad.engine.commons.dto.AdPlatformCreativeDTO;
 import com.tzld.piaoquan.ad.engine.commons.enums.GuaranteedTypeEnum;
@@ -20,9 +21,7 @@ import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Objects;
+import java.util.*;
 
 @RestController
 @RequestMapping("/recommend")
@@ -70,6 +69,12 @@ public class AdRecommendController {
                 } else {
                     contentMap.put("type", GuaranteedTypeEnum.NOT_GUARANTEED.getType());
                 }
+                List<String> participateCompetitionType = new ArrayList<>();
+                participateCompetitionType.add("engine");
+                if (rankResult.getExt().containsKey("isGuaranteeType") && (boolean) rankResult.getExt().get("isGuaranteeType")) {
+                    participateCompetitionType.add("guarantee");
+                }
+                contentMap.put("participateCompetitionType", participateCompetitionType);
                 map.put("content", contentMap);
                 return map;
             }

+ 22 - 6
ad-engine-service/src/main/java/com/tzld/piaoquan/ad/engine/service/score/strategy/RankStrategyBasic.java

@@ -65,6 +65,12 @@ public abstract class RankStrategyBasic implements RankStrategy {
     @Value("${correct.cpa.view:1000}")
     protected Integer correctCpaView;
 
+    @Value("${guarantee.weight:30}")
+    protected Integer guaranteeWeight;
+
+    @Value("${guarantee.switching.time:1753286400000}")
+    protected Long guaranteeSwitchingTime;
+
     @Autowired
     private FeatureService featureService;
     @Autowired
@@ -216,10 +222,19 @@ public abstract class RankStrategyBasic implements RankStrategy {
 
     }
 
-    protected Map<String, GuaranteeView> getGuaranteeViewMap(RankRecommendRequestParam request, ScoreParam scoreParam) {
+    protected boolean getIsGuaranteedFlow(ScoreParam scoreParam) {
+        if (System.currentTimeMillis() < guaranteeSwitchingTime) {
+            return scoreParam.getExpCodeSet().contains(guaranteeExp);
+        }
+        Random random = new Random();
+        int i = random.nextInt(100);
+        return i < guaranteeWeight;
+    }
+
+    protected Map<String, GuaranteeView> getGuaranteeViewMap(RankRecommendRequestParam request, boolean isGuaranteedFlow) {
         Map<String, GuaranteeView> map = new HashMap<>();
         try {
-            if (scoreParam.getExpCodeSet().contains(guaranteeExp)) {
+            if (isGuaranteedFlow) {
                 String thatDayDateString = DateUtils.getThatDayDateString();
                 String redisKey = adPlatformGuaranteeKey.replace("{date}", thatDayDateString);
                 List<String> adVerIds = request.getAdIdList().stream().map(AdPlatformCreativeDTO::getAdVerId).distinct()
@@ -243,8 +258,8 @@ public abstract class RankStrategyBasic implements RankStrategy {
         return map;
     }
 
-    protected void setGuaranteeWeight(Map<String, GuaranteeView> map, String adVerId, Map<String, Object> ext) {
-        if (MapUtils.isNotEmpty(map)) {
+    protected void setGuaranteeWeight(Map<String, GuaranteeView> map, String adVerId, Map<String, Object> ext, boolean isGuaranteedFlow) {
+        if (isGuaranteedFlow && MapUtils.isNotEmpty(map)) {
             GuaranteeView guaranteeView = map.get(adVerId);
             if (guaranteeView != null) {
                 double guaranteeWeight = calculateGuaranteedWeight(guaranteeView);
@@ -252,6 +267,7 @@ public abstract class RankStrategyBasic implements RankStrategy {
                 ext.put("guaranteeView", guaranteeView.toString());
                 ext.put("guaranteeWeight", guaranteeWeight);
                 ext.put("isGuaranteed", isGuaranteed);
+                ext.put("isGuaranteedFlow", isGuaranteedFlow);
             }
         }
     }
@@ -294,8 +310,8 @@ public abstract class RankStrategyBasic implements RankStrategy {
                 && guaranteeView.getGuaranteeRate() != null && guaranteeView.getGuaranteeRate() != 0.0;
     }
 
-    protected double getGuaranteeScoreCoefficient(ScoreParam scoreParam, Map<String, Object> ext) {
-        if (scoreParam.getExpCodeSet().contains(guaranteeExp)) {
+    protected double getGuaranteeScoreCoefficient(boolean isGuaranteedFlow, Map<String, Object> ext) {
+        if (isGuaranteedFlow) {
             if (ext.get("guaranteeWeight") == null) {
                 return 1.0;
             } else {

+ 9 - 4
ad-engine-service/src/main/java/com/tzld/piaoquan/ad/engine/service/score/strategy/RankStrategyBy679.java

@@ -95,7 +95,8 @@ public class RankStrategyBy679 extends RankStrategyBasic {
 
         Map<String, String> sceneFeatureMap = this.handleSceneFeature(ts);
         long time1 = System.currentTimeMillis();
-        Map<String, GuaranteeView> map = getGuaranteeViewMap(request, scoreParam);
+        boolean isGuaranteedFlow = getIsGuaranteedFlow();
+        Map<String, GuaranteeView> map = getGuaranteeViewMap(request, isGuaranteedFlow);
         Map<Long, CorrectCpaParam> correctCpaMap = getCorrectCpaParamMap(request, scoreParam);
         List<AdRankItem> adRankItems = new ArrayList<>();
         Random random = new Random();
@@ -124,7 +125,7 @@ public class RankStrategyBy679 extends RankStrategyBasic {
                     adRankItem.getExt().put("recallsources", dto.getRecallSources());
                     adRankItem.getExt().put("correctCpaMap", JSONObject.toJSONString(correctCpaMap.get(dto.getCreativeId())));
                     adRankItem.getExt().put("correctionFactor", correctCpaMap.get(dto.getCreativeId()).getCorrectionFactor());
-                    setGuaranteeWeight(map, dto.getAdVerId(), adRankItem.getExt());
+                    setGuaranteeWeight(map, dto.getAdVerId(), adRankItem.getExt(), isGuaranteedFlow);
                     String cidStr = dto.getCreativeId().toString();
                     Map<String, String> cidFeatureMap = adRankItem.getFeatureMap();
                     Map<String, Map<String, String>> cidFeature = allCidFeature.getOrDefault(cidStr, new HashMap<>());
@@ -220,10 +221,13 @@ public class RankStrategyBy679 extends RankStrategyBasic {
         long time5 = System.currentTimeMillis();
         // loop
         double cpmCoefficient = weightParam.getOrDefault("cpmCoefficient", 0.9);
+        boolean isGuaranteeType = false;
         for (AdRankItem item : result) {
-
+            if (isGuaranteedFlow && item.getExt().get("isGuaranteed") != null && (boolean) item.getExt().get("isGuaranteed")) {
+                isGuaranteeType = true;
+            }
             double scoreCoefficient = creativeScoreCoefficient.getOrDefault(item.getAdId(), 1d);
-            double guaranteeScoreCoefficient = getGuaranteeScoreCoefficient(scoreParam, item.getExt());
+            double guaranteeScoreCoefficient = getGuaranteeScoreCoefficient(isGuaranteedFlow, item.getExt());
             double score = item.getLrScore() * scoreCoefficient * item.getCpa() * guaranteeScoreCoefficient;
             item.getScoreMap().put("guaranteeScoreCoefficient", guaranteeScoreCoefficient);
             item.getScoreMap().put("cpa", item.getCpa());
@@ -254,6 +258,7 @@ public class RankStrategyBy679 extends RankStrategyBasic {
 
         if (CollectionUtils.isNotEmpty(result)) {
             AdRankItem top1Item = result.get(0);
+            top1Item.getExt().put("isGuaranteeType", isGuaranteeType);
             putMetaFeature(top1Item, feature, reqFeature, sceneFeatureMap, request);
         }
         return result;

+ 9 - 4
ad-engine-service/src/main/java/com/tzld/piaoquan/ad/engine/service/score/strategy/RankStrategyBy680.java

@@ -131,7 +131,8 @@ public class RankStrategyBy680 extends RankStrategyBasic {
         Map<String, String> sceneFeatureMap = this.handleSceneFeature(ts);
         long time1 = System.currentTimeMillis();
 
-        Map<String, GuaranteeView> map = getGuaranteeViewMap(request, scoreParam);
+        boolean isGuaranteedFlow = getIsGuaranteedFlow();
+        Map<String, GuaranteeView> map = getGuaranteeViewMap(request, isGuaranteedFlow);
         Map<Long, CorrectCpaParam> correctCpaMap = getCorrectCpaParamMap(request, scoreParam);
         List<AdRankItem> adRankItems = new ArrayList<>();
         Random random = new Random();
@@ -161,7 +162,7 @@ public class RankStrategyBy680 extends RankStrategyBasic {
                     adRankItem.getExt().put("recallsources", dto.getRecallSources());
                     adRankItem.getExt().put("correctCpaMap", JSONObject.toJSONString(correctCpaMap.get(dto.getCreativeId())));
                     adRankItem.getExt().put("correctionFactor", correctCpaMap.get(dto.getCreativeId()).getCorrectionFactor());
-                    setGuaranteeWeight(map, dto.getAdVerId(), adRankItem.getExt());
+                    setGuaranteeWeight(map, dto.getAdVerId(), adRankItem.getExt(), isGuaranteedFlow);
                     String cidStr = dto.getCreativeId().toString();
                     Map<String, String> cidFeatureMap = adRankItem.getFeatureMap();
                     Map<String, Map<String, String>> cidFeature = allCidFeature.getOrDefault(cidStr, new HashMap<>());
@@ -265,10 +266,13 @@ public class RankStrategyBy680 extends RankStrategyBasic {
         // loop
         double cpmCoefficient = weightParam.getOrDefault("cpmCoefficient", 0.9);
 
+        boolean isGuaranteeType = false;
         for (AdRankItem item : result) {
-
+            if (isGuaranteedFlow && item.getExt().get("isGuaranteed") != null && (boolean) item.getExt().get("isGuaranteed")) {
+                isGuaranteeType = true;
+            }
             double scoreCoefficient = creativeScoreCoefficient.getOrDefault(item.getAdId(), 1d);
-            double guaranteeScoreCoefficient = getGuaranteeScoreCoefficient(scoreParam, item.getExt());
+            double guaranteeScoreCoefficient = getGuaranteeScoreCoefficient(isGuaranteedFlow, item.getExt());
             double score = item.getLrScore() * scoreCoefficient * item.getCpa() * guaranteeScoreCoefficient;
             item.getScoreMap().put("guaranteeScoreCoefficient", guaranteeScoreCoefficient);
             item.getScoreMap().put("cpa", item.getCpa());
@@ -294,6 +298,7 @@ public class RankStrategyBy680 extends RankStrategyBasic {
 
         if (CollectionUtils.isNotEmpty(result)) {
             AdRankItem top1Item = result.get(0);
+            top1Item.getExt().put("isGuaranteeType", isGuaranteeType);
             putMetaFeature(top1Item, feature, reqFeature, sceneFeatureMap, request);
         }
         long time6 = System.currentTimeMillis();

+ 9 - 5
ad-engine-service/src/main/java/com/tzld/piaoquan/ad/engine/service/score/strategy/RankStrategyBy683.java

@@ -104,7 +104,8 @@ public class RankStrategyBy683 extends RankStrategyBasic {
         Map<String, String> sceneFeatureMap = this.handleSceneFeature(ts);
         long time1 = System.currentTimeMillis();
 
-        Map<String, GuaranteeView> map = getGuaranteeViewMap(request, scoreParam);
+        boolean isGuaranteedFlow = getIsGuaranteedFlow();
+        Map<String, GuaranteeView> map = getGuaranteeViewMap(request, isGuaranteedFlow);
         Map<Long, CorrectCpaParam> correctCpaMap = getCorrectCpaParamMap(request, scoreParam);
         List<AdRankItem> adRankItems = new ArrayList<>();
         Random random = new Random();
@@ -134,7 +135,7 @@ public class RankStrategyBy683 extends RankStrategyBasic {
                     adRankItem.getExt().put("recallsources", dto.getRecallSources());
                     adRankItem.getExt().put("correctCpaMap", JSONObject.toJSONString(correctCpaMap.get(dto.getCreativeId())));
                     adRankItem.getExt().put("correctionFactor", correctCpaMap.get(dto.getCreativeId()).getCorrectionFactor());
-                    setGuaranteeWeight(map, dto.getAdVerId(), adRankItem.getExt());
+                    setGuaranteeWeight(map, dto.getAdVerId(), adRankItem.getExt(), isGuaranteedFlow);
                     String cidStr = dto.getCreativeId().toString();
                     Map<String, String> cidFeatureMap = adRankItem.getFeatureMap();
                     Map<String, Map<String, String>> cidFeature = allCidFeature.getOrDefault(cidStr, new HashMap<>());
@@ -237,11 +238,13 @@ public class RankStrategyBy683 extends RankStrategyBasic {
 
         // loop
         double cpmCoefficient = weightParam.getOrDefault("cpmCoefficient", 0.9);
-
+        boolean isGuaranteeType = false;
         for (AdRankItem item : result) {
-
+            if (isGuaranteedFlow && item.getExt().get("isGuaranteed") != null && (boolean) item.getExt().get("isGuaranteed")) {
+                isGuaranteeType = true;
+            }
             double scoreCoefficient = creativeScoreCoefficient.getOrDefault(item.getAdId(), 1d);
-            double guaranteeScoreCoefficient = getGuaranteeScoreCoefficient(scoreParam, item.getExt());
+            double guaranteeScoreCoefficient = getGuaranteeScoreCoefficient(isGuaranteedFlow, item.getExt());
             double score = item.getLrScore() * scoreCoefficient * item.getCpa() * guaranteeScoreCoefficient;
             item.getScoreMap().put("guaranteeScoreCoefficient", guaranteeScoreCoefficient);
             item.getScoreMap().put("cpa", item.getCpa());
@@ -268,6 +271,7 @@ public class RankStrategyBy683 extends RankStrategyBasic {
 
         if (CollectionUtils.isNotEmpty(result)) {
             AdRankItem top1Item = result.get(0);
+            top1Item.getExt().put("isGuaranteeType", isGuaranteeType);
             putMetaFeature(top1Item, feature, reqFeature, sceneFeatureMap, request);
         }
         long time6 = System.currentTimeMillis();

+ 9 - 5
ad-engine-service/src/main/java/com/tzld/piaoquan/ad/engine/service/score/strategy/RankStrategyBy688.java

@@ -168,7 +168,8 @@ public class RankStrategyBy688 extends RankStrategyBasic {
         Map<String, String> sceneFeatureMap = this.handleSceneFeature(ts);
         long time1 = System.currentTimeMillis();
 
-        Map<String, GuaranteeView> map = getGuaranteeViewMap(request, scoreParam);
+        boolean isGuaranteedFlow = getIsGuaranteedFlow(scoreParam);
+        Map<String, GuaranteeView> map = getGuaranteeViewMap(request, isGuaranteedFlow);
         Map<Long, CorrectCpaParam> correctCpaMap = getCorrectCpaParamMap(request, scoreParam);
         List<AdRankItem> adRankItems = new ArrayList<>();
         Random random = new Random();
@@ -197,7 +198,7 @@ public class RankStrategyBy688 extends RankStrategyBasic {
                     adRankItem.getExt().put("recallsources", dto.getRecallSources());
                     adRankItem.getExt().put("correctCpaMap", JSONObject.toJSONString(correctCpaMap.get(dto.getCreativeId())));
                     adRankItem.getExt().put("correctionFactor", correctCpaMap.get(dto.getCreativeId()).getCorrectionFactor());
-                    setGuaranteeWeight(map, dto.getAdVerId(), adRankItem.getExt());
+                    setGuaranteeWeight(map, dto.getAdVerId(), adRankItem.getExt(), isGuaranteedFlow);
                     String cidStr = dto.getCreativeId().toString();
                     Map<String, String> cidFeatureMap = adRankItem.getFeatureMap();
                     Map<String, Map<String, String>> cidFeature = allCidFeature.getOrDefault(cidStr, new HashMap<>());
@@ -320,11 +321,13 @@ public class RankStrategyBy688 extends RankStrategyBasic {
 
         // loop
         double cpmCoefficient = weightParam.getOrDefault("cpmCoefficient", 0.9);
-
+        boolean isGuaranteeType = false;
         for (AdRankItem item : result) {
-
+            if (isGuaranteedFlow && item.getExt().get("isGuaranteed") != null && (boolean) item.getExt().get("isGuaranteed")) {
+                isGuaranteeType = true;
+            }
             double scoreCoefficient = creativeScoreCoefficient.getOrDefault(item.getAdId(), 1d);
-            double guaranteeScoreCoefficient = getGuaranteeScoreCoefficient(scoreParam, item.getExt());
+            double guaranteeScoreCoefficient = getGuaranteeScoreCoefficient(isGuaranteedFlow, item.getExt());
             double score = item.getLrScore() * scoreCoefficient * item.getCpa() * guaranteeScoreCoefficient;
             item.getScoreMap().put("guaranteeScoreCoefficient", guaranteeScoreCoefficient);
             item.getScoreMap().put("cpa", item.getCpa());
@@ -351,6 +354,7 @@ public class RankStrategyBy688 extends RankStrategyBasic {
 
         if (CollectionUtils.isNotEmpty(result)) {
             AdRankItem top1Item = result.get(0);
+            top1Item.getExt().put("isGuaranteeType", isGuaranteeType);
             putMetaFeature(top1Item, feature, reqFeature, sceneFeatureMap, request);
         }
         long time6 = System.currentTimeMillis();