|
@@ -41,7 +41,7 @@ public class RankStrategyBy687 extends RankStrategyBasic {
|
|
|
@Value("${cid.hot.rank.max.weight:1000}")
|
|
|
private Double hotRankMaxWeight;
|
|
|
|
|
|
- private static final String CUSTOMER_FIELD_NAME = "customer";
|
|
|
+ private static final String CUSTOMER_FIELD_NAME = "customer_name";
|
|
|
|
|
|
@Override
|
|
|
public List<AdRankItem> adItemRank(RankRecommendRequestParam request, ScoreParam scoreParam) {
|
|
@@ -134,6 +134,9 @@ public class RankStrategyBy687 extends RankStrategyBasic {
|
|
|
|
|
|
for (int i = 0; i < customers.size(); i++) {
|
|
|
String value = values.get(i);
|
|
|
+ if (StringUtils.isEmpty(value)) {
|
|
|
+ value = "{}";
|
|
|
+ }
|
|
|
HotRankFeatureInfo hotRankFeatureInfo = JSON.parseObject(value, HotRankFeatureInfo.class);
|
|
|
hotRankFeatureInfo.setLabel(customers.get(i));
|
|
|
hotRankFeatureInfos.add(hotRankFeatureInfo);
|
|
@@ -146,17 +149,17 @@ public class RankStrategyBy687 extends RankStrategyBasic {
|
|
|
Map<String, Map<String, String>> feature = cidFeature.getOrDefault(String.valueOf(rankItem.getAdId()), new HashMap<>());
|
|
|
Map<String, String> basicInfo = feature.getOrDefault("alg_cid_feature_basic_info", new HashMap<>());
|
|
|
String customer = basicInfo.getOrDefault(CUSTOMER_FIELD_NAME, "");
|
|
|
- rankItem.getExt().put("customer", customer);
|
|
|
+ rankItem.getExt().put("customer_name", customer);
|
|
|
}
|
|
|
|
|
|
private String choose(List<HotRankFeatureInfo> hotRankFeatureInfos) {
|
|
|
// 按CPM排序
|
|
|
- hotRankFeatureInfos.sort(Comparator.comparing(HotRankFeatureInfo::getCpm));
|
|
|
+ hotRankFeatureInfos.sort(Comparator.comparing(HotRankFeatureInfo::getCpm).reversed());
|
|
|
|
|
|
// 按照曝光拆分
|
|
|
List<HotRankFeatureInfo> highView = new ArrayList<>();
|
|
|
List<HotRankFeatureInfo> tailView = new ArrayList<>();
|
|
|
- int highIdx = 0, tailIdx = 0;
|
|
|
+ int highIdx = 1, tailIdx = 1;
|
|
|
for (HotRankFeatureInfo hotRankFeatureInfo : hotRankFeatureInfos) {
|
|
|
if (hotRankFeatureInfo.getView() >= hotRankViewThreshold) {
|
|
|
hotRankFeatureInfo.setRank(highIdx++);
|
|
@@ -224,7 +227,7 @@ public class RankStrategyBy687 extends RankStrategyBasic {
|
|
|
continue;
|
|
|
}
|
|
|
HotRankFeatureInfo prev = rankItem.get(i - 1);
|
|
|
- double currWeight1 = prev.getWeight() * (1 - (1 - curr.getCpm() / prev.getCpm())) * hotRankCalcWeightCoefficient;
|
|
|
+ double currWeight1 = prev.getWeight() * (1 - (1 - curr.getCpm() / prev.getCpm()) * hotRankCalcWeightCoefficient);
|
|
|
double currWeight2 = prev.getWeight() / hotRankCalcWeightCoefficient;
|
|
|
double currWeight = Math.max(currWeight1, currWeight2);
|
|
|
curr.setWeight(Math.max(1, currWeight));
|
|
@@ -233,19 +236,31 @@ public class RankStrategyBy687 extends RankStrategyBasic {
|
|
|
|
|
|
private void fullMetaFeature(AdRankItem rankItem, String userLayer, Map<String, HotRankFeatureInfo> allCustomerFeatureMap, Map<Long, HotRankFeatureInfo> allCreativeFeatureMap, Feature feature) {
|
|
|
String customer = rankItem.getExt().getOrDefault(CUSTOMER_FIELD_NAME, "").toString();
|
|
|
+
|
|
|
+ Map<String, Double> scoreMap = new HashMap<>();
|
|
|
+
|
|
|
if (StringUtils.isNotBlank(customer) && allCustomerFeatureMap.containsKey(customer)) {
|
|
|
HotRankFeatureInfo customerFeatureInfo = allCustomerFeatureMap.get(customer);
|
|
|
rankItem.getMetaFeatureMap().put("customerFeature", customerFeatureInfo.covertToFeatureMap());
|
|
|
+
|
|
|
+ scoreMap.put("customer_weight", customerFeatureInfo.getWeight());
|
|
|
+ scoreMap.put("customer_rank", (double) customerFeatureInfo.getRank());
|
|
|
+
|
|
|
}
|
|
|
|
|
|
if (allCreativeFeatureMap.containsKey(rankItem.getAdId())) {
|
|
|
- HotRankFeatureInfo customerFeatureInfo = allCreativeFeatureMap.get(rankItem.getAdId());
|
|
|
- rankItem.getMetaFeatureMap().put("creativeFeature", customerFeatureInfo.covertToFeatureMap());
|
|
|
+ HotRankFeatureInfo creativeFeatureInfo = allCreativeFeatureMap.get(rankItem.getAdId());
|
|
|
+ rankItem.getMetaFeatureMap().put("creativeFeature", creativeFeatureInfo.covertToFeatureMap());
|
|
|
+
|
|
|
+ scoreMap.put("weight", creativeFeatureInfo.getWeight());
|
|
|
+ scoreMap.put("rank", (double) creativeFeatureInfo.getRank());
|
|
|
}
|
|
|
|
|
|
Map<String, String> midFeature = new HashMap<>(4);
|
|
|
midFeature.put("userLayer", userLayer);
|
|
|
rankItem.getMetaFeatureMap().put("midFeature", midFeature);
|
|
|
+
|
|
|
+ rankItem.getScoreMap().putAll(scoreMap);
|
|
|
}
|
|
|
|
|
|
@Data
|
|
@@ -254,9 +269,9 @@ public class RankStrategyBy687 extends RankStrategyBasic {
|
|
|
private static class HotRankFeatureInfo {
|
|
|
private String label;
|
|
|
|
|
|
- private double cpm;
|
|
|
+ private double cpm = 0;
|
|
|
|
|
|
- private int view;
|
|
|
+ private int view = 0;
|
|
|
|
|
|
private double weight = 1;
|
|
|
|
|
@@ -264,6 +279,7 @@ public class RankStrategyBy687 extends RankStrategyBasic {
|
|
|
|
|
|
public Map<String, String> covertToFeatureMap() {
|
|
|
Map<String, String> featureMap = new HashMap<>(4);
|
|
|
+ featureMap.put("label", label);
|
|
|
featureMap.put("rank", String.valueOf(this.getRank()));
|
|
|
featureMap.put("cpm", String.valueOf(this.getCpm()));
|
|
|
featureMap.put("view", String.valueOf(this.getView()));
|