|
|
@@ -0,0 +1,153 @@
|
|
|
+package com.tzld.piaoquan.ad.engine.service.predict.v2;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.ctrip.framework.apollo.spring.annotation.ApolloJsonValue;
|
|
|
+import com.tzld.piaoquan.ad.engine.commons.util.JSONUtils;
|
|
|
+import com.tzld.piaoquan.ad.engine.service.predict.param.request.ThresholdPredictModelRequestParam;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class PredictStrategyBy823 extends BasicPredict {
|
|
|
+
|
|
|
+ @Value("${experiment.823.ad.hour:0,8}")
|
|
|
+ private String experiment823WithAdHour;
|
|
|
+
|
|
|
+ @ApolloJsonValue("${experiment.823.config:{}}")
|
|
|
+ private JSONObject experiment823Config;
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String name() {
|
|
|
+ return "823";
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> predict(PredictContext ctx) {
|
|
|
+
|
|
|
+ String rootSessionId = ctx.getRootSessionId();
|
|
|
+ String userLayer = ctx.getUserLayer();
|
|
|
+ String shareType = ctx.getShareType();
|
|
|
+
|
|
|
+ double score = this.calcScoreByMid(ctx.getMid());
|
|
|
+ String tail = rootSessionId.substring(rootSessionId.length() - 1);
|
|
|
+ shareType = ctx.getShareType()
|
|
|
+ .replace("return", "")
|
|
|
+ .replace("mids", "");
|
|
|
+
|
|
|
+ Map<String, Object> returnMap = new HashMap<>();
|
|
|
+
|
|
|
+
|
|
|
+ returnMap.putAll(rtnAdPredict(ctx));
|
|
|
+ returnMap.put("model", this.name());
|
|
|
+
|
|
|
+ returnMap.put("score", score);
|
|
|
+ returnMap.put("userLayer", userLayer);
|
|
|
+
|
|
|
+ JSONObject logJson = new JSONObject();
|
|
|
+ logJson.putAll(returnMap);
|
|
|
+ logJson.put("mid", ctx.getMid());
|
|
|
+ logJson.put("appType", ctx.getAppType());
|
|
|
+ logJson.put("rootSessionIdTail", tail);
|
|
|
+ logJson.put("shareType", shareType);
|
|
|
+
|
|
|
+ logJson.put("expId", "userLayerRootSessionIdTailExp");
|
|
|
+ logJson.put("adPlatformType", ctx.getAdPlatformType());
|
|
|
+ logJson.put("abCode", ctx.getAdAbCode());
|
|
|
+ logJson.put("rootSessionId", ctx.getRootSessionId());
|
|
|
+
|
|
|
+ log.info("广告跳出选择 -- 823实验结果: {}, 参数: {}",
|
|
|
+ JSONUtils.toJson(returnMap), logJson.toJSONString());
|
|
|
+
|
|
|
+ return returnMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void addConfigExt(ThresholdPredictModelRequestParam params, Map<String, Object> resultMap) {
|
|
|
+ String channel = "*";
|
|
|
+ List<String> channels = new ArrayList<>(experiment823Config.keySet());
|
|
|
+ for (String s : channels) {
|
|
|
+ if (params.getRootSourceId().startsWith(s)) {
|
|
|
+ channel = s;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ JSONObject LayerConfig = experiment823Config.getJSONObject(channel);
|
|
|
+ JSONObject config;
|
|
|
+ if (params.getUserShareDepth() == 0) {
|
|
|
+ config = LayerConfig.getJSONObject("首层");
|
|
|
+ } else {
|
|
|
+ config = LayerConfig.getJSONObject("非首层");
|
|
|
+ }
|
|
|
+
|
|
|
+ resultMap.put("headVideo", config.getJSONObject("headVideo"));
|
|
|
+ resultMap.put("recommend", config.getJSONObject("recommend"));
|
|
|
+ }
|
|
|
+
|
|
|
+ public boolean in823Ab(ThresholdPredictModelRequestParam params, Set<String> expCodes, int hourOfDay) {
|
|
|
+ if (params.getUserShareDepth() != 0 || !expCodes.contains("823")) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ boolean isIn823Time = false;
|
|
|
+ try {
|
|
|
+ String[] split = experiment823WithAdHour.split(",");
|
|
|
+ if (Integer.parseInt(split[0]) <= hourOfDay && hourOfDay < Integer.parseInt(split[1])) {
|
|
|
+ isIn823Time = true;
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("experiment823WithAdHour配置异常", e);
|
|
|
+ }
|
|
|
+ if (!isIn823Time) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ String channel = "*";
|
|
|
+ List<String> channels = new ArrayList<>(experiment823Config.keySet());
|
|
|
+ for (String s : channels) {
|
|
|
+ if (params.getRootSourceId().startsWith(s)) {
|
|
|
+ channel = s;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ JSONObject LayerConfig = experiment823Config.getJSONObject(channel);
|
|
|
+ JSONObject config;
|
|
|
+ if (params.getUserShareDepth() == 0) {
|
|
|
+ config = LayerConfig.getJSONObject("首层");
|
|
|
+ } else {
|
|
|
+ config = LayerConfig.getJSONObject("非首层");
|
|
|
+ }
|
|
|
+ JSONArray rootSessionIds = config.getJSONArray("rootSessionId");
|
|
|
+ if (Objects.isNull(rootSessionIds) || !rootSessionIds.contains(getGroup(params.getRootSessionId()))) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ JSONArray putScenes = config.getJSONArray("putScene");
|
|
|
+ if (Objects.isNull(putScenes)) {
|
|
|
+ if (channel.equals("*")) {
|
|
|
+ return false;
|
|
|
+ } else {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ boolean isScene = false;
|
|
|
+ for (Object putScene : putScenes) {
|
|
|
+ if (params.getRootSourceId().startsWith((String) putScene)) {
|
|
|
+ isScene = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return isScene;
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getGroup(String rootSessionId) {
|
|
|
+ if (StringUtils.isBlank(rootSessionId)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ return String.valueOf(rootSessionId.charAt(rootSessionId.length() - 1));
|
|
|
+ }
|
|
|
+}
|
|
|
+
|