|
@@ -0,0 +1,88 @@
|
|
|
+package com.tzld.piaoquan.ad.engine.service.predict.v2;
|
|
|
+
|
|
|
+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.container.RandWContainer;
|
|
|
+import lombok.Data;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@Component
|
|
|
+public class RootSessionIdPredict extends BasicPredict {
|
|
|
+
|
|
|
+ @ApolloJsonValue("${root.session.id.tail.predict.config:[]}")
|
|
|
+ private List<ConfigItem> configItems;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> predict(PredictContext ctx) {
|
|
|
+ String rootSessionId = ctx.getRootSessionId();
|
|
|
+ if (CollectionUtils.isEmpty(configItems) || StringUtils.isEmpty(rootSessionId) || StringUtils.isEmpty(ctx.getShareType())) {
|
|
|
+ return Collections.emptyMap();
|
|
|
+ }
|
|
|
+
|
|
|
+ int hash = ctx.getMid().hashCode();
|
|
|
+ hash = hash < 0 ? -hash : hash;
|
|
|
+ double score = (hash + RandWContainer.getRandW()) % 100 / 100d;
|
|
|
+
|
|
|
+ String appType = ctx.getAppType();
|
|
|
+ String tail = rootSessionId.substring(rootSessionId.length() - 1);
|
|
|
+ String shareType = ctx.getShareType()
|
|
|
+ .replace("return", "")
|
|
|
+ .replace("mids", "");
|
|
|
+
|
|
|
+
|
|
|
+ for (ConfigItem item : configItems) {
|
|
|
+ if (item.getAppType().contains(appType) && item.getTail().contains(tail)) {
|
|
|
+ double threshold;
|
|
|
+ if (item.getConfig().containsKey(shareType)) {
|
|
|
+ threshold = item.getConfig().getOrDefault(shareType, 0d);
|
|
|
+ } else {
|
|
|
+ threshold = item.getConfig().getOrDefault("threshold", 0d);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (score < threshold) {
|
|
|
+ Map<String, Object> returnMap = rtnAdPredict(ctx);
|
|
|
+ returnMap.put("score", score);
|
|
|
+ returnMap.put("threshold", threshold);
|
|
|
+ returnMap.put("model", "rootSessionIdTailModel");
|
|
|
+
|
|
|
+ JSONObject logJson = new JSONObject();
|
|
|
+ logJson.putAll(returnMap);
|
|
|
+ logJson.put("mid", ctx.getMid());
|
|
|
+ logJson.put("appType", appType);
|
|
|
+ logJson.put("rootSessionIdTail", tail);
|
|
|
+ logJson.put("shareType", shareType);
|
|
|
+
|
|
|
+ logJson.put("expId", "rootSessionIdTailExp");
|
|
|
+ logJson.put("thresholdParamKey", shareType);
|
|
|
+ logJson.put("adPlatformType", ctx.getAdPlatformType());
|
|
|
+ logJson.put("abCode", ctx.getAdAbCode());
|
|
|
+ logJson.put("extraParam", ctx.getExpConfigMap());
|
|
|
+ logJson.put("configItem", item);
|
|
|
+
|
|
|
+ log.info("广告跳出选择 -- rootSessionId尾号实验结果: {}, 参数: {}",
|
|
|
+ JSONUtils.toJson(returnMap), logJson.toJSONString());
|
|
|
+
|
|
|
+ return returnMap;
|
|
|
+ } else {
|
|
|
+ return rtnNoAdPredict(ctx);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return Collections.emptyMap();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Data
|
|
|
+ private static class ConfigItem {
|
|
|
+ private Set<String> appType = new HashSet<>();
|
|
|
+ private Set<String> tail = new HashSet<>();
|
|
|
+ private Map<String, Double> config = new HashMap<>();
|
|
|
+ }
|
|
|
+}
|