|
@@ -2,11 +2,13 @@ package com.tzld.piaoquan.ad.engine.service.predict.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.alibaba.fastjson.TypeReference;
|
|
|
import com.google.common.reflect.TypeToken;
|
|
|
import com.tzld.piaoquan.ad.engine.commons.enums.AppTypeEnum;
|
|
|
import com.tzld.piaoquan.ad.engine.commons.redis.AlgorithmRedisHelper;
|
|
|
import com.tzld.piaoquan.ad.engine.commons.util.DateUtils;
|
|
|
import com.tzld.piaoquan.ad.engine.commons.util.JSONUtils;
|
|
|
+import com.tzld.piaoquan.ad.engine.commons.util.TimerWatchUtil;
|
|
|
import com.tzld.piaoquan.ad.engine.service.predict.config.RoiModelConfig;
|
|
|
import com.tzld.piaoquan.ad.engine.service.predict.constant.RuleRedisKeyConst;
|
|
|
import com.tzld.piaoquan.ad.engine.service.predict.PredictModelService;
|
|
@@ -15,7 +17,6 @@ import com.tzld.piaoquan.ad.engine.service.predict.container.AbTestConfigContain
|
|
|
import com.tzld.piaoquan.ad.engine.service.predict.container.ThresholdModelContainer;
|
|
|
import com.tzld.piaoquan.ad.engine.service.predict.container.TopOneVideoContainer;
|
|
|
import com.tzld.piaoquan.ad.engine.service.predict.param.RoiThresholdPredictModelParam;
|
|
|
-import com.tzld.piaoquan.ad.engine.service.predict.param.RuleParamHelper;
|
|
|
import com.tzld.piaoquan.ad.engine.service.predict.param.ThresholdPredictModelParam;
|
|
|
import com.tzld.piaoquan.ad.engine.service.predict.param.request.RoiPredictModelRequestParam;
|
|
|
import com.tzld.piaoquan.ad.engine.service.predict.param.request.ThresholdPredictModelRequestParam;
|
|
@@ -52,176 +53,57 @@ public class PredictModelServiceImpl implements PredictModelService {
|
|
|
|
|
|
@Value("${ad.predict.break.switch:false}")
|
|
|
private boolean adPredictBreakSwitch;
|
|
|
- @Value("${ad.predict.break.exp.code:0}")
|
|
|
+ @Value("${ad.predict.break.exp.code:570}")
|
|
|
private String adPredictBreakExpCode;
|
|
|
|
|
|
- public Map<String, Object> adPredict(ThresholdPredictModelRequestParam requestParam) {
|
|
|
+ @Value("${ad.predict.share0.exp.code:000}")
|
|
|
+ private String adPredictNoShareUserExpCode;
|
|
|
|
|
|
- boolean isHit = false;
|
|
|
+ @Value("${ad.predict.param.testIds:0}")
|
|
|
+ private String testIds;
|
|
|
+ @Value("${ad.predict.without.ad.video_ids:0}")
|
|
|
+ private String withoutAdVideoIds;
|
|
|
|
|
|
- try {
|
|
|
- JSONObject object = requestParam.getAbExpInfo();
|
|
|
- if (object != null) {
|
|
|
- JSONArray array = object.getJSONArray("ab_test002");
|
|
|
- if (array != null) {
|
|
|
- List<Map<String, String>> abExps = JSONUtils.fromJson(array.toJSONString(),
|
|
|
- new TypeToken<List<Map<String, String>>>() {
|
|
|
- }, Collections.emptyList());
|
|
|
- for (Map<String, String> abExpMap : abExps) {
|
|
|
- if (StringUtils.equals(abExpMap.get("abExpCode"), adPredictBreakExpCode)) {
|
|
|
- isHit = true;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
+ 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;
|
|
|
}
|
|
|
}
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("adPredict hit error", e);
|
|
|
}
|
|
|
|
|
|
- if (adPredictBreakSwitch || isHit) {
|
|
|
- return adPredictNew(requestParam);
|
|
|
- } else {
|
|
|
- return adPredictOld(requestParam);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public Map<String, Object> adPredictNew(ThresholdPredictModelRequestParam requestParam) {
|
|
|
- JSONObject object=requestParam.getAbExpInfo();
|
|
|
- //临时解决方案
|
|
|
- List<Map<String,Object>> mapList=(List)requestParam.getAbExpInfo().get("ab_test002");
|
|
|
- Map<String,List<JSONObject>> configMap=new HashMap<>();
|
|
|
- for(Map<String,Object> map:mapList){
|
|
|
- if("555".equals(map.getOrDefault("abExpCode",""))){
|
|
|
- configMap=JSONObject.parseObject(map.get("configValue").toString(),Map.class);
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
//先判断是否开启实验 和是否不出广告时间 而后判断默认0-8
|
|
|
+ //不出广告时间判定
|
|
|
Map<String,Object> result=new HashMap<>();
|
|
|
- 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[] abParamArr = abConfig.getAbParams(requestParam.getAbTestCode(), requestParam.getAbExpInfo());
|
|
|
- if (abParamArr == null) {
|
|
|
- result.put("msg", "abConfig_error");
|
|
|
- return result;
|
|
|
- }
|
|
|
- String abtestId = abParamArr[0];
|
|
|
- String abTestConfigTag = abParamArr[1];
|
|
|
-
|
|
|
- if("173".equals(abtestId)&&(requestParam.getAbTestCode().equals("ab3")||requestParam.getAbTestCode().equals("ab4"))){
|
|
|
- requestParam.setAbTestCode("ab5");
|
|
|
- }
|
|
|
- if("243".equals(abtestId)&&(requestParam.getAbTestCode().equals("ab1")||requestParam.getAbTestCode().equals("ab2")||requestParam.getAbTestCode().equals("ab3"))){
|
|
|
- requestParam.setAbTestCode("ab5");
|
|
|
- }
|
|
|
-
|
|
|
- HashMap<String, Map<String, Object>> abConfigMap = abConfig.getAbConfigMap();
|
|
|
- Map<String, Object> abtestParam = abConfigMap.getOrDefault(abtestId + "-" + abTestConfigTag, null);
|
|
|
- if (abtestParam == null) {
|
|
|
- result.put("msg", "abConfig_error");
|
|
|
- return result;
|
|
|
- }
|
|
|
- //市-中文
|
|
|
- requestParam.setRegion(requestParam.getRegion().replace("省", ""));
|
|
|
- requestParam.setCity(requestParam.getCity().replace("市", ""));
|
|
|
-
|
|
|
-
|
|
|
- // 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();
|
|
|
- String midGroup = redisHelper.getString(midGroupKeyName);
|
|
|
- if (midGroup == null) {
|
|
|
- midGroup = "mean_group";
|
|
|
- }
|
|
|
-
|
|
|
- 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;
|
|
|
- }
|
|
|
-
|
|
|
- //设置信息
|
|
|
- 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);
|
|
|
- result = ThresholdModelContainer.
|
|
|
- getThresholdPredictModel("modelV2")
|
|
|
- .predict(modelParam);
|
|
|
-
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
- public Map<String, Object> adPredictOld(ThresholdPredictModelRequestParam requestParam) {
|
|
|
-
|
|
|
- JSONObject object=requestParam.getAbExpInfo();
|
|
|
- //临时解决方案
|
|
|
List<Map<String,Object>> mapList=(List)requestParam.getAbExpInfo().get("ab_test002");
|
|
|
Map<String,List<JSONObject>> configMap=new HashMap<>();
|
|
|
+ //该用户所有实验合集
|
|
|
+ Set<String> expCodes=new HashSet<>();
|
|
|
+ boolean isHit = false;
|
|
|
for(Map<String,Object> map:mapList){
|
|
|
- if("555".equals(map.getOrDefault("abExpCode",""))){
|
|
|
+ String expCode=map.getOrDefault("abExpCode","").toString();
|
|
|
+ expCodes.add(expCode);
|
|
|
+ if("555".equals(expCode)){
|
|
|
configMap=JSONObject.parseObject(map.get("configValue").toString(),Map.class);
|
|
|
- break;
|
|
|
+ }
|
|
|
+ //判断570是否命中
|
|
|
+ if (StringUtils.equals(expCode, adPredictBreakExpCode)) {
|
|
|
+ isHit = true;
|
|
|
}
|
|
|
}
|
|
|
- //先判断是否开启实验 和是否不出广告时间 而后判断默认0-8
|
|
|
- Map<String,Object> result=new HashMap<>();
|
|
|
+
|
|
|
int hourOfDay= DateUtils.getCurrentHour();
|
|
|
Boolean condition1=abTestConfigContainer.inAdTimeTest(requestParam.getAbExpInfo());
|
|
|
Boolean condition2=abTestConfigContainer.containsCode(configMap,requestParam.getAbTestCode());
|
|
|
-
|
|
|
-
|
|
|
if(condition1
|
|
|
&&
|
|
|
condition2
|
|
@@ -239,6 +121,26 @@ public class PredictModelServiceImpl implements PredictModelService {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+ //人群选择算法判定-570
|
|
|
+// try {
|
|
|
+// JSONObject object = requestParam.getAbExpInfo();
|
|
|
+// if (object != null) {
|
|
|
+// JSONArray array = object.getJSONArray("ab_test002");
|
|
|
+// if (array != null) {
|
|
|
+// List<Map<String, String>> abExps = JSONUtils.fromJson(array.toJSONString(),
|
|
|
+// new TypeToken<List<Map<String, String>>>() {
|
|
|
+// }, Collections.emptyList());
|
|
|
+// for (Map<String, String> abExpMap : abExps) {
|
|
|
+// if (StringUtils.equals(abExpMap.get("abExpCode"), adPredictBreakExpCode)) {
|
|
|
+// isHit = true;
|
|
|
+// break;
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// } catch (Exception e) {
|
|
|
+// log.error("adPredict hit error", e);
|
|
|
+// }
|
|
|
|
|
|
String[] abParamArr = abConfig.getAbParams(requestParam.getAbTestCode(), requestParam.getAbExpInfo());
|
|
|
if (abParamArr == null) {
|
|
@@ -247,13 +149,12 @@ public class PredictModelServiceImpl implements PredictModelService {
|
|
|
}
|
|
|
String abtestId = abParamArr[0];
|
|
|
String abTestConfigTag = abParamArr[1];
|
|
|
- if("173".equals(abtestId)&&(requestParam.getAbTestCode().equals("ab3")||requestParam.getAbTestCode().equals("ab4"))){
|
|
|
- requestParam.setAbTestCode("ab5");
|
|
|
- }
|
|
|
- if("243".equals(abtestId)&&(requestParam.getAbTestCode().equals("ab1")||requestParam.getAbTestCode().equals("ab2")||requestParam.getAbTestCode().equals("ab3"))){
|
|
|
- requestParam.setAbTestCode("ab5");
|
|
|
- }
|
|
|
-
|
|
|
+// if("173".equals(abtestId)&&(requestParam.getAbTestCode().equals("ab3")||requestParam.getAbTestCode().equals("ab4"))){
|
|
|
+// requestParam.setAbTestCode("ab5");
|
|
|
+// }
|
|
|
+// if("243".equals(abtestId)&&(requestParam.getAbTestCode().equals("ab1")||requestParam.getAbTestCode().equals("ab2")||requestParam.getAbTestCode().equals("ab3"))){
|
|
|
+// requestParam.setAbTestCode("ab5");
|
|
|
+// }
|
|
|
|
|
|
HashMap<String, Map<String, Object>> abConfigMap = abConfig.getAbConfigMap();
|
|
|
Map<String, Object> abtestParam = abConfigMap.getOrDefault(abtestId + "-" + abTestConfigTag, null);
|
|
@@ -265,13 +166,15 @@ public class PredictModelServiceImpl implements PredictModelService {
|
|
|
requestParam.setRegion(requestParam.getRegion().replace("省", ""));
|
|
|
requestParam.setCity(requestParam.getCity().replace("市", ""));
|
|
|
|
|
|
-
|
|
|
// 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();
|
|
|
+ //没有时为新用户或者无分享用户
|
|
|
String midGroup = redisHelper.getString(midGroupKeyName);
|
|
|
+ String shareType =midGroup;
|
|
|
if (midGroup == null) {
|
|
|
midGroup = "mean_group";
|
|
|
+ shareType="noShare";
|
|
|
}
|
|
|
|
|
|
String[] noAdMidGroupList = new String[0];
|
|
@@ -314,10 +217,33 @@ public class PredictModelServiceImpl implements PredictModelService {
|
|
|
modelParam.setAbTestConfigTag(abTestConfigTag);
|
|
|
modelParam.setAbtestParam(abtestParam);
|
|
|
modelParam.setMidGroup(midGroup);
|
|
|
- Object thresholdMixFunc = abtestParam.getOrDefault("threshold_mix_func", "basic");
|
|
|
- result = ThresholdModelContainer.
|
|
|
- getThresholdPredictModel(thresholdMixFunc.toString())
|
|
|
- .predict(modelParam);
|
|
|
+ modelParam.setExtraParam(new HashMap<>());
|
|
|
+ modelParam.addUserExtraFuture("shareType",shareType);
|
|
|
+ setExtraParam(modelParam);
|
|
|
+ if(expCodes.contains("599")){
|
|
|
+ result = ThresholdModelContainer.
|
|
|
+ getThresholdPredictModel("random")
|
|
|
+ .predict(modelParam);
|
|
|
+ } else if (adPredictBreakSwitch || isHit) {
|
|
|
+ if(expCodes.contains(adPredictNoShareUserExpCode)&&"noShare".equals(shareType)){
|
|
|
+ result = ThresholdModelContainer.
|
|
|
+ getThresholdPredictModel("share0")
|
|
|
+ .predict(modelParam);
|
|
|
+ }else if(expCodes.contains(adPredictNoShareUserExpCode)&&"return25_nmids".equals(shareType)){
|
|
|
+ result.put("mid_group", midGroup);
|
|
|
+ result.put("ad_predict", 1);
|
|
|
+ result.put("no_ad_strategy", adPredictNoShareUserExpCode+"_"+midGroup);
|
|
|
+ }else {
|
|
|
+ result = ThresholdModelContainer.
|
|
|
+ getThresholdPredictModel("modelV2")
|
|
|
+ .predict(modelParam);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ Object thresholdMixFunc = abtestParam.getOrDefault("threshold_mix_func", "basic");
|
|
|
+ result = ThresholdModelContainer.
|
|
|
+ getThresholdPredictModel(thresholdMixFunc.toString())
|
|
|
+ .predict(modelParam);
|
|
|
+ }
|
|
|
|
|
|
return result;
|
|
|
}
|
|
@@ -350,4 +276,26 @@ public class PredictModelServiceImpl implements PredictModelService {
|
|
|
.predict(modelParam);
|
|
|
}
|
|
|
|
|
|
+ public void setExtraParam(ThresholdPredictModelParam modelParam){
|
|
|
+ String[] ids=testIds.split(",");
|
|
|
+ List<String> idList=Arrays.asList(ids);
|
|
|
+ List<Map<String,Object>> mapList=(List)modelParam.getAbExpInfo().get("ab_test002");
|
|
|
+ Collections.sort(mapList,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()) ;
|
|
|
+ int abExpCode2 =Integer.parseInt(map2.get("abExpCode").toString());
|
|
|
+ return Integer.compare(abExpCode1, abExpCode2);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ Map<String,Object> configMap;
|
|
|
+ for(Map<String,Object> map:mapList){
|
|
|
+ if(idList.contains(map.getOrDefault("abExpCode",""))){
|
|
|
+ configMap=JSONObject.parseObject(map.get("configValue").toString(),new TypeReference<Map<String,Object>>(){});
|
|
|
+ for(Map.Entry<String,Object> entry:configMap.entrySet()){
|
|
|
+ modelParam.getExtraParam().put(entry.getKey(),entry.getValue());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|