|
@@ -11,7 +11,9 @@ import com.tzld.piaoquan.ad.engine.commons.redis.AdRedisHelper;
|
|
|
import com.tzld.piaoquan.ad.engine.commons.redis.AlgorithmRedisHelper;
|
|
|
import com.tzld.piaoquan.ad.engine.commons.score.ScoreParam;
|
|
|
import com.tzld.piaoquan.ad.engine.commons.util.DateUtils;
|
|
|
+import com.tzld.piaoquan.ad.engine.commons.util.NumUtil;
|
|
|
import com.tzld.piaoquan.ad.engine.commons.util.ObjUtil;
|
|
|
+import com.tzld.piaoquan.ad.engine.service.entity.CorrectCpaParam;
|
|
|
import com.tzld.piaoquan.ad.engine.service.entity.GuaranteeView;
|
|
|
import com.tzld.piaoquan.ad.engine.service.feature.Feature;
|
|
|
import com.tzld.piaoquan.ad.engine.service.feature.FeatureService;
|
|
@@ -37,8 +39,31 @@ public abstract class RankStrategyBasic implements RankStrategy {
|
|
|
|
|
|
@Value("${guarantee.exp:742}")
|
|
|
protected String guaranteeExp;
|
|
|
+
|
|
|
@ApolloJsonValue("${alpha:1.0}")
|
|
|
protected Double alpha;
|
|
|
+
|
|
|
+ @Value("${correct.cpa.exp.1:}")
|
|
|
+ protected String correctCpaExp1;
|
|
|
+
|
|
|
+ @Value("${correct.cpa.exp.2:}")
|
|
|
+ protected String correctCpaExp2;
|
|
|
+
|
|
|
+ @Value("${correct.cpa.alpha.1:1.0}")
|
|
|
+ protected Double correctCpaAlpha1;
|
|
|
+
|
|
|
+ @Value("${correct.cpa.beta.1:1.0}")
|
|
|
+ protected Double correctCpaBeta1;
|
|
|
+
|
|
|
+ @Value("${correct.cpa.alpha.2:0.7}")
|
|
|
+ protected Double correctCpaAlpha2;
|
|
|
+
|
|
|
+ @Value("${correct.cpa.beta.2:0.2}")
|
|
|
+ protected Double correctCpaBeta2;
|
|
|
+
|
|
|
+ @Value("${correct.cpa.view:1000}")
|
|
|
+ protected Integer correctCpaView;
|
|
|
+
|
|
|
@Autowired
|
|
|
private FeatureService featureService;
|
|
|
@Autowired
|
|
@@ -48,6 +73,15 @@ public abstract class RankStrategyBasic implements RankStrategy {
|
|
|
|
|
|
String adPlatformGuaranteeKey = "ad:platform:guarantee:data:{date}:{adverId}";
|
|
|
|
|
|
+ String adCustomerLayerHourKey = "ad:platform:customer:hour:{layer}:{clazz}:{customerId}";
|
|
|
+
|
|
|
+ String adVerLayerHourKey = "ad:platform:adver:hour:{layer}:{clazz}:{adverId}";
|
|
|
+
|
|
|
+ String adCustomerLayerDayKey = "ad:platform:customer:day:{layer}:{clazz}:{customerId}";
|
|
|
+
|
|
|
+ String adVerLayerDayKey = "ad:platform:adver:day:{layer}:{clazz}:{adverId}";
|
|
|
+
|
|
|
+
|
|
|
protected static final List<String> hasChannelScenes = new ArrayList<String>() {{
|
|
|
add("DaiTou");
|
|
|
add("GzhTouLiu");
|
|
@@ -271,6 +305,119 @@ public abstract class RankStrategyBasic implements RankStrategy {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ protected Map<Long, CorrectCpaParam> getCorrectCpaParamMap(RankRecommendRequestParam request, ScoreParam scoreParam) {
|
|
|
+ Map<String, String> userLayer = this.getUserLayer(request.getMid());
|
|
|
+
|
|
|
+ String layer = userLayer.getOrDefault("layer", "无曝光");
|
|
|
+ String clazz = userLayer.getOrDefault("class", "近期未出现");
|
|
|
+
|
|
|
+ if (request.getIsFilterUser()) {
|
|
|
+ layer = layer + "-炸";
|
|
|
+ }
|
|
|
+
|
|
|
+ String redisAdCustomerLayerHourKey = adCustomerLayerHourKey.replace("{layer}", layer).replace("{clazz}", clazz);
|
|
|
+ String redisAdVerLayerHourKey = adVerLayerHourKey.replace("{layer}", layer).replace("{clazz}", clazz);
|
|
|
+ String redisAadCustomerLayerDayKey = adCustomerLayerDayKey.replace("{layer}", layer).replace("{clazz}", clazz);
|
|
|
+ String redisAdVerLayerDayKey = adVerLayerDayKey.replace("{layer}", layer).replace("{clazz}", clazz);
|
|
|
+
|
|
|
+
|
|
|
+ Map<Long, CorrectCpaParam> resultMap = new HashMap<>();
|
|
|
+ try {
|
|
|
+ List<Long> customerIds = request.getAdIdList().stream().map(AdPlatformCreativeDTO::getCustomerId).distinct().collect(Collectors.toList());
|
|
|
+ List<String> customerLayerHourKeys = customerIds.stream().map(e -> redisAdCustomerLayerHourKey.replace("{customerId}", String.valueOf(e))).collect(Collectors.toList());
|
|
|
+ List<String> customerLayerHourValues = adRedisHelper.mget(customerLayerHourKeys);
|
|
|
+ List<String> customerLayerDayKeys = customerIds.stream().map(e -> redisAadCustomerLayerDayKey.replace("{customerId}", String.valueOf(e))).collect(Collectors.toList());
|
|
|
+ List<String> customerLayerDayValues = adRedisHelper.mget(customerLayerDayKeys);
|
|
|
+
|
|
|
+ Map<Long, JSONObject> customerLayerMap = new HashMap<>();
|
|
|
+ for (int i = 0; i < customerIds.size(); i++) {
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ if (StringUtils.isNotEmpty(customerLayerHourValues.get(i))) {
|
|
|
+ JSONObject jsonObject1 = JSONObject.parseObject(customerLayerHourValues.get(i));
|
|
|
+ jsonObject.put("realCtcvrHour", jsonObject1.get("ctcvr"));
|
|
|
+ jsonObject.put("pCtcvrHour", jsonObject1.get("pCtcvr"));
|
|
|
+ jsonObject.put("viewsHour", jsonObject1.get("views"));
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(customerLayerDayValues.get(i))) {
|
|
|
+ JSONObject jsonObject1 = JSONObject.parseObject(customerLayerDayValues.get(i));
|
|
|
+ jsonObject.put("realCtcvrDay", jsonObject1.get("ctcvr"));
|
|
|
+ jsonObject.put("pCtcvrDay", jsonObject1.get("pCtcvr"));
|
|
|
+ jsonObject.put("viewsDay", jsonObject1.get("views"));
|
|
|
+ }
|
|
|
+ customerLayerMap.put(customerIds.get(i), jsonObject);
|
|
|
+ }
|
|
|
+ List<String> adVerIds = request.getAdIdList().stream().map(AdPlatformCreativeDTO::getAdVerId).distinct().collect(Collectors.toList());
|
|
|
+ List<String> adVerLayerHourKeys = adVerIds.stream().map(e -> redisAdVerLayerHourKey.replace("{adverId}", e)).collect(Collectors.toList());
|
|
|
+ List<String> adVerLayerHourValues = adRedisHelper.mget(adVerLayerHourKeys);
|
|
|
+ List<String> adVerLayerDayKeys = adVerIds.stream().map(e -> redisAdVerLayerDayKey.replace("{adverId}", e)).collect(Collectors.toList());
|
|
|
+ List<String> adVerLayerDayValues = adRedisHelper.mget(adVerLayerDayKeys);
|
|
|
+ Map<String, JSONObject> adVerLayerMap = new HashMap<>();
|
|
|
+ for (int i = 0; i < adVerIds.size(); i++) {
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ if (StringUtils.isNotEmpty(adVerLayerHourValues.get(i))) {
|
|
|
+ JSONObject jsonObject1 = JSONObject.parseObject(adVerLayerHourValues.get(i));
|
|
|
+ jsonObject.put("realCtcvrHour", jsonObject1.get("ctcvr"));
|
|
|
+ jsonObject.put("pCtcvrHour", jsonObject1.get("pCtcvr"));
|
|
|
+ jsonObject.put("viewsHour", jsonObject1.get("views"));
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(adVerLayerDayValues.get(i))) {
|
|
|
+ JSONObject jsonObject1 = JSONObject.parseObject(adVerLayerDayValues.get(i));
|
|
|
+ jsonObject.put("realCtcvrDay", jsonObject1.get("ctcvr"));
|
|
|
+ jsonObject.put("pCtcvrDay", jsonObject1.get("pCtcvr"));
|
|
|
+ jsonObject.put("viewsDay", jsonObject1.get("views"));
|
|
|
+ }
|
|
|
+ adVerLayerMap.put(adVerIds.get(i), jsonObject);
|
|
|
+ }
|
|
|
+ for (AdPlatformCreativeDTO adPlatformCreativeDTO : request.getAdIdList()) {
|
|
|
+ Long creativeId = adPlatformCreativeDTO.getCreativeId();
|
|
|
+ Long customerId = adPlatformCreativeDTO.getCustomerId();
|
|
|
+ JSONObject jsonObject;
|
|
|
+ if (customerId != null && customerId != 0 && customerLayerMap.containsKey(customerId)) {
|
|
|
+ jsonObject = customerLayerMap.get(customerId);
|
|
|
+ } else {
|
|
|
+ jsonObject = adVerLayerMap.get(adPlatformCreativeDTO.getAdVerId());
|
|
|
+ }
|
|
|
+ CorrectCpaParam correctCpaParam = new CorrectCpaParam();
|
|
|
+ Integer view = jsonObject.getInteger("view");
|
|
|
+ Double realCtcvrHour = jsonObject.getDouble("realCtcvrHour");
|
|
|
+ Double pCtcvrHour = jsonObject.getDouble("pCtcvrHour");
|
|
|
+ Double realCtcvrDay = jsonObject.getDouble("realCtcvrDay");
|
|
|
+ Double pCtcvrDay = jsonObject.getDouble("pCtcvrDay");
|
|
|
+ correctCpaParam.setRealCtcvrHour(realCtcvrHour);
|
|
|
+ correctCpaParam.setPCtcvrHour(pCtcvrHour);
|
|
|
+ correctCpaParam.setRealCtcvrDay(realCtcvrDay);
|
|
|
+ correctCpaParam.setPCtcvrDay(pCtcvrDay);
|
|
|
+ correctCpaParam.setView(view);
|
|
|
+ double correctionFactor = 1;
|
|
|
+ //曝光数小于目标曝光数,不进行修正
|
|
|
+ if (view < correctCpaView) {
|
|
|
+ correctCpaParam.setCorrectionFactor(correctionFactor);
|
|
|
+ resultMap.put(creativeId, correctCpaParam);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (realCtcvrHour != null && pCtcvrHour != null && realCtcvrDay != null && pCtcvrDay != null) {
|
|
|
+ if (scoreParam.getExpCodeSet().contains(correctCpaExp2)) {
|
|
|
+ correctionFactor = (1 - correctCpaAlpha2 - correctCpaBeta2) +
|
|
|
+ NumUtil.div(realCtcvrHour, pCtcvrHour) * correctCpaAlpha2 +
|
|
|
+ NumUtil.div(realCtcvrDay, pCtcvrDay) * correctCpaBeta2;
|
|
|
+ } else {
|
|
|
+ correctionFactor = Math.pow(NumUtil.div(realCtcvrHour, pCtcvrHour), correctCpaAlpha1) *
|
|
|
+ Math.pow(NumUtil.div(realCtcvrDay, pCtcvrDay), correctCpaBeta1);
|
|
|
+ }
|
|
|
+ if (correctionFactor <= 0) {
|
|
|
+ correctionFactor = 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ correctCpaParam.setCorrectionFactor(correctionFactor);
|
|
|
+ resultMap.put(creativeId, correctCpaParam);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("getCorrectCpaParamMap error", e);
|
|
|
+ }
|
|
|
+ return resultMap;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
protected AdRankItem creativeCovertRankItem(AdPlatformCreativeDTO dto, RankRecommendRequestParam request, Set<String> noApiAdVerIds) {
|
|
|
AdRankItem adRankItem = new AdRankItem();
|
|
|
adRankItem.setAdId(dto.getCreativeId());
|