|
|
@@ -7,6 +7,7 @@ import com.tzld.piaoquan.ad.engine.commons.dto.AdPlatformCreativeDTO;
|
|
|
import com.tzld.piaoquan.ad.engine.commons.enums.CrowdLayerEnum;
|
|
|
import com.tzld.piaoquan.ad.engine.commons.enums.FilterTypeEnum;
|
|
|
import com.tzld.piaoquan.ad.engine.commons.enums.RedisPrefixEnum;
|
|
|
+import com.tzld.piaoquan.ad.engine.commons.helper.LayerCustomerFlowControlDataHelper;
|
|
|
import com.tzld.piaoquan.ad.engine.commons.param.RankRecommendRequestParam;
|
|
|
import com.tzld.piaoquan.ad.engine.commons.redis.AdRedisHelper;
|
|
|
import com.tzld.piaoquan.ad.engine.commons.redis.AlgorithmRedisHelper;
|
|
|
@@ -14,6 +15,8 @@ import com.tzld.piaoquan.ad.engine.commons.score.ScoreParam;
|
|
|
import com.tzld.piaoquan.ad.engine.commons.thread.ThreadPoolFactory;
|
|
|
import com.tzld.piaoquan.ad.engine.commons.util.DateUtils;
|
|
|
import com.tzld.piaoquan.ad.engine.commons.util.ObjUtil;
|
|
|
+import com.tzld.piaoquan.ad.engine.commons.util.RootSessionIdExpConfig;
|
|
|
+import com.tzld.piaoquan.ad.engine.commons.util.RootSessionIdTailUtil;
|
|
|
import com.tzld.piaoquan.ad.engine.service.entity.*;
|
|
|
import com.tzld.piaoquan.ad.engine.service.feature.Feature;
|
|
|
import com.tzld.piaoquan.ad.engine.service.feature.FeatureService;
|
|
|
@@ -46,6 +49,12 @@ public abstract class RankStrategyBasic implements RankStrategy {
|
|
|
@ApolloJsonValue("${h5.score.suppress:{}}")
|
|
|
private Map<String, Double> h5ScoreSuppress;
|
|
|
|
|
|
+ @ApolloJsonValue("${rerank.strategy.flow.control:{}}")
|
|
|
+ private Map<String, Double> flowControlParams;
|
|
|
+
|
|
|
+ @ApolloJsonValue("${rerank.root.session.id.tail.config:[]}")
|
|
|
+ private List<RootSessionIdExpConfig> rerankRootSessionIdConfig;
|
|
|
+
|
|
|
@ApolloJsonValue("${h5.score.suppress.customer.white:[]}")
|
|
|
private Set<Long> customerIdWhiteSet;
|
|
|
|
|
|
@@ -1329,4 +1338,93 @@ public abstract class RankStrategyBasic implements RankStrategy {
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ // rerank
|
|
|
+ protected void calRerankWeight(ScoreParam scoreParam, String layer, List<AdRankItem> items) {
|
|
|
+ try {
|
|
|
+ List<RootSessionIdExpConfig> expConfigs = RootSessionIdTailUtil.getRootSessionIdTailConfig(scoreParam, RootSessionIdTailUtil.reRankTailN, rerankRootSessionIdConfig);
|
|
|
+ if (expConfigs.isEmpty()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Set<String> hit = new HashSet<>();
|
|
|
+ for (RootSessionIdExpConfig expConfig : expConfigs) {
|
|
|
+ if (null != expConfig && null != expConfig.getConfig()) {
|
|
|
+ String rerankStrategy = expConfig.getConfig().get("rerank");
|
|
|
+ if (null == rerankStrategy || hit.contains(rerankStrategy)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ hit.add(rerankStrategy);
|
|
|
+ switch (rerankStrategy) {
|
|
|
+ case "flowControl":
|
|
|
+ calFlowControlWeight(layer, items);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("cal rerank weight error", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 控制流量
|
|
|
+ protected void calFlowControlWeight(String layer, List<AdRankItem> items) {
|
|
|
+ try {
|
|
|
+ if (org.springframework.util.CollectionUtils.isEmpty(flowControlParams)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ double cpmPow = flowControlParams.getOrDefault("cpmPow", 0.3);
|
|
|
+ double lowerCpmWeight = flowControlParams.getOrDefault("lowerCpmWeight", 1.0);
|
|
|
+ double upperCpmWeight = flowControlParams.getOrDefault("upperCpmWeight", 1.2);
|
|
|
+ double flowPow = flowControlParams.getOrDefault("flowPow", 1.2);
|
|
|
+ double lowerFlowWeight = flowControlParams.getOrDefault("lowerFlowWeight", 0.77);
|
|
|
+ double upperFlowWeight = flowControlParams.getOrDefault("upperFlowWeight", 1.0);
|
|
|
+
|
|
|
+ double hitViewRate = flowControlParams.getOrDefault("hitViewRate", 0.05);
|
|
|
+ double plusViewRate = flowControlParams.getOrDefault("plusViewRate", 20.0);
|
|
|
+ double viewRatePow = flowControlParams.getOrDefault("viewRatePow", 0.2);
|
|
|
+ double viewRateScale = flowControlParams.getOrDefault("viewRateScale", 0.5491);
|
|
|
+ for (AdRankItem item : items) {
|
|
|
+ double flowWeight = getFlowControlWeight(layer, item,
|
|
|
+ cpmPow, lowerCpmWeight, upperCpmWeight,
|
|
|
+ flowPow, lowerFlowWeight, upperFlowWeight,
|
|
|
+ hitViewRate, plusViewRate, viewRatePow, viewRateScale);
|
|
|
+ item.getScoreMap().put("flow", flowWeight);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("cal flow control weight error", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private double getFlowControlWeight(String layer, AdRankItem item,
|
|
|
+ double cpmPow, double lowerCpmWeight, double upperCpmWeight,
|
|
|
+ double flowPow, double lowerFlowWeight, double upperFlowWeight,
|
|
|
+ double hitViewRate, double plusViewRate, double viewRatePow, double viewRateScale) {
|
|
|
+ try {
|
|
|
+ String profession = item.getProfession();
|
|
|
+ String customerId = String.valueOf(item.getCustomerId());
|
|
|
+ Pair<Double, Double> pair = LayerCustomerFlowControlDataHelper.getWeight(layer, profession, customerId);
|
|
|
+ if (null != pair) {
|
|
|
+ double cpmWeight = 1;
|
|
|
+ double flowWeight = 1;
|
|
|
+ double cpmDiff = pair.getLeft();
|
|
|
+ double viewRate = pair.getRight();
|
|
|
+ if (cpmDiff > 0) {
|
|
|
+ cpmWeight = Math.pow(cpmDiff, cpmPow);
|
|
|
+ cpmWeight = Math.min(Math.max(lowerCpmWeight, cpmWeight), upperCpmWeight);
|
|
|
+ }
|
|
|
+ if (viewRate > hitViewRate) {
|
|
|
+ flowWeight = 1 / Math.pow(viewRate * 100 + plusViewRate, viewRatePow) / viewRateScale;
|
|
|
+ flowWeight = Math.pow(flowWeight, flowPow);
|
|
|
+ flowWeight = Math.min(Math.max(lowerFlowWeight, flowWeight), upperFlowWeight);
|
|
|
+ }
|
|
|
+ return cpmWeight * flowWeight;
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("flowWeight error", e);
|
|
|
+ }
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
}
|