浏览代码

特定人群特定实验交换目标客户广告top1

xueyiming 1 天之前
父节点
当前提交
b944911d4c

+ 1 - 1
ad-engine-commons/pom.xml

@@ -26,7 +26,7 @@
         <dependency>
             <groupId>com.tzld.piaoquan</groupId>
             <artifactId>recommend-feature-client</artifactId>
-            <version>1.1.22</version>
+            <version>1.1.23</version>
         </dependency>
         <dependency>
             <groupId>com.tzld.piaoquan</groupId>

+ 2 - 0
ad-engine-commons/src/main/java/com/tzld/piaoquan/ad/engine/commons/dto/AdPlatformCreativeDTO.java

@@ -48,4 +48,6 @@ public class AdPlatformCreativeDTO {
     private String profession;
 
     private Long skuId;
+
+    private Long customerId;
 }

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

@@ -49,6 +49,14 @@ public class RankStrategyBy680 extends RankStrategyBasic {
     @ApolloJsonValue("${rank.score.neg_sample_rate:0.04}")
     Double negSampleRate;
 
+
+    private static final Long feibianCustomerId = 13L;
+
+    private static final Long yuanwanCustomerId = 70L;
+
+    @Value("${swap.exp:770}")
+    protected String swapExp;
+
     @PostConstruct
     public void afterInit() {
         this.readBucketFile();
@@ -85,6 +93,12 @@ public class RankStrategyBy680 extends RankStrategyBasic {
 
         Map<String, String> userFeatureMap = new HashMap<>();
         Map<String, String> c1Feature = userFeature.getOrDefault("alg_mid_feature_ad_action", new HashMap<>());
+        boolean targetCrowd = false;
+        if (c1Feature.containsKey("user_conver_ad_class") && StringUtils.isNotEmpty(c1Feature.get("user_conver_ad_class"))) {
+            if (c1Feature.get("user_conver_ad_class").contains("中医")) {
+                targetCrowd = true;
+            }
+        }
         List<TupleMapEntry<Tuple5>> midActionList = this.handleC1Feature(c1Feature, userFeatureMap);
 
         Map<String, Double> midTimeDiffMap = this.parseC1FeatureListToTimeDiffMap(midActionList, ts);
@@ -119,6 +133,7 @@ public class RankStrategyBy680 extends RankStrategyBasic {
                     adRankItem.setCampaignId(dto.getCampaignId());
                     adRankItem.setCpm(ObjUtil.nullOrDefault(dto.getCpm(), 90).doubleValue());
                     adRankItem.setSkuId(dto.getSkuId());
+                    adRankItem.setCustomerId(dto.getCustomerId());
                     adRankItem.setRandom(random.nextInt(1000));
                     if (noApiAdVerIds.contains(dto.getAdVerId())) {
                         adRankItem.getExt().put("isApi", "0");
@@ -252,6 +267,29 @@ public class RankStrategyBy680 extends RankStrategyBasic {
 
 
         result.sort(ComparatorUtil.equalsRandomComparator());
+        if (scoreParam.getExpCodeSet().contains(swapExp) && targetCrowd) {
+            AdRankItem top1Item = result.get(0);
+            // 确定要查找的目标客户ID
+            Long targetCustomerId = null;
+            if (Objects.equals(top1Item.getCustomerId(), feibianCustomerId)) {
+                targetCustomerId = yuanwanCustomerId;
+            } else if (Objects.equals(top1Item.getCustomerId(), yuanwanCustomerId)) {
+                targetCustomerId = feibianCustomerId;
+            }
+
+            // 如果需要交换,查找目标ID并交换位置
+            if (targetCustomerId != null) {
+                for (int i = 1; i < result.size(); i++) {
+                    AdRankItem adRankItem = result.get(i);
+                    if (adRankItem != null && Objects.equals(adRankItem.getCustomerId(), targetCustomerId)) {
+                        log.info("swapExp source={} target={}, mid={}", result.get(0), result.get(i), request.getMid());
+                        Collections.swap(result, 0, i);
+                        break;
+                    }
+                }
+            }
+        }
+
 
         if (CollectionUtils.isNotEmpty(result)) {
             AdRankItem top1Item = result.get(0);

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

@@ -41,6 +41,13 @@ public class RankStrategyBy688 extends RankStrategyBasic {
 
     private Map<String, Double> bucketsLen = new HashMap<>();
 
+    private static final Long feibianCustomerId = 13L;
+
+    private static final Long yuanwanCustomerId = 70L;
+
+    @Value("${swap.exp:770}")
+    protected String swapExp;
+
     @Value("${word2vec.exp:694}")
     private String word2vecExp;
 
@@ -92,6 +99,12 @@ public class RankStrategyBy688 extends RankStrategyBasic {
 
         Map<String, String> userFeatureMap = new HashMap<>();
         Map<String, String> c1Feature = userFeature.getOrDefault("alg_mid_feature_ad_action", new HashMap<>());
+        boolean targetCrowd = false;
+        if (c1Feature.containsKey("user_conver_ad_class") && StringUtils.isNotEmpty(c1Feature.get("user_conver_ad_class"))) {
+            if (c1Feature.get("user_conver_ad_class").contains("中医")) {
+                targetCrowd = true;
+            }
+        }
         List<TupleMapEntry<Tuple5>> midActionList = this.handleC1Feature(c1Feature, userFeatureMap);
 
         Map<String, Double> midTimeDiffMap = this.parseC1FeatureListToTimeDiffMap(midActionList, ts);
@@ -156,6 +169,7 @@ public class RankStrategyBy688 extends RankStrategyBasic {
                     adRankItem.setCampaignId(dto.getCampaignId());
                     adRankItem.setCpm(ObjUtil.nullOrDefault(dto.getCpm(), 90).doubleValue());
                     adRankItem.setSkuId(dto.getSkuId());
+                    adRankItem.setCustomerId(dto.getCustomerId());
                     adRankItem.setRandom(random.nextInt(1000));
                     if (noApiAdVerIds.contains(dto.getAdVerId())) {
                         adRankItem.getExt().put("isApi", "0");
@@ -308,6 +322,28 @@ public class RankStrategyBy688 extends RankStrategyBasic {
 
 
         result.sort(ComparatorUtil.equalsRandomComparator());
+        if (scoreParam.getExpCodeSet().contains(swapExp) && targetCrowd) {
+            AdRankItem top1Item = result.get(0);
+            // 确定要查找的目标客户ID
+            Long targetCustomerId = null;
+            if (Objects.equals(top1Item.getCustomerId(), feibianCustomerId)) {
+                targetCustomerId = yuanwanCustomerId;
+            } else if (Objects.equals(top1Item.getCustomerId(), yuanwanCustomerId)) {
+                targetCustomerId = feibianCustomerId;
+            }
+
+            // 如果需要交换,查找目标ID并交换位置
+            if (targetCustomerId != null) {
+                for (int i = 1; i < result.size(); i++) {
+                    AdRankItem adRankItem = result.get(i);
+                    if (adRankItem != null && Objects.equals(adRankItem.getCustomerId(), targetCustomerId)) {
+                        log.info("swapExp source={} target={}, mid={}", result.get(0), result.get(i), request.getMid());
+                        Collections.swap(result, 0, i);
+                        break;
+                    }
+                }
+            }
+        }
 
         if (CollectionUtils.isNotEmpty(result)) {
             AdRankItem top1Item = result.get(0);