|
@@ -1,10 +1,13 @@
|
|
|
package com.tzld.piaoquan.ad.engine.service.score.strategy;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.ctrip.framework.apollo.spring.annotation.ApolloJsonValue;
|
|
|
+import com.tzld.piaoquan.ad.engine.commons.redis.AdRedisHelper;
|
|
|
import com.tzld.piaoquan.ad.engine.commons.score.ScoreParam;
|
|
|
import com.tzld.piaoquan.ad.engine.commons.score.ScorerUtils;
|
|
|
import com.tzld.piaoquan.ad.engine.commons.thread.ThreadPoolFactory;
|
|
|
import com.tzld.piaoquan.ad.engine.commons.util.*;
|
|
|
+import com.tzld.piaoquan.ad.engine.service.entity.GuaranteeView;
|
|
|
import com.tzld.piaoquan.ad.engine.service.feature.Feature;
|
|
|
import com.tzld.piaoquan.ad.engine.commons.dto.AdPlatformCreativeDTO;
|
|
|
import com.tzld.piaoquan.ad.engine.commons.param.RankRecommendRequestParam;
|
|
@@ -13,6 +16,7 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.apache.commons.collections4.MapUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.xm.Similarity;
|
|
@@ -42,6 +46,9 @@ public class RankStrategyBy688 extends RankStrategyBasic {
|
|
|
@Value("${word2vec.exp:694}")
|
|
|
private String word2vecExp;
|
|
|
|
|
|
+ @Value("${guarantee.exp:742}")
|
|
|
+ private String guaranteeExp;
|
|
|
+
|
|
|
// FIXME(zhoutian): 可能需要独立配置
|
|
|
@ApolloJsonValue("${rank.score.weight.680:{}}")
|
|
|
private Map<String, Double> weightMap;
|
|
@@ -49,8 +56,14 @@ public class RankStrategyBy688 extends RankStrategyBasic {
|
|
|
@ApolloJsonValue("${rank.score.neg_sample_rate:0.01}")
|
|
|
Double negSampleRate;
|
|
|
|
|
|
+ @ApolloJsonValue("${alpha:1.0}")
|
|
|
+ Double alpha;
|
|
|
+
|
|
|
Set<String> sparseFeatureSet;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private AdRedisHelper adRedisHelper;
|
|
|
+
|
|
|
@PostConstruct
|
|
|
public void afterInit() {
|
|
|
this.readBucketFile();
|
|
@@ -168,6 +181,20 @@ public class RankStrategyBy688 extends RankStrategyBasic {
|
|
|
userFeatureMap.put("root_source_channel", rootSourceChannel);
|
|
|
}
|
|
|
}
|
|
|
+ Map<String, GuaranteeView> map = new HashMap<>();
|
|
|
+ if (scoreParam.getExpCodeSet().contains(guaranteeExp)) {
|
|
|
+ List<String> adVerIdList = request.getAdIdList().stream().map(AdPlatformCreativeDTO::getAdVerId).distinct().collect(Collectors.toList());
|
|
|
+ List<String> values = adRedisHelper.mget(adVerIdList);
|
|
|
+ if (CollectionUtils.isNotEmpty(values)) {
|
|
|
+ for (int i = 0; i < adVerIdList.size(); i++) {
|
|
|
+ String value = values.get(i);
|
|
|
+ if (value != null) {
|
|
|
+ GuaranteeView guaranteeView = JSONObject.parseObject(value, GuaranteeView.class);
|
|
|
+ map.put(adVerIdList.get(i), guaranteeView);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
Map<String, String> sceneFeatureMap = this.handleSceneFeature(ts);
|
|
|
long time1 = System.currentTimeMillis();
|
|
@@ -194,9 +221,13 @@ public class RankStrategyBy688 extends RankStrategyBasic {
|
|
|
} else {
|
|
|
adRankItem.getExt().put("isApi", "1");
|
|
|
}
|
|
|
-
|
|
|
adRankItem.getExt().put("recallsources", dto.getRecallSources());
|
|
|
-
|
|
|
+ if (MapUtils.isNotEmpty(map)) {
|
|
|
+ GuaranteeView guaranteeView = map.get(dto.getAdVerId());
|
|
|
+ double guaranteeWeight = getGuaranteeWeight(guaranteeView);
|
|
|
+ adRankItem.getExt().put("guaranteeView", guaranteeView.toString());
|
|
|
+ adRankItem.getExt().put("guaranteeWeight", guaranteeWeight);
|
|
|
+ }
|
|
|
String cidStr = dto.getCreativeId().toString();
|
|
|
Map<String, String> cidFeatureMap = adRankItem.getFeatureMap();
|
|
|
Map<String, Map<String, String>> cidFeature = allCidFeature.getOrDefault(cidStr, new HashMap<>());
|
|
@@ -308,8 +339,18 @@ public class RankStrategyBy688 extends RankStrategyBasic {
|
|
|
for (AdRankItem item : result) {
|
|
|
|
|
|
double scoreCoefficient = creativeScoreCoefficient.getOrDefault(item.getAdId(), 1d);
|
|
|
- item.setScore(item.getLrScore() * scoreCoefficient * item.getCpa());
|
|
|
-
|
|
|
+ if (scoreParam.getExpCodeSet().contains(guaranteeExp)) {
|
|
|
+ double guaranteeScoreCoefficient;
|
|
|
+ if (item.getExt().get("guaranteeWeight") == null) {
|
|
|
+ guaranteeScoreCoefficient = 1.0;
|
|
|
+ } else {
|
|
|
+ guaranteeScoreCoefficient = Math.pow((double) item.getExt().get("guaranteeWeight"), alpha);
|
|
|
+ }
|
|
|
+ item.setScore(item.getLrScore() * scoreCoefficient * item.getCpa() * guaranteeScoreCoefficient);
|
|
|
+ item.getScoreMap().put("guaranteeScoreCoefficient", guaranteeScoreCoefficient);
|
|
|
+ } else {
|
|
|
+ item.setScore(item.getLrScore() * scoreCoefficient * item.getCpa());
|
|
|
+ }
|
|
|
item.getScoreMap().put("cpa", item.getCpa());
|
|
|
item.getScoreMap().put("cpm", item.getCpm());
|
|
|
item.getScoreMap().put("cpmCoefficient", cpmCoefficient);
|