Prechádzať zdrojové kódy

Merge branch 'feature_20240614_zhaohaipeng_676' into test

zhaohaipeng 11 mesiacov pred
rodič
commit
71b127d58f

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

@@ -66,6 +66,10 @@ public class PredictModelServiceImpl implements PredictModelService {
     private String withoutAdVideoIds;
     @Value("${ad.predict.old.exp.appId:0,3,4,5,6,17,18,19,21,22}")
     private String oldExpGroupAppId = "";
+
+    @Value("${user.source.layer.ad.rate.exp.ids:673,676}")
+    private String userSourceLayerAdRateExpIds;
+
     List<Integer> appIdArr = Arrays.asList(new Integer[]{0, 3, 4, 5, 6, 17, 18, 19, 21, 22});
 
 
@@ -225,13 +229,12 @@ public class PredictModelServiceImpl implements PredictModelService {
 
             String appTypeStr = requestParam.getAppType().toString();
 
-            boolean in676Exp = expCodes.contains("673")
-                    || NewExpInfoHelper.checkInNewExpGroupAndSetParamIfIn(expCodes, appTypeStr, requestParam.getNewExpGroup(), "673", modelParam);
-            if (in676Exp) {
+            List<String> userSourceAndLayerAdRateExpIds = Arrays.asList(userSourceLayerAdRateExpIds.split(","));
+            boolean inAdRateExp = this.checkInAnyExpIdsAndNewAb(expCodes, userSourceAndLayerAdRateExpIds, appTypeStr, requestParam.getNewExpGroup(), modelParam);
+            if (inAdRateExp) {
                 result = ThresholdModelContainer.getThresholdPredictModel("random673").predict(modelParam);
                 // 如果676实验返回结果,表示未命中规则即对应的用户来源和所属层存在配置,使用676实验的结果,否则继续走599实验
                 if (Objects.nonNull(result)) {
-                    log.info("广告跳出选择 -- 673实验结果: {}", JSONUtils.toJson(result));
                     return result;
                 }
             }
@@ -244,7 +247,6 @@ public class PredictModelServiceImpl implements PredictModelService {
                 result = ThresholdModelContainer.
                         getThresholdPredictModel("random")
                         .predict(modelParam);
-                log.info("广告跳出选择 -- 599实验结果: {}", JSONUtils.toJson(result));
             } else if (expCodes.contains("667") ||
                     (expCodes.contains(NewExpInfoHelper.flagId) && NewExpInfoHelper.checkInNewExpGroupAndSetParamIfIn(
                             requestParam.getAppType().toString(), requestParam.getNewExpGroup(), "667", modelParam))) {
@@ -307,10 +309,9 @@ public class PredictModelServiceImpl implements PredictModelService {
     }
 
     public void setExtraParam(ThresholdPredictModelParam modelParam) {
-        String[] ids = testIds.split(",");
-        List<String> idList = Arrays.asList(ids);
+        List<String> idList = Arrays.asList(testIds.split(","));
         List<Map<String, Object>> mapList = (List) modelParam.getAbExpInfo().get("ab_test002");
-        Collections.sort(mapList, new Comparator<Map<String, Object>>() {
+        mapList.sort(new Comparator<Map<String, Object>>() {
             @Override
             public int compare(Map<String, Object> map1, Map<String, Object> map2) {
                 int abExpCode1 = Integer.parseInt(map1.get("abExpCode").toString());
@@ -333,7 +334,7 @@ public class PredictModelServiceImpl implements PredictModelService {
     }
 
 
-    boolean inExpList(Set<String> set, String expCodes) {
+    private boolean inExpList(Set<String> set, String expCodes) {
         String[] expArr = expCodes.split(",");
         for (String str : expArr) {
             if (set.contains(str)) {
@@ -342,4 +343,24 @@ public class PredictModelServiceImpl implements PredictModelService {
         }
         return false;
     }
+
+    /**
+     * 判断用户是否处于某些实验中
+     *
+     * @param userExpIdSet 用户所在的实验
+     * @param expIds       需要判断的实验
+     */
+    private boolean checkInAnyExpIdsAndNewAb(Collection<String> userExpIdSet, Collection<String> expIds, String appId, int groupNumber, ThresholdPredictModelParam modelParam) {
+        for (String expId : expIds) {
+            // 如果包含,返回true
+            if (userExpIdSet.contains(expId)) {
+                return true;
+            }
+            // 在新实验系统中有配置
+            if (NewExpInfoHelper.checkInNewExpGroupAndSetParamIfIn(userExpIdSet, appId, groupNumber, expId, modelParam)) {
+                return true;
+            }
+        }
+        return false;
+    }
 }

+ 9 - 2
ad-engine-service/src/main/java/com/tzld/piaoquan/ad/engine/service/predict/model/threshold/RandomPredict673Model.java

@@ -1,5 +1,6 @@
 package com.tzld.piaoquan.ad.engine.service.predict.model.threshold;
 
+import com.tzld.piaoquan.ad.engine.commons.util.JSONUtils;
 import com.tzld.piaoquan.ad.engine.service.predict.container.RandWContainer;
 import com.tzld.piaoquan.ad.engine.service.predict.param.ThresholdPredictModelParam;
 import org.apache.commons.lang3.StringUtils;
@@ -51,9 +52,12 @@ public class RandomPredict673Model extends ThresholdPredictModel {
                 .replace("mids", "");
         Integer appType = modelParam.getAppType();
 
-        double threshold = Double.parseDouble(abParam.getOrDefault(appType + "_" + keySuffix, -1).toString());
+        String thresholdParamKey = appType + "_" + keySuffix;
+
+        double threshold = Double.parseDouble(abParam.getOrDefault(thresholdParamKey, -1).toString());
         if (threshold < 0d) {
-            threshold = Double.parseDouble(abParam.getOrDefault("default_" + keySuffix, "-1").toString());
+            thresholdParamKey = "default_" + keySuffix;
+            threshold = Double.parseDouble(abParam.getOrDefault(thresholdParamKey, "-1").toString());
         }
         Map<String, Object> result = new HashMap<>();
         result.put("ad_predict", score < threshold ? 2 : 1);
@@ -61,6 +65,9 @@ public class RandomPredict673Model extends ThresholdPredictModel {
         result.put("threshold", threshold);
         result.put("model", this.initName());
 
+        log.info("广告跳出选择 -- 673实验结果: {}, 参数: {}, {}, {}, {}",
+                JSONUtils.toJson(result), appType, modelParam.getMid(), abParamKey, thresholdParamKey);
+
         return result;
     }
 

+ 15 - 8
ad-engine-service/src/main/java/com/tzld/piaoquan/ad/engine/service/predict/model/threshold/RandomPredictModel.java

@@ -1,6 +1,7 @@
 package com.tzld.piaoquan.ad.engine.service.predict.model.threshold;
 
 import com.tzld.piaoquan.ad.engine.commons.util.DateUtils;
+import com.tzld.piaoquan.ad.engine.commons.util.JSONUtils;
 import com.tzld.piaoquan.ad.engine.service.predict.container.RandWContainer;
 import com.tzld.piaoquan.ad.engine.service.predict.param.ThresholdPredictModelParam;
 import org.slf4j.Logger;
@@ -22,25 +23,31 @@ public class RandomPredictModel extends ThresholdPredictModel {
 
     @Override
     public Map<String, Object> predict(ThresholdPredictModelParam modelParam) {
-        int hash=modelParam.getMid().hashCode();
-        hash=hash<0?-hash:hash;
-        double score=(hash+ RandWContainer.getRandW())%100/100d;
+        int hash = modelParam.getMid().hashCode();
+        hash = hash < 0 ? -hash : hash;
+        double score = (hash + RandWContainer.getRandW()) % 100 / 100d;
+
+        String keySuffix = modelParam.getUserExtraFuture("shareType").toString()
+                .replace("return", "")
+                .replace("mids", "");
 
-        String keySuffix = modelParam.getUserExtraFuture("shareType").toString().replace("return", "").replace("mids", "");
         Integer appType = modelParam.getAppType();
+        String thresholdParamKey = appType + "_" + keySuffix;
 
-        double threshold = Double.parseDouble(modelParam.getExtraParam().getOrDefault(appType + "_" + keySuffix, -1).toString());
+        double threshold = Double.parseDouble(modelParam.getExtraParam().getOrDefault(thresholdParamKey, -1).toString());
         if (threshold < 0d) {
-            threshold = Double.parseDouble(modelParam.getExtraParam().getOrDefault("default_" + keySuffix, "-1").toString());
+            thresholdParamKey = "default_" + keySuffix;
+            threshold = Double.parseDouble(modelParam.getExtraParam().getOrDefault(thresholdParamKey, "-1").toString());
         }
         double correction = Double.parseDouble(modelParam.getExtraParam().getOrDefault("E620_" + appType + "_" + DateUtils.getCurrentHour(), 1).toString());
-        threshold=threshold*correction;
+        threshold = threshold * correction;
         Map<String, Object> result = new HashMap<>();
         result.put("ad_predict", score < threshold ? 2 : 1);
         result.put("score", score);
         result.put("threshold", threshold);
         result.put("model", "random");
-
+        log.info("广告跳出选择 -- 599实验结果: {}, 参数: {}, {}, {}",
+                JSONUtils.toJson(result), appType, modelParam.getMid(), thresholdParamKey);
         return result;
     }