Browse Source

817实验

yaodaoseng 1 week ago
parent
commit
adb6c3c6ea

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

@@ -106,7 +106,7 @@ public class PredictModelServiceImpl implements PredictModelService {
     @Value("#{'${show.ad.whitelist.mid:}'.split(',')}")
     private Set<String> showAdWhitelistMidSet;
 
-    @Value("${experiment.817.ad.hour:0,8}")
+    @Value("${experiment.817.ad.hour:5,8}")
     private String experiment817WithAdHour;
 
     @Autowired
@@ -161,11 +161,11 @@ public class PredictModelServiceImpl implements PredictModelService {
             int hourOfDay = DateUtils.getCurrentHour();
             if ( 0 <= hourOfDay && hourOfDay < 8 && !isAdvanceShowAd() ) {
                 // 0点到8点 && 不是节日
-                boolean isIn817Time = true;
+                boolean isIn817Time = false;
                 try{
                     String[] split = experiment817WithAdHour.split(",");
-                    if ( !(Integer.parseInt(split[0]) <= hourOfDay && hourOfDay < Integer.parseInt(split[1])) ) {
-                        isIn817Time = false;
+                    if ( Integer.parseInt(split[0]) <= hourOfDay && hourOfDay < Integer.parseInt(split[1]) ) {
+                        isIn817Time = true;
                     }
                 }catch (Exception e){
                     log.error("experiment817WithAdHour配置异常", e);

+ 75 - 21
ad-engine-service/src/main/java/com/tzld/piaoquan/ad/engine/service/predict/v2/PredictStrategyBy817.java

@@ -2,42 +2,96 @@ package com.tzld.piaoquan.ad.engine.service.predict.v2;
 
 import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson.TypeReference;
+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.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
 import java.util.*;
 
 @Slf4j
 @Service
-public class PredictStrategyBy817 extends ThresholdPredictStrategy {
+public class PredictStrategyBy817 extends BasicPredict {
+
+    @ApolloJsonValue("${experiment.817.root.session.id.tail.config:[]}")
+    private List<RootSessionIdTailConfigItem> configItems;
+
     @Override
-    Map<String, Double> thresholdConfig(PredictContext ctx) {
-        try {
-            JSONObject json = ctx.getExpConfigMap().getOrDefault("817", new JSONObject());
-            return json.toJavaObject(new TypeReference<Map<String, Double>>() {
-            });
-        } catch (Exception e) {
-            log.error("PredictStrategyBy817 parse 817 exp param error \n", e);
-            return Collections.emptyMap();
-        }
+    public String name() {
+        return "817";
     }
 
     @Override
-    List<String> genThresholdKeys(PredictContext ctx) {
+    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;
+                    }
+                }
 
-        List<String> keys = new ArrayList<>();
-        for (String appType : Arrays.asList(ctx.getAppType(), "default")) {
-            for (String userLayer : Arrays.asList(ctx.getUserLayer(), "default")) {
-                keys.add(String.join("_", appType, userLayer, ctx.getHandleAfterShareType()));
+
+                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("广告跳出选择 -- 817实验结果: {}, 参数: {}",
+                        JSONUtils.toJson(returnMap), logJson.toJSONString());
+
+                return returnMap;
             }
         }
-        keys.add("default_threshold");
-        return keys;
-    }
 
-    @Override
-    public String name() {
-        return "817";
+        return Collections.emptyMap();
     }
 
 }