|
@@ -3,39 +3,98 @@ package com.tzld.piaoquan.recommend.server.service.rank.strategy;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.google.common.reflect.TypeToken;
|
|
|
+import com.tzld.piaoquan.recommend.feature.domain.video.base.UserFeature;
|
|
|
import com.tzld.piaoquan.recommend.server.common.base.RankItem;
|
|
|
import com.tzld.piaoquan.recommend.server.model.Video;
|
|
|
+import com.tzld.piaoquan.recommend.server.service.flowpool.FlowPoolConstants;
|
|
|
import com.tzld.piaoquan.recommend.server.service.rank.RankParam;
|
|
|
+import com.tzld.piaoquan.recommend.server.service.rank.RankResult;
|
|
|
import com.tzld.piaoquan.recommend.server.service.rank.RankService;
|
|
|
import com.tzld.piaoquan.recommend.server.service.rank.extractor.ExtractorUtils;
|
|
|
-import com.tzld.piaoquan.recommend.server.service.rank.extractor.RankExtractorItemFeature;
|
|
|
-import com.tzld.piaoquan.recommend.server.service.rank.extractor.RankExtractorUserFeature;
|
|
|
+import com.tzld.piaoquan.recommend.server.service.rank.extractor.RankExtractorItemFeatureV2;
|
|
|
+import com.tzld.piaoquan.recommend.server.service.rank.extractor.RankExtractorItemTags;
|
|
|
+import com.tzld.piaoquan.recommend.server.service.rank.extractor.RankExtractorUserFeatureV2;
|
|
|
+import com.tzld.piaoquan.recommend.server.service.rank.processor.RankProcessorBoost;
|
|
|
+import com.tzld.piaoquan.recommend.server.service.rank.processor.RankProcessorDensity;
|
|
|
+import com.tzld.piaoquan.recommend.server.service.rank.processor.RankProcessorInsert;
|
|
|
+import com.tzld.piaoquan.recommend.server.service.rank.processor.RankProcessorTagFilter;
|
|
|
+import com.tzld.piaoquan.recommend.server.service.recall.RecallResult;
|
|
|
import com.tzld.piaoquan.recommend.server.service.recall.strategy.*;
|
|
|
+import com.tzld.piaoquan.recommend.server.service.score.ScoreParam;
|
|
|
import com.tzld.piaoquan.recommend.server.service.score.ScorerUtils;
|
|
|
import com.tzld.piaoquan.recommend.server.util.CommonCollectionUtils;
|
|
|
import com.tzld.piaoquan.recommend.server.util.JSONUtils;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
|
+import org.apache.commons.lang3.RandomUtils;
|
|
|
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
|
|
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
|
|
|
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
-
|
|
|
+import com.tzld.piaoquan.recommend.server.service.rank.extractor.ExtractorUtils;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* @author zhangbo
|
|
|
- * @desc 地域召回融合
|
|
|
+ * @desc 地域召回融合 流量池汤姆森
|
|
|
*/
|
|
|
@Service
|
|
|
@Slf4j
|
|
|
public class RankStrategy4RegionMergeModelV1 extends RankService {
|
|
|
-// @ApolloJsonValue("${video.model.weightv3:}")
|
|
|
-// private Map<String, Double> mergeWeight;
|
|
|
+ @ApolloJsonValue("${rank.score.merge.weightv1:}")
|
|
|
+ private Map<String, Double> mergeWeight;
|
|
|
+ @ApolloJsonValue("${RankStrategy4DensityFilterV2:}")
|
|
|
+ private Map<String,Map<String, Map<String, String>>> filterRules = new HashMap<>();
|
|
|
final private String CLASS_NAME = this.getClass().getSimpleName();
|
|
|
+ @Override
|
|
|
+ public List<Video> mergeAndRankFlowPoolRecall(RankParam param) {
|
|
|
+ List<Video> quickFlowPoolVideos = sortFlowPoolByThompson(param, FlowPoolConstants.QUICK_PUSH_FORM);
|
|
|
+ if (CollectionUtils.isNotEmpty(quickFlowPoolVideos)) {
|
|
|
+ return quickFlowPoolVideos;
|
|
|
+ } else {
|
|
|
+ return sortFlowPoolByThompson(param, FlowPoolConstants.PUSH_FORM);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ public List<Video> sortFlowPoolByThompson(RankParam param, String pushFrom) {
|
|
|
+
|
|
|
+ //初始化 userid
|
|
|
+ UserFeature userFeature = new UserFeature();
|
|
|
+ userFeature.setMid(param.getMid());
|
|
|
+
|
|
|
+ // 初始化RankItem
|
|
|
+ Optional<RecallResult.RecallData> data = param.getRecallResult().getData().stream()
|
|
|
+ .filter(d -> d.getPushFrom().equals(pushFrom))
|
|
|
+ .findFirst();
|
|
|
+ List<Video> videoList = data.get().getVideos();
|
|
|
+ if (videoList == null) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+ List<RankItem> rankItems = new ArrayList<>();
|
|
|
+ for (int i = 0; i < videoList.size(); i++) {
|
|
|
+ RankItem rankItem = new RankItem(videoList.get(i));
|
|
|
+ rankItems.add(rankItem);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 初始化上下文参数
|
|
|
+ ScoreParam scoreParam = convert(param);
|
|
|
+ List<RankItem> rovRecallScore = ScorerUtils.getScorerPipeline(ScorerUtils.FLOWPOOL_CONF)
|
|
|
+ .scoring(scoreParam, userFeature, rankItems);
|
|
|
+
|
|
|
+ if (rovRecallScore == null) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+
|
|
|
+ return CommonCollectionUtils.toList(rovRecallScore, i -> {
|
|
|
+ // hard code 将排序分数 赋值给video的sortScore
|
|
|
+ Video v = i.getVideo();
|
|
|
+ v.setSortScore(i.getScore());
|
|
|
+ return v;
|
|
|
+ });
|
|
|
+ }
|
|
|
public void duplicate(Set<Long> setVideo, List<Video> videos){
|
|
|
Iterator<Video> iterator = videos.iterator();
|
|
|
while(iterator.hasNext()){
|
|
@@ -49,58 +108,64 @@ public class RankStrategy4RegionMergeModelV1 extends RankService {
|
|
|
}
|
|
|
@Override
|
|
|
public List<Video> mergeAndRankRovRecall(RankParam param) {
|
|
|
- //-------------------地域内部融合+去重复-------------------
|
|
|
+ Map<String, Double> mergeWeight = this.mergeWeight != null? this.mergeWeight: new HashMap<>(0);
|
|
|
+ //-------------------融-------------------
|
|
|
+ //-------------------合-------------------
|
|
|
+ //-------------------逻-------------------
|
|
|
+ //-------------------辑-------------------
|
|
|
+
|
|
|
+ List<Video> oldRovs = new ArrayList<>();
|
|
|
+ oldRovs.addAll(extractAndSort(param, RegionHRecallStrategy.PUSH_FORM));
|
|
|
+ oldRovs.addAll(extractAndSort(param, RegionHDupRecallStrategy.PUSH_FORM));
|
|
|
+ oldRovs.addAll(extractAndSort(param, Region24HRecallStrategy.PUSH_FORM));
|
|
|
+ oldRovs.addAll(extractAndSort(param, RegionRelative24HRecallStrategy.PUSH_FORM));
|
|
|
+ oldRovs.addAll(extractAndSort(param, RegionRelative24HDupRecallStrategy.PUSH_FORM));
|
|
|
+ int sizeReturn = param.getSize();
|
|
|
+ removeDuplicate(oldRovs);
|
|
|
+ oldRovs = oldRovs.size() <= sizeReturn
|
|
|
+ ? oldRovs
|
|
|
+ : oldRovs.subList(0, sizeReturn);
|
|
|
+ Set<Long> setVideo = new HashSet<>();
|
|
|
+ this.duplicate(setVideo, oldRovs);
|
|
|
+
|
|
|
+ //-------------------地域相关召回 融合+去重-------------------
|
|
|
List<Video> rovRecallRank = new ArrayList<>();
|
|
|
- List<Video> v1 = extractAndSort(param, RegionRealtimeRecallStrategyV1.PUSH_FORM);
|
|
|
+ List<Video> v1 = extractAndSort(param, RegionRealtimeRecallStrategyV1_default.PUSH_FORM);
|
|
|
List<Video> v2 = extractAndSort(param, RegionRealtimeRecallStrategyV2.PUSH_FORM);
|
|
|
- List<Video> v3 = extractAndSort(param, RegionRealtimeRecallStrategyV3.PUSH_FORM);
|
|
|
+ List<Video> v3 = extractAndSort(param, RegionRealtimeRecallStrategyV3_default.PUSH_FORM);
|
|
|
List<Video> v4 = extractAndSort(param, RegionRealtimeRecallStrategyV4.PUSH_FORM);
|
|
|
- Set<Long> setVideo = new HashSet<>();
|
|
|
this.duplicate(setVideo, v1);
|
|
|
this.duplicate(setVideo, v2);
|
|
|
this.duplicate(setVideo, v3);
|
|
|
this.duplicate(setVideo, v4);
|
|
|
- //-------------------地域 sim returnv2 融合+去重复-------------------
|
|
|
+ //-------------------相关性召回 融合+去重-------------------
|
|
|
List<Video> v5 = extractAndSort(param, SimHotVideoRecallStrategy.PUSH_FORM);
|
|
|
List<Video> v6 = extractAndSort(param, ReturnVideoRecallStrategy.PUSH_FORM);
|
|
|
this.duplicate(setVideo, v5);
|
|
|
this.duplicate(setVideo, v6);
|
|
|
+ //-------------------节日扶持召回 融合+去重-------------------
|
|
|
+ List<Video> v7 = extractAndSort(param, FestivalRecallStrategyV1.PUSH_FORM);
|
|
|
+ this.duplicate(setVideo, v7);
|
|
|
+
|
|
|
+ rovRecallRank.addAll(oldRovs);
|
|
|
+ rovRecallRank.addAll(v1.subList(0, Math.min(mergeWeight.getOrDefault("v1", 20.0).intValue(), v1.size())));
|
|
|
+ rovRecallRank.addAll(v2.subList(0, Math.min(mergeWeight.getOrDefault("v2", 15.0).intValue(), v2.size())));
|
|
|
+ rovRecallRank.addAll(v3.subList(0, Math.min(mergeWeight.getOrDefault("v3", 10.0).intValue(), v3.size())));
|
|
|
+ rovRecallRank.addAll(v4.subList(0, Math.min(mergeWeight.getOrDefault("v4", 0.0).intValue(), v4.size())));
|
|
|
+ rovRecallRank.addAll(v5.subList(0, Math.min(mergeWeight.getOrDefault("v5", 10.0).intValue(), v5.size())));
|
|
|
+ rovRecallRank.addAll(v6.subList(0, Math.min(mergeWeight.getOrDefault("v6", 10.0).intValue(), v6.size())));
|
|
|
+ rovRecallRank.addAll(v7.subList(0, Math.min(mergeWeight.getOrDefault("v7", 10.0).intValue(), v7.size())));
|
|
|
+
|
|
|
|
|
|
-// rovRecallRank.addAll(v1);
|
|
|
-// rovRecallRank.addAll(v2);
|
|
|
-// rovRecallRank.addAll(v3);
|
|
|
-// rovRecallRank.addAll(v4);
|
|
|
-// rovRecallRank.addAll(v5);
|
|
|
-// rovRecallRank.addAll(v6);
|
|
|
|
|
|
- rovRecallRank.addAll(v1.subList(0, Math.min(20, v1.size())));
|
|
|
- rovRecallRank.addAll(v2.subList(0, Math.min(15, v2.size())));
|
|
|
- rovRecallRank.addAll(v3.subList(0, Math.min(10, v3.size())));
|
|
|
- rovRecallRank.addAll(v4.subList(0, Math.min(5, v4.size())));
|
|
|
- rovRecallRank.addAll(v5.subList(0, Math.min(10, v5.size())));
|
|
|
- rovRecallRank.addAll(v6.subList(0, Math.min(10, v6.size())));
|
|
|
|
|
|
//-------------------排-------------------
|
|
|
//-------------------序-------------------
|
|
|
//-------------------逻-------------------
|
|
|
//-------------------辑-------------------
|
|
|
-// List<String> videoIdKeys = rovRecallRank.stream()
|
|
|
-// .map(t -> param.getRankKeyPrefix() + t.getVideoId())
|
|
|
-// .collect(Collectors.toList());
|
|
|
-// List<String> videoScores = this.redisTemplate.opsForValue().multiGet(videoIdKeys);
|
|
|
-// log.info("rank mergeAndRankRovRecall videoIdKeys={}, videoScores={}", JSONUtils.toJson(videoIdKeys),
|
|
|
-// JSONUtils.toJson(videoScores));
|
|
|
-// if (CollectionUtils.isNotEmpty(videoScores)
|
|
|
-// && videoScores.size() == rovRecallRank.size()) {
|
|
|
-// for (int i = 0; i < videoScores.size(); i++) {
|
|
|
-// rovRecallRank.get(i).setSortScore(NumberUtils.toDouble(videoScores.get(i), 0.0));
|
|
|
-// }
|
|
|
-// Collections.sort(rovRecallRank, Comparator.comparingDouble(o -> -o.getSortScore()));
|
|
|
-// }
|
|
|
|
|
|
// 1 模型分
|
|
|
- List<String> rtFeaPart = new ArrayList<>();
|
|
|
- List<RankItem> items = model(rovRecallRank, param, rtFeaPart);
|
|
|
+ List<RankItem> items = model(rovRecallRank, param);
|
|
|
List<String> rtFeaPartKey = new ArrayList<>(Arrays.asList("item_rt_fea_1day_partition", "item_rt_fea_1h_partition"));
|
|
|
List<String> rtFeaPartKeyResult = this.redisTemplate.opsForValue().multiGet(rtFeaPartKey);
|
|
|
Calendar calendar = Calendar.getInstance();
|
|
@@ -114,7 +179,7 @@ public class RankStrategy4RegionMergeModelV1 extends RankService {
|
|
|
}
|
|
|
// 2 统计分
|
|
|
String cur = rtFeaPart1h;
|
|
|
- List<String> datehours = new LinkedList<>();
|
|
|
+ List<String> datehours = new LinkedList<>(); // 时间是倒叙的
|
|
|
for (int i=0; i<24; ++i){
|
|
|
datehours.add(cur);
|
|
|
cur = ExtractorUtils.subtractHours(cur, 1);
|
|
@@ -141,25 +206,103 @@ public class RankStrategy4RegionMergeModelV1 extends RankService {
|
|
|
item.scoresMap.put("view2playScore", view2playScore);
|
|
|
item.scoresMap.put("play2shareScore", play2shareScore);
|
|
|
|
|
|
+ // 全部回流的rov和ros
|
|
|
+ List<Double> share2allreturn = getRateData(returns, shares, 1.0, 10.0);
|
|
|
+ Double share2allreturnScore = calScoreWeight(share2allreturn);
|
|
|
+ List<Double> view2allreturn = getRateData(returns, views, 0.0, 0.0);
|
|
|
+ Double view2allreturnScore = calScoreWeight(view2allreturn);
|
|
|
+ item.scoresMap.put("share2allreturnScore", share2allreturnScore);
|
|
|
+ item.scoresMap.put("view2allreturnScore", view2allreturnScore);
|
|
|
+
|
|
|
+ // 全部回流
|
|
|
Double allreturnsScore = calScoreWeight(allreturns);
|
|
|
item.scoresMap.put("allreturnsScore", allreturnsScore);
|
|
|
+
|
|
|
+ // 平台回流
|
|
|
+ Double preturnsScore = calScoreWeight(returns);
|
|
|
+ item.scoresMap.put("preturnsScore", preturnsScore);
|
|
|
+
|
|
|
+ // rov的趋势
|
|
|
+ double trendScore = calTrendScore(view2return);
|
|
|
+ item.scoresMap.put("trendScore", trendScore);
|
|
|
+
|
|
|
+ // 新视频提取
|
|
|
+ double newVideoScore = calNewVideoScore(itemBasicMap);
|
|
|
+ item.scoresMap.put("newVideoScore", newVideoScore);
|
|
|
+
|
|
|
}
|
|
|
// 3 融合公式
|
|
|
List<Video> result = new ArrayList<>();
|
|
|
+ double a = mergeWeight.getOrDefault("a", 0.1);
|
|
|
+ double b = mergeWeight.getOrDefault("b", 0.0);
|
|
|
+ double bb = mergeWeight.getOrDefault("bb", 0.005);
|
|
|
+ double c = mergeWeight.getOrDefault("c", 0.0002);
|
|
|
+ double d = mergeWeight.getOrDefault("d", 1.0);
|
|
|
+ double e = mergeWeight.getOrDefault("e", 1.0);
|
|
|
+ double f = mergeWeight.getOrDefault("f", 0.1);
|
|
|
+ double g = mergeWeight.getOrDefault("g", 1.0);
|
|
|
+ double h = mergeWeight.getOrDefault("h", 20.0);
|
|
|
+ double ifAdd = mergeWeight.getOrDefault("ifAdd", 1.0);
|
|
|
for (RankItem item : items){
|
|
|
- double score = item.getScoreStr() *
|
|
|
- item.scoresMap.getOrDefault("share2returnScore", 0.0);
|
|
|
+ double trendScore = item.scoresMap.getOrDefault("trendScore", 0.0) > 1E-8 ?
|
|
|
+ item.scoresMap.getOrDefault("trendScore", 0.0) : 0.0;
|
|
|
+ double newVideoScore = item.scoresMap.getOrDefault("newVideoScore", 0.0) > 1E-8 ?
|
|
|
+ item.scoresMap.getOrDefault("newVideoScore", 0.0) : 0.0;
|
|
|
+ double strScore = item.getScoreStr();
|
|
|
+ double rosScoreModel = item.getScoreRos();
|
|
|
+ double rosScore = item.scoresMap.getOrDefault("share2returnScore", 0.0);
|
|
|
+ double share2allreturnScore = item.scoresMap.getOrDefault("share2allreturnScore", 0.0);
|
|
|
+ double view2allreturnScore = item.scoresMap.getOrDefault("view2allreturnScore", 0.0);
|
|
|
+ double preturnsScore = Math.log(1 + item.scoresMap.getOrDefault("preturnsScore", 0.0));
|
|
|
+ double score = 0.0;
|
|
|
+ if (ifAdd < 0.5){
|
|
|
+ score = Math.pow(strScore, a) * Math.pow(rosScore, b) + c * preturnsScore +
|
|
|
+ (newVideoScore > 1E-8? d * trendScore * (e + newVideoScore): 0.0);
|
|
|
+ }else {
|
|
|
+ score = a * strScore + b * rosScore + c * preturnsScore +
|
|
|
+ (newVideoScore > 1E-8? d * trendScore * (e + newVideoScore): 0.0);
|
|
|
+
|
|
|
+ }
|
|
|
+ double allreturnsScore = item.scoresMap.getOrDefault("allreturnsScore", 0.0);
|
|
|
+ if (allreturnsScore > h){
|
|
|
+ score += (bb * rosScoreModel + f * share2allreturnScore + g * view2allreturnScore);
|
|
|
+ }
|
|
|
Video video = item.getVideo();
|
|
|
video.setScore(score);
|
|
|
video.setSortScore(score);
|
|
|
video.setScoreStr(item.getScoreStr());
|
|
|
+ video.setScoreRos(item.getScoreRos());
|
|
|
video.setScoresMap(item.getScoresMap());
|
|
|
result.add(video);
|
|
|
}
|
|
|
Collections.sort(result, Comparator.comparingDouble(o -> -o.getSortScore()));
|
|
|
return result;
|
|
|
}
|
|
|
-
|
|
|
+ public double calNewVideoScore(Map<String, String> itemBasicMap){
|
|
|
+ double existenceDays = Double.valueOf(itemBasicMap.getOrDefault("existence_days", "30"));
|
|
|
+ if (existenceDays > 5){
|
|
|
+ return 0.0;
|
|
|
+ }
|
|
|
+ double score = 1.0 / (existenceDays + 10.0);
|
|
|
+ return score;
|
|
|
+ }
|
|
|
+ public double calTrendScore(List<Double> data){
|
|
|
+ double sum = 0.0;
|
|
|
+ int size = data.size();
|
|
|
+ for (int i=0; i<size-4; ++i){
|
|
|
+ sum += data.get(i) - data.get(i+4);
|
|
|
+ }
|
|
|
+ if (sum * 10 > 0.6){
|
|
|
+ sum = 0.6;
|
|
|
+ }else{
|
|
|
+ sum = sum * 10;
|
|
|
+ }
|
|
|
+ if (sum > 0){
|
|
|
+ // 为了打断点
|
|
|
+ sum = sum;
|
|
|
+ }
|
|
|
+ return sum;
|
|
|
+ }
|
|
|
public Double calScoreWeight(List<Double> data){
|
|
|
Double up = 0.0;
|
|
|
Double down = 0.0;
|
|
@@ -172,13 +315,16 @@ public class RankStrategy4RegionMergeModelV1 extends RankService {
|
|
|
public List<Double> getRateData(List<Double> ups, List<Double> downs, Double up, Double down){
|
|
|
List<Double> data = new LinkedList<>();
|
|
|
for(int i=0; i<ups.size(); ++i){
|
|
|
- data.add(
|
|
|
- (ups.get(i) + up) / (downs.get(i) + down)
|
|
|
- );
|
|
|
+ if (ExtractorUtils.isDoubleEqualToZero(downs.get(i) + down)){
|
|
|
+ data.add(0.0);
|
|
|
+ }else{
|
|
|
+ data.add(
|
|
|
+ (ups.get(i) + up) / (downs.get(i) + down)
|
|
|
+ );
|
|
|
+ }
|
|
|
}
|
|
|
return data;
|
|
|
}
|
|
|
-
|
|
|
public List<Double> getStaticData(Map<String, Map<String, Double>> itemRealMap,
|
|
|
List<String> datehours, String key){
|
|
|
List<Double> views = new LinkedList<>();
|
|
@@ -190,9 +336,7 @@ public class RankStrategy4RegionMergeModelV1 extends RankService {
|
|
|
}
|
|
|
return views;
|
|
|
}
|
|
|
-
|
|
|
- public List<RankItem> model(List<Video> videos, RankParam param,
|
|
|
- List<String> rtFeaPart){
|
|
|
+ public List<RankItem> model(List<Video> videos, RankParam param){
|
|
|
List<RankItem> result = new ArrayList<>();
|
|
|
if (videos.isEmpty()){
|
|
|
return result;
|
|
@@ -228,14 +372,13 @@ public class RankStrategy4RegionMergeModelV1 extends RankService {
|
|
|
JSONObject obj = new JSONObject();
|
|
|
obj.put("name", "user_key_in_model_is_null");
|
|
|
obj.put("class", this.CLASS_NAME);
|
|
|
- log.info(obj.toString());
|
|
|
-// return videos;
|
|
|
}
|
|
|
}
|
|
|
final Set<String> userFeatureSet = new HashSet<>(Arrays.asList(
|
|
|
"machineinfo_brand", "machineinfo_model", "machineinfo_platform", "machineinfo_system",
|
|
|
"u_1day_exp_cnt", "u_1day_click_cnt", "u_1day_share_cnt", "u_1day_return_cnt",
|
|
|
- "u_3day_exp_cnt", "u_3day_click_cnt", "u_3day_share_cnt", "u_3day_return_cnt"
|
|
|
+ "u_3day_exp_cnt", "u_3day_click_cnt", "u_3day_share_cnt", "u_3day_return_cnt",
|
|
|
+ "u_7day_exp_cnt", "u_7day_click_cnt", "u_7day_share_cnt", "u_7day_return_cnt"
|
|
|
));
|
|
|
Iterator<Map.Entry<String, String>> iterator = userFeatureMap.entrySet().iterator();
|
|
|
while (iterator.hasNext()) {
|
|
@@ -244,27 +387,29 @@ public class RankStrategy4RegionMergeModelV1 extends RankService {
|
|
|
iterator.remove();
|
|
|
}
|
|
|
}
|
|
|
- Map<String, String> f1 = RankExtractorUserFeature.getOriginFeature(userFeatureMap,
|
|
|
+ Map<String, String> f1 = RankExtractorUserFeatureV2.getOriginFeature(userFeatureMap,
|
|
|
new HashSet<String>(Arrays.asList(
|
|
|
"machineinfo_brand", "machineinfo_model", "machineinfo_platform", "machineinfo_system"
|
|
|
))
|
|
|
);
|
|
|
- Map<String, String> f2 = RankExtractorUserFeature.getUserRateFeature(userFeatureMap);
|
|
|
- Map<String, String> f3 = RankExtractorUserFeature.cntFeatureChange(userFeatureMap,
|
|
|
+ Map<String, Double> f2__ = RankExtractorUserFeatureV2.getUserRateFeature(userFeatureMap);
|
|
|
+ Map<String, String> f2 = RankExtractorUserFeatureV2.rateFeatureChange(f2__);
|
|
|
+ Map<String, String> f3 = RankExtractorUserFeatureV2.cntFeatureChange(userFeatureMap,
|
|
|
new HashSet<String>(Arrays.asList(
|
|
|
"u_1day_exp_cnt", "u_1day_click_cnt", "u_1day_share_cnt", "u_1day_return_cnt",
|
|
|
- "u_3day_exp_cnt", "u_3day_click_cnt", "u_3day_share_cnt", "u_3day_return_cnt"
|
|
|
+ "u_3day_exp_cnt", "u_3day_click_cnt", "u_3day_share_cnt", "u_3day_return_cnt",
|
|
|
+ "u_7day_exp_cnt", "u_7day_click_cnt", "u_7day_share_cnt", "u_7day_return_cnt"
|
|
|
))
|
|
|
);
|
|
|
f1.putAll(f2);
|
|
|
f1.putAll(f3);
|
|
|
- log.info("userFeature in model = {}", JSONUtils.toJson(f1));
|
|
|
|
|
|
// 2-1: item特征处理
|
|
|
final Set<String> itemFeatureSet = new HashSet<>(Arrays.asList(
|
|
|
"total_time", "play_count_total",
|
|
|
"i_1day_exp_cnt", "i_1day_click_cnt", "i_1day_share_cnt", "i_1day_return_cnt",
|
|
|
- "i_3day_exp_cnt", "i_3day_click_cnt", "i_3day_share_cnt", "i_3day_return_cnt"
|
|
|
+ "i_3day_exp_cnt", "i_3day_click_cnt", "i_3day_share_cnt", "i_3day_return_cnt",
|
|
|
+ "i_7day_exp_cnt", "i_7day_click_cnt", "i_7day_share_cnt", "i_7day_return_cnt"
|
|
|
));
|
|
|
|
|
|
List<RankItem> rankItems = CommonCollectionUtils.toList(videos, RankItem::new);
|
|
@@ -281,7 +426,8 @@ public class RankStrategy4RegionMergeModelV1 extends RankService {
|
|
|
}
|
|
|
try{
|
|
|
vfMap = JSONUtils.fromJson(vF, new TypeToken<Map<String, String>>() {}, vfMap);
|
|
|
- rankItems.get(i).setItemBasicFeature(vfMap);
|
|
|
+ Map<String, String> vfMapCopy = new HashMap<>(vfMap);
|
|
|
+ rankItems.get(i).setItemBasicFeature(vfMapCopy);
|
|
|
Iterator<Map.Entry<String, String>> iteratorIn = vfMap.entrySet().iterator();
|
|
|
while (iteratorIn.hasNext()) {
|
|
|
Map.Entry<String, String> entry = iteratorIn.next();
|
|
@@ -289,12 +435,14 @@ public class RankStrategy4RegionMergeModelV1 extends RankService {
|
|
|
iteratorIn.remove();
|
|
|
}
|
|
|
}
|
|
|
- Map<String, String> f4 = RankExtractorItemFeature.getItemRateFeature(vfMap);
|
|
|
- Map<String, String> f5 = RankExtractorItemFeature.cntFeatureChange(vfMap,
|
|
|
+ Map<String, Double> f4__ = RankExtractorItemFeatureV2.getItemRateFeature(vfMap);
|
|
|
+ Map<String, String> f4 = RankExtractorItemFeatureV2.rateFeatureChange(f4__);
|
|
|
+ Map<String, String> f5 = RankExtractorItemFeatureV2.cntFeatureChange(vfMap,
|
|
|
new HashSet<String>(Arrays.asList(
|
|
|
"total_time", "play_count_total",
|
|
|
"i_1day_exp_cnt", "i_1day_click_cnt", "i_1day_share_cnt", "i_1day_return_cnt",
|
|
|
- "i_3day_exp_cnt", "i_3day_click_cnt", "i_3day_share_cnt", "i_3day_return_cnt"))
|
|
|
+ "i_3day_exp_cnt", "i_3day_click_cnt", "i_3day_share_cnt", "i_3day_return_cnt",
|
|
|
+ "i_7day_exp_cnt", "i_7day_click_cnt", "i_7day_share_cnt", "i_7day_return_cnt"))
|
|
|
);
|
|
|
f4.putAll(f5);
|
|
|
rankItems.get(i).setFeatureMap(f4);
|
|
@@ -327,7 +475,6 @@ public class RankStrategy4RegionMergeModelV1 extends RankService {
|
|
|
videoRtKeys1.addAll(videoRtKeys2);
|
|
|
List<String> videoRtFeatures = this.redisTemplate.opsForValue().multiGet(videoRtKeys1);
|
|
|
|
|
|
-
|
|
|
if (videoRtFeatures != null){
|
|
|
int j = 0;
|
|
|
for (RankItem item: rankItems){
|
|
@@ -356,7 +503,8 @@ public class RankStrategy4RegionMergeModelV1 extends RankService {
|
|
|
}catch (Exception e){
|
|
|
log.error(String.format("parse video item_rt_fea_1day_ json is wrong in {} with {}", this.CLASS_NAME, e));
|
|
|
}
|
|
|
- Map<String, String> f8 = RankExtractorItemFeature.getItemRealtimeRate(vfMapNew, rtFeaPart1day);
|
|
|
+ Map<String, Double> f8__ = RankExtractorItemFeatureV2.getItemRealtimeRate(vfMapNew, rtFeaPart1day);
|
|
|
+ Map<String, String> f8 = RankExtractorItemFeatureV2.rateFeatureChange(f8__);
|
|
|
item.getFeatureMap().putAll(f8);
|
|
|
}
|
|
|
for (RankItem item: rankItems){
|
|
@@ -387,26 +535,19 @@ public class RankStrategy4RegionMergeModelV1 extends RankService {
|
|
|
}catch (Exception e){
|
|
|
log.error(String.format("parse video item_rt_fea_1h_ json is wrong in {} with {}", this.CLASS_NAME, e));
|
|
|
}
|
|
|
- Map<String, String> f8 = RankExtractorItemFeature.getItemRealtimeRate(vfMapNew, rtFeaPart1h);
|
|
|
+ Map<String, Double> f8__ = RankExtractorItemFeatureV2.getItemRealtimeRate(vfMapNew, rtFeaPart1h);
|
|
|
+ Map<String, String> f8 = RankExtractorItemFeatureV2.rateFeatureChange(f8__);
|
|
|
item.getFeatureMap().putAll(f8);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- log.info("ItemFeature = {}", JSONUtils.toJson(videoFeatures));
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- List<RankItem> rovRecallScore = ScorerUtils.getScorerPipeline(ScorerUtils.BASE_CONF)
|
|
|
+ List<RankItem> rovRecallScore = ScorerUtils.getScorerPipeline("feeds_score_config_20240228.conf")
|
|
|
.scoring(sceneFeatureMap, userFeatureMap, rankItems);
|
|
|
- log.info("mergeAndRankRovRecallNew rovRecallScore={}", JSONUtils.toJson(rovRecallScore));
|
|
|
JSONObject obj = new JSONObject();
|
|
|
obj.put("name", "user_key_in_model_is_not_null");
|
|
|
obj.put("class", this.CLASS_NAME);
|
|
|
- log.info(obj.toString());
|
|
|
return rovRecallScore;
|
|
|
}
|
|
|
-
|
|
|
private Map<String, String> getSceneFeature(RankParam param) {
|
|
|
Map<String, String> sceneFeatureMap = new HashMap<>();
|
|
|
String provinceCn = param.getProvince();
|
|
@@ -435,5 +576,92 @@ public class RankStrategy4RegionMergeModelV1 extends RankService {
|
|
|
|
|
|
return sceneFeatureMap;
|
|
|
}
|
|
|
+ @Override
|
|
|
+ public RankResult mergeAndSort(RankParam param, List<Video> rovVideos, List<Video> flowVideos) {
|
|
|
+
|
|
|
+ //1 兜底策略,rov池子不足时,用冷启池填补。直接返回。
|
|
|
+ if (CollectionUtils.isEmpty(rovVideos)) {
|
|
|
+ if (param.getSize() < flowVideos.size()) {
|
|
|
+ return new RankResult(flowVideos.subList(0, param.getSize()));
|
|
|
+ } else {
|
|
|
+ return new RankResult(flowVideos);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //2 根据实验号解析阿波罗参数。
|
|
|
+ String abCode = param.getAbCode();
|
|
|
+ Map<String, Map<String, String>> rulesMap = this.filterRules.getOrDefault(abCode, new HashMap<>(0));
|
|
|
+
|
|
|
+ //3 标签读取
|
|
|
+ if (rulesMap != null && !rulesMap.isEmpty()){
|
|
|
+ RankExtractorItemTags extractorItemTags = new RankExtractorItemTags(this.redisTemplate);
|
|
|
+ extractorItemTags.processor(rovVideos, flowVideos);
|
|
|
+ }
|
|
|
+ //6 合并结果时间卡控
|
|
|
+ if (rulesMap != null && !rulesMap.isEmpty()){
|
|
|
+ RankProcessorTagFilter.processor(rovVideos, flowVideos, rulesMap);
|
|
|
+ }
|
|
|
+
|
|
|
+ //4 rov池提权功能
|
|
|
+ RankProcessorBoost.boostByTag(rovVideos, rulesMap);
|
|
|
+
|
|
|
+ //5 rov池强插功能
|
|
|
+ RankProcessorInsert.insertByTag(param, rovVideos, rulesMap);
|
|
|
+
|
|
|
+ //7 流量池按比例强插
|
|
|
+ List<Video> result = new ArrayList<>();
|
|
|
+ for (int i = 0; i < param.getTopK() && i < rovVideos.size(); i++) {
|
|
|
+ result.add(rovVideos.get(i));
|
|
|
+ }
|
|
|
+ double flowPoolP = getFlowPoolP(param);
|
|
|
+ int flowPoolIndex = 0;
|
|
|
+ int rovPoolIndex = param.getTopK();
|
|
|
+ for (int i = 0; i < param.getSize() - param.getTopK(); i++) {
|
|
|
+ double rand = RandomUtils.nextDouble(0, 1);
|
|
|
+ log.info("rand={}, flowPoolP={}", rand, flowPoolP);
|
|
|
+ if (rand < flowPoolP) {
|
|
|
+ if (flowPoolIndex < flowVideos.size()) {
|
|
|
+ result.add(flowVideos.get(flowPoolIndex++));
|
|
|
+ } else {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (rovPoolIndex < rovVideos.size()) {
|
|
|
+ result.add(rovVideos.get(rovPoolIndex++));
|
|
|
+ } else {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (rovPoolIndex >= rovVideos.size()) {
|
|
|
+ for (int i = flowPoolIndex; i < flowVideos.size() && result.size() < param.getSize(); i++) {
|
|
|
+ result.add(flowVideos.get(i));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (flowPoolIndex >= flowVideos.size()) {
|
|
|
+ for (int i = rovPoolIndex; i < rovVideos.size() && result.size() < param.getSize(); i++) {
|
|
|
+ result.add(rovVideos.get(i));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //8 合并结果密度控制
|
|
|
+ Map<String, Integer> densityRules = new HashMap<>();
|
|
|
+ if (rulesMap != null && !rulesMap.isEmpty()) {
|
|
|
+ for (Map.Entry<String, Map<String, String>> entry : rulesMap.entrySet()) {
|
|
|
+ String key = entry.getKey();
|
|
|
+ Map<String, String> value = entry.getValue();
|
|
|
+ if (value.containsKey("density")) {
|
|
|
+ densityRules.put(key, Integer.valueOf(value.get("density")));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Set<Long> videosSet = result.stream().map(Video::getVideoId).collect(Collectors.toSet());
|
|
|
+ List<Video> rovRecallRankNew = rovVideos.stream().filter(r -> !videosSet.contains(r.getVideoId())).collect(Collectors.toList());
|
|
|
+ List<Video> flowPoolRankNew = flowVideos.stream().filter(r -> !videosSet.contains(r.getVideoId())).collect(Collectors.toList());
|
|
|
+ List<Video> resultWithDensity = RankProcessorDensity.mergeDensityControl(result,
|
|
|
+ rovRecallRankNew, flowPoolRankNew, densityRules);
|
|
|
+
|
|
|
+ return new RankResult(resultWithDensity);
|
|
|
+ }
|
|
|
|
|
|
}
|