浏览代码

Merge branch 'refs/heads/dev-xym-swap' into pre-master

# Conflicts:
#	ad-engine-service/src/main/java/com/tzld/piaoquan/ad/engine/service/score/strategy/RankStrategyBy688.java
xueyiming 1 天之前
父节点
当前提交
5083801ce2

+ 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);

+ 43 - 1
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");
@@ -271,7 +285,13 @@ public class RankStrategyBy688 extends RankStrategyBasic {
             double calibratedScore = originalScore / (originalScore + (1 - originalScore) / negSampleRate);
             // 该创意尚未在模型中训练,打分不可靠
             if (CollectionUtils.isNotEmpty(DnnCidDataHelper.getCidSet()) && !DnnCidDataHelper.getCidSet().contains(item.getAdId())) {
-                log.info("not cid calibratedScore={}, cid={}", calibratedScore, item.getAdId());
+                Map<String, Map<String, String>> cidFeature = allCidFeature.getOrDefault(String.valueOf(item.getAdId()), new HashMap<>());
+                Map<String, String> b3Feature = cidFeature.getOrDefault("alg_cid_feature_cid_action", new HashMap<>());
+                double view = Double.parseDouble(b3Feature.getOrDefault("ad_view_14d", "0"));
+                double conver = Double.parseDouble(b3Feature.getOrDefault("ad_conversion_14d", "0"));
+                double smoothCxr = NumUtil.divSmoothV1(conver, view, 1.64);
+                //模型打分和统计计算取打分更低的
+                calibratedScore = Math.min(smoothCxr, calibratedScore);
             }
             item.setLrScore(calibratedScore);
             item.getScoreMap().put("originCtcvrScore", originalScore);
@@ -302,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);