|
@@ -1,13 +1,10 @@
|
|
|
package com.tzld.piaoquan.recommend.server.service.rank.strategy;
|
|
|
|
|
|
-
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.ctrip.framework.apollo.spring.annotation.ApolloJsonValue;
|
|
|
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;
|
|
@@ -19,9 +16,7 @@ import com.tzld.piaoquan.recommend.server.service.rank.processor.RankProcessorBo
|
|
|
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;
|
|
@@ -41,100 +36,80 @@ import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* @author zhangbo
|
|
|
- * @desc 地域召回融合
|
|
|
+ * @desc 地域召回融合 流量池汤姆森
|
|
|
*/
|
|
|
@Service
|
|
|
@Slf4j
|
|
|
-public class RankStrategy4RegionMergeModelV3 extends RankService {
|
|
|
- @ApolloJsonValue("${rank.score.merge.weightv3:}")
|
|
|
+public class RankStrategy4RegionMergeModelV551 extends RankService {
|
|
|
+ @ApolloJsonValue("${rank.score.merge.weightv551:}")
|
|
|
private Map<String, Double> mergeWeight;
|
|
|
@ApolloJsonValue("${RankStrategy4DensityFilterV2:}")
|
|
|
- private final Map<String,Map<String, Map<String, String>>> filterRules = new HashMap<>();
|
|
|
+ private Map<String, Map<String, Map<String, String>>> filterRules = new HashMap<>();
|
|
|
final private String CLASS_NAME = this.getClass().getSimpleName();
|
|
|
- public void duplicate(Set<Long> setVideo, List<Video> videos){
|
|
|
+
|
|
|
+ public void duplicate(Set<Long> setVideo, List<Video> videos) {
|
|
|
Iterator<Video> iterator = videos.iterator();
|
|
|
- while(iterator.hasNext()){
|
|
|
+ while (iterator.hasNext()) {
|
|
|
Video v = iterator.next();
|
|
|
- if (setVideo.contains(v.getVideoId())){
|
|
|
+ if (setVideo.contains(v.getVideoId())) {
|
|
|
iterator.remove();
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
setVideo.add(v.getVideoId());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
@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();
|
|
|
- if (!data.isPresent()){
|
|
|
- return Collections.emptyList();
|
|
|
- }
|
|
|
- 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);
|
|
|
- }
|
|
|
+ public List<Video> mergeAndRankRovRecall(RankParam param) {
|
|
|
+ Map<String, Double> mergeWeight = this.mergeWeight != null ? this.mergeWeight : new HashMap<>(0);
|
|
|
+ //-------------------融-------------------
|
|
|
+ //-------------------合-------------------
|
|
|
+ //-------------------逻-------------------
|
|
|
+ //-------------------辑-------------------
|
|
|
|
|
|
- // 初始化上下文参数
|
|
|
- ScoreParam scoreParam = convert(param);
|
|
|
- List<RankItem> rovRecallScore = ScorerUtils.getScorerPipeline(ScorerUtils.FLOWPOOL_CONF)
|
|
|
- .scoring(scoreParam, userFeature, rankItems);
|
|
|
+ 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);
|
|
|
+ List<Video> v0 = oldRovs.size() <= sizeReturn
|
|
|
+ ? oldRovs
|
|
|
+ : oldRovs.subList(0, sizeReturn);
|
|
|
+ Set<Long> setVideo = new HashSet<>();
|
|
|
+ this.duplicate(setVideo, v0);
|
|
|
|
|
|
- if (rovRecallScore == null) {
|
|
|
- return Collections.emptyList();
|
|
|
- }
|
|
|
+ //-------------------root rov召回 融合+去重-------------------
|
|
|
+ List<Video> v8 = extractAndSort(param, RegionRealtimeRecallStrategyV6RootRov.PUSH_FORM);
|
|
|
+ this.duplicate(setVideo, v8);
|
|
|
|
|
|
- return CommonCollectionUtils.toList(rovRecallScore, i -> {
|
|
|
- // hard code 将排序分数 赋值给video的sortScore
|
|
|
- Video v = i.getVideo();
|
|
|
- v.setSortScore(i.getScore());
|
|
|
- return v;
|
|
|
- });
|
|
|
- }
|
|
|
- @Override
|
|
|
- public List<Video> mergeAndRankRovRecall(RankParam param) {
|
|
|
- //-------------------地域内部融合+去重复-------------------
|
|
|
- List<Video> rovRecallRank = new ArrayList<>();
|
|
|
+ //-------------------地域相关召回 融合+去重-------------------
|
|
|
List<Video> v1 = extractAndSort(param, RegionRealtimeRecallStrategyV1.PUSH_FORM);
|
|
|
List<Video> v2 = extractAndSort(param, RegionRealtimeRecallStrategyV2.PUSH_FORM);
|
|
|
List<Video> v3 = extractAndSort(param, RegionRealtimeRecallStrategyV3.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);
|
|
|
|
|
|
+ List<Video> rovRecallRank = new ArrayList<>();
|
|
|
+ rovRecallRank.addAll(v0);
|
|
|
+ rovRecallRank.addAll(v8.subList(0, Math.min(mergeWeight.getOrDefault("v8", 10.0).intValue(), v8.size())));
|
|
|
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", 5.0).intValue(), v4.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())));
|
|
@@ -153,43 +128,56 @@ public class RankStrategy4RegionMergeModelV3 extends RankService {
|
|
|
String date = new SimpleDateFormat("yyyyMMdd").format(calendar.getTime());
|
|
|
String hour = new SimpleDateFormat("HH").format(calendar.getTime());
|
|
|
String rtFeaPart1h = date + hour;
|
|
|
- if (rtFeaPartKeyResult != null){
|
|
|
- if (rtFeaPartKeyResult.get(1) != null){
|
|
|
+ if (rtFeaPartKeyResult != null) {
|
|
|
+ if (rtFeaPartKeyResult.get(1) != null) {
|
|
|
rtFeaPart1h = rtFeaPartKeyResult.get(1);
|
|
|
}
|
|
|
}
|
|
|
// 2 统计分
|
|
|
String cur = rtFeaPart1h;
|
|
|
- List<String> datehours = new LinkedList<>();
|
|
|
- for (int i=0; i<24; ++i){
|
|
|
+ List<String> datehours = new LinkedList<>(); // 时间是倒叙的
|
|
|
+ for (int i = 0; i < 24; ++i) {
|
|
|
datehours.add(cur);
|
|
|
cur = ExtractorUtils.subtractHours(cur, 1);
|
|
|
}
|
|
|
- for (RankItem item : items){
|
|
|
+ for (RankItem item : items) {
|
|
|
Map<String, String> itemBasicMap = item.getItemBasicFeature();
|
|
|
Map<String, Map<String, Double>> itemRealMap = item.getItemRealTimeFeature();
|
|
|
List<Double> views = getStaticData(itemRealMap, datehours, "view_pv_list_1h");
|
|
|
List<Double> plays = getStaticData(itemRealMap, datehours, "play_pv_list_1h");
|
|
|
List<Double> shares = getStaticData(itemRealMap, datehours, "share_pv_list_1h");
|
|
|
- List<Double> returns = getStaticData(itemRealMap, datehours, "p_return_uv_list_1h");
|
|
|
+ List<Double> preturns = getStaticData(itemRealMap, datehours, "p_return_uv_list_1h");
|
|
|
List<Double> allreturns = getStaticData(itemRealMap, datehours, "return_uv_list_1h");
|
|
|
|
|
|
- List<Double> share2return = getRateData(returns, shares, 1.0, 1000.0);
|
|
|
- Double share2returnScore = calScoreWeight(share2return);
|
|
|
- List<Double> view2return = getRateData(returns, views, 1.0, 1000.0);
|
|
|
- Double view2returnScore = calScoreWeight(view2return);
|
|
|
+ List<Double> share2return = getRateData(preturns, shares, 1.0, 1000.0);
|
|
|
+ Double share2returnScore = calScoreWeightNoTimeDecay(share2return);
|
|
|
+ List<Double> view2return = getRateData(preturns, views, 1.0, 1000.0);
|
|
|
+ Double view2returnScore = calScoreWeightNoTimeDecay(view2return);
|
|
|
List<Double> view2play = getRateData(plays, views, 1.0, 1000.0);
|
|
|
- Double view2playScore = calScoreWeight(view2play);
|
|
|
+ Double view2playScore = calScoreWeightNoTimeDecay(view2play);
|
|
|
List<Double> play2share = getRateData(shares, plays, 1.0, 1000.0);
|
|
|
- Double play2shareScore = calScoreWeight(play2share);
|
|
|
+ Double play2shareScore = calScoreWeightNoTimeDecay(play2share);
|
|
|
item.scoresMap.put("share2returnScore", share2returnScore);
|
|
|
item.scoresMap.put("view2returnScore", view2returnScore);
|
|
|
item.scoresMap.put("view2playScore", view2playScore);
|
|
|
item.scoresMap.put("play2shareScore", play2shareScore);
|
|
|
|
|
|
- Double allreturnsScore = calScoreWeight(allreturns);
|
|
|
+ // 全部回流的rov和ros
|
|
|
+ List<Double> share2allreturn = getRateData(allreturns, shares, 1.0, 10.0);
|
|
|
+ Double share2allreturnScore = calScoreWeightNoTimeDecay(share2allreturn);
|
|
|
+ List<Double> view2allreturn = getRateData(allreturns, views, 0.0, 0.0);
|
|
|
+ Double view2allreturnScore = calScoreWeightNoTimeDecay(view2allreturn);
|
|
|
+ item.scoresMap.put("share2allreturnScore", share2allreturnScore);
|
|
|
+ item.scoresMap.put("view2allreturnScore", view2allreturnScore);
|
|
|
+
|
|
|
+ // 全部回流
|
|
|
+ Double allreturnsScore = calScoreWeightNoTimeDecay(allreturns);
|
|
|
item.scoresMap.put("allreturnsScore", allreturnsScore);
|
|
|
|
|
|
+ // 平台回流
|
|
|
+ Double preturnsScore = calScoreWeightNoTimeDecay(preturns);
|
|
|
+ item.scoresMap.put("preturnsScore", preturnsScore);
|
|
|
+
|
|
|
// rov的趋势
|
|
|
double trendScore = calTrendScore(view2return);
|
|
|
item.scoresMap.put("trendScore", trendScore);
|
|
@@ -201,18 +189,38 @@ public class RankStrategy4RegionMergeModelV3 extends RankService {
|
|
|
}
|
|
|
// 3 融合公式
|
|
|
List<Video> result = new ArrayList<>();
|
|
|
- double alpha = this.mergeWeight.getOrDefault("alpha", 1.0);
|
|
|
- double beta = this.mergeWeight.getOrDefault("beta", 1.0);
|
|
|
- for (RankItem item : items){
|
|
|
- double trendScore = item.scoresMap.getOrDefault("trendScore", 0.0) > 0.0 ?
|
|
|
+ double a = mergeWeight.getOrDefault("a", 0.1);
|
|
|
+ double b = mergeWeight.getOrDefault("b", 0.0);
|
|
|
+ double c = mergeWeight.getOrDefault("c", 0.000001);
|
|
|
+ double d = mergeWeight.getOrDefault("d", 1.0);
|
|
|
+ double e = mergeWeight.getOrDefault("e", 1.0);
|
|
|
+ double f = mergeWeight.getOrDefault("f", 0.6);
|
|
|
+ double g = mergeWeight.getOrDefault("g", 2.0);
|
|
|
+ double h = mergeWeight.getOrDefault("h", 240.0);
|
|
|
+ double ifAdd = mergeWeight.getOrDefault("ifAdd", 1.0);
|
|
|
+ for (RankItem item : items) {
|
|
|
+ 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) > 0.0 ?
|
|
|
+ double newVideoScore = item.scoresMap.getOrDefault("newVideoScore", 0.0) > 1E-8 ?
|
|
|
item.scoresMap.getOrDefault("newVideoScore", 0.0) : 0.0;
|
|
|
- double score = item.getScoreStr() *
|
|
|
- item.scoresMap.getOrDefault("share2returnScore", 0.0)
|
|
|
- + alpha * trendScore
|
|
|
- + beta * newVideoScore
|
|
|
- ;
|
|
|
+ double strScore = item.getScoreStr();
|
|
|
+ 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 += (f * share2allreturnScore + g * view2allreturnScore);
|
|
|
+ }
|
|
|
Video video = item.getVideo();
|
|
|
video.setScore(score);
|
|
|
video.setSortScore(score);
|
|
@@ -223,66 +231,74 @@ public class RankStrategy4RegionMergeModelV3 extends RankService {
|
|
|
Collections.sort(result, Comparator.comparingDouble(o -> -o.getSortScore()));
|
|
|
return result;
|
|
|
}
|
|
|
- public double calNewVideoScore(Map<String, String> itemBasicMap){
|
|
|
+
|
|
|
+ public double calNewVideoScore(Map<String, String> itemBasicMap) {
|
|
|
double existenceDays = Double.valueOf(itemBasicMap.getOrDefault("existence_days", "30"));
|
|
|
- if (existenceDays > 8){
|
|
|
+ if (existenceDays > 5) {
|
|
|
return 0.0;
|
|
|
}
|
|
|
- double score = 1.0 / (existenceDays + 5.0);
|
|
|
+ double score = 1.0 / (existenceDays + 10.0);
|
|
|
return score;
|
|
|
}
|
|
|
- public double calTrendScore(List<Double> data){
|
|
|
+
|
|
|
+ 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);
|
|
|
+ for (int i = 0; i < size - 4; ++i) {
|
|
|
+ sum += data.get(i) - data.get(i + 4);
|
|
|
}
|
|
|
- if (sum * 10 > 0.6){
|
|
|
+ if (sum * 10 > 0.6) {
|
|
|
sum = 0.6;
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
sum = sum * 10;
|
|
|
}
|
|
|
- if (sum > 0){
|
|
|
+ if (sum > 0) {
|
|
|
// 为了打断点
|
|
|
sum = sum;
|
|
|
}
|
|
|
return sum;
|
|
|
}
|
|
|
|
|
|
- public Double calScoreWeight(List<Double> data){
|
|
|
+ public Double calScoreWeightNoTimeDecay(List<Double> data) {
|
|
|
Double up = 0.0;
|
|
|
Double down = 0.0;
|
|
|
- for (int i=0; i<data.size(); ++i){
|
|
|
- up += 1.0 / (i + 1) * data.get(i);
|
|
|
- down += 1.0 / (i + 1);
|
|
|
+ for (int i = 0; i < data.size(); ++i) {
|
|
|
+ up += 1.0 * data.get(i);
|
|
|
+ down += 1.0;
|
|
|
}
|
|
|
- return down > 1E-8? up / down: 0.0;
|
|
|
+ return down > 1E-8 ? up / down : 0.0;
|
|
|
}
|
|
|
- public List<Double> getRateData(List<Double> ups, List<Double> downs, Double up, Double down){
|
|
|
+
|
|
|
+ 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)
|
|
|
- );
|
|
|
+ for (int i = 0; i < ups.size(); ++i) {
|
|
|
+ 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<String> datehours, String key) {
|
|
|
List<Double> views = new LinkedList<>();
|
|
|
Map<String, Double> tmp = itemRealMap.getOrDefault(key, new HashMap<>());
|
|
|
- for (String dh : datehours){
|
|
|
+ for (String dh : datehours) {
|
|
|
views.add(tmp.getOrDefault(dh, 0.0D) +
|
|
|
- (views.isEmpty() ? 0.0: views.get(views.size()-1))
|
|
|
+ (views.isEmpty() ? 0.0 : views.get(views.size() - 1))
|
|
|
);
|
|
|
}
|
|
|
return views;
|
|
|
}
|
|
|
|
|
|
public List<RankItem> model(List<Video> videos, RankParam param,
|
|
|
- List<String> rtFeaPart){
|
|
|
+ List<String> rtFeaPart) {
|
|
|
List<RankItem> result = new ArrayList<>();
|
|
|
- if (videos.isEmpty()){
|
|
|
+ if (videos.isEmpty()) {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
@@ -297,19 +313,20 @@ public class RankStrategy4RegionMergeModelV3 extends RankService {
|
|
|
redisTemplate.afterPropertiesSet();
|
|
|
|
|
|
// 0: 场景特征处理
|
|
|
- Map<String, String> sceneFeatureMap = this.getSceneFeature(param);
|
|
|
+ Map<String, String> sceneFeatureMap = this.getSceneFeature(param);
|
|
|
|
|
|
// 1: user特征处理
|
|
|
Map<String, String> userFeatureMap = new HashMap<>();
|
|
|
- if (param.getMid() != null && !param.getMid().isEmpty()){
|
|
|
+ if (param.getMid() != null && !param.getMid().isEmpty()) {
|
|
|
String midKey = "user_info_4video_" + param.getMid();
|
|
|
String userFeatureStr = redisTemplate.opsForValue().get(midKey);
|
|
|
- if (userFeatureStr != null){
|
|
|
- try{
|
|
|
+ if (userFeatureStr != null) {
|
|
|
+ try {
|
|
|
userFeatureMap = JSONUtils.fromJson(userFeatureStr,
|
|
|
- new TypeToken<Map<String, String>>() {},
|
|
|
+ new TypeToken<Map<String, String>>() {
|
|
|
+ },
|
|
|
userFeatureMap);
|
|
|
- }catch (Exception e){
|
|
|
+ } catch (Exception e) {
|
|
|
log.error(String.format("parse user json is wrong in {} with {}", this.CLASS_NAME, e));
|
|
|
}
|
|
|
}
|
|
@@ -326,6 +343,7 @@ public class RankStrategy4RegionMergeModelV3 extends RankService {
|
|
|
iterator.remove();
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
Map<String, String> f1 = RankExtractorUserFeature.getOriginFeature(userFeatureMap,
|
|
|
new HashSet<String>(Arrays.asList(
|
|
|
"machineinfo_brand", "machineinfo_model", "machineinfo_platform", "machineinfo_system"
|
|
@@ -350,18 +368,19 @@ public class RankStrategy4RegionMergeModelV3 extends RankService {
|
|
|
|
|
|
List<RankItem> rankItems = CommonCollectionUtils.toList(videos, RankItem::new);
|
|
|
List<Long> videoIds = CommonCollectionUtils.toListDistinct(videos, Video::getVideoId);
|
|
|
- List<String> videoFeatureKeys = videoIds.stream().map(r-> "video_info_" + r)
|
|
|
+ List<String> videoFeatureKeys = videoIds.stream().map(r -> "video_info_" + r)
|
|
|
.collect(Collectors.toList());
|
|
|
List<String> videoFeatures = redisTemplate.opsForValue().multiGet(videoFeatureKeys);
|
|
|
- if (videoFeatures != null){
|
|
|
- for (int i=0; i<videoFeatures.size(); ++i){
|
|
|
+ if (videoFeatures != null) {
|
|
|
+ for (int i = 0; i < videoFeatures.size(); ++i) {
|
|
|
String vF = videoFeatures.get(i);
|
|
|
Map<String, String> vfMap = new HashMap<>();
|
|
|
- if (vF == null){
|
|
|
+ if (vF == null) {
|
|
|
continue;
|
|
|
}
|
|
|
- try{
|
|
|
- vfMap = JSONUtils.fromJson(vF, new TypeToken<Map<String, String>>() {}, vfMap);
|
|
|
+ try {
|
|
|
+ vfMap = JSONUtils.fromJson(vF, new TypeToken<Map<String, String>>() {
|
|
|
+ }, vfMap);
|
|
|
Map<String, String> vfMapCopy = new HashMap<>(vfMap);
|
|
|
rankItems.get(i).setItemBasicFeature(vfMapCopy);
|
|
|
Iterator<Map.Entry<String, String>> iteratorIn = vfMap.entrySet().iterator();
|
|
@@ -380,7 +399,7 @@ public class RankStrategy4RegionMergeModelV3 extends RankService {
|
|
|
);
|
|
|
f4.putAll(f5);
|
|
|
rankItems.get(i).setFeatureMap(f4);
|
|
|
- }catch (Exception e){
|
|
|
+ } catch (Exception e) {
|
|
|
log.error(String.format("parse video json is wrong in {} with {}", this.CLASS_NAME, e));
|
|
|
}
|
|
|
}
|
|
@@ -393,80 +412,82 @@ public class RankStrategy4RegionMergeModelV3 extends RankService {
|
|
|
String hour = new SimpleDateFormat("HH").format(calendar.getTime());
|
|
|
String rtFeaPart1day = date + hour;
|
|
|
String rtFeaPart1h = date + hour;
|
|
|
- if (rtFeaPartKeyResult != null){
|
|
|
- if (rtFeaPartKeyResult.get(0) != null){
|
|
|
+ if (rtFeaPartKeyResult != null) {
|
|
|
+ if (rtFeaPartKeyResult.get(0) != null) {
|
|
|
rtFeaPart1day = rtFeaPartKeyResult.get(0);
|
|
|
}
|
|
|
- if (rtFeaPartKeyResult.get(1) != null){
|
|
|
+ if (rtFeaPartKeyResult.get(1) != null) {
|
|
|
rtFeaPart1h = rtFeaPartKeyResult.get(1);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- List<String> videoRtKeys1 = videoIds.stream().map(r-> "item_rt_fea_1day_" + r)
|
|
|
+ List<String> videoRtKeys1 = videoIds.stream().map(r -> "item_rt_fea_1day_" + r)
|
|
|
.collect(Collectors.toList());
|
|
|
- List<String> videoRtKeys2 = videoIds.stream().map(r-> "item_rt_fea_1h_" + r)
|
|
|
+ List<String> videoRtKeys2 = videoIds.stream().map(r -> "item_rt_fea_1h_" + r)
|
|
|
.collect(Collectors.toList());
|
|
|
videoRtKeys1.addAll(videoRtKeys2);
|
|
|
List<String> videoRtFeatures = this.redisTemplate.opsForValue().multiGet(videoRtKeys1);
|
|
|
|
|
|
|
|
|
- if (videoRtFeatures != null){
|
|
|
+ if (videoRtFeatures != null) {
|
|
|
int j = 0;
|
|
|
- for (RankItem item: rankItems){
|
|
|
+ for (RankItem item : rankItems) {
|
|
|
String vF = videoRtFeatures.get(j);
|
|
|
++j;
|
|
|
- if (vF == null){
|
|
|
+ if (vF == null) {
|
|
|
continue;
|
|
|
}
|
|
|
Map<String, String> vfMap = new HashMap<>();
|
|
|
Map<String, Map<String, Double>> vfMapNew = new HashMap<>();
|
|
|
- try{
|
|
|
- vfMap = JSONUtils.fromJson(vF, new TypeToken<Map<String, String>>() {}, vfMap);
|
|
|
- for (Map.Entry<String, String> entry : vfMap.entrySet()){
|
|
|
+ try {
|
|
|
+ vfMap = JSONUtils.fromJson(vF, new TypeToken<Map<String, String>>() {
|
|
|
+ }, vfMap);
|
|
|
+ for (Map.Entry<String, String> entry : vfMap.entrySet()) {
|
|
|
String value = entry.getValue();
|
|
|
- if (value == null){
|
|
|
+ if (value == null) {
|
|
|
continue;
|
|
|
}
|
|
|
- String [] var1 = value.split(",");
|
|
|
+ String[] var1 = value.split(",");
|
|
|
Map<String, Double> tmp = new HashMap<>();
|
|
|
- for (String var2 : var1){
|
|
|
- String [] var3 = var2.split(":");
|
|
|
+ for (String var2 : var1) {
|
|
|
+ String[] var3 = var2.split(":");
|
|
|
tmp.put(var3[0], Double.valueOf(var3[1]));
|
|
|
}
|
|
|
vfMapNew.put(entry.getKey(), tmp);
|
|
|
}
|
|
|
- }catch (Exception e){
|
|
|
+ } 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);
|
|
|
item.getFeatureMap().putAll(f8);
|
|
|
}
|
|
|
- for (RankItem item: rankItems){
|
|
|
+ for (RankItem item : rankItems) {
|
|
|
String vF = videoRtFeatures.get(j);
|
|
|
++j;
|
|
|
- if (vF == null){
|
|
|
+ if (vF == null) {
|
|
|
continue;
|
|
|
}
|
|
|
Map<String, String> vfMap = new HashMap<>();
|
|
|
Map<String, Map<String, Double>> vfMapNew = new HashMap<>();
|
|
|
- try{
|
|
|
- vfMap = JSONUtils.fromJson(vF, new TypeToken<Map<String, String>>() {}, vfMap);
|
|
|
+ try {
|
|
|
+ vfMap = JSONUtils.fromJson(vF, new TypeToken<Map<String, String>>() {
|
|
|
+ }, vfMap);
|
|
|
|
|
|
- for (Map.Entry<String, String> entry : vfMap.entrySet()){
|
|
|
+ for (Map.Entry<String, String> entry : vfMap.entrySet()) {
|
|
|
String value = entry.getValue();
|
|
|
- if (value == null){
|
|
|
+ if (value == null) {
|
|
|
continue;
|
|
|
}
|
|
|
- String [] var1 = value.split(",");
|
|
|
+ String[] var1 = value.split(",");
|
|
|
Map<String, Double> tmp = new HashMap<>();
|
|
|
- for (String var2 : var1){
|
|
|
- String [] var3 = var2.split(":");
|
|
|
+ for (String var2 : var1) {
|
|
|
+ String[] var3 = var2.split(":");
|
|
|
tmp.put(var3[0], Double.valueOf(var3[1]));
|
|
|
}
|
|
|
vfMapNew.put(entry.getKey(), tmp);
|
|
|
}
|
|
|
item.setItemRealTimeFeature(vfMapNew);
|
|
|
- }catch (Exception e){
|
|
|
+ } 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);
|
|
@@ -475,7 +496,6 @@ public class RankStrategy4RegionMergeModelV3 extends RankService {
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
List<RankItem> rovRecallScore = ScorerUtils.getScorerPipeline(ScorerUtils.BASE_CONF)
|
|
|
.scoring(sceneFeatureMap, userFeatureMap, rankItems);
|
|
|
return rovRecallScore;
|
|
@@ -497,8 +517,8 @@ public class RankStrategy4RegionMergeModelV3 extends RankService {
|
|
|
"吉林市".equals(city) |
|
|
|
"新竹市".equals(city) |
|
|
|
"嘉义市".equals(city)
|
|
|
- ){
|
|
|
- }else{
|
|
|
+ ) {
|
|
|
+ } else {
|
|
|
city = city.replaceAll("市$", "");
|
|
|
}
|
|
|
sceneFeatureMap.put("ctx_city", city);
|
|
@@ -527,12 +547,12 @@ public class RankStrategy4RegionMergeModelV3 extends RankService {
|
|
|
Map<String, Map<String, String>> rulesMap = this.filterRules.getOrDefault(abCode, new HashMap<>(0));
|
|
|
|
|
|
//3 标签读取
|
|
|
- if (rulesMap != null && !rulesMap.isEmpty()){
|
|
|
+ if (rulesMap != null && !rulesMap.isEmpty()) {
|
|
|
RankExtractorItemTags extractorItemTags = new RankExtractorItemTags(this.redisTemplate);
|
|
|
extractorItemTags.processor(rovVideos, flowVideos);
|
|
|
}
|
|
|
//6 合并结果时间卡控
|
|
|
- if (rulesMap != null && !rulesMap.isEmpty()){
|
|
|
+ if (rulesMap != null && !rulesMap.isEmpty()) {
|
|
|
RankProcessorTagFilter.processor(rovVideos, flowVideos, rulesMap);
|
|
|
}
|
|
|
|