Browse Source

Merge branch 'feature_gufengshou_20240407_new_exp_sys' into pre-master

gufengshou1 11 months ago
parent
commit
694e0b997c

+ 13 - 1
ad-engine-service/src/main/java/com/tzld/piaoquan/ad/engine/service/predict/helper/NewExpInfoHelper.java

@@ -56,7 +56,10 @@ public class NewExpInfoHelper {
             if(appExpIdCache.get(appId)==null||!appExpIdCache.get(appId).contains(expId)){
             if(appExpIdCache.get(appId)==null||!appExpIdCache.get(appId).contains(expId)){
                 return false;
                 return false;
             }
             }
-            if(expIdAndRangeCache.get(expId).getRange()[0]<=groupNumber&&expIdAndRangeCache.get(expId).getRange()[1]>=groupNumber){
+            if((expIdAndRangeCache.get(expId).getAllEnter()&&groupNumber<0)
+                    ||(
+                    expIdAndRangeCache.get(expId).getRange()[0]<=groupNumber&&expIdAndRangeCache.get(expId).getRange()[1]>=groupNumber)
+            ){
                 for(Map.Entry<String,Object> entry:expIdAndRangeCache.get(expId).getParam().entrySet()){
                 for(Map.Entry<String,Object> entry:expIdAndRangeCache.get(expId).getParam().entrySet()){
                     modelParam.getExtraParam().put(entry.getKey(),entry.getValue());
                     modelParam.getExtraParam().put(entry.getKey(),entry.getValue());
                 }
                 }
@@ -134,6 +137,15 @@ public class NewExpInfoHelper {
         private String expId;
         private String expId;
         private int[] range;
         private int[] range;
 
 
+        public Boolean getAllEnter() {
+            return allEnter;
+        }
+
+        public void setAllEnter(Boolean allEnter) {
+            this.allEnter = allEnter;
+        }
+
+        private Boolean allEnter;
         private Map<String,Object> param;
         private Map<String,Object> param;
 
 
         public String getExpId() {
         public String getExpId() {

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

@@ -28,7 +28,7 @@ import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 
 
 import java.util.*;
 import java.util.*;
-
+//
 @Service
 @Service
 public class PredictModelServiceImpl implements PredictModelService {
 public class PredictModelServiceImpl implements PredictModelService {
     private final static Logger log = LoggerFactory.getLogger(PredictModelServiceImpl.class);
     private final static Logger log = LoggerFactory.getLogger(PredictModelServiceImpl.class);
@@ -63,180 +63,196 @@ public class PredictModelServiceImpl implements PredictModelService {
     private String testIds;
     private String testIds;
     @Value("${ad.predict.without.ad.video_ids:0}")
     @Value("${ad.predict.without.ad.video_ids:0}")
     private String withoutAdVideoIds;
     private String withoutAdVideoIds;
-
+    @Value("${ad.predict.old.exp.appId:0,3,4,5,6,17,18,19,21,22}")
+    private String oldExpGroupAppId="";
     List<Integer> appIdArr=Arrays.asList(new Integer[]{0,3,4,5,6,17,18,19,21,22});
     List<Integer> appIdArr=Arrays.asList(new Integer[]{0,3,4,5,6,17,18,19,21,22});
 
 
 
 
     public Map<String, Object> adPredict(ThresholdPredictModelRequestParam requestParam) {
     public Map<String, Object> adPredict(ThresholdPredictModelRequestParam requestParam) {
-        String[] withoutAdVideoIdsArr=withoutAdVideoIds.split(",");
-        for(String videoId:withoutAdVideoIdsArr){
-            if(videoId.equals(requestParam.getVideoId()+"")){
-                if(requestParam.getAppType().equals(0)
-                        ||requestParam.getAppType().equals(4)
-                        ||requestParam.getAppType().equals(5)
-                        ||requestParam.getAppType().equals(21)
-                ){
-                    Map<String,Object> result=new HashMap<>();
-                    result.put("ad_predict", 1);
-                    result.put("no_ad_strategy", "no_ad_with_video_in_white_list");
-                    return result;
+        Map<String,Object> result=new HashMap<>();
+        result.put("logTraceId", requestParam.getLogTraceId());
+        try {
+            String[] withoutAdVideoIdsArr=withoutAdVideoIds.split(",");
+            for(String videoId:withoutAdVideoIdsArr){
+                if(videoId.equals(requestParam.getVideoId()+"")){
+                    if(requestParam.getAppType().equals(0)
+                            ||requestParam.getAppType().equals(4)
+                            ||requestParam.getAppType().equals(5)
+                            ||requestParam.getAppType().equals(21)
+                    ){
+                         result=new HashMap<>();
+                        result.put("ad_predict", 1);
+                        result.put("no_ad_strategy", "no_ad_with_video_in_white_list");
+                        return result;
+                    }
                 }
                 }
             }
             }
-        }
 
 
-        Map<String,Object> result=new HashMap<>();
-        List<Map<String,Object>> mapList=(List)requestParam.getAbExpInfo().get("ab_test002");
-        Map<String,List<JSONObject>> configMap=new HashMap<>();
-        //该用户所有实验合集
-        Set<String> expCodes=new HashSet<>();
-        for(Map<String,Object> map:mapList){
-            String expCode=map.getOrDefault("abExpCode","").toString();
-            expCodes.add(expCode);
-            if("555".equals(expCode)){
-                configMap=JSONObject.parseObject(map.get("configValue").toString(),Map.class);
-            }
-        }
 
 
-        int hourOfDay= DateUtils.getCurrentHour();
-        Boolean condition1=abTestConfigContainer.inAdTimeTest(requestParam.getAbExpInfo());
-        Boolean condition2=abTestConfigContainer.containsCode(configMap,requestParam.getAbTestCode());
-        if(condition1
-                &&
-                condition2
-                &&
-                abTestConfigContainer.inWithoutAdTime(configMap,requestParam.getAbTestCode(),hourOfDay)){
-            result.put("ad_predict", 1);
-            result.put("no_ad_strategy", "no_ad_time_with_time_plan");
-            return result;
-        } else if (
-                (!condition1 || (condition1 && !condition2))
-                        &&
-                        (0 <= hourOfDay && hourOfDay < 8)) {
-            result.put("ad_predict", 1);
-            result.put("no_ad_strategy", "no_ad_time_with_fixed_time");
-            return result;
-        }
-        String abtestId=null;
-        String abTestConfigTag=null;
-        Map<String, Object> abtestParam=null;
-        String midGroup =null;
-        String shareType =null;
-        if(appIdArr.contains(requestParam.getAppType())){
+            List<Map<String,Object>> mapList=(List)requestParam.getAbExpInfo().get("ab_test002");
+            Map<String,List<JSONObject>> configMap=new HashMap<>();
+            //该用户所有实验合集
+            Set<String> expCodes=new HashSet<>();
+            for(Map<String,Object> map:mapList){
+                String expCode=map.getOrDefault("abExpCode","").toString();
+                expCodes.add(expCode);
+                if("555".equals(expCode)){
+                    configMap=JSONObject.parseObject(map.get("configValue").toString(),Map.class);
+                }
+            }
             //先判断是否开启实验 和是否不出广告时间 而后判断默认0-8
             //先判断是否开启实验 和是否不出广告时间 而后判断默认0-8
             //不出广告时间判定
             //不出广告时间判定
-            String[] abParamArr = abConfig.getAbParams(requestParam.getAbTestCode(), requestParam.getAbExpInfo());
-            if (abParamArr == null) {
-                abParamArr= NewExpUserGroupConfig.newExpUserGroupMap.get(requestParam.getAppType().toString());
+            int hourOfDay= DateUtils.getCurrentHour();
+            Boolean condition1=abTestConfigContainer.inAdTimeTest(requestParam.getAbExpInfo());
+            Boolean condition2=abTestConfigContainer.containsCode(configMap,requestParam.getAbTestCode());
+            if(condition1
+                    &&
+                    condition2
+                    &&
+                    abTestConfigContainer.inWithoutAdTime(configMap,requestParam.getAbTestCode(),hourOfDay)){
+                result.put("ad_predict", 1);
+                result.put("no_ad_strategy", "no_ad_time_with_time_plan");
+                return result;
+            } else if (
+                    (!condition1 || (condition1 && !condition2))
+                            &&
+                            (0 <= hourOfDay && hourOfDay < 8)) {
+                result.put("ad_predict", 1);
+                result.put("no_ad_strategy", "no_ad_time_with_fixed_time");
+                return result;
+            }
+            String abtestId=null;
+            String abTestConfigTag=null;
+            Map<String, Object> abtestParam=null;
+            String midGroup =null;
+            String shareType =null;
+
+            String[] appIdArr=oldExpGroupAppId.split(",");
+            List<String> appIdList=Arrays.asList(appIdArr);
+            if(appIdList.contains(requestParam.getAppType().toString())){
+//            if(appIdArr.contains(requestParam.getAppType())){
+                String[] abParamArr = abConfig.getAbParams(requestParam.getAbTestCode(), requestParam.getAbExpInfo());
                 if (abParamArr == null) {
                 if (abParamArr == null) {
+                    abParamArr= NewExpUserGroupConfig.newExpUserGroupMap.get(requestParam.getAppType().toString());
+                    if (abParamArr == null) {
+                        result.put("msg", "abConfig_error");
+                        return result;
+                    }
+                }
+                abtestId = abParamArr[0];
+                abTestConfigTag = abParamArr[1];
+                HashMap<String, Map<String, Object>> abConfigMap = abConfig.getAbConfigMap();
+                abtestParam = abConfigMap.getOrDefault(abtestId + "-" + abTestConfigTag, null);
+                if (abtestParam == null) {
                     result.put("msg", "abConfig_error");
                     result.put("msg", "abConfig_error");
                     return result;
                     return result;
                 }
                 }
-            }
-            abtestId = abParamArr[0];
-            abTestConfigTag = abParamArr[1];
-            HashMap<String, Map<String, Object>> abConfigMap = abConfig.getAbConfigMap();
-            abtestParam = abConfigMap.getOrDefault(abtestId + "-" + abTestConfigTag, null);
-            if (abtestParam == null) {
-                result.put("msg", "abConfig_error");
-                return result;
-            }
-            // Determine the group to which mid belongs
-            String groupClassKey = (String) abtestParam.get("group_class_key");
-            String midGroupKeyName = RuleRedisKeyConst.KEY_NAME_PREFIX_MID_GROUP + groupClassKey + ":" + requestParam.getMid();
-            midGroup = redisHelper.getString(midGroupKeyName);
+                // Determine the group to which mid belongs
+                String groupClassKey = (String) abtestParam.get("group_class_key");
+                String midGroupKeyName = RuleRedisKeyConst.KEY_NAME_PREFIX_MID_GROUP + groupClassKey + ":" + requestParam.getMid();
+                midGroup = redisHelper.getString(midGroupKeyName);
 //        if(expCodes.contains(adPredict90DNoShareUserExpCode)){
 //        if(expCodes.contains(adPredict90DNoShareUserExpCode)){
 //            midGroup = redisHelper.getString(RuleRedisKeyConst.KEY_NAME_PREFIX_90_SHARE_TYPE+requestParam.getMid());
 //            midGroup = redisHelper.getString(RuleRedisKeyConst.KEY_NAME_PREFIX_90_SHARE_TYPE+requestParam.getMid());
 //        }else {
 //        }else {
 //            midGroup = redisHelper.getString(midGroupKeyName);
 //            midGroup = redisHelper.getString(midGroupKeyName);
 //        }
 //        }
-            //没有时为新用户或者无分享用户
-            shareType =midGroup;
-            if (midGroup == null) {
-                midGroup = "mean_group";
-                shareType="noShare";
-            }
-            String[] noAdMidGroupList = new String[0];
-            noAdMidGroupList = ((JSONArray) abtestParam.get("no_ad_mid_group_list")).toArray(noAdMidGroupList);
-
-            boolean inNoAdGroup = false;
-            for (String group : noAdMidGroupList) {
-                if (group.equals(midGroup)) {
-                    inNoAdGroup = true;
-                    break;
+                //没有时为新用户或者无分享用户
+                shareType =midGroup;
+                if (midGroup == null) {
+                    midGroup = "mean_group";
+                    shareType="noShare";
+                }
+                String[] noAdMidGroupList = new String[0];
+                noAdMidGroupList = ((JSONArray) abtestParam.get("no_ad_mid_group_list")).toArray(noAdMidGroupList);
+
+                boolean inNoAdGroup = false;
+                for (String group : noAdMidGroupList) {
+                    if (group.equals(midGroup)) {
+                        inNoAdGroup = true;
+                        break;
+                    }
+                }
+                //不出广告组
+                if (inNoAdGroup) {
+                    // User is in the no-ad group, no ad should be shown
+                    result.put("mid_group", midGroup);
+                    result.put("ad_predict", 1);
+                    result.put("no_ad_strategy", "no_ad_mid_group_with_video");
+                    return result;
+                }
+                //top1广告不出视频
+                Map<String, List<String>> noAdGroupWithVideoMapping = (Map) abtestParam.getOrDefault("no_ad_group_with_video_mapping", new HashMap<>());
+                if (noAdGroupWithVideoMapping.keySet().contains(midGroup)
+                        &&
+                        topOneVideoContainer.inNoAdTopVideo(requestParam.getAppType().longValue(), requestParam.getVideoId())
+                ) {
+                    result.put("mid_group", midGroup);
+                    result.put("ad_predict", 1);
+                    result.put("no_ad_strategy", "no_ad_mid_group_with_video");
+                    return result;
+                }
+            }else {
+                String midGroupKeyName = RuleRedisKeyConst.KEY_NAME_PREFIX_MID_GROUP +  "class1:" + requestParam.getMid();
+                midGroup = redisHelper.getString(midGroupKeyName);
+                shareType =midGroup;
+                if (midGroup == null) {
+                    midGroup = "mean_group";
+                    shareType="noShare";
                 }
                 }
             }
             }
-            //不出广告组
-            if (inNoAdGroup) {
-                // User is in the no-ad group, no ad should be shown
-                result.put("mid_group", midGroup);
-                result.put("ad_predict", 1);
-                result.put("no_ad_strategy", "no_ad_mid_group_with_video");
-                return result;
-            }
-            //top1广告不出视频
-            Map<String, List<String>> noAdGroupWithVideoMapping = (Map) abtestParam.getOrDefault("no_ad_group_with_video_mapping", new HashMap<>());
-            if (noAdGroupWithVideoMapping.keySet().contains(midGroup)
-                    &&
-                    topOneVideoContainer.inNoAdTopVideo(requestParam.getAppType().longValue(), requestParam.getVideoId())
-            ) {
-                result.put("mid_group", midGroup);
-                result.put("ad_predict", 1);
-                result.put("no_ad_strategy", "no_ad_mid_group_with_video");
-                return result;
-            }
-        }else {
-            String midGroupKeyName = RuleRedisKeyConst.KEY_NAME_PREFIX_MID_GROUP +  "class1:" + requestParam.getMid();
-            midGroup = redisHelper.getString(midGroupKeyName);
-            shareType =midGroup;
-            if (midGroup == null) {
-                midGroup = "mean_group";
-                shareType="noShare";
-            }
-        }
 
 
 
 
 
 
-        //市-中文
-        requestParam.setRegion(requestParam.getRegion().replace("省", ""));
-        requestParam.setCity(requestParam.getCity().replace("市", ""));
-        //设置信息
-        ThresholdPredictModelParam modelParam = ThresholdPredictModelParam.builder()
-                .build();
-        BeanUtils.copyProperties(requestParam, modelParam);
-        modelParam.setDate(new Date());
-        modelParam.setAbtestId(abtestId);
-        modelParam.setAbTestConfigTag(abTestConfigTag);
-        modelParam.setAbtestParam(abtestParam);
-        modelParam.setMidGroup(midGroup);
-        modelParam.setExtraParam(new HashMap<>());
-        modelParam.addUserExtraFuture("shareType",shareType);
-        setExtraParam(modelParam);
+            //市-中文
+            requestParam.setRegion(requestParam.getRegion().replace("省", ""));
+            requestParam.setCity(requestParam.getCity().replace("市", ""));
+            //设置信息
+            ThresholdPredictModelParam modelParam = ThresholdPredictModelParam.builder()
+                    .build();
+            BeanUtils.copyProperties(requestParam, modelParam);
+            modelParam.setDate(new Date());
+            modelParam.setAbtestId(abtestId);
+            modelParam.setAbTestConfigTag(abTestConfigTag);
+            modelParam.setAbtestParam(abtestParam);
+            modelParam.setMidGroup(midGroup);
+            modelParam.setExtraParam(new HashMap<>());
+            modelParam.addUserExtraFuture("shareType",shareType);
+            setExtraParam(modelParam);
 
 
-          if(expCodes.contains("599")|| (expCodes.contains(NewExpInfoHelper.flagId)&&NewExpInfoHelper.checkInNewExpGroupAndSetParamIfIn(
-                  requestParam.getAppType().toString(),requestParam.getNewExpGroup(),"599",modelParam))){
+            if(expCodes.contains("599")||
+                    (expCodes.contains(NewExpInfoHelper.flagId)&&NewExpInfoHelper.checkInNewExpGroupAndSetParamIfIn(
+                            requestParam.getAppType().toString(),requestParam.getNewExpGroup(),"599",modelParam))){
 //        if(randomModelExpCode!=null){
 //        if(randomModelExpCode!=null){
 //            modelParam.addUserExtraFuture("randomModelKey",ExpCodeEnum.valueOfExpCode(randomModelExpCode).getRandomModelKey());
 //            modelParam.addUserExtraFuture("randomModelKey",ExpCodeEnum.valueOfExpCode(randomModelExpCode).getRandomModelKey());
-            result = ThresholdModelContainer.
-                    getThresholdPredictModel("random")
-                    .predict(modelParam);
-        }else if(inExpList(expCodes,adPredictImmersionExpCode)
-                  ||
-                  (expCodes.contains(NewExpInfoHelper.flagId)&&NewExpInfoHelper.checkInNewExpGroupAndSetParamIfIn(
-                          requestParam.getAppType().toString(),requestParam.getNewExpGroup(),"607",modelParam))){
+                result = ThresholdModelContainer.
+                        getThresholdPredictModel("random")
+                        .predict(modelParam);
+            }else if(inExpList(expCodes,adPredictImmersionExpCode)
+                    ||
+                    (expCodes.contains(NewExpInfoHelper.flagId)&&NewExpInfoHelper.checkInNewExpGroupAndSetParamIfIn(
+                            requestParam.getAppType().toString(),requestParam.getNewExpGroup(),"607",modelParam))){
 //        if(randomModelExpCode!=null){
 //        if(randomModelExpCode!=null){
 //            modelParam.addUserExtraFuture("randomModelKey",ExpCodeEnum.valueOfExpCode(randomModelExpCode).getRandomModelKey());
 //            modelParam.addUserExtraFuture("randomModelKey",ExpCodeEnum.valueOfExpCode(randomModelExpCode).getRandomModelKey());
-            result = ThresholdModelContainer.
-                    getThresholdPredictModel("immersion")
-                    .predict(modelParam);
-        }
-        else {
-            Object thresholdMixFunc = abtestParam.getOrDefault("threshold_mix_func", "basic");
-            result = ThresholdModelContainer.
-                    getThresholdPredictModel(thresholdMixFunc.toString())
-                    .predict(modelParam);
+                result = ThresholdModelContainer.
+                        getThresholdPredictModel("immersion")
+                        .predict(modelParam);
+            }
+            else {
+                Object thresholdMixFunc = abtestParam.getOrDefault("threshold_mix_func", "basic");
+                result = ThresholdModelContainer.
+                        getThresholdPredictModel(thresholdMixFunc.toString())
+                        .predict(modelParam);
+            }
+
+            return result;
+        }catch (Exception e){
+            log.error("svc=adPredict appType={} group={} newGroup={} logTraceId={}"
+                    ,requestParam.getAppType(),requestParam.getAbTestCode(),requestParam.getNewExpGroup(),requestParam.getLogTraceId());
+            result.put("ad_predict", 1);
+            result.put("no_ad_strategy", "error");
+            return result;
         }
         }
-        result.put("logTraceId", requestParam.getLogTraceId());
-        return result;
+
     }
     }
 
 
     public Map<String, Object> adRecommendPredictByRoiModel(RoiPredictModelRequestParam requestParam) {
     public Map<String, Object> adRecommendPredictByRoiModel(RoiPredictModelRequestParam requestParam) {