Prechádzať zdrojové kódy

feat:视频分发接口添加tab信息

zhaohaipeng 2 týždňov pred
rodič
commit
cbcf85886e

+ 11 - 1
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/rank/RankRouter.java

@@ -1,10 +1,13 @@
 package com.tzld.piaoquan.recommend.server.service.rank;
 
+import com.tzld.piaoquan.recommend.server.common.enums.TabType;
+import com.tzld.piaoquan.recommend.server.model.Tab;
 import com.tzld.piaoquan.recommend.server.service.ExperimentService;
 import com.tzld.piaoquan.recommend.server.service.ServiceBeanFactory;
 import com.tzld.piaoquan.recommend.server.service.rank.strategy.*;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
@@ -39,6 +42,7 @@ public class RankRouter {
         STRATEGY_CLASSES.put("569", RankStrategy4RegionMergeModelV569.class);
         STRATEGY_CLASSES.put("568", RankStrategy4RegionMergeModelV568.class);
         STRATEGY_CLASSES.put("839", RankStrategy4RegionMergeModelV839.class);
+        STRATEGY_CLASSES.put("sequence", RankSequenceStrategy.class);
         STRATEGY_CLASSES.put(relevantRank, RankStrategy4RelevantModelV1.class);
     }
 
@@ -59,7 +63,13 @@ public class RankRouter {
             return strategyMap.get(relevantRank).rank(param);
         }
 
-
+        Tab tab = param.getTab();
+        if (Objects.nonNull(tab) && StringUtils.isNotBlank(tab.getType())) {
+            TabType type = TabType.getByType(tab.getType());
+            if (Objects.equals(TabType.territory, type)) {
+                return strategyMap.get("sequence").rank(param);
+            }
+        }
 
         // 裂变层实验,使用RootSessionId尾号进行实验
         for (Map.Entry<String, RankService> entry : strategyMap.entrySet()) {

+ 10 - 2
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/rank/RankService.java

@@ -112,7 +112,9 @@ public abstract class RankService {
         return result;
     }
 
-    /** 阶段 4 + 阶段 5: 合并 + 排序打分 — rovRecallRank 顺序即合并顺序,Video.sortScore 是 rank 模型最终分 */
+    /**
+     * 阶段 4 + 阶段 5: 合并 + 排序打分 — rovRecallRank 顺序即合并顺序,Video.sortScore 是 rank 模型最终分
+     */
     private static void writeFunnelMergedStage(RankParam param, List<Video> rovRecallRank) {
         if (param == null || param.getFunnelContext() == null || CollectionUtils.isEmpty(rovRecallRank)) return;
         FunnelContext ctx = param.getFunnelContext();
@@ -125,7 +127,9 @@ public abstract class RankService {
         }
     }
 
-    /** 阶段 6: 排序截断 — 纯 rank 排序后的前 size 条(不含冷启,作为冷启替换前的快照) */
+    /**
+     * 阶段 6: 排序截断 — 纯 rank 排序后的前 size 条(不含冷启,作为冷启替换前的快照)
+     */
     private static void writeFunnelRankTruncatedStage(RankParam param, List<Video> rovRecallRank, int size) {
         if (param == null || param.getFunnelContext() == null || CollectionUtils.isEmpty(rovRecallRank)) return;
         FunnelContext ctx = param.getFunnelContext();
@@ -334,4 +338,8 @@ public abstract class RankService {
             log.error("addPushFromVideoRank ", e);
         }
     }
+
+    private void sequenceReturn() {
+
+    }
 }

+ 59 - 0
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/rank/strategy/RankSequenceStrategy.java

@@ -0,0 +1,59 @@
+package com.tzld.piaoquan.recommend.server.service.rank.strategy;
+
+import com.google.common.collect.Lists;
+import com.tzld.piaoquan.recommend.server.common.enums.TabType;
+import com.tzld.piaoquan.recommend.server.model.Tab;
+import com.tzld.piaoquan.recommend.server.model.Video;
+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.recall.strategy.CityRovnAllRovRecallStrategy;
+import com.tzld.piaoquan.recommend.server.service.recall.strategy.CityRovnRecallStrategy;
+import com.tzld.piaoquan.recommend.server.service.recall.strategy.RegionHRecallStrategy;
+import com.tzld.piaoquan.recommend.server.service.recall.strategy.RegionRealtimeRecallStrategyV1;
+import com.tzld.piaoquan.recommend.server.util.RecallUtils;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.stereotype.Service;
+
+import java.util.*;
+
+@Slf4j
+@Service
+public class RankSequenceStrategy extends RankService {
+
+    private static final List<String> territoryRecall = Lists.newArrayList(
+            CityRovnAllRovRecallStrategy.PUSH_FROM,
+            CityRovnRecallStrategy.PUSH_FROM,
+            RegionHRecallStrategy.PUSH_FORM,
+            RegionRealtimeRecallStrategyV1.PUSH_FORM
+    );
+
+    @Override
+    public List<Video> mergeAndRankRovRecall(RankParam param) {
+        List<Video> rovRecallRank = new ArrayList<>();
+        Tab tab = param.getTab();
+        if (Objects.nonNull(tab) && StringUtils.isNotBlank(tab.getType())) {
+            TabType type = TabType.getByType(tab.getType());
+            if (Objects.equals(TabType.territory, type)) {
+                this.extractRecall(param, territoryRecall, rovRecallRank);
+            }
+        }
+
+        // 记录召回源中的视频
+        this.rankBeforePostProcessor(rovRecallRank);
+        return rovRecallRank;
+    }
+
+    private void extractRecall(RankParam param, List<String> recalls, List<Video> videos) {
+        Set<Long> setVideo = new HashSet<>();
+        for (String recall : recalls) {
+            RecallUtils.extractRecall(10000, param, recall, setVideo, videos);
+        }
+    }
+
+    @Override
+    public RankResult mergeAndSort(RankParam param, List<Video> rovRecallRank, List<Video> flowPoolRank, List<Video> douHotFlowPoolRank) {
+        return new RankResult(rovRecallRank);
+    }
+}