Quellcode durchsuchen

Merge branch '20251106_feature_fjy_show_ad' of algorithm/ad-engine into master

fanjinyang vor 6 Tagen
Ursprung
Commit
ca9e6c85bd

+ 16 - 0
ad-engine-service/src/main/java/com/tzld/piaoquan/ad/engine/service/predict/impl/PredictModelServiceImpl.java

@@ -75,6 +75,8 @@ public class PredictModelServiceImpl implements PredictModelService {
     private PredictStrategyBy817 predictStrategyBy817;
     @Autowired
     private PredictStrategyBy819 predictStrategyBy819;
+    @Autowired
+    private PredictStrategyBy820 predictStrategyBy820;
 
     @Autowired
     private UserService userService;
@@ -211,6 +213,20 @@ public class PredictModelServiceImpl implements PredictModelService {
                 return userLayerPredict;
             }
 
+
+            if (expCodes.contains("820")) {
+                Map<String, Object> userLayerPredict820 = predictStrategyBy820.predict(predictContext);
+                if (MapUtils.isNotEmpty(userLayerPredict820)) {
+                    // 填充 819 参数
+                    if (MapUtils.isNotEmpty(predictExtInfo)) {
+                        userLayerPredict820.putAll(predictExtInfo);
+                    }
+                    return userLayerPredict820;
+                }
+            }
+
+
+
             if (expCodes.contains("673")) {
                 Map<String, Object> predictResult = predictStrategyBy673.predict(predictContext);
                 if (Objects.nonNull(predictResult)) {

+ 93 - 0
ad-engine-service/src/main/java/com/tzld/piaoquan/ad/engine/service/predict/v2/PredictStrategyBy820.java

@@ -0,0 +1,93 @@
+package com.tzld.piaoquan.ad.engine.service.predict.v2;
+
+import com.alibaba.fastjson.JSONObject;
+import com.ctrip.framework.apollo.spring.annotation.ApolloJsonValue;
+import com.tzld.piaoquan.ad.engine.commons.util.JSONUtils;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.stereotype.Service;
+
+import java.util.*;
+
+@Slf4j
+@Service
+public class PredictStrategyBy820 extends BasicPredict {
+
+    @ApolloJsonValue("${experiment.820.root.session.id.tail.config:[]}")
+    private List<RootSessionIdTailConfigItem> configItems;
+
+    @Override
+    public String name() {
+        return "820";
+    }
+
+    @Override
+    public Map<String, Object> predict(PredictContext ctx) {
+
+        String rootSessionId = ctx.getRootSessionId();
+        String userLayer = ctx.getUserLayer();
+        String shareType = ctx.getShareType();
+        if (CollectionUtils.isEmpty(configItems) || StringUtils.isAnyBlank(rootSessionId, userLayer, shareType)) {
+            return Collections.emptyMap();
+        }
+        double score = this.calcScoreByMid(ctx.getMid());
+        String tail = rootSessionId.substring(rootSessionId.length() - 1);
+        shareType = ctx.getShareType()
+                .replace("return", "")
+                .replace("mids", "");
+
+        for (RootSessionIdTailConfigItem item : configItems) {
+            if (item.getTail().contains(tail)) {
+                Map<String, Object> returnMap = new HashMap<>();
+                double threshold;
+                String thresholdKey = "";
+
+                // 生成可用的Key列表
+                List<String> keys = Arrays.asList(userLayer + "_" + shareType, "default_" + shareType, "default_threshold");
+                for (String key : keys) {
+                    if (item.getConfig().containsKey(key)) {
+                        thresholdKey = key;
+                        break;
+                    }
+                }
+
+
+                threshold = item.getConfig().getOrDefault(thresholdKey, 0.0);
+
+                if (score < threshold) {
+                    returnMap.putAll(rtnAdPredict(ctx));
+                    returnMap.put("model", this.name());
+                } else {
+                    returnMap.putAll(rtnNoAdPredict(ctx));
+                    returnMap.put("no_ad_strategy", this.name());
+                }
+
+                returnMap.put("score", score);
+                returnMap.put("threshold", threshold);
+                returnMap.put("userLayer", userLayer);
+
+                JSONObject logJson = new JSONObject();
+                logJson.putAll(returnMap);
+                logJson.put("mid", ctx.getMid());
+                logJson.put("appType", ctx.getAppType());
+                logJson.put("rootSessionIdTail", tail);
+                logJson.put("shareType", shareType);
+
+                logJson.put("expId", "userLayerRootSessionIdTailExp");
+                logJson.put("thresholdParamKey", thresholdKey);
+                logJson.put("adPlatformType", ctx.getAdPlatformType());
+                logJson.put("abCode", ctx.getAdAbCode());
+                logJson.put("configItem", item);
+                logJson.put("rootSessionId", ctx.getRootSessionId());
+
+                log.info("广告跳出选择 -- 820实验结果: {}, 参数: {}",
+                        JSONUtils.toJson(returnMap), logJson.toJSONString());
+
+                return returnMap;
+            }
+        }
+        return Collections.emptyMap();
+    }
+
+}