|
@@ -7,6 +7,7 @@ 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.score.ScorerUtils;
|
|
import com.tzld.piaoquan.ad.engine.commons.thread.ThreadPoolFactory;
|
|
import com.tzld.piaoquan.ad.engine.commons.thread.ThreadPoolFactory;
|
|
import com.tzld.piaoquan.ad.engine.commons.util.*;
|
|
import com.tzld.piaoquan.ad.engine.commons.util.*;
|
|
|
|
+import com.tzld.piaoquan.ad.engine.service.entity.FeatureContainer;
|
|
import com.tzld.piaoquan.ad.engine.service.entity.GuaranteeView;
|
|
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.Feature;
|
|
import com.tzld.piaoquan.ad.engine.commons.dto.AdPlatformCreativeDTO;
|
|
import com.tzld.piaoquan.ad.engine.commons.dto.AdPlatformCreativeDTO;
|
|
@@ -81,36 +82,15 @@ public class RankStrategyBy688 extends RankStrategyBasic {
|
|
|
|
|
|
long start = System.currentTimeMillis();
|
|
long start = System.currentTimeMillis();
|
|
// 特征处理
|
|
// 特征处理
|
|
- // feature1
|
|
|
|
- Feature feature = this.getFeature(scoreParam, request);
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- Map<String, Map<String, String>> userFeature = feature.getUserFeature();
|
|
|
|
- Map<String, Map<String, String>> videoFeature = feature.getVideoFeature();
|
|
|
|
- Map<String, Map<String, Map<String, String>>> allAdVerFeature = feature.getAdVerFeature();
|
|
|
|
- Map<String, Map<String, Map<String, String>>> allCidFeature = feature.getCidFeature();
|
|
|
|
- Map<String, Map<String, Map<String, String>>> allSkuFeature = feature.getSkuFeature();
|
|
|
|
- Map<String, String> reqFeature = this.getReqFeature(scoreParam, request);
|
|
|
|
|
|
+ FeatureContainer featureContainer = this.extractAndProcessFeatures(scoreParam, request, ts);
|
|
|
|
|
|
Map<String, String> userFeatureMap = new HashMap<>();
|
|
Map<String, String> userFeatureMap = new HashMap<>();
|
|
- Map<String, String> c1Feature = userFeature.getOrDefault("alg_mid_feature_ad_action", new HashMap<>());
|
|
|
|
- List<TupleMapEntry<Tuple5>> midActionList = this.handleC1Feature(c1Feature, userFeatureMap);
|
|
|
|
-
|
|
|
|
|
|
+ List<TupleMapEntry<Tuple5>> midActionList = this.handleC1Feature(featureContainer.getC1Feature(), userFeatureMap);
|
|
Map<String, Double> midTimeDiffMap = this.parseC1FeatureListToTimeDiffMap(midActionList, ts);
|
|
Map<String, Double> midTimeDiffMap = this.parseC1FeatureListToTimeDiffMap(midActionList, ts);
|
|
Map<String, Double> actionStaticMap = this.parseC1FeatureListToActionStaticMap(midActionList);
|
|
Map<String, Double> actionStaticMap = this.parseC1FeatureListToActionStaticMap(midActionList);
|
|
|
|
+ Map<String, Map<String, Double>> vidRankMaps = this.parseD2FeatureMap(featureContainer.getD2Feature());
|
|
|
|
|
|
- Map<String, String> d2Feature = videoFeature.getOrDefault("alg_cid_feature_vid_cf_rank", new HashMap<>());
|
|
|
|
- Map<String, String> d3Feature = videoFeature.getOrDefault("alg_vid_feature_basic_info", new HashMap<>());
|
|
|
|
-
|
|
|
|
- Map<String, Map<String, Double>> vidRankMaps = this.parseD2FeatureMap(d2Feature);
|
|
|
|
-
|
|
|
|
- Map<String, String> e1Feature = userFeature.getOrDefault("alg_mid_feature_return_tags", new HashMap<>());
|
|
|
|
- Map<String, String> e2Feature = userFeature.getOrDefault("alg_mid_feature_share_tags", new HashMap<>());
|
|
|
|
-
|
|
|
|
- Map<String, String> g1Feature = userFeature.getOrDefault("mid_return_video_cate", new HashMap<>());
|
|
|
|
- Map<String, String> g2Feature = userFeature.getOrDefault("mid_share_video_cate", new HashMap<>());
|
|
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+ Map<String, String> reqFeature = featureContainer.getReqFeature();
|
|
userFeatureMap.put("brand", reqFeature.getOrDefault("brand", ""));
|
|
userFeatureMap.put("brand", reqFeature.getOrDefault("brand", ""));
|
|
userFeatureMap.put("region", reqFeature.getOrDefault("region", ""));
|
|
userFeatureMap.put("region", reqFeature.getOrDefault("region", ""));
|
|
userFeatureMap.put("city", reqFeature.getOrDefault("city", ""));
|
|
userFeatureMap.put("city", reqFeature.getOrDefault("city", ""));
|
|
@@ -120,7 +100,11 @@ public class RankStrategyBy688 extends RankStrategyBasic {
|
|
userFeatureMap.put("root_source_scene", reqFeature.getOrDefault("root_source_scene", ""));
|
|
userFeatureMap.put("root_source_scene", reqFeature.getOrDefault("root_source_scene", ""));
|
|
userFeatureMap.put("root_source_channel", reqFeature.getOrDefault("root_source_channel", ""));
|
|
userFeatureMap.put("root_source_channel", reqFeature.getOrDefault("root_source_channel", ""));
|
|
|
|
|
|
-
|
|
|
|
|
|
+ Map<String, String> d3Feature = featureContainer.getD3Feature();
|
|
|
|
+ Map<String, String> e1Feature = featureContainer.getE1Feature();
|
|
|
|
+ Map<String, String> e2Feature = featureContainer.getE2Feature();
|
|
|
|
+ Map<String, String> g1Feature = featureContainer.getG1Feature();
|
|
|
|
+ Map<String, String> g2Feature = featureContainer.getG2Feature();
|
|
userFeatureMap.put("cate1", d3Feature.get("merge_first_level_cate"));
|
|
userFeatureMap.put("cate1", d3Feature.get("merge_first_level_cate"));
|
|
userFeatureMap.put("cate2", d3Feature.get("merge_second_level_cate"));
|
|
userFeatureMap.put("cate2", d3Feature.get("merge_second_level_cate"));
|
|
userFeatureMap.put("user_vid_return_tags_2h", e1Feature.getOrDefault("tags_2h", null));
|
|
userFeatureMap.put("user_vid_return_tags_2h", e1Feature.getOrDefault("tags_2h", null));
|
|
@@ -135,9 +119,6 @@ public class RankStrategyBy688 extends RankStrategyBasic {
|
|
userFeatureMap.put("user_vid_return_cate2_14d", g1Feature.getOrDefault("cate2_14d", null));
|
|
userFeatureMap.put("user_vid_return_cate2_14d", g1Feature.getOrDefault("cate2_14d", null));
|
|
userFeatureMap.put("user_vid_share_cate1_14d", g2Feature.getOrDefault("cate1_14d", null));
|
|
userFeatureMap.put("user_vid_share_cate1_14d", g2Feature.getOrDefault("cate1_14d", null));
|
|
userFeatureMap.put("user_vid_share_cate2_14d", g2Feature.getOrDefault("cate2_14d", null));
|
|
userFeatureMap.put("user_vid_share_cate2_14d", g2Feature.getOrDefault("cate2_14d", null));
|
|
-
|
|
|
|
-
|
|
|
|
- Map<String, String> sceneFeatureMap = this.handleSceneFeature(ts);
|
|
|
|
long time1 = System.currentTimeMillis();
|
|
long time1 = System.currentTimeMillis();
|
|
|
|
|
|
Map<String, GuaranteeView> map = getGuaranteeViewMap(request, scoreParam);
|
|
Map<String, GuaranteeView> map = getGuaranteeViewMap(request, scoreParam);
|
|
@@ -168,11 +149,11 @@ public class RankStrategyBy688 extends RankStrategyBasic {
|
|
setGuaranteeWeight(map, dto.getAdVerId(), adRankItem.getExt());
|
|
setGuaranteeWeight(map, dto.getAdVerId(), adRankItem.getExt());
|
|
String cidStr = dto.getCreativeId().toString();
|
|
String cidStr = dto.getCreativeId().toString();
|
|
Map<String, String> cidFeatureMap = adRankItem.getFeatureMap();
|
|
Map<String, String> cidFeatureMap = adRankItem.getFeatureMap();
|
|
- Map<String, Map<String, String>> cidFeature = allCidFeature.getOrDefault(cidStr, new HashMap<>());
|
|
|
|
|
|
+ Map<String, Map<String, String>> cidFeature = featureContainer.getCidFeature().getOrDefault(cidStr, new HashMap<>());
|
|
Map<String, String> b1Feature = cidFeature.getOrDefault("alg_cid_feature_basic_info", new HashMap<>());
|
|
Map<String, String> b1Feature = cidFeature.getOrDefault("alg_cid_feature_basic_info", new HashMap<>());
|
|
|
|
|
|
- Map<String, Map<String, String>> adVerFeature = allAdVerFeature.getOrDefault(dto.getAdVerId(), new HashMap<>());
|
|
|
|
- Map<String, Map<String, String>> skuFeature = allSkuFeature.getOrDefault(String.valueOf(dto.getSkuId()), new HashMap<>());
|
|
|
|
|
|
+ Map<String, Map<String, String>> adVerFeature = featureContainer.getAdVerFeature().getOrDefault(dto.getAdVerId(), new HashMap<>());
|
|
|
|
+ Map<String, Map<String, String>> skuFeature = featureContainer.getSkuFeature().getOrDefault(String.valueOf(dto.getSkuId()), new HashMap<>());
|
|
Map<String, String> d1Feature = cidFeature.getOrDefault("alg_cid_feature_vid_cf", new HashMap<>());
|
|
Map<String, String> d1Feature = cidFeature.getOrDefault("alg_cid_feature_vid_cf", new HashMap<>());
|
|
|
|
|
|
this.handleB1Feature(b1Feature, cidFeatureMap, cidStr);
|
|
this.handleB1Feature(b1Feature, cidFeatureMap, cidStr);
|
|
@@ -214,7 +195,7 @@ public class RankStrategyBy688 extends RankStrategyBasic {
|
|
CountDownLatch cdl2 = new CountDownLatch(adRankItems.size() * 2);
|
|
CountDownLatch cdl2 = new CountDownLatch(adRankItems.size() * 2);
|
|
for (AdRankItem item : adRankItems) {
|
|
for (AdRankItem item : adRankItems) {
|
|
String cidStr = String.valueOf(item.getAdId());
|
|
String cidStr = String.valueOf(item.getAdId());
|
|
- Map<String, Map<String, String>> cidFeature = allCidFeature.getOrDefault(cidStr, new HashMap<>());
|
|
|
|
|
|
+ Map<String, Map<String, String>> cidFeature = featureContainer.getCidFeature().getOrDefault(cidStr, new HashMap<>());
|
|
Map<String, String> b1Feature = cidFeature.getOrDefault("alg_cid_feature_basic_info", new HashMap<>());
|
|
Map<String, String> b1Feature = cidFeature.getOrDefault("alg_cid_feature_basic_info", new HashMap<>());
|
|
String title = b1Feature.getOrDefault("cidtitle", "");
|
|
String title = b1Feature.getOrDefault("cidtitle", "");
|
|
ThreadPoolFactory.defaultPool().submit(() -> {
|
|
ThreadPoolFactory.defaultPool().submit(() -> {
|
|
@@ -260,7 +241,8 @@ public class RankStrategyBy688 extends RankStrategyBasic {
|
|
long time4 = System.currentTimeMillis();
|
|
long time4 = System.currentTimeMillis();
|
|
// 打分排序
|
|
// 打分排序
|
|
// getScorerPipeline
|
|
// getScorerPipeline
|
|
- List<AdRankItem> result = ScorerUtils.getScorerPipeline(ScorerUtils.PAI_SCORE_CONF_20250214).scoring(sceneFeatureMap, userFeatureMap, adRankItems);
|
|
|
|
|
|
+ List<AdRankItem> result = ScorerUtils.getScorerPipeline(ScorerUtils.PAI_SCORE_CONF_20250214)
|
|
|
|
+ .scoring(featureContainer.getSceneFeatureMap(), userFeatureMap, adRankItems);
|
|
long time5 = System.currentTimeMillis();
|
|
long time5 = System.currentTimeMillis();
|
|
|
|
|
|
// calibrate score for negative sampling
|
|
// calibrate score for negative sampling
|
|
@@ -286,7 +268,7 @@ public class RankStrategyBy688 extends RankStrategyBasic {
|
|
item.getScoreMap().put("cpmCoefficient", cpmCoefficient);
|
|
item.getScoreMap().put("cpmCoefficient", cpmCoefficient);
|
|
item.getScoreMap().put("scoreCoefficient", scoreCoefficient);
|
|
item.getScoreMap().put("scoreCoefficient", scoreCoefficient);
|
|
item.getFeatureMap().putAll(userFeatureMap);
|
|
item.getFeatureMap().putAll(userFeatureMap);
|
|
- item.getFeatureMap().putAll(sceneFeatureMap);
|
|
|
|
|
|
+ item.getFeatureMap().putAll(featureContainer.getSceneFeatureMap());
|
|
|
|
|
|
// 没有转化回传的广告主,使用后台配置的CPM
|
|
// 没有转化回传的广告主,使用后台配置的CPM
|
|
if (noApiAdVerIds.contains(item.getAdVerId())) {
|
|
if (noApiAdVerIds.contains(item.getAdVerId())) {
|
|
@@ -294,45 +276,11 @@ public class RankStrategyBy688 extends RankStrategyBasic {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
result.sort(ComparatorUtil.equalsRandomComparator());
|
|
result.sort(ComparatorUtil.equalsRandomComparator());
|
|
|
|
|
|
if (CollectionUtils.isNotEmpty(result)) {
|
|
if (CollectionUtils.isNotEmpty(result)) {
|
|
AdRankItem top1Item = result.get(0);
|
|
AdRankItem top1Item = result.get(0);
|
|
- for (Map.Entry<String, Map<String, String>> entry : videoFeature.entrySet()) {
|
|
|
|
- if (MapUtils.isNotEmpty(entry.getValue())) {
|
|
|
|
- top1Item.getMetaFeatureMap().put(entry.getKey(), entry.getValue());
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- for (Map.Entry<String, Map<String, String>> entry : userFeature.entrySet()) {
|
|
|
|
- if (MapUtils.isNotEmpty(entry.getValue())) {
|
|
|
|
- top1Item.getMetaFeatureMap().put(entry.getKey(), entry.getValue());
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- Map<String, Map<String, String>> adVerFeature = allAdVerFeature.getOrDefault(top1Item.getAdVerId(), new HashMap<>());
|
|
|
|
- for (Map.Entry<String, Map<String, String>> entry : adVerFeature.entrySet()) {
|
|
|
|
- if (MapUtils.isNotEmpty(entry.getValue())) {
|
|
|
|
- top1Item.getMetaFeatureMap().put(entry.getKey(), entry.getValue());
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- Map<String, Map<String, String>> cidFeature = allCidFeature.getOrDefault(String.valueOf(top1Item.getAdId()), new HashMap<>());
|
|
|
|
- for (Map.Entry<String, Map<String, String>> entry : cidFeature.entrySet()) {
|
|
|
|
- if (MapUtils.isNotEmpty(entry.getValue())) {
|
|
|
|
- top1Item.getMetaFeatureMap().put(entry.getKey(), entry.getValue());
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- Map<String, Map<String, String>> skuFeature = allSkuFeature.getOrDefault(String.valueOf(top1Item.getSkuId()), new HashMap<>());
|
|
|
|
- for (Map.Entry<String, Map<String, String>> entry : skuFeature.entrySet()) {
|
|
|
|
- if (MapUtils.isNotEmpty(entry.getValue())) {
|
|
|
|
- top1Item.getMetaFeatureMap().put(entry.getKey(), entry.getValue());
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- top1Item.getMetaFeatureMap().put("reqFeature", reqFeature);
|
|
|
|
- top1Item.getMetaFeatureMap().put("sceneFeature", sceneFeatureMap);
|
|
|
|
|
|
+ setMetaFeatureMap(featureContainer, top1Item);
|
|
}
|
|
}
|
|
long time6 = System.currentTimeMillis();
|
|
long time6 = System.currentTimeMillis();
|
|
log.info("cost={}, getFeature={}, handleFeature={}, similar={}, bucketFeature={}, getScorerPipeline={}, " +
|
|
log.info("cost={}, getFeature={}, handleFeature={}, similar={}, bucketFeature={}, getScorerPipeline={}, " +
|
|
@@ -343,105 +291,8 @@ public class RankStrategyBy688 extends RankStrategyBasic {
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|
|
|
|
|
|
- private void handleB1Feature(Map<String, String> b1Feature, Map<String, String> cidFeatureMap, String cid) {
|
|
|
|
- cidFeatureMap.put("cid_" + cid, "0.1");
|
|
|
|
- // if (StringUtils.isNotBlank(b1Feature.get("adid"))) {
|
|
|
|
- // String adId = b1Feature.get("adid");
|
|
|
|
- // cidFeatureMap.put("adid_" + adId, idDefaultValue);
|
|
|
|
- // }
|
|
|
|
- if (StringUtils.isNotBlank(b1Feature.get("adverid"))) {
|
|
|
|
- String adVerId = b1Feature.get("adverid");
|
|
|
|
- cidFeatureMap.put("adverid_" + adVerId, "0.1");
|
|
|
|
- }
|
|
|
|
- // if (StringUtils.isNotBlank(b1Feature.get("targeting_conversion"))) {
|
|
|
|
- // String targetingConversion = b1Feature.get("targeting_conversion");
|
|
|
|
- // cidFeatureMap.put("targeting_conversion_" + targetingConversion, idDefaultValue);
|
|
|
|
- // }
|
|
|
|
- if (StringUtils.isNotBlank(b1Feature.get("cpa"))) {
|
|
|
|
- String cpa = b1Feature.get("cpa");
|
|
|
|
- cidFeatureMap.put("cpa", cpa);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private void handleB2ToB5AndB8ToB9Feature(Map<String, Map<String, String>> c1Feature, Map<String, Map<String, String>> adVerFeature, Map<String, String> cidFeatureMap) {
|
|
|
|
- Map<String, String> b2Feature = adVerFeature.getOrDefault("alg_cid_feature_adver_action", new HashMap<>());
|
|
|
|
- Map<String, String> b3Feature = c1Feature.getOrDefault("alg_cid_feature_cid_action", new HashMap<>());
|
|
|
|
- Map<String, String> b4Feature = c1Feature.getOrDefault("alg_cid_feature_region_action", new HashMap<>());
|
|
|
|
- Map<String, String> b5Feature = c1Feature.getOrDefault("alg_cid_feature_app_action", new HashMap<>());
|
|
|
|
- Map<String, String> b8Feature = c1Feature.getOrDefault("alg_cid_feature_brand_action", new HashMap<>());
|
|
|
|
- Map<String, String> b9Feature = c1Feature.getOrDefault("alg_cid_feature_weChatVersion_action", new HashMap<>());
|
|
|
|
|
|
|
|
- List<String> timeList = Arrays.asList("1h", "2h", "3h", "6h", "12h", "1d", "3d", "7d", "yesterday", "today");
|
|
|
|
- List<Tuple2<Map<String, String>, String>> featureList = Arrays.asList(
|
|
|
|
- new Tuple2<>(b2Feature, "b2"),
|
|
|
|
- new Tuple2<>(b3Feature, "b3"),
|
|
|
|
- new Tuple2<>(b4Feature, "b4"),
|
|
|
|
- new Tuple2<>(b5Feature, "b5"),
|
|
|
|
- new Tuple2<>(b8Feature, "b8"),
|
|
|
|
- new Tuple2<>(b9Feature, "b9")
|
|
|
|
- );
|
|
|
|
- for (Tuple2<Map<String, String>, String> tuple2 : featureList) {
|
|
|
|
- Map<String, String> feature = tuple2.f1;
|
|
|
|
- String prefix = tuple2.f2;
|
|
|
|
- for (String time : timeList) {
|
|
|
|
- double view = Double.parseDouble(feature.getOrDefault("ad_view_" + time, "0"));
|
|
|
|
- double click = Double.parseDouble(feature.getOrDefault("ad_click_" + time, "0"));
|
|
|
|
- double conver = Double.parseDouble(feature.getOrDefault("ad_conversion_" + time, "0"));
|
|
|
|
- double income = Double.parseDouble(feature.getOrDefault("ad_income_" + time, "0"));
|
|
|
|
- double cpc = NumUtil.div(income, click);
|
|
|
|
- double ctr = NumUtil.divSmoothV2(click, view, CTR_SMOOTH_BETA_FACTOR);
|
|
|
|
- double ctcvr = NumUtil.divSmoothV2(conver, view, CTCVR_SMOOTH_BETA_FACTOR);
|
|
|
|
- double ecpm = ctr * cpc * 1000;
|
|
|
|
- cidFeatureMap.put(prefix + "_" + time + "_ctr", String.valueOf(ctr));
|
|
|
|
- cidFeatureMap.put(prefix + "_" + time + "_ctcvr", String.valueOf(ctcvr));
|
|
|
|
- cidFeatureMap.put(prefix + "_" + time + "_cvr", String.valueOf(NumUtil.divSmoothV2(conver, click, CVR_SMOOTH_BETA_FACTOR)));
|
|
|
|
- cidFeatureMap.put(prefix + "_" + time + "_conver", String.valueOf(conver));
|
|
|
|
- cidFeatureMap.put(prefix + "_" + time + "_ecpm", String.valueOf(ecpm));
|
|
|
|
-
|
|
|
|
- cidFeatureMap.put(prefix + "_" + time + "_click", String.valueOf(click));
|
|
|
|
- cidFeatureMap.put(prefix + "_" + time + "_conver*log(view)", String.valueOf(conver * NumUtil.log(view)));
|
|
|
|
- cidFeatureMap.put(prefix + "_" + time + "_conver*ctcvr", String.valueOf(conver * ctcvr));
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private void handleB6ToB7Feature(Map<String, Map<String, String>> c1Feature, Map<String, String> cidFeatureMap) {
|
|
|
|
- Map<String, String> b6Feature = c1Feature.getOrDefault("alg_cid_feature_week_action", new HashMap<>());
|
|
|
|
- Map<String, String> b7Feature = c1Feature.getOrDefault("alg_cid_feature_hour_action", new HashMap<>());
|
|
|
|
-
|
|
|
|
- List<String> timeList = Arrays.asList("7d", "14d");
|
|
|
|
- List<Tuple2<Map<String, String>, String>> featureList = Arrays.asList(
|
|
|
|
- new Tuple2<>(b6Feature, "b6"),
|
|
|
|
- new Tuple2<>(b7Feature, "b7")
|
|
|
|
- );
|
|
|
|
- for (Tuple2<Map<String, String>, String> tuple2 : featureList) {
|
|
|
|
- Map<String, String> feature = tuple2.f1;
|
|
|
|
- String prefix = tuple2.f2;
|
|
|
|
- for (String time : timeList) {
|
|
|
|
- double view = Double.parseDouble(feature.getOrDefault("ad_view_" + time, "0"));
|
|
|
|
- double click = Double.parseDouble(feature.getOrDefault("ad_click_" + time, "0"));
|
|
|
|
- double conver = Double.parseDouble(feature.getOrDefault("ad_conversion_" + time, "0"));
|
|
|
|
- double income = Double.parseDouble(feature.getOrDefault("ad_income_" + time, "0"));
|
|
|
|
- double cpc = NumUtil.div(income, click);
|
|
|
|
- double ctr = NumUtil.divSmoothV2(click, view, CTR_SMOOTH_BETA_FACTOR);
|
|
|
|
- double ctcvr = NumUtil.divSmoothV2(conver, view, CTCVR_SMOOTH_BETA_FACTOR);
|
|
|
|
- double ecpm = ctr * cpc * 1000;
|
|
|
|
- cidFeatureMap.put(prefix + "_" + time + "_ctr", String.valueOf(ctr));
|
|
|
|
- cidFeatureMap.put(prefix + "_" + time + "_ctcvr", String.valueOf(ctcvr));
|
|
|
|
- cidFeatureMap.put(prefix + "_" + time + "_cvr", String.valueOf(NumUtil.divSmoothV2(conver, click, CVR_SMOOTH_BETA_FACTOR)));
|
|
|
|
- cidFeatureMap.put(prefix + "_" + time + "_conver", String.valueOf(conver));
|
|
|
|
- cidFeatureMap.put(prefix + "_" + time + "_ecpm", String.valueOf(ecpm));
|
|
|
|
-
|
|
|
|
- cidFeatureMap.put(prefix + "_" + time + "_click", String.valueOf(click));
|
|
|
|
- cidFeatureMap.put(prefix + "_" + time + "_conver*log(view)", String.valueOf(conver * NumUtil.log(view)));
|
|
|
|
- cidFeatureMap.put(prefix + "_" + time + "_conver*ctcvr", String.valueOf(conver * ctcvr));
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private List<TupleMapEntry<Tuple5>> handleC1Feature(Map<String, String> c1Feature, Map<String, String> featureMap) {
|
|
|
|
|
|
+ protected List<TupleMapEntry<Tuple5>> handleC1Feature(Map<String, String> c1Feature, Map<String, String> featureMap) {
|
|
|
|
|
|
//用户近1年内是否有转化
|
|
//用户近1年内是否有转化
|
|
if (c1Feature.containsKey("user_has_conver_1y") && c1Feature.get("user_has_conver_1y") != null) {
|
|
if (c1Feature.containsKey("user_has_conver_1y") && c1Feature.get("user_has_conver_1y") != null) {
|
|
@@ -490,83 +341,6 @@ public class RankStrategyBy688 extends RankStrategyBasic {
|
|
return midActionList;
|
|
return midActionList;
|
|
}
|
|
}
|
|
|
|
|
|
- private void handleC1UIFeature(Map<String, Double> midTimeDiffMap, Map<String, Double> midActionStatic, Map<String, String> featureMap, String cid) {
|
|
|
|
- if (midTimeDiffMap.containsKey("timediff_view_" + cid)) {
|
|
|
|
- featureMap.put("timediff_view", String.valueOf(midTimeDiffMap.getOrDefault("timediff_view_" + cid, 0.0)));
|
|
|
|
- }
|
|
|
|
- if (midTimeDiffMap.containsKey("timediff_click_" + cid)) {
|
|
|
|
- featureMap.put("timediff_click", String.valueOf(midTimeDiffMap.getOrDefault("timediff_click_" + cid, 0.0)));
|
|
|
|
- }
|
|
|
|
- if (midTimeDiffMap.containsKey("timediff_conver_" + cid)) {
|
|
|
|
- featureMap.put("timediff_conver", String.valueOf(midTimeDiffMap.getOrDefault("timediff_conver_" + cid, 0.0)));
|
|
|
|
- }
|
|
|
|
- if (midActionStatic.containsKey("actionstatic_view_" + cid)) {
|
|
|
|
- featureMap.put("actionstatic_view", String.valueOf(midActionStatic.getOrDefault("actionstatic_view_" + cid, 0.0)));
|
|
|
|
- }
|
|
|
|
- if (midActionStatic.containsKey("actionstatic_click_" + cid)) {
|
|
|
|
- featureMap.put("actionstatic_click", String.valueOf(midActionStatic.getOrDefault("actionstatic_click_" + cid, 0.0)));
|
|
|
|
- }
|
|
|
|
- if (midActionStatic.containsKey("actionstatic_conver_" + cid)) {
|
|
|
|
- featureMap.put("actionstatic_conver", String.valueOf(midActionStatic.getOrDefault("actionstatic_conver_" + cid, 0.0)));
|
|
|
|
- }
|
|
|
|
- if (midActionStatic.containsKey("actionstatic_income_" + cid)) {
|
|
|
|
- featureMap.put("actionstatic_income", String.valueOf(midActionStatic.getOrDefault("actionstatic_income_" + cid, 0.0)));
|
|
|
|
- }
|
|
|
|
- if (midActionStatic.containsKey("actionstatic_view_" + cid) && midActionStatic.containsKey("actionstatic_click_" + cid)) {
|
|
|
|
- double ctr = NumUtil.div(
|
|
|
|
- midActionStatic.getOrDefault("actionstatic_click_" + cid, 0.0),
|
|
|
|
- midActionStatic.getOrDefault("actionstatic_view_" + cid, 0.0)
|
|
|
|
- );
|
|
|
|
- featureMap.put("actionstatic_ctr", String.valueOf(ctr));
|
|
|
|
- }
|
|
|
|
- if (midActionStatic.containsKey("actionstatic_view_" + cid) && midActionStatic.containsKey("actionstatic_conver_" + cid)) {
|
|
|
|
- double ctcvr = NumUtil.div(midActionStatic.getOrDefault("actionstatic_conver_" + cid, 0.0), midActionStatic.getOrDefault("actionstatic_view_" + cid, 0.0));
|
|
|
|
- featureMap.put("actionstatic_ctcvr", String.valueOf(ctcvr));
|
|
|
|
- }
|
|
|
|
- if (midActionStatic.containsKey("actionstatic_conver_" + cid) && midActionStatic.containsKey("actionstatic_click_" + cid)) {
|
|
|
|
- double cvr = NumUtil.div(midActionStatic.getOrDefault("actionstatic_conver_" + cid, 0.0), midActionStatic.getOrDefault("actionstatic_click_" + cid, 0.0));
|
|
|
|
- featureMap.put("actionstatic_cvr", String.valueOf(cvr));
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private void handleD1Feature(Map<String, String> d1Feature, Map<String, String> featureMap) {
|
|
|
|
- for (String prefix : Arrays.asList("3h", "6h", "12h", "1d", "3d", "7d")) {
|
|
|
|
- double view = Double.parseDouble(d1Feature.getOrDefault("ad_view_" + prefix, "0"));
|
|
|
|
- double click = Double.parseDouble(d1Feature.getOrDefault("ad_click_" + prefix, "0"));
|
|
|
|
- double conver = Double.parseDouble(d1Feature.getOrDefault("ad_conversion_" + prefix, "0"));
|
|
|
|
- double income = Double.parseDouble(d1Feature.getOrDefault("ad_income_" + prefix, "0"));
|
|
|
|
- double cpc = NumUtil.div(income, click);
|
|
|
|
- double ctr = NumUtil.divSmoothV2(click, view, CTR_SMOOTH_BETA_FACTOR);
|
|
|
|
- featureMap.put("d1_feature_" + prefix + "_ctr", String.valueOf(ctr));
|
|
|
|
- featureMap.put("d1_feature_" + prefix + "_ctcvr", String.valueOf(NumUtil.divSmoothV2(conver, view, CTCVR_SMOOTH_BETA_FACTOR)));
|
|
|
|
- featureMap.put("d1_feature_" + prefix + "_cvr", String.valueOf(NumUtil.divSmoothV2(conver, click, CVR_SMOOTH_BETA_FACTOR)));
|
|
|
|
- featureMap.put("d1_feature_" + prefix + "_conver", String.valueOf(conver));
|
|
|
|
- featureMap.put("d1_feature_" + prefix + "_ecpm", String.valueOf(ctr * cpc * 1000));
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private void handleD2Feature(Map<String, Map<String, Double>> vidRankMaps, Map<String, String> featureMap, String cid) {
|
|
|
|
- if (MapUtils.isEmpty(vidRankMaps)) {
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- List<String> prefixes1 = Arrays.asList("ctr", "ctcvr", "ecpm");
|
|
|
|
- // List<String> prefixes1 = Arrays.asList("ctr", "ctcvr");
|
|
|
|
- List<String> prefixes2 = Arrays.asList("1d", "3d", "7d", "14d");
|
|
|
|
-
|
|
|
|
- for (String prefix1 : prefixes1) {
|
|
|
|
- for (String prefix2 : prefixes2) {
|
|
|
|
- String combinedKey = prefix1 + "_" + prefix2;
|
|
|
|
- if (vidRankMaps.containsKey(combinedKey)) {
|
|
|
|
- Double rank = vidRankMaps.get(combinedKey).getOrDefault(cid, 0.0);
|
|
|
|
- if (rank >= 1.0) {
|
|
|
|
- featureMap.put("vid_rank_" + combinedKey, String.valueOf(NumUtil.div(1, rank)));
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
private void handleH1AndH2Feature(Map<String, Map<String, String>> skuFeature,
|
|
private void handleH1AndH2Feature(Map<String, Map<String, String>> skuFeature,
|
|
Map<String, Map<String, String>> adVerFeature,
|
|
Map<String, Map<String, String>> adVerFeature,
|
|
Map<String, String> cidFeatureMap) {
|
|
Map<String, String> cidFeatureMap) {
|
|
@@ -594,111 +368,6 @@ public class RankStrategyBy688 extends RankStrategyBasic {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- private void handleD3AndB1Feature(Map<String, String> d3Feature, String cTitle, Map<String, String> featureMap,
|
|
|
|
- ScoreParam scoreParam) {
|
|
|
|
- if (MapUtils.isEmpty(d3Feature) || !d3Feature.containsKey("title") || StringUtils.isEmpty(cTitle)) {
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- String vTitle = d3Feature.get("title");
|
|
|
|
- double score;
|
|
|
|
- if (scoreParam.getExpCodeSet().contains(word2vecExp)) {
|
|
|
|
- score = SimilarityUtils.word2VecSimilarity(cTitle, vTitle);
|
|
|
|
- } else {
|
|
|
|
- score = Similarity.conceptSimilarity(cTitle, vTitle);
|
|
|
|
- }
|
|
|
|
- featureMap.put("ctitle_vtitle_similarity", String.valueOf(score));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private void handleE1AndE2Feature(Map<String, String> e1Feature, Map<String, String> e2Feature, String title,
|
|
|
|
- Map<String, String> featureMap, ScoreParam scoreParam) {
|
|
|
|
- if (StringUtils.isEmpty(title)) {
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- List<Tuple2<Map<String, String>, String>> tuple2List = Arrays.asList(new Tuple2<>(e1Feature, "e1"), new Tuple2<>(e2Feature, "e2"));
|
|
|
|
-
|
|
|
|
- List<String> tagsFieldList = Arrays.asList("tags_3d", "tags_7d", "tags_14d");
|
|
|
|
- for (Tuple2<Map<String, String>, String> tuple2 : tuple2List) {
|
|
|
|
- Map<String, String> feature = tuple2.f1;
|
|
|
|
- String prefix = tuple2.f2;
|
|
|
|
- if (MapUtils.isEmpty(feature)) {
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- for (String tagsField : tagsFieldList) {
|
|
|
|
- if (StringUtils.isNotEmpty(feature.get(tagsField))) {
|
|
|
|
- String tags = feature.get(tagsField);
|
|
|
|
- // Double[] doubles = ExtractorUtils.funcC34567ForTags(tags, title);
|
|
|
|
- Double[] doubles;
|
|
|
|
- if (scoreParam.getExpCodeSet().contains(word2vecExp)) {
|
|
|
|
- doubles = ExtractorUtils.funcC34567ForTagsNew(tags, title);
|
|
|
|
- } else {
|
|
|
|
- doubles = ExtractorUtils.funcC34567ForTags(tags, title);
|
|
|
|
- }
|
|
|
|
- featureMap.put(prefix + "_" + tagsField + "_matchnum", String.valueOf(doubles[0]));
|
|
|
|
- featureMap.put(prefix + "_" + tagsField + "_maxscore", String.valueOf(doubles[1]));
|
|
|
|
- featureMap.put(prefix + "_" + tagsField + "_avgscore", String.valueOf(doubles[2]));
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private Map<String, Double> parseC1FeatureListToTimeDiffMap(List<TupleMapEntry<Tuple5>> midActionList, long ts) {
|
|
|
|
- Map<String, Double> midTimeDiffMap = new HashMap<>();
|
|
|
|
- for (TupleMapEntry<Tuple5> entry : midActionList) {
|
|
|
|
- String cid = entry.key;
|
|
|
|
- double tsHistory = Double.parseDouble(entry.value.f1);
|
|
|
|
- double click = Double.parseDouble(entry.value.f2);
|
|
|
|
- double conver = Double.parseDouble(entry.value.f3);
|
|
|
|
- double d = (ts - tsHistory) / 3600 / 24;
|
|
|
|
- if (!midTimeDiffMap.containsKey("timediff_view_" + cid)) {
|
|
|
|
- midTimeDiffMap.put("timediff_view_" + cid, NumUtil.div(1, d));
|
|
|
|
- }
|
|
|
|
- if (!midTimeDiffMap.containsKey("timediff_click_" + cid) && click > 0) {
|
|
|
|
- midTimeDiffMap.put("timediff_click_" + cid, NumUtil.div(1, d));
|
|
|
|
- }
|
|
|
|
- if (!midTimeDiffMap.containsKey("timediff_conver_" + cid) && conver > 0) {
|
|
|
|
- midTimeDiffMap.put("timediff_conver_" + cid, NumUtil.div(1, d));
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return midTimeDiffMap;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private Map<String, Double> parseC1FeatureListToActionStaticMap(List<TupleMapEntry<Tuple5>> midActionList) {
|
|
|
|
- Map<String, Double> midActionStaticsMap = new HashMap<>();
|
|
|
|
- for (TupleMapEntry<Tuple5> entry : midActionList) {
|
|
|
|
- String cid = entry.key;
|
|
|
|
- double click = Double.parseDouble(entry.value.f2);
|
|
|
|
- double conver = Double.parseDouble(entry.value.f3);
|
|
|
|
- double income = Double.parseDouble(entry.value.f4);
|
|
|
|
-
|
|
|
|
- Double viewSum = midActionStaticsMap.getOrDefault("actionstatic_view_" + cid, 0.0);
|
|
|
|
- midActionStaticsMap.put("actionstatic_view_" + cid, 1 + viewSum);
|
|
|
|
-
|
|
|
|
- Double clickSum = midActionStaticsMap.getOrDefault("actionstatic_click_" + cid, 0.0);
|
|
|
|
- midActionStaticsMap.put("actionstatic_click_" + cid, clickSum + click);
|
|
|
|
-
|
|
|
|
- Double converSum = midActionStaticsMap.getOrDefault("actionstatic_conver_" + cid, 0.0);
|
|
|
|
- midActionStaticsMap.put("actionstatic_conver_" + cid, converSum + conver);
|
|
|
|
-
|
|
|
|
- Double incomSum = midActionStaticsMap.getOrDefault("actionstatic_income_" + cid, 0.0);
|
|
|
|
- midActionStaticsMap.put("actionstatic_income_" + cid, incomSum + income);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return midActionStaticsMap;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private Map<String, Map<String, Double>> parseD2FeatureMap(Map<String, String> d2Feature) {
|
|
|
|
- Map<String, Map<String, Double>> vidRankMaps = new HashMap<>();
|
|
|
|
- for (Map.Entry<String, String> entry : d2Feature.entrySet()) {
|
|
|
|
- String key = entry.getKey();
|
|
|
|
- String value = entry.getValue();
|
|
|
|
- Map<String, Double> valueMap = Arrays.stream(value.split(",")).map(r -> r.split(":")).collect(Collectors.toMap(rList -> rList[0], rList -> Double.parseDouble(rList[2])));
|
|
|
|
- vidRankMaps.put(key, valueMap);
|
|
|
|
- }
|
|
|
|
- return vidRankMaps;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
private void readBucketFile() {
|
|
private void readBucketFile() {
|
|
if (MapUtils.isNotEmpty(bucketsMap)) {
|
|
if (MapUtils.isNotEmpty(bucketsMap)) {
|
|
return;
|
|
return;
|