瀏覽代碼

Merge branch '20251105_feature_fjy_819' of algorithm/ad-engine into master

fanjinyang 1 周之前
父節點
當前提交
5aca9a69bb

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

@@ -73,6 +73,8 @@ public class PredictModelServiceImpl implements PredictModelService {
     private PredictStrategyBy599 predictStrategyBy599;
     @Autowired
     private PredictStrategyBy817 predictStrategyBy817;
+    @Autowired
+    private PredictStrategyBy819 predictStrategyBy819;
 
     @Autowired
     private UserService userService;
@@ -194,25 +196,45 @@ public class PredictModelServiceImpl implements PredictModelService {
                 return predictStrategyBy817.predict(predictContext);
             }
 
+            // 819只做参数填充
+            Map<String, Object> predictExtInfo = null;
+            if (expCodes.contains("819")) {
+                predictExtInfo = predictStrategyBy819.predict(predictContext);
+            }
+
             Map<String, Object> userLayerPredict = userLayerRootSessionIdPredict.predict(predictContext);
             if (MapUtils.isNotEmpty(userLayerPredict)) {
+                // 填充 819 参数
+                if (MapUtils.isNotEmpty(predictExtInfo)) {
+                    userLayerPredict.putAll(predictExtInfo);
+                }
                 return userLayerPredict;
             }
 
             if (expCodes.contains("673")) {
                 Map<String, Object> predictResult = predictStrategyBy673.predict(predictContext);
                 if (Objects.nonNull(predictResult)) {
+                    // 填充 819 参数
+                    if (MapUtils.isNotEmpty(predictExtInfo)) {
+                        predictResult.putAll(predictExtInfo);
+                    }
                     return predictResult;
                 }
             }
 
+            Map<String, Object> predictResult;
             if (expCodes.contains("599")){
-                return predictStrategyBy599.predict(predictContext);
+                predictResult = predictStrategyBy599.predict(predictContext);
             }else if (expCodes.contains("667")){
-                return predictStrategyBy667.predict(predictContext);
+                predictResult = predictStrategyBy667.predict(predictContext);
             }else {
-                return predictStrategyBy599.predict(predictContext);
+                predictResult = predictStrategyBy599.predict(predictContext);
+            }
+            // 填充 819 参数
+            if (MapUtils.isNotEmpty(predictResult) && MapUtils.isNotEmpty(predictExtInfo)) {
+                predictResult.putAll(predictExtInfo);
             }
+            return predictResult;
             
         } catch (Exception e) {
             log.error("svc=adPredict appType={} group={} newGroup={} pqtId={}"

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

@@ -0,0 +1,85 @@
+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.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@Slf4j
+@Service
+public class PredictStrategyBy819 extends BasicPredict {
+
+    @ApolloJsonValue("${experiment.819.root.session.id.tail.config:[]}")
+    private List<RootSessionIdTailConfigItem> configItems;
+
+    @Override
+    public String name() {
+        return "819";
+    }
+
+    @Override
+    public Map<String, Object> predict(PredictContext ctx) {
+        Map<String, Object> returnMap = new HashMap<>();
+        String rootSessionId = ctx.getRootSessionId();
+        String userLayer = ctx.getUserLayer();
+        String shareType = ctx.getShareType();
+        returnMap.put("ecpm_model","819");
+        if (CollectionUtils.isEmpty(configItems) || StringUtils.isAnyBlank(rootSessionId, userLayer, shareType)) {
+            returnMap.put("ecpm_msg","no_config_error");
+            return returnMap;
+        }
+        String tail = rootSessionId.substring(rootSessionId.length() - 1);
+        shareType = ctx.getShareType()
+                .replace("return", "")
+                .replace("mids", "");
+
+        for (RootSessionIdTailConfigItem item : configItems) {
+            if (item.getTail().contains(tail)) {
+                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;
+                    }
+                }
+
+                double ecpm = item.getConfig().getOrDefault(thresholdKey, -1.0);
+                returnMap.put("ecpm_value", ecpm);
+                returnMap.put("ecpm_thresholdKey", thresholdKey);
+                returnMap.put("ecpm_userLayer", userLayer);
+                returnMap.put("ecpm_rootSessionId", ctx.getRootSessionId());
+                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("广告跳出选择 -- 819实验结果: {}, 参数: {}",
+                        JSONUtils.toJson(returnMap), logJson.toJSONString());
+
+                return returnMap;
+            }
+        }
+        returnMap.put("ecpm_msg","未命中");
+        return returnMap;
+    }
+
+}

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

@@ -435,6 +435,10 @@ public abstract class RankStrategyBasic implements RankStrategy {
         if( scoreParam.getEngineInfo() != null && "817".equals(scoreParam.getEngineInfo().get("model"))){
             return false;
         }
+        // 819实验不要保量
+        if( valid819Ab(scoreParam)){
+            return false;
+        }
         if (System.currentTimeMillis() < guaranteeSwitchingTime) {
             return scoreParam.getExpCodeSet().contains(guaranteeExp);
         }
@@ -443,6 +447,15 @@ public abstract class RankStrategyBasic implements RankStrategy {
         return i < guaranteeWeight;
     }
 
+    private boolean valid819Ab(ScoreParam scoreParam){
+        // 819实验判断
+        boolean in819Ab = scoreParam.getEngineInfo() != null
+                && "819".equals(scoreParam.getEngineInfo().get("ecpm_model"))
+                && scoreParam.getEngineInfo().get("ecpm_value") != null
+                && Double.parseDouble(scoreParam.getEngineInfo().get("ecpm_value").toString()) >= 0;
+        return in819Ab;
+    }
+
     protected Map<String, GuaranteeView> getGuaranteeViewMap(RankRecommendRequestParam request, boolean isGuaranteedFlow) {
         Map<String, GuaranteeView> map = new HashMap<>();
         try {