fanjinyang 1 dia atrás
pai
commit
0725d12b44

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

@@ -362,11 +362,9 @@ public class RankStrategyBy897 extends RankStrategyBasic {
         double maxValidCopc = NumberUtils.toDouble(paramsMap.getOrDefault("maxValidCopc", "10"));
         double minCopc = NumberUtils.toDouble(paramsMap.getOrDefault("minCopc", "0.2"));
         double maxCopc = NumberUtils.toDouble(paramsMap.getOrDefault("maxCopc", "2.5"));
-        boolean cidCtcvrCorrected = calibrationCidCtcvr(result, calibModelName, reqFeature,
+        List<AdRankItem> layerTargetCopcFallbackItems = calibrationCidCtcvr(result, calibModelName, reqFeature,
                 minValidCopc, maxValidCopc, minCopc, maxCopc);
-        if (!cidCtcvrCorrected) {
-            calculateLayerTargetCopc(result, calibModelName, reqFeature);
-        }
+        calculateLayerTargetCopc(layerTargetCopcFallbackItems, calibModelName, reqFeature);
         if (CollectionUtils.isEmpty(result)) {
             log.error("calculateCtcvrScore result is empty");
         }
@@ -1118,30 +1116,47 @@ public class RankStrategyBy897 extends RankStrategyBasic {
         return Math.min(Math.max(lowerWeight, weight), upperWeight);
     }
 
-    private boolean calibrationCidCtcvr(List<AdRankItem> items, String modelName, Map<String, String> reqFeature,
-                                        double minValid, double maxValid,
-                                        double minVal, double maxVal) {
-        boolean corrected = false;
-        try {
-            String layer = reqFeature.get("layer_l6");
-            for (AdRankItem item : items) {
+    private List<AdRankItem> calibrationCidCtcvr(List<AdRankItem> items, String modelName,
+                                                 Map<String, String> reqFeature,
+                                                 double minValid, double maxValid,
+                                                 double minVal, double maxVal) {
+        if (CollectionUtils.isEmpty(items)) {
+            return Collections.emptyList();
+        }
+
+        List<AdRankItem> fallbackItems = new ArrayList<>();
+        String layer = MapUtils.isEmpty(reqFeature) ? null : reqFeature.get("layer_l6");
+        if (StringUtils.isBlank(modelName) || StringUtils.isBlank(layer)) {
+            fallbackItems.addAll(items);
+            return fallbackItems;
+        }
+
+        for (AdRankItem item : items) {
+            if (item == null) {
+                continue;
+            }
+
+            try {
                 String cid = String.valueOf(item.getAdId());
                 Double diff = CreativeUserLayerDataHelperV2L6.getCopc(modelName, cid, layer);
-                if (null != diff) {
-                    double newDiff = Math.min(Math.max(minVal, diff), maxVal);
-                    if (newDiff < minValid || newDiff > maxValid) {
-                        double ctcvr = item.getLrScore() * newDiff;
-                        item.getScoreMap().put("cidCtcvrScore", ctcvr);
-                        item.getScoreMap().put("ctcvrScore", ctcvr);
-                        item.setLrScore(ctcvr);
-                        corrected = true;
-                    }
+                if (diff == null) {
+                    fallbackItems.add(item);
+                    continue;
                 }
+
+                double newDiff = Math.min(Math.max(minVal, diff), maxVal);
+                if (newDiff < minValid || newDiff > maxValid) {
+                    double ctcvr = item.getLrScore() * newDiff;
+                    item.getScoreMap().put("cidCtcvrScore", ctcvr);
+                    item.getScoreMap().put("ctcvrScore", ctcvr);
+                    item.setLrScore(ctcvr);
+                }
+            } catch (Exception e) {
+                log.error("calibrationCidCtcvr error, adId={}", item.getAdId(), e);
+                fallbackItems.add(item);
             }
-        } catch (Exception e) {
-            log.error("calibCidScore error", e);
         }
-        return corrected;
+        return fallbackItems;
     }
 
     private void calculateLayerTargetCopc(List<AdRankItem> items, String modelName, Map<String, String> reqFeature) {