ソースを参照

Merge branch '20260710_feature_fjy_copc_v3' of algorithm/ad-engine into master

fanjinyang 1 週間 前
コミット
4323b6efb4

+ 35 - 9
ad-engine-commons/src/main/java/com/tzld/piaoquan/ad/engine/commons/helper/CopcV3DataHelper.java

@@ -24,6 +24,9 @@ public class CopcV3DataHelper {
     private static final long REFRESH_INTERVAL_MILLIS = 5 * 60 * 1000L;
     private static final String EDGE_KEY_PREFIX = "edge:";
     private static final String LANDING_KEY_PREFIX = "landing";
+    private static final String BUCKET_KEY_PREFIX = "bucket";
+    private static final String EVENT_KEY_PREFIX = "event";
+    private static final String GLOBAL_KEY = "global";
     private static final int BUCKET_COUNT = 6;
 
     @Autowired
@@ -53,24 +56,47 @@ public class CopcV3DataHelper {
     }
 
     /**
-     * 按分数所在分桶获取 landing 维度的 COPC 加权系数。
+     * 按分数所在分桶获取 COPC 加权系数。
      *
      * <p>分桶规则为:{@code score <= edge:1} 属于第 1 桶,依次类推;
-     * 大于 {@code edge:5} 的分数属于第 6 桶。</p>
+     * 大于 {@code edge:5} 的分数属于第 6 桶。查询顺序为
+     * {@code landing -> bucket -> event -> global}。</p>
      */
     public static Double getLandingCoefficient(Double score, Integer landingPageType, String targetingConversion) {
-        if (!isFinite(score) || landingPageType == null || targetingConversion == null
-                || targetingConversion.trim().isEmpty()) {
+        if (!isFinite(score)) {
             return null;
         }
 
         int bucketNo = getBucketNo(score);
-        if (bucketNo == 0) {
-            return null;
+        String event = targetingConversion == null ? null : targetingConversion.trim();
+//        log.info("getLandingCoefficient score={}, landingPageType={},targetingConversion={},bucketNo={}",score,landingPageType, targetingConversion,bucketNo);
+        if (event != null && !event.isEmpty()) {
+            Double coefficient;
+            if (bucketNo > 0 && landingPageType != null) {
+                String landingKey = String.format("%s:%s:%s:%s", LANDING_KEY_PREFIX, event,
+                        landingPageType, bucketNo);
+                coefficient = getFiniteDoubleValue(landingKey);
+                if (coefficient != null) {
+//                    log.info("landing key={}",landingKey);
+                    return coefficient;
+                }
+            }
+            if (bucketNo > 0) {
+                String bucketKey = String.format("%s:%s:%s", BUCKET_KEY_PREFIX, event, bucketNo);
+                coefficient = getFiniteDoubleValue(bucketKey);
+                if (coefficient != null) {
+//                    log.info("bucketKey key={}",bucketKey);
+                    return coefficient;
+                }
+            }
+            coefficient = getFiniteDoubleValue(EVENT_KEY_PREFIX + ":" + event);
+            if (coefficient != null) {
+//                log.info("EVENT_KEY_PREFIX key={}",EVENT_KEY_PREFIX + ":" + event);
+                return coefficient;
+            }
         }
-        String key = String.format("%s:%s:%s:%s", LANDING_KEY_PREFIX, targetingConversion,
-                landingPageType, bucketNo);
-        return getFiniteDoubleValue(key);
+//        return getFiniteDoubleValue(GLOBAL_KEY);
+        return null;
     }
 
     private static int getBucketNo(double score) {