|
@@ -16,7 +16,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;
|
|
@@ -29,7 +28,6 @@ import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.*;
|
|
|
-import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
|
|
@Service
|
|
|
public class PredictModelServiceImpl implements PredictModelService {
|
|
@@ -54,9 +52,12 @@ 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;
|
|
|
|
|
|
+ @Value("${ad.predict.share0.exp.code:000}")
|
|
|
+ private String adPredictNoShareUserExpCode;
|
|
|
+
|
|
|
@Value("${ad.predict.param.testIds:0}")
|
|
|
private String testIds;
|
|
|
@Value("${ad.predict.without.ad.video_ids:0}")
|
|
@@ -78,173 +79,28 @@ public class PredictModelServiceImpl implements PredictModelService {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- boolean isHit = false;
|
|
|
-
|
|
|
- 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);
|
|
|
- }
|
|
|
-
|
|
|
- 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);
|
|
|
- modelParam.setExtraParam(new HashMap<>());
|
|
|
- setExtraParam(modelParam);
|
|
|
- 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
|
|
@@ -262,6 +118,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) {
|
|
@@ -277,7 +153,6 @@ public class PredictModelServiceImpl implements PredictModelService {
|
|
|
requestParam.setAbTestCode("ab5");
|
|
|
}
|
|
|
|
|
|
-
|
|
|
HashMap<String, Map<String, Object>> abConfigMap = abConfig.getAbConfigMap();
|
|
|
Map<String, Object> abtestParam = abConfigMap.getOrDefault(abtestId + "-" + abTestConfigTag, null);
|
|
|
if (abtestParam == null) {
|
|
@@ -288,13 +163,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];
|
|
@@ -338,12 +215,29 @@ public class PredictModelServiceImpl implements PredictModelService {
|
|
|
modelParam.setAbtestParam(abtestParam);
|
|
|
modelParam.setMidGroup(midGroup);
|
|
|
modelParam.setExtraParam(new HashMap<>());
|
|
|
+ modelParam.addUserExtraFuture("shareType",shareType);
|
|
|
setExtraParam(modelParam);
|
|
|
- Object thresholdMixFunc = abtestParam.getOrDefault("threshold_mix_func", "basic");
|
|
|
- result = ThresholdModelContainer.
|
|
|
- getThresholdPredictModel(thresholdMixFunc.toString())
|
|
|
- .predict(modelParam);
|
|
|
|
|
|
+ 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;
|
|
|
}
|
|
|
|
|
@@ -375,7 +269,6 @@ public class PredictModelServiceImpl implements PredictModelService {
|
|
|
.predict(modelParam);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
public void setExtraParam(ThresholdPredictModelParam modelParam){
|
|
|
String[] ids=testIds.split(",");
|
|
|
List<String> idList=Arrays.asList(ids);
|