|
@@ -68,175 +68,186 @@ public class PredictModelServiceImpl implements PredictModelService {
|
|
|
|
|
|
|
|
|
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
|
|
|
//不出广告时间判定
|
|
|
- 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;
|
|
|
+ if(appIdArr.contains(requestParam.getAppType())){
|
|
|
+
|
|
|
+ String[] abParamArr = abConfig.getAbParams(requestParam.getAbTestCode(), requestParam.getAbExpInfo());
|
|
|
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");
|
|
|
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)){
|
|
|
// midGroup = redisHelper.getString(RuleRedisKeyConst.KEY_NAME_PREFIX_90_SHARE_TYPE+requestParam.getMid());
|
|
|
// }else {
|
|
|
// 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){
|
|
|
// 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){
|
|
|
// 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){
|
|
|
+ e.printStackTrace();
|
|
|
+ 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) {
|