|
@@ -3,10 +3,8 @@ 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;
|
|
@@ -18,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;
|
|
@@ -42,8 +38,8 @@ import java.util.stream.Collectors;
|
|
|
* @author zhangbo
|
|
|
* @desc 地域召回融合 流量池汤姆森
|
|
|
*/
|
|
|
-@Slf4j
|
|
|
@Service
|
|
|
+@Slf4j
|
|
|
public class RankStrategy4RegionMergeModelV547 extends RankService {
|
|
|
@ApolloJsonValue("${rank.score.merge.weightv547:}")
|
|
|
private Map<String, Double> mergeWeight;
|
|
@@ -51,56 +47,6 @@ public class RankStrategy4RegionMergeModelV547 extends RankService {
|
|
|
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();
|
|
|
- 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);
|
|
|
- }
|
|
|
-
|
|
|
- // 初始化上下文参数
|
|
|
- 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()) {
|
|
@@ -200,13 +146,13 @@ public class RankStrategy4RegionMergeModelV547 extends RankService {
|
|
|
List<Double> allreturns = getStaticData(itemRealMap, datehours, "return_uv_list_1h");
|
|
|
|
|
|
List<Double> share2return = getRateData(preturns, shares, 1.0, 1000.0);
|
|
|
- Double share2returnScore = calScoreWeight(share2return);
|
|
|
+ Double share2returnScore = calScoreWeightNoTimeDecay(share2return);
|
|
|
List<Double> view2return = getRateData(preturns, views, 1.0, 1000.0);
|
|
|
- Double view2returnScore = calScoreWeight(view2return);
|
|
|
+ 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);
|
|
@@ -214,18 +160,18 @@ public class RankStrategy4RegionMergeModelV547 extends RankService {
|
|
|
|
|
|
// 全部回流的rov和ros
|
|
|
List<Double> share2allreturn = getRateData(allreturns, shares, 1.0, 10.0);
|
|
|
- Double share2allreturnScore = calScoreWeight(share2allreturn);
|
|
|
+ Double share2allreturnScore = calScoreWeightNoTimeDecay(share2allreturn);
|
|
|
List<Double> view2allreturn = getRateData(allreturns, views, 0.0, 0.0);
|
|
|
- Double view2allreturnScore = calScoreWeight(view2allreturn);
|
|
|
+ Double view2allreturnScore = calScoreWeightNoTimeDecay(view2allreturn);
|
|
|
item.scoresMap.put("share2allreturnScore", share2allreturnScore);
|
|
|
item.scoresMap.put("view2allreturnScore", view2allreturnScore);
|
|
|
|
|
|
// 全部回流
|
|
|
- Double allreturnsScore = calScoreWeight(allreturns);
|
|
|
+ Double allreturnsScore = calScoreWeightNoTimeDecay(allreturns);
|
|
|
item.scoresMap.put("allreturnsScore", allreturnsScore);
|
|
|
|
|
|
// 平台回流
|
|
|
- Double preturnsScore = calScoreWeight(preturns);
|
|
|
+ Double preturnsScore = calScoreWeightNoTimeDecay(preturns);
|
|
|
item.scoresMap.put("preturnsScore", preturnsScore);
|
|
|
|
|
|
// rov的趋势
|
|
@@ -309,12 +255,12 @@ public class RankStrategy4RegionMergeModelV547 extends RankService {
|
|
|
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);
|
|
|
+ up += 1.0 * data.get(i);
|
|
|
+ down += 1.0;
|
|
|
}
|
|
|
return down > 1E-8 ? up / down : 0.0;
|
|
|
}
|
|
@@ -678,12 +624,12 @@ public class RankStrategy4RegionMergeModelV547 extends RankService {
|
|
|
|
|
|
RankStrategy4RegionMergeModelV547 job = new RankStrategy4RegionMergeModelV547();
|
|
|
List<Double> l1 = job.getRateData(job.help(up1, "2024031115", 24), job.help(down1, "2024031115", 24), 1., 10.);
|
|
|
- Double d1 = job.calScoreWeight(l1);
|
|
|
+ Double d1 = job.calScoreWeightNoTimeDecay(l1);
|
|
|
|
|
|
System.out.println(d1);
|
|
|
|
|
|
List<Double> l2 = job.getRateData(job.help(up2, "2024031115", 24), job.help(down2, "2024031115", 24), 1., 10.);
|
|
|
- Double d2 = job.calScoreWeight(l2);
|
|
|
+ Double d2 = job.calScoreWeightNoTimeDecay(l2);
|
|
|
|
|
|
System.out.println(d2);
|
|
|
|