瀏覽代碼

Merge branch 'master' into feature/zhangbo_rank

# Conflicts:
#	recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/RecommendService.java
#	recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/recall/RecallParam.java
zhangbo 1 年之前
父節點
當前提交
80db0ac302
共有 37 個文件被更改,包括 986 次插入709 次删除
  1. 0 3
      recommend-server-client/src/main/java/com/tzld/piaoquan/recommend/server/client/ModelClient.java
  2. 94 11
      recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/implement/TopRecommendPipeline.java
  3. 1 0
      recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/model/RecommendParam.java
  4. 6 4
      recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/RecommendService.java
  5. 12 15
      recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/filter/AbstractFilterService.java
  6. 0 3
      recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/filter/FlowPoolWithScoreFilterService.java
  7. 0 2
      recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/filter/strategy/AllowListStrategy.java
  8. 1 3
      recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/rank/RankRouter.java
  9. 3 8
      recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/rank/RankService.java
  10. 0 2
      recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/rank/strategy/FestivalStrategy4RankModel.java
  11. 0 1
      recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/rank/strategy/RankStrategy4Density.java
  12. 75 96
      recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/rank/strategy/RankStrategy4RankModel.java
  13. 113 99
      recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/rank/strategy/RankStrategy4RegionMergeModelV2.java
  14. 3 0
      recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/rank/strategy/RankStrategy4RegionMergeModelV3.java
  15. 3 5
      recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/rank/strategy/RankStrategy4RegionMergeModelV4.java
  16. 3 1
      recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/rank/strategy/RankStrategy4RegionMergeModelV5.java
  17. 3 1
      recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/rank/strategy/RankStrategy4RegionMergeModelV536.java
  18. 112 110
      recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/rank/strategy/RankStrategy4RegionMergeModelV547.java
  19. 95 102
      recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/rank/strategy/RankStrategy4RegionMergeModelV548.java
  20. 0 1
      recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/rank/strategy/RankStrategy4RegionMergeModelV561.java
  21. 0 1
      recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/rank/strategy/RankStrategy4RegionMergeModelV562.java
  22. 0 1
      recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/rank/strategy/RankStrategy4RegionMergeModelV6.java
  23. 3 0
      recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/rank/strategy/RankStrategyFlowThompsonModel.java
  24. 1 1
      recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/recall/RecallParam.java
  25. 54 16
      recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/recall/RecallService.java
  26. 0 5
      recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/recall/strategy/AbstractFlowPoolWithLevelRecallStrategy.java
  27. 0 7
      recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/recall/strategy/AbstractFlowPoolWithLevelScoreRecallStrategy.java
  28. 0 6
      recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/recall/strategy/AbstractFlowPoolWithScoreRecallStrategy.java
  29. 6 16
      recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/recall/strategy/BlessRecallStrategy.java
  30. 6 14
      recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/recall/strategy/FestivalRecallStrategyV1.java
  31. 145 0
      recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/recall/strategy/FlowPoolWithLevelRecallStrategyFilterDigit.java
  32. 164 0
      recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/recall/strategy/FlowPoolWithLevelRecallStrategyTomsonFilterDigit.java
  33. 0 5
      recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/recall/strategy/FlowPoolWithLevelScoreRecallStrategy.java
  34. 11 33
      recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/recall/strategy/RegionRealtimeRecallStrategyV1.java
  35. 9 31
      recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/recall/strategy/RegionRealtimeRecallStrategyV1_default.java
  36. 63 66
      recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/score4recall/strategy/BlessRecallScore.java
  37. 0 40
      recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/util/HttpClientFactory.java

+ 0 - 3
recommend-server-client/src/main/java/com/tzld/piaoquan/recommend/server/client/ModelClient.java

@@ -27,12 +27,9 @@ public class ModelClient {
                 .build();
         ScoreResponse response = client.score(request);
         if (response == null || !response.hasResult()) {
-//            log.info("score grpc error");
             return null;
         }
         if (response.getResult().getCode() != 1) {
-//            log.info("score grpc code={}, msg={}", response.getResult().getCode(),
-//                    response.getResult().getMessage());
             return null;
         }
         return response.getScoreMap();

+ 94 - 11
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/implement/TopRecommendPipeline.java

@@ -2,6 +2,7 @@ package com.tzld.piaoquan.recommend.server.implement;
 
 
 import com.alibaba.fastjson.JSONObject;
+import com.ctrip.framework.apollo.spring.annotation.ApolloJsonValue;
 import com.google.common.base.Stopwatch;
 import com.google.common.reflect.TypeToken;
 import com.tzld.piaoquan.recommend.server.common.base.RankItem;
@@ -46,6 +47,8 @@ public class TopRecommendPipeline {
 
     @Value("${recommend.recall.num:500}")
     private int recallNum;
+    @ApolloJsonValue("${rank.score.merge.weightv547:}")
+    private Map<String, Double> mergeWeight;
     @Resource
     private RedisSmartClient client;
     @Resource
@@ -55,6 +58,7 @@ public class TopRecommendPipeline {
     @PostConstruct
     public void init() {
         queueProvider = new RedisBackedQueue(client, 15 * 60 * 1000L);
+        mergeWeight = mergeWeight == null ? new HashMap<>() : mergeWeight;
     }
 
     public List<Video> feeds(final RecommendRequest requestData,
@@ -183,21 +187,23 @@ public class TopRecommendPipeline {
     }
 
     private List<Video> rankItem2Video(List<RankItem> items) {
+        // 1 模型分
+        List<String> rtFeaPart = new ArrayList<>();
         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();
         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);
         }
@@ -207,12 +213,12 @@ public class TopRecommendPipeline {
             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);
+            List<Double> share2return = getRateData(preturns, shares, 1.0, 1000.0);
             Double share2returnScore = calScoreWeight(share2return);
-            List<Double> view2return = getRateData(returns, views, 1.0, 1000.0);
+            List<Double> view2return = getRateData(preturns, views, 1.0, 1000.0);
             Double view2returnScore = calScoreWeight(view2return);
             List<Double> view2play = getRateData(plays, views, 1.0, 1000.0);
             Double view2playScore = calScoreWeight(view2play);
@@ -223,15 +229,65 @@ public class TopRecommendPipeline {
             item.scoresMap.put("view2playScore", view2playScore);
             item.scoresMap.put("play2shareScore", play2shareScore);
 
+            // 全部回流的rov和ros
+            List<Double> share2allreturn = getRateData(allreturns, shares, 1.0, 10.0);
+            Double share2allreturnScore = calScoreWeight(share2allreturn);
+            List<Double> view2allreturn = getRateData(allreturns, 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(preturns);
+            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<>();
-        for (RankItem item : items){
-            double score = item.getScoreStr() *
-                    item.scoresMap.getOrDefault("share2returnScore", 0.0) *
-                    Math.log(1 + item.scoresMap.getOrDefault("allreturnsScore", 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.8);
+        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) > 1E-8 ?
+                    item.scoresMap.getOrDefault("newVideoScore", 0.0) : 0.0;
+            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 = new Video();
             video.setVideoId(Long.parseLong(item.getId()));
             video.setPushFrom(item.getQueue());
@@ -245,6 +301,33 @@ public class TopRecommendPipeline {
         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;
+    }
+
     private void duplicate(List<RankItem> items) {
         Set<String> ids = new HashSet<>();
         List<RankItem> result = new ArrayList<>();

+ 1 - 0
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/model/RecommendParam.java

@@ -28,6 +28,7 @@ public class RecommendParam {
     private String hRuleKey;
 
     private int flowPoolId;
+    private int lastDigit;
     private String flowPoolAbtestGroup;
     private String rankKeyPrefix;
     private int appType;

+ 6 - 4
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/RecommendService.java

@@ -125,8 +125,6 @@ public class RecommendService {
                 stopwatch.stop().elapsed(TimeUnit.MILLISECONDS));
         stopwatch.reset().start();
         List<Video> videos = videoRecommend(param);
-        // log.info("videoRecommend={}, videoRecommend cost={}", JSONUtils.toJson(videos),
-//        stopwatch.stop().elapsed(TimeUnit.MILLISECONDS));
         stopwatch.reset().start();
         updateCache(request, param, videos);
 
@@ -332,7 +330,7 @@ public class RecommendService {
         }
 
         // 流量池分发实验组划分
-        int flowPoolIdChoice = flowPoolIds.get(RandomUtils.nextInt(0, flowPoolIds.size() - 1));
+        int flowPoolIdChoice = flowPoolIds.get(RandomUtils.nextInt(0, flowPoolIds.size()));
         param.setFlowPoolId(flowPoolIdChoice);
         param.setFlowPoolAbtestGroup("control_group");
         Map<String, List<Integer>> flowPoolConfig = flowPoolConfigService.getFlowPoolConfig();
@@ -342,6 +340,10 @@ public class RecommendService {
             }
         }
 
+        // @desc 新的流量池分发实验组划分,每个尾号不同策略分组。 @time 20240318 @author 张博
+        int lastDigit = RandomUtils.nextInt(0, 10);
+        param.setLastDigit(lastDigit);
+
         // 风险过滤
         List<String> keysRisk = new ArrayList<>();
         keysRisk.add("RISK_SHIELD_FILTER_RULE_V1_JSON");
@@ -497,7 +499,7 @@ public class RecommendService {
 
         recallParam.setVideoId(param.getVideoId());
         recallParam.setFlowPoolAbtestGroup(param.getFlowPoolAbtestGroup());
-        recallParam.setFlowPoolId(param.getFlowPoolId());
+        recallParam.setLastDigit(param.getLastDigit());
 
         String provinceCode = StringUtils.isNotBlank(param.getProvinceCode())
                 ? param.getProvinceCode()

+ 12 - 15
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/filter/AbstractFilterService.java

@@ -51,10 +51,11 @@ public abstract class AbstractFilterService {
 
     @ApolloJsonValue("${supply.exp.video.list:[]}")
     private Set<Long> supplyExpVideos;
+    @ApolloJsonValue("${not.supply.exp.video.list:[]}")
+    private Set<Long> notSupplyExpVideos;
 
 
     private List<Long> viewFilterOld(FilterParam param) {
-        // log.info("filterParam={}", JSONUtils.toJson(param));
         // 风险过滤
         List<Long> videoIds = filterWithRiskVideo(param.getRiskFilterFlag(),
                 param.getAppType(), param.getRegionCode(), param.getAppRegionFiltered(), param.getVideosWithRisk(),
@@ -82,20 +83,18 @@ public abstract class AbstractFilterService {
         if (MapUtils.isEmpty(expIdMap)) {
             return videoIds;
         }
-        // A VS A+B 模式:供给实验的视频只在实验组出
+        // 供给实验
         if (supplyExpId == NumberUtils.toInt(expIdMap.get("supply"), -1)) {
-            // 命中实验,都可以出
-            return videoIds;
+            // 对照组视频只在对照组出
+            return videoIds.stream()
+                    .filter(l -> !notSupplyExpVideos.contains(l))
+                    .collect(Collectors.toList());
+        } else {
+            // 实验组视频只在实验组出
+            return videoIds.stream()
+                    .filter(l -> !supplyExpVideos.contains(l))
+                    .collect(Collectors.toList());
         }
-        // 对照组,需要过滤掉视频
-        Map<String, String> obj = new HashMap<>();
-        obj.put("before", JSONUtils.toJson(videoIds));
-        List<Long> result = videoIds.stream()
-                .filter(l -> !supplyExpVideos.contains(l))
-                .collect(Collectors.toList());
-        obj.put("after", JSONUtils.toJson(result));
-        log.info("supply filter {}", JSONUtils.toJson(obj));
-        return result;
     }
 
     private List<Long> filterByViewedConcurrent(int appType, String mid, String uid, List<Long> videoIds) {
@@ -160,8 +159,6 @@ public abstract class AbstractFilterService {
             return videoIds;
         }
         Set<Long> preViewedVideoIds = preViewedService.getVideoIds(appType, mid);
-//        log.info("preViewedService.getVideoIds preViewedVideoIds={}, appType={}, mid={}",
-//                JSONUtils.toJson(preViewedVideoIds), appType, mid);
         return videoIds.stream()
                 .filter(l -> !preViewedVideoIds.contains(l))
                 .collect(Collectors.toList());

+ 0 - 3
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/filter/FlowPoolWithScoreFilterService.java

@@ -18,7 +18,6 @@ import java.util.stream.Collectors;
  * @author dyp
  */
 @Service
-@Slf4j
 public class FlowPoolWithScoreFilterService extends AbstractFilterService {
     @Autowired
     private FlowPoolService flowPoolService;
@@ -27,7 +26,6 @@ public class FlowPoolWithScoreFilterService extends AbstractFilterService {
         List<Long> videoIds = viewFilter(param);
 
         videoIds = filterDistributeCountAndDel(param, videoIds);
-        // log.info("filterDistributeCountAndDel videoIds={}", JSONUtils.toJson(videoIds));
         return new FilterResult(videoIds);
     }
 
@@ -44,7 +42,6 @@ public class FlowPoolWithScoreFilterService extends AbstractFilterService {
                         v -> param.getFlowPoolMap().get(v)));
 
         Map<Long, Integer> distributeCountMap = flowPoolService.getDistributeCountWithScore(flowPoolMap);
-        // log.info("getDistributeCountWithScore distributeCountMap={}", JSONUtils.toJson(distributeCountMap));
         List<Long> remainVideoIds = new ArrayList<>();
         for (Long videoId : videoIds) {
             if (distributeCountMap.get(videoId) != null

+ 0 - 2
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/filter/strategy/AllowListStrategy.java

@@ -56,9 +56,7 @@ public class AllowListStrategy implements FilterStrategy {
         for (int i = 0; i < 100; i++) {
             int finalI = i;
             allowVideoCache.getUnchecked(finalI);
-            // ThreadPoolFactory.defaultPool().submit(() -> allowVideoCache.getUnchecked(finalI));
         }
-        log.info("allowVideoCache size {} ", allowVideoCache.size());
     }
 
     @Override

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

@@ -43,13 +43,13 @@ public class RankRouter {
     private RankStrategy4RegionMerge rankStrategy4RegionMerge;
 
     public RankResult rank(RankParam param) {
-        // log.info("RankParam {}", JSONUtils.toJson(param));
         String abCode = param.getAbCode();
         if (StringUtils.isBlank(abCode)) {
             return rankService.rank(param);
         }
         switch (abCode) {
             case "60097":
+            case "60121": // 536
                 return rankStrategy4Density.rank(param);
             case "60106":
                 return rankStrategy4Rankv2Model.rank(param);
@@ -70,8 +70,6 @@ public class RankRouter {
                 return rankStrategyFlowThompsonModel.rank(param);
             case "60120": // 576
                 return rankStrategy4RegionMerge.rank(param);
-            case "60121": // 536
-                return rankStrategy4RegionMergeModelV536.rank(param);
             case "60122": // 537
                 return rankStrategy4RegionMergeModelV2.rank(param);
             case "60123": // 541

+ 3 - 8
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/rank/RankService.java

@@ -67,8 +67,8 @@ public class RankService {
         }
         // 1 通过 apptype 判断该小程序走怎样的排序策略。
         if (param.getAppType() == AppTypeEnum.PIAO_QUAN_MEIHAO_ZHUFU.getCode() && Objects.equals(param.getCategoryId(), 100)) {
-            List<Video> results = new ArrayList<>();
-            results.addAll(extractAndSort(param, BlessRecallStrategy.PUSH_FORM));
+            List<Video> results = new ArrayList<>(extractAndSort(param, BlessRecallStrategy.PUSH_FORM));
+            removeDuplicate(results);
             List<String> videoIdKeys = results.stream()
                     .map(t -> param.getRankKeyPrefix() + t.getVideoId())
                     .collect(Collectors.toList());
@@ -80,9 +80,6 @@ public class RankService {
                 }
                 Collections.sort(results, Comparator.comparingDouble(o -> -o.getSortScore()));
             }
-            results.addAll(extractAndSort(param, RegionRealtimeRecallStrategyV2.PUSH_FORM));
-            results.addAll(extractAndSort(param, RegionRealtimeRecallStrategyV3.PUSH_FORM));
-            removeDuplicate(results);
             return new RankResult(results);
         }
 
@@ -141,6 +138,7 @@ public class RankService {
                 || param.getAbCode().equals("60095")
                 || param.getAbCode().equals("60096")
                 || param.getAbCode().equals("60097")
+                || param.getAbCode().equals("60121")
                 || param.getAbCode().equals("60098")
                 || param.getAbCode().equals("60103")
                 || param.getAbCode().equals("60104")
@@ -178,8 +176,6 @@ public class RankService {
                     .map(t -> param.getRankKeyPrefix() + t.getVideoId())
                     .collect(Collectors.toList());
             List<String> videoScores = 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++) {
@@ -379,7 +375,6 @@ public class RankService {
 
         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 < flowPoolRank.size()) {
                     result.add(flowPoolRank.get(flowPoolIndex++));

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

@@ -63,8 +63,6 @@ public class FestivalStrategy4RankModel extends RankService {
                 .map(t -> param.getRankKeyPrefix() + t.getVideoId())
                 .collect(Collectors.toList());
         List<String> videoScores = 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++) {

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

@@ -74,7 +74,6 @@ public class RankStrategy4Density extends RankService {
         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++));

+ 75 - 96
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/rank/strategy/RankStrategy4RankModel.java

@@ -40,13 +40,6 @@ public class RankStrategy4RankModel extends RankService {
     private Map<String, Double> mergeWeightNew;
     final private String CLASS_NAME = this.getClass().getSimpleName();
 
-//    public Video getTestVideo(Long id, String s){
-//        Video a1 = new Video();
-//        a1.setVideoId(id);
-//        a1.setFlowPool(s);
-//        a1.setPushFrom("recall_pool_region_h");
-//        return a1;
-//    }
     @Override
     public List<Video> mergeAndRankRovRecall(RankParam param) {
 
@@ -80,8 +73,6 @@ public class RankStrategy4RankModel extends RankService {
                 .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++) {
@@ -92,13 +83,13 @@ public class RankStrategy4RankModel extends RankService {
 
         //------------------- todo zhangbo 增加排序str ros模型逻辑 合并二者得分-------------------
         List<Video> videosWithModel = model(rovRecallRank, param);
-        Map<String, Double> mergeWeight = this.mergeWeightNew == null? new HashMap<>(): this.mergeWeightNew;
+        Map<String, Double> mergeWeight = this.mergeWeightNew == null ? new HashMap<>() : this.mergeWeightNew;
         double alpha = mergeWeight.getOrDefault("alpha", 1.0D);
         double beta = mergeWeight.getOrDefault("beta", 0.0D);
         double gamma = mergeWeight.getOrDefault("gamma", 0.0D);
-        for (Video v : videosWithModel){
+        for (Video v : videosWithModel) {
             double score = alpha * v.getSortScore() + beta * v.getScoreStr() + gamma * v.getScoreRos();
-            if (mergeWeight.containsKey("mul") && mergeWeight.getOrDefault("mul", 0.0D) > 0.5){
+            if (mergeWeight.containsKey("mul") && mergeWeight.getOrDefault("mul", 0.0D) > 0.5) {
                 score = alpha * v.getSortScore() + (beta + v.getScoreStr()) * (gamma + v.getScoreRos());
             }
             v.setScoreRegion(v.getSortScore());
@@ -109,36 +100,24 @@ public class RankStrategy4RankModel extends RankService {
 
         //------------------- 增加日志 -------------------
         int size = 4;
-        List<Long> oldRes = rovRecallRank.subList(0, Math.min(rovRecallRank.size(), size)).stream().map(r-> r.getVideoId()).collect(Collectors.toList());
-        List<Long> newRes = videosWithModel.subList(0, Math.min(videosWithModel.size(), size)).stream().map(r-> r.getVideoId()).collect(Collectors.toList());
+        List<Long> oldRes = rovRecallRank.subList(0, Math.min(rovRecallRank.size(), size)).stream().map(r -> r.getVideoId()).collect(Collectors.toList());
+        List<Long> newRes = videosWithModel.subList(0, Math.min(videosWithModel.size(), size)).stream().map(r -> r.getVideoId()).collect(Collectors.toList());
         int diffpos = 0;
         int difftop = 0;
-        for (int i=0; i<newRes.size(); ++i){
-            if (!oldRes.get(i).equals(newRes.get(i))){
+        for (int i = 0; i < newRes.size(); ++i) {
+            if (!oldRes.get(i).equals(newRes.get(i))) {
                 ++diffpos;
             }
-            if (!oldRes.contains(newRes.get(i))){
+            if (!oldRes.contains(newRes.get(i))) {
                 ++difftop;
             }
         }
-        JSONObject obj = new JSONObject();
-        obj.put("name", "RankStrategy4RankModel");
-        obj.put("diffpos", diffpos);
-        obj.put("difftop", difftop);
-        obj.put("videosWithModel_size", videosWithModel.size());
-        obj.put("oldRes", oldRes.stream()
-                .map(String::valueOf)
-                .collect(Collectors.joining(",")));
-        obj.put("newRes", newRes.stream()
-                .map(String::valueOf)
-                .collect(Collectors.joining(",")));
-        log.info(obj.toString());
 
         return videosWithModel;
     }
 
-    public List<Video> model(List<Video> videos, RankParam param){
-        if (videos.isEmpty()){
+    public List<Video> model(List<Video> videos, RankParam param) {
+        if (videos.isEmpty()) {
             return videos;
         }
 
@@ -153,32 +132,30 @@ public class RankStrategy4RankModel 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));
                 }
-            }else{
-                JSONObject obj = new JSONObject();
-                obj.put("name", "user_key_in_model_is_null");
-                log.info(obj.toString());
+            } else {
                 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"
+                "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"
         ));
         Iterator<Map.Entry<String, String>> iterator = userFeatureMap.entrySet().iterator();
         while (iterator.hasNext()) {
@@ -189,14 +166,14 @@ public class RankStrategy4RankModel extends RankService {
         }
         Map<String, String> f1 = RankExtractorUserFeature.getOriginFeature(userFeatureMap,
                 new HashSet<String>(Arrays.asList(
-                    "machineinfo_brand", "machineinfo_model", "machineinfo_platform", "machineinfo_system"
+                        "machineinfo_brand", "machineinfo_model", "machineinfo_platform", "machineinfo_system"
                 ))
         );
         Map<String, String> f2 = RankExtractorUserFeature.getUserRateFeature(userFeatureMap);
         Map<String, String> f3 = RankExtractorUserFeature.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_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"
                 ))
         );
         f1.putAll(f2);
@@ -208,22 +185,23 @@ public class RankStrategy4RankModel extends RankService {
                 "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"
-                ));
+        ));
 
         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);
                     Iterator<Map.Entry<String, String>> iteratorIn = vfMap.entrySet().iterator();
                     while (iteratorIn.hasNext()) {
                         Map.Entry<String, String> entry = iteratorIn.next();
@@ -234,13 +212,13 @@ public class RankStrategy4RankModel extends RankService {
                     Map<String, String> f4 = RankExtractorItemFeature.getItemRateFeature(vfMap);
                     Map<String, String> f5 = RankExtractorItemFeature.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"))
+                                    "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"))
                     );
                     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));
                 }
             }
@@ -253,78 +231,80 @@ public class RankStrategy4RankModel extends RankService {
         String hour = new SimpleDateFormat("HH").format(calendar.getTime());
         String rtFeaPart1day = date + hour;
         String rtFeaPart1h = date + hour;
-        if (rtFeaPart != null){
-            if (rtFeaPart.get(0) != null){
+        if (rtFeaPart != null) {
+            if (rtFeaPart.get(0) != null) {
                 rtFeaPart1day = rtFeaPart.get(0);
             }
-            if (rtFeaPart.get(1) != null){
+            if (rtFeaPart.get(1) != null) {
                 rtFeaPart1h = rtFeaPart.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);
-                    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_1h_ json is wrong in {} with {}", this.CLASS_NAME, e));
                 }
                 Map<String, String> f8 = RankExtractorItemFeature.getItemRealtimeRate(vfMapNew, rtFeaPart1h);
@@ -336,7 +316,6 @@ public class RankStrategy4RankModel extends RankService {
         log.info("ItemFeature = {}", JSONUtils.toJson(videoFeatures));
 
 
-
         List<RankItem> rovRecallScore = ScorerUtils.getScorerPipeline(ScorerUtils.BASE_CONF)
                 .scoring(sceneFeatureMap, userFeatureMap, rankItems);
         log.info("mergeAndRankRovRecallNew rovRecallScore={}", JSONUtils.toJson(rovRecallScore));
@@ -359,17 +338,17 @@ public class RankStrategy4RankModel extends RankService {
         sceneFeatureMap.put("ctx_region", provinceCn);
         String city = param.getCity();
         if ("台北市".equals(city) |
-            "高雄市".equals(city) |
-            "台中市".equals(city) |
-            "桃园市".equals(city) |
-            "新北市".equals(city) |
-            "台南市".equals(city) |
-            "基隆市".equals(city) |
-            "吉林市".equals(city) |
-            "新竹市".equals(city) |
-            "嘉义市".equals(city)
-        ){
-        }else{
+                "高雄市".equals(city) |
+                "台中市".equals(city) |
+                "桃园市".equals(city) |
+                "新北市".equals(city) |
+                "台南市".equals(city) |
+                "基隆市".equals(city) |
+                "吉林市".equals(city) |
+                "新竹市".equals(city) |
+                "嘉义市".equals(city)
+        ) {
+        } else {
             city = city.replaceAll("市$", "");
         }
         sceneFeatureMap.put("ctx_city", city);

+ 113 - 99
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/rank/strategy/RankStrategy4RegionMergeModelV2.java

@@ -1,7 +1,9 @@
 package com.tzld.piaoquan.recommend.server.service.rank.strategy;
+
 import java.util.stream.Collectors;
 import java.util.Arrays;
 import java.util.Map;
+
 import com.alibaba.fastjson.JSONObject;
 import com.ctrip.framework.apollo.spring.annotation.ApolloJsonValue;
 import com.google.common.reflect.TypeToken;
@@ -37,6 +39,7 @@ 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;
@@ -51,8 +54,9 @@ public class RankStrategy4RegionMergeModelV2 extends RankService {
     @ApolloJsonValue("${rank.score.merge.weightv2:}")
     private Map<String, Double> mergeWeight;
     @ApolloJsonValue("${RankStrategy4DensityFilterV2:}")
-    private 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();
+
     @Override
     public List<Video> mergeAndRankFlowPoolRecall(RankParam param) {
         List<Video> quickFlowPoolVideos = sortFlowPoolByThompson(param, FlowPoolConstants.QUICK_PUSH_FORM);
@@ -62,6 +66,7 @@ public class RankStrategy4RegionMergeModelV2 extends RankService {
             return sortFlowPoolByThompson(param, FlowPoolConstants.PUSH_FORM);
         }
     }
+
     public List<Video> sortFlowPoolByThompson(RankParam param, String pushFrom) {
 
         //初始化 userid
@@ -72,6 +77,9 @@ public class RankStrategy4RegionMergeModelV2 extends RankService {
         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();
@@ -98,20 +106,22 @@ public class RankStrategy4RegionMergeModelV2 extends RankService {
             return v;
         });
     }
-    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> mergeAndRankRovRecall(RankParam param) {
-        Map<String, Double> mergeWeight = this.mergeWeight != null? this.mergeWeight: new HashMap<>(0);
+        Map<String, Double> mergeWeight = this.mergeWeight != null ? this.mergeWeight : new HashMap<>(0);
         //-------------------融-------------------
         //-------------------合-------------------
         //-------------------逻-------------------
@@ -160,8 +170,6 @@ public class RankStrategy4RegionMergeModelV2 extends RankService {
         rovRecallRank.addAll(v7.subList(0, Math.min(mergeWeight.getOrDefault("v7", 10.0).intValue(), v7.size())));
 
 
-
-
         //-------------------排-------------------
         //-------------------序-------------------
         //-------------------逻-------------------
@@ -176,19 +184,19 @@ public class RankStrategy4RegionMergeModelV2 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){
+        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");
@@ -246,10 +254,10 @@ public class RankStrategy4RegionMergeModelV2 extends RankService {
         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 trendScore =  item.scoresMap.getOrDefault("trendScore", 0.0) > 1E-8 ?
+        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) > 1E-8 ?
+            double newVideoScore = item.scoresMap.getOrDefault("newVideoScore", 0.0) > 1E-8 ?
                     item.scoresMap.getOrDefault("newVideoScore", 0.0) : 0.0;
             double strScore = item.getScoreStr();
             double rosScore = item.scoresMap.getOrDefault("share2returnScore", 0.0);
@@ -257,16 +265,16 @@ public class RankStrategy4RegionMergeModelV2 extends RankService {
             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){
+            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 {
+                        (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);
+                        (newVideoScore > 1E-8 ? d * trendScore * (e + newVideoScore) : 0.0);
 
             }
             double allreturnsScore = item.scoresMap.getOrDefault("allreturnsScore", 0.0);
-            if (allreturnsScore > h){
+            if (allreturnsScore > h) {
                 score += (f * share2allreturnScore + g * view2allreturnScore);
             }
             Video video = item.getVideo();
@@ -279,46 +287,50 @@ public class RankStrategy4RegionMergeModelV2 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 > 5){
+        if (existenceDays > 5) {
             return 0.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 calScoreWeight(List<Double> data) {
         Double up = 0.0;
         Double down = 0.0;
-        for (int i=0; i<data.size(); ++i){
+        for (int i = 0; i < data.size(); ++i) {
             up += 1.0 / (i + 1) * data.get(i);
             down += 1.0 / (i + 1);
         }
-        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){
-            if (ExtractorUtils.isDoubleEqualToZero(downs.get(i) + down)){
+        for (int i = 0; i < ups.size(); ++i) {
+            if (ExtractorUtils.isDoubleEqualToZero(downs.get(i) + down)) {
                 data.add(0.0);
-            }else{
+            } else {
                 data.add(
                         (ups.get(i) + up) / (downs.get(i) + down)
                 );
@@ -326,21 +338,23 @@ public class RankStrategy4RegionMergeModelV2 extends RankService {
         }
         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;
         }
 
@@ -355,27 +369,22 @@ public class RankStrategy4RegionMergeModelV2 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));
                 }
-            }else{
-                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(
@@ -390,6 +399,7 @@ public class RankStrategy4RegionMergeModelV2 extends RankService {
                 iterator.remove();
             }
         }
+
         Map<String, String> f1 = RankExtractorUserFeature.getOriginFeature(userFeatureMap,
                 new HashSet<String>(Arrays.asList(
                         "machineinfo_brand", "machineinfo_model", "machineinfo_platform", "machineinfo_system"
@@ -415,18 +425,19 @@ public class RankStrategy4RegionMergeModelV2 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();
@@ -445,7 +456,7 @@ public class RankStrategy4RegionMergeModelV2 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));
                 }
             }
@@ -458,80 +469,82 @@ public class RankStrategy4RegionMergeModelV2 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);
@@ -543,7 +556,6 @@ public class RankStrategy4RegionMergeModelV2 extends RankService {
 //        log.info("ItemFeature = {}", JSONUtils.toJson(videoFeatures));
 
 
-
         List<RankItem> rovRecallScore = ScorerUtils.getScorerPipeline(ScorerUtils.BASE_CONF)
                 .scoring(sceneFeatureMap, userFeatureMap, rankItems);
 //        log.info("mergeAndRankRovRecallNew rovRecallScore={}", JSONUtils.toJson(rovRecallScore));
@@ -553,6 +565,7 @@ public class RankStrategy4RegionMergeModelV2 extends RankService {
 //        log.info(obj.toString());
         return rovRecallScore;
     }
+
     private Map<String, String> getSceneFeature(RankParam param) {
         Map<String, String> sceneFeatureMap = new HashMap<>();
         String provinceCn = param.getProvince();
@@ -569,8 +582,8 @@ public class RankStrategy4RegionMergeModelV2 extends RankService {
                 "吉林市".equals(city) |
                 "新竹市".equals(city) |
                 "嘉义市".equals(city)
-        ){
-        }else{
+        ) {
+        } else {
             city = city.replaceAll("市$", "");
         }
         sceneFeatureMap.put("ctx_city", city);
@@ -581,6 +594,7 @@ public class RankStrategy4RegionMergeModelV2 extends RankService {
 
         return sceneFeatureMap;
     }
+
     @Override
     public RankResult mergeAndSort(RankParam param, List<Video> rovVideos, List<Video> flowVideos) {
 
@@ -598,12 +612,12 @@ public class RankStrategy4RegionMergeModelV2 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);
         }
 
@@ -679,28 +693,28 @@ public class RankStrategy4RegionMergeModelV2 extends RankService {
         String down2 = "2024031012:748,2024031013:886,2024031014:788,2024031015:1029,2024031016:957,2024031017:1170,2024031018:1208,2024031019:1181,2024031020:1275,2024031021:1265,2024031022:1512,2024031023:1190,2024031100:1127,2024031101:486,2024031102:289,2024031103:254,2024031104:197,2024031105:310,2024031106:344,2024031107:693,2024031108:976,2024031109:1045,2024031110:1039,2024031111:1257,2024031112:1202,2024031113:1454,2024031114:1785,2024031115:1544";
 
         RankStrategy4RegionMergeModelV2 job = new RankStrategy4RegionMergeModelV2();
-        List<Double> l1 = job.getRateData(job.help(up1, "2024031115", 24),job.help(down1, "2024031115", 24),1.,10.);
+        List<Double> l1 = job.getRateData(job.help(up1, "2024031115", 24), job.help(down1, "2024031115", 24), 1., 10.);
         Double d1 = job.calScoreWeight(l1);
 
         System.out.println(d1);
 
-        List<Double> l2 = job.getRateData(job.help(up2, "2024031115", 24),job.help(down2, "2024031115", 24),1.,10.);
+        List<Double> l2 = job.getRateData(job.help(up2, "2024031115", 24), job.help(down2, "2024031115", 24), 1., 10.);
         Double d2 = job.calScoreWeight(l2);
 
         System.out.println(d2);
 
     }
 
-    List<Double> help(String s, String date, Integer h){
+    List<Double> help(String s, String date, Integer h) {
         Map<String, Double> maps = Arrays.stream(s.split(",")).map(pair -> pair.split(":"))
-            .collect(Collectors.toMap(
-                    arr -> arr[0],
-                    arr -> Double.valueOf(arr[1])
-        ));
+                .collect(Collectors.toMap(
+                        arr -> arr[0],
+                        arr -> Double.valueOf(arr[1])
+                ));
         List<String> datehours = new LinkedList<>(); // 时间是倒叙的
         List<Double> result = new ArrayList<>();
-        for (int i=0; i<h; ++i){
-            Double d = (result.isEmpty() ? 0.0: result.get(result.size()-1));
+        for (int i = 0; i < h; ++i) {
+            Double d = (result.isEmpty() ? 0.0 : result.get(result.size() - 1));
             result.add(d + maps.getOrDefault(date, 0D));
             datehours.add(date);
             date = ExtractorUtils.subtractHours(date, 1);

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

@@ -81,6 +81,9 @@ public class RankStrategy4RegionMergeModelV3 extends RankService {
         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();

+ 3 - 5
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/rank/strategy/RankStrategy4RegionMergeModelV4.java

@@ -71,6 +71,9 @@ public class RankStrategy4RegionMergeModelV4 extends RankService {
         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();
@@ -506,11 +509,6 @@ public class RankStrategy4RegionMergeModelV4 extends RankService {
 
         List<RankItem> rovRecallScore = ScorerUtils.getScorerPipeline(ScorerUtils.BASE_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) {

+ 3 - 1
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/rank/strategy/RankStrategy4RegionMergeModelV5.java

@@ -72,6 +72,9 @@ public class RankStrategy4RegionMergeModelV5 extends RankService {
         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();
@@ -596,7 +599,6 @@ public class RankStrategy4RegionMergeModelV5 extends RankService {
         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++));

+ 3 - 1
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/rank/strategy/RankStrategy4RegionMergeModelV536.java

@@ -70,6 +70,9 @@ public class RankStrategy4RegionMergeModelV536 extends RankService {
         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();
@@ -623,7 +626,6 @@ public class RankStrategy4RegionMergeModelV536 extends RankService {
         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++));

+ 112 - 110
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/rank/strategy/RankStrategy4RegionMergeModelV547.java

@@ -42,14 +42,15 @@ import java.util.stream.Collectors;
  * @author zhangbo
  * @desc 地域召回融合 流量池汤姆森
  */
-@Service
 @Slf4j
+@Service
 public class RankStrategy4RegionMergeModelV547 extends RankService {
     @ApolloJsonValue("${rank.score.merge.weightv547:}")
     private Map<String, Double> mergeWeight;
     @ApolloJsonValue("${RankStrategy4DensityFilterV2:}")
-    private 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();
+
     @Override
     public List<Video> mergeAndRankFlowPoolRecall(RankParam param) {
         List<Video> quickFlowPoolVideos = sortFlowPoolByThompson(param, FlowPoolConstants.QUICK_PUSH_FORM);
@@ -59,6 +60,7 @@ public class RankStrategy4RegionMergeModelV547 extends RankService {
             return sortFlowPoolByThompson(param, FlowPoolConstants.PUSH_FORM);
         }
     }
+
     public List<Video> sortFlowPoolByThompson(RankParam param, String pushFrom) {
 
         //初始化 userid
@@ -69,6 +71,9 @@ public class RankStrategy4RegionMergeModelV547 extends RankService {
         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();
@@ -95,20 +100,22 @@ public class RankStrategy4RegionMergeModelV547 extends RankService {
             return v;
         });
     }
-    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> mergeAndRankRovRecall(RankParam param) {
-        Map<String, Double> mergeWeight = this.mergeWeight != null? this.mergeWeight: new HashMap<>(0);
+        Map<String, Double> mergeWeight = this.mergeWeight != null ? this.mergeWeight : new HashMap<>(0);
         //-------------------融-------------------
         //-------------------合-------------------
         //-------------------逻-------------------
@@ -157,8 +164,6 @@ public class RankStrategy4RegionMergeModelV547 extends RankService {
         rovRecallRank.addAll(v7.subList(0, Math.min(mergeWeight.getOrDefault("v7", 10.0).intValue(), v7.size())));
 
 
-
-
         //-------------------排-------------------
         //-------------------序-------------------
         //-------------------逻-------------------
@@ -173,19 +178,19 @@ public class RankStrategy4RegionMergeModelV547 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){
+        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");
@@ -243,10 +248,10 @@ public class RankStrategy4RegionMergeModelV547 extends RankService {
         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 ?
+        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) > 1E-8 ?
+            double newVideoScore = item.scoresMap.getOrDefault("newVideoScore", 0.0) > 1E-8 ?
                     item.scoresMap.getOrDefault("newVideoScore", 0.0) : 0.0;
             double strScore = item.getScoreStr();
             double rosScore = item.scoresMap.getOrDefault("share2returnScore", 0.0);
@@ -254,16 +259,16 @@ public class RankStrategy4RegionMergeModelV547 extends RankService {
             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){
+            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 {
+                        (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);
+                        (newVideoScore > 1E-8 ? d * trendScore * (e + newVideoScore) : 0.0);
 
             }
             double allreturnsScore = item.scoresMap.getOrDefault("allreturnsScore", 0.0);
-            if (allreturnsScore > h){
+            if (allreturnsScore > h) {
                 score += (f * share2allreturnScore + g * view2allreturnScore);
             }
             Video video = item.getVideo();
@@ -276,46 +281,50 @@ public class RankStrategy4RegionMergeModelV547 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 > 5){
+        if (existenceDays > 5) {
             return 0.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 calScoreWeight(List<Double> data) {
         Double up = 0.0;
         Double down = 0.0;
-        for (int i=0; i<data.size(); ++i){
+        for (int i = 0; i < data.size(); ++i) {
             up += 1.0 / (i + 1) * data.get(i);
             down += 1.0 / (i + 1);
         }
-        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){
-            if (ExtractorUtils.isDoubleEqualToZero(downs.get(i) + down)){
+        for (int i = 0; i < ups.size(); ++i) {
+            if (ExtractorUtils.isDoubleEqualToZero(downs.get(i) + down)) {
                 data.add(0.0);
-            }else{
+            } else {
                 data.add(
                         (ups.get(i) + up) / (downs.get(i) + down)
                 );
@@ -323,21 +332,23 @@ public class RankStrategy4RegionMergeModelV547 extends RankService {
         }
         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;
         }
 
@@ -352,27 +363,22 @@ public class RankStrategy4RegionMergeModelV547 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));
                 }
-            }else{
-                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(
@@ -387,6 +393,7 @@ public class RankStrategy4RegionMergeModelV547 extends RankService {
                 iterator.remove();
             }
         }
+
         Map<String, String> f1 = RankExtractorUserFeature.getOriginFeature(userFeatureMap,
                 new HashSet<String>(Arrays.asList(
                         "machineinfo_brand", "machineinfo_model", "machineinfo_platform", "machineinfo_system"
@@ -402,7 +409,7 @@ public class RankStrategy4RegionMergeModelV547 extends RankService {
         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",
@@ -412,18 +419,19 @@ public class RankStrategy4RegionMergeModelV547 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();
@@ -442,7 +450,7 @@ public class RankStrategy4RegionMergeModelV547 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));
                 }
             }
@@ -455,80 +463,82 @@ public class RankStrategy4RegionMergeModelV547 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);
@@ -537,19 +547,11 @@ public class RankStrategy4RegionMergeModelV547 extends RankService {
         }
 
 
-//        log.info("ItemFeature = {}", JSONUtils.toJson(videoFeatures));
-
-
-
         List<RankItem> rovRecallScore = ScorerUtils.getScorerPipeline(ScorerUtils.BASE_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();
@@ -566,8 +568,8 @@ public class RankStrategy4RegionMergeModelV547 extends RankService {
                 "吉林市".equals(city) |
                 "新竹市".equals(city) |
                 "嘉义市".equals(city)
-        ){
-        }else{
+        ) {
+        } else {
             city = city.replaceAll("市$", "");
         }
         sceneFeatureMap.put("ctx_city", city);
@@ -578,6 +580,7 @@ public class RankStrategy4RegionMergeModelV547 extends RankService {
 
         return sceneFeatureMap;
     }
+
     @Override
     public RankResult mergeAndSort(RankParam param, List<Video> rovVideos, List<Video> flowVideos) {
 
@@ -595,12 +598,12 @@ public class RankStrategy4RegionMergeModelV547 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);
         }
 
@@ -620,7 +623,6 @@ public class RankStrategy4RegionMergeModelV547 extends RankService {
         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++));
@@ -676,28 +678,28 @@ public class RankStrategy4RegionMergeModelV547 extends RankService {
         String down2 = "2024031012:748,2024031013:886,2024031014:788,2024031015:1029,2024031016:957,2024031017:1170,2024031018:1208,2024031019:1181,2024031020:1275,2024031021:1265,2024031022:1512,2024031023:1190,2024031100:1127,2024031101:486,2024031102:289,2024031103:254,2024031104:197,2024031105:310,2024031106:344,2024031107:693,2024031108:976,2024031109:1045,2024031110:1039,2024031111:1257,2024031112:1202,2024031113:1454,2024031114:1785,2024031115:1544";
 
         RankStrategy4RegionMergeModelV547 job = new RankStrategy4RegionMergeModelV547();
-        List<Double> l1 = job.getRateData(job.help(up1, "2024031115", 24),job.help(down1, "2024031115", 24),1.,10.);
+        List<Double> l1 = job.getRateData(job.help(up1, "2024031115", 24), job.help(down1, "2024031115", 24), 1., 10.);
         Double d1 = job.calScoreWeight(l1);
 
         System.out.println(d1);
 
-        List<Double> l2 = job.getRateData(job.help(up2, "2024031115", 24),job.help(down2, "2024031115", 24),1.,10.);
+        List<Double> l2 = job.getRateData(job.help(up2, "2024031115", 24), job.help(down2, "2024031115", 24), 1., 10.);
         Double d2 = job.calScoreWeight(l2);
 
         System.out.println(d2);
 
     }
 
-    List<Double> help(String s, String date, Integer h){
+    List<Double> help(String s, String date, Integer h) {
         Map<String, Double> maps = Arrays.stream(s.split(",")).map(pair -> pair.split(":"))
-            .collect(Collectors.toMap(
-                    arr -> arr[0],
-                    arr -> Double.valueOf(arr[1])
-        ));
+                .collect(Collectors.toMap(
+                        arr -> arr[0],
+                        arr -> Double.valueOf(arr[1])
+                ));
         List<String> datehours = new LinkedList<>(); // 时间是倒叙的
         List<Double> result = new ArrayList<>();
-        for (int i=0; i<h; ++i){
-            Double d = (result.isEmpty() ? 0.0: result.get(result.size()-1));
+        for (int i = 0; i < h; ++i) {
+            Double d = (result.isEmpty() ? 0.0 : result.get(result.size() - 1));
             result.add(d + maps.getOrDefault(date, 0D));
             datehours.add(date);
             date = ExtractorUtils.subtractHours(date, 1);

+ 95 - 102
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/rank/strategy/RankStrategy4RegionMergeModelV548.java

@@ -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;
@@ -48,23 +44,24 @@ public class RankStrategy4RegionMergeModelV548 extends RankService {
     @ApolloJsonValue("${rank.score.merge.weightv548:}")
     private Map<String, Double> mergeWeight;
     @ApolloJsonValue("${RankStrategy4DensityFilterV2:}")
-    private 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> mergeAndRankRovRecall(RankParam param) {
-        Map<String, Double> mergeWeight = this.mergeWeight != null? this.mergeWeight: new HashMap<>(0);
+        Map<String, Double> mergeWeight = this.mergeWeight != null ? this.mergeWeight : new HashMap<>(0);
         //-------------------融-------------------
         //-------------------合-------------------
         //-------------------逻-------------------
@@ -113,8 +110,6 @@ public class RankStrategy4RegionMergeModelV548 extends RankService {
         rovRecallRank.addAll(v7.subList(0, Math.min(mergeWeight.getOrDefault("v7", 10.0).intValue(), v7.size())));
 
 
-
-
         //-------------------排-------------------
         //-------------------序-------------------
         //-------------------逻-------------------
@@ -129,19 +124,19 @@ public class RankStrategy4RegionMergeModelV548 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){
+        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");
@@ -199,10 +194,10 @@ public class RankStrategy4RegionMergeModelV548 extends RankService {
         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 ?
+        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) > 1E-8 ?
+            double newVideoScore = item.scoresMap.getOrDefault("newVideoScore", 0.0) > 1E-8 ?
                     item.scoresMap.getOrDefault("newVideoScore", 0.0) : 0.0;
             double strScore = item.getScoreStr();
             double rosScore = item.scoresMap.getOrDefault("share2returnScore", 0.0);
@@ -210,16 +205,16 @@ public class RankStrategy4RegionMergeModelV548 extends RankService {
             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){
+            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 {
+                        (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);
+                        (newVideoScore > 1E-8 ? d * trendScore * (e + newVideoScore) : 0.0);
 
             }
             double allreturnsScore = item.scoresMap.getOrDefault("allreturnsScore", 0.0);
-            if (allreturnsScore > h){
+            if (allreturnsScore > h) {
                 score += (f * share2allreturnScore + g * view2allreturnScore);
             }
             Video video = item.getVideo();
@@ -232,46 +227,50 @@ public class RankStrategy4RegionMergeModelV548 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 > 5){
+        if (existenceDays > 5) {
             return 0.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 calScoreWeight(List<Double> data) {
         Double up = 0.0;
         Double down = 0.0;
-        for (int i=0; i<data.size(); ++i){
+        for (int i = 0; i < data.size(); ++i) {
             up += 1.0 / (i + 1) * data.get(i);
             down += 1.0 / (i + 1);
         }
-        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){
-            if (ExtractorUtils.isDoubleEqualToZero(downs.get(i) + down)){
+        for (int i = 0; i < ups.size(); ++i) {
+            if (ExtractorUtils.isDoubleEqualToZero(downs.get(i) + down)) {
                 data.add(0.0);
-            }else{
+            } else {
                 data.add(
                         (ups.get(i) + up) / (downs.get(i) + down)
                 );
@@ -279,21 +278,23 @@ public class RankStrategy4RegionMergeModelV548 extends RankService {
         }
         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;
         }
 
@@ -308,27 +309,22 @@ public class RankStrategy4RegionMergeModelV548 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));
                 }
-            }else{
-                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(
@@ -343,6 +339,7 @@ public class RankStrategy4RegionMergeModelV548 extends RankService {
                 iterator.remove();
             }
         }
+
         Map<String, String> f1 = RankExtractorUserFeature.getOriginFeature(userFeatureMap,
                 new HashSet<String>(Arrays.asList(
                         "machineinfo_brand", "machineinfo_model", "machineinfo_platform", "machineinfo_system"
@@ -368,18 +365,19 @@ public class RankStrategy4RegionMergeModelV548 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();
@@ -398,7 +396,7 @@ public class RankStrategy4RegionMergeModelV548 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));
                 }
             }
@@ -411,80 +409,82 @@ public class RankStrategy4RegionMergeModelV548 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);
@@ -493,19 +493,12 @@ public class RankStrategy4RegionMergeModelV548 extends RankService {
         }
 
 
-//        log.info("ItemFeature = {}", JSONUtils.toJson(videoFeatures));
-
-
 
         List<RankItem> rovRecallScore = ScorerUtils.getScorerPipeline(ScorerUtils.BASE_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();
@@ -522,8 +515,8 @@ public class RankStrategy4RegionMergeModelV548 extends RankService {
                 "吉林市".equals(city) |
                 "新竹市".equals(city) |
                 "嘉义市".equals(city)
-        ){
-        }else{
+        ) {
+        } else {
             city = city.replaceAll("市$", "");
         }
         sceneFeatureMap.put("ctx_city", city);
@@ -534,6 +527,7 @@ public class RankStrategy4RegionMergeModelV548 extends RankService {
 
         return sceneFeatureMap;
     }
+
     @Override
     public RankResult mergeAndSort(RankParam param, List<Video> rovVideos, List<Video> flowVideos) {
 
@@ -551,12 +545,12 @@ public class RankStrategy4RegionMergeModelV548 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);
         }
 
@@ -576,7 +570,6 @@ public class RankStrategy4RegionMergeModelV548 extends RankService {
         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++));

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

@@ -513,7 +513,6 @@ public class RankStrategy4RegionMergeModelV561 extends RankService {
         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++));

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

@@ -537,7 +537,6 @@ public class RankStrategy4RegionMergeModelV562 extends RankService {
         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++));

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

@@ -575,7 +575,6 @@ public class RankStrategy4RegionMergeModelV6 extends RankService {
         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++));

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

@@ -59,6 +59,9 @@ public class RankStrategyFlowThompsonModel extends RankService {
         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();

+ 1 - 1
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/recall/RecallParam.java

@@ -25,7 +25,7 @@ public class RecallParam {
     private String abCode;
     private int size;
     private String flowPoolAbtestGroup;
-    private int flowPoolId;
+    private int lastDigit;
     private Long videoId;
     private String uid;
     private boolean specialRecommend;

+ 54 - 16
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/recall/RecallService.java

@@ -1,5 +1,6 @@
 package com.tzld.piaoquan.recommend.server.service.recall;
 
+import com.ctrip.framework.apollo.spring.annotation.ApolloJsonValue;
 import com.tzld.piaoquan.recommend.server.common.ThreadPoolFactory;
 import com.tzld.piaoquan.recommend.server.common.enums.AppTypeEnum;
 import com.tzld.piaoquan.recommend.server.model.Video;
@@ -29,6 +30,8 @@ public class RecallService implements ApplicationContextAware {
     private final Map<String, RecallStrategy> strategyMap = new HashMap<>();
     private ApplicationContext applicationContext;
     private final ExecutorService pool = ThreadPoolFactory.recallPool();
+    @ApolloJsonValue("${last.digit.abcode:{}}")
+    protected Map<Integer, String> lastDigitAbcode;
 
     @PostConstruct
     public void init() {
@@ -40,9 +43,7 @@ public class RecallService implements ApplicationContextAware {
     }
 
     public RecallResult recall(RecallParam param) {
-       //  log.info("RecallParam {}", JSONUtils.toJson(param));
         List<RecallStrategy> strategies = getRecallStrategy(param);
-        // log.info("strategies {}", JSONUtils.toJson(CommonCollectionUtils.toList(strategies, o -> o.pushFrom())));
         CountDownLatch cdl = new CountDownLatch(strategies.size());
         List<Future<RecallResult.RecallData>> recallResultFutures = new ArrayList<>();
         for (final RecallStrategy strategy : strategies) {
@@ -86,8 +87,6 @@ public class RecallService implements ApplicationContextAware {
             strategies.addAll(getRegionRecallStrategy(param));
         } else if (param.getAppType() == AppTypeEnum.PIAO_QUAN_MEIHAO_ZHUFU.getCode() && Objects.equals(param.getCategoryId(), 100)) {
             strategies.add(strategyMap.get(BlessRecallStrategy.class.getSimpleName()));
-            strategies.add(strategyMap.get(RegionRealtimeRecallStrategyV2.class.getSimpleName()));
-            strategies.add(strategyMap.get(RegionRealtimeRecallStrategyV3.class.getSimpleName()));
             return strategies;
         } else {
             switch (abCode) {
@@ -121,20 +120,59 @@ public class RecallService implements ApplicationContextAware {
                     strategies.addAll(getRegionRecallStrategy(param));
             }
             //2:通过“流量池标记”控制“流量池召回子策略” 其中有9组会走EXPERIMENTAL_FLOW_SET_LEVEL 有1组会走EXPERIMENTAL_FLOW_SET_LEVEL_SCORE
-            if (param.getFlowPoolAbtestGroup().equals(FlowPoolConstants.EXPERIMENTAL_FLOW_SET_LEVEL)) {
-                strategies.add(strategyMap.get(QuickFlowPoolWithLevelRecallStrategy.class.getSimpleName()));
-                if ("60126".equals(abCode)){
-                    strategies.add(strategyMap.get(FlowPoolWithLevelRecallStrategyTomson.class.getSimpleName()));
-                }else {
-                    strategies.add(strategyMap.get(FlowPoolWithLevelRecallStrategy.class.getSimpleName()));
+            if ("60111".equals(abCode) || "60112".equals(abCode)){
+                int lastDigit = param.getLastDigit();
+                String lastDigitAB = lastDigitAbcode != null? lastDigitAbcode.getOrDefault(lastDigit, "default"): "default";
+                switch (lastDigitAB){
+                    case "random":
+                        strategies.add(strategyMap.get(FlowPoolWithLevelRecallStrategyFilterDigit.class.getSimpleName()));
+                        break;
+                    case "tomson":
+                        strategies.add(strategyMap.get(FlowPoolWithLevelRecallStrategyTomsonFilterDigit.class.getSimpleName()));
+                        break;
+                    case "score":
+                        strategies.add(strategyMap.get(FlowPoolWithLevelScoreRecallStrategy.class.getSimpleName()));
+                        break;
+                    default:
+                        strategies.add(strategyMap.get(FlowPoolWithLevelRecallStrategyFilterDigit.class.getSimpleName()));
+                        break;
+                }
+            }else{
+                if (param.getFlowPoolAbtestGroup().equals(FlowPoolConstants.EXPERIMENTAL_FLOW_SET_LEVEL)) {
+                    strategies.add(strategyMap.get(QuickFlowPoolWithLevelRecallStrategy.class.getSimpleName()));
+                    if ("60126".equals(abCode)){
+                        strategies.add(strategyMap.get(FlowPoolWithLevelRecallStrategyTomson.class.getSimpleName()));
+                    }else {
+                        strategies.add(strategyMap.get(FlowPoolWithLevelRecallStrategy.class.getSimpleName()));
+                    }
+                } else if (param.getFlowPoolAbtestGroup().equals(FlowPoolConstants.EXPERIMENTAL_FLOW_SET_LEVEL_SCORE)) {
+                    strategies.add(strategyMap.get(QuickFlowPoolWithLevelScoreRecallStrategy.class.getSimpleName()));
+                    strategies.add(strategyMap.get(FlowPoolWithLevelScoreRecallStrategy.class.getSimpleName()));
+                } else {
+                    strategies.add(strategyMap.get(QuickFlowPoolWithScoreRecallStrategy.class.getSimpleName()));
+                    strategies.add(strategyMap.get(FlowPoolWithScoreRecallStrategy.class.getSimpleName()));
                 }
-            } else if (param.getFlowPoolAbtestGroup().equals(FlowPoolConstants.EXPERIMENTAL_FLOW_SET_LEVEL_SCORE)) {
-                strategies.add(strategyMap.get(QuickFlowPoolWithLevelScoreRecallStrategy.class.getSimpleName()));
-                strategies.add(strategyMap.get(FlowPoolWithLevelScoreRecallStrategy.class.getSimpleName()));
-            } else {
-                strategies.add(strategyMap.get(QuickFlowPoolWithScoreRecallStrategy.class.getSimpleName()));
-                strategies.add(strategyMap.get(FlowPoolWithScoreRecallStrategy.class.getSimpleName()));
             }
+//            if ("60126".equals(abCode)){
+//                strategies.add(strategyMap.get(FlowPoolWithLevelRecallStrategyTomsonFilterDigit.class.getSimpleName()));
+//            }else{
+//                int lastDigit = param.getLastDigit();
+//                String lastDigitAB = lastDigitAbcode != null? lastDigitAbcode.getOrDefault(lastDigit, "default"): "default";
+//                switch (lastDigitAB){
+//                    case "random":
+//                        strategies.add(strategyMap.get(FlowPoolWithLevelRecallStrategyFilterDigit.class.getSimpleName()));
+//                        break;
+//                    case "tomson":
+//                        strategies.add(strategyMap.get(FlowPoolWithLevelRecallStrategyTomsonFilterDigit.class.getSimpleName()));
+//                        break;
+//                    case "score":
+//                        strategies.add(strategyMap.get(FlowPoolWithLevelScoreRecallStrategy.class.getSimpleName()));
+//                        break;
+//                    default:
+//                        strategies.add(strategyMap.get(FlowPoolWithLevelRecallStrategyFilterDigit.class.getSimpleName()));
+//                        break;
+//                }
+//            }
         }
 
         //3:通过“abcode”控制“召回子策略”

+ 0 - 5
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/recall/strategy/AbstractFlowPoolWithLevelRecallStrategy.java

@@ -6,8 +6,6 @@ import com.tzld.piaoquan.recommend.server.service.filter.FlowPoolWithLevelFilter
 import com.tzld.piaoquan.recommend.server.service.recall.FilterParamFactory;
 import com.tzld.piaoquan.recommend.server.service.recall.RecallParam;
 import com.tzld.piaoquan.recommend.server.service.recall.RecallStrategy;
-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.apache.commons.lang3.math.NumberUtils;
@@ -24,7 +22,6 @@ import java.util.Map;
 /**
  * @author dyp
  */
-@Slf4j
 public abstract class AbstractFlowPoolWithLevelRecallStrategy implements RecallStrategy {
     @Autowired
     @Qualifier("redisTemplate")
@@ -40,9 +37,7 @@ public abstract class AbstractFlowPoolWithLevelRecallStrategy implements RecallS
         String level = flowPoolKeyAndLevel.getRight();
         int getSize = param.getSize() * 5;
         List<Video> results = new ArrayList<>();
-        // log.info("flowPoolKeyAndLevel={}", JSONUtils.toJson(flowPoolKeyAndLevel));
         List<String> data = redisTemplate.opsForSet().randomMembers(flowPoolKey, getSize);
-        // log.info("randomMembers flowPoolKey={}, data={}", flowPoolKey, JSONUtils.toJson(data));
         if (CollectionUtils.isEmpty(data)) {
             return null;
         }

+ 0 - 7
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/recall/strategy/AbstractFlowPoolWithLevelScoreRecallStrategy.java

@@ -6,8 +6,6 @@ import com.tzld.piaoquan.recommend.server.service.filter.FlowPoolWithLevelScoreF
 import com.tzld.piaoquan.recommend.server.service.recall.FilterParamFactory;
 import com.tzld.piaoquan.recommend.server.service.recall.RecallParam;
 import com.tzld.piaoquan.recommend.server.service.recall.RecallStrategy;
-import com.tzld.piaoquan.recommend.server.util.JSONUtils;
-import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.lang3.math.NumberUtils;
 import org.apache.commons.lang3.tuple.Pair;
@@ -21,7 +19,6 @@ import java.util.*;
 /**
  * @author dyp
  */
-@Slf4j
 public abstract class AbstractFlowPoolWithLevelScoreRecallStrategy implements RecallStrategy {
     @Autowired
     @Qualifier("redisTemplate")
@@ -38,7 +35,6 @@ public abstract class AbstractFlowPoolWithLevelScoreRecallStrategy implements Re
 
         int getSize = param.getSize() * 5;
         List<Video> results = new ArrayList<>();
-        // log.info("flowPoolKeyAndLevel={}", JSONUtils.toJson(flowPoolKeyAndLevel));
         Set<ZSetOperations.TypedTuple<String>> data = redisTemplate.opsForZSet().reverseRangeWithScores(flowPoolKey, 0,
                 getSize - 1);
         if (CollectionUtils.isEmpty(data)) {
@@ -52,9 +48,6 @@ public abstract class AbstractFlowPoolWithLevelScoreRecallStrategy implements Re
             videoFlowPoolMap.put(NumberUtils.toLong(values[0], 0), values[1]);
             videoScoreMap.put(NumberUtils.toLong(values[0], 0), t.getScore());
         }
-//        log.info("abstractFlowPoolWithLevelScoreRecallStrategy videoScoreMap={}, videoFlowPoolMap={}",
-//                JSONUtils.toJson(videoScoreMap),
-//                JSONUtils.toJson(videoFlowPoolMap));
         FilterResult filterResult = filterService.filter(FilterParamFactory.create(param, videoFlowPoolMap));
 
         if (filterResult != null && CollectionUtils.isNotEmpty(filterResult.getVideoIds())) {

+ 0 - 6
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/recall/strategy/AbstractFlowPoolWithScoreRecallStrategy.java

@@ -6,7 +6,6 @@ import com.tzld.piaoquan.recommend.server.service.filter.FlowPoolWithScoreFilter
 import com.tzld.piaoquan.recommend.server.service.recall.FilterParamFactory;
 import com.tzld.piaoquan.recommend.server.service.recall.RecallParam;
 import com.tzld.piaoquan.recommend.server.service.recall.RecallStrategy;
-import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.lang3.math.NumberUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -19,7 +18,6 @@ import java.util.*;
 /**
  * @author dyp
  */
-@Slf4j
 public abstract class AbstractFlowPoolWithScoreRecallStrategy implements RecallStrategy {
     @Autowired
     @Qualifier("redisTemplate")
@@ -34,7 +32,6 @@ public abstract class AbstractFlowPoolWithScoreRecallStrategy implements RecallS
 
         int getSize = param.getSize() * 5;
         List<Video> results = new ArrayList<>();
-        // log.info("flowPoolKey={}", JSONUtils.toJson(flowPoolKey));
         Set<ZSetOperations.TypedTuple<String>> data = redisTemplate.opsForZSet().reverseRangeWithScores(flowPoolKey, 0,
                 getSize - 1);
         if (CollectionUtils.isEmpty(data)) {
@@ -48,9 +45,6 @@ public abstract class AbstractFlowPoolWithScoreRecallStrategy implements RecallS
             videoFlowPoolMap.put(NumberUtils.toLong(values[0], 0), values[1]);
             videoScoreMap.put(NumberUtils.toLong(values[0], 0), t.getScore());
         }
-//        log.info("AbstractFlowPoolWithScoreRecallStrategy videoScoreMap={}, videoFlowPoolMap={}",
-//                JSONUtils.toJson(videoScoreMap),
-//                JSONUtils.toJson(videoFlowPoolMap));
         FilterResult filterResult = filterService.filter(FilterParamFactory.create(param, videoFlowPoolMap));
 
         if (filterResult != null && CollectionUtils.isNotEmpty(filterResult.getVideoIds())) {

+ 6 - 16
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/recall/strategy/BlessRecallStrategy.java

@@ -1,6 +1,5 @@
 package com.tzld.piaoquan.recommend.server.service.recall.strategy;
 
-import com.alibaba.fastjson.JSONObject;
 import com.google.common.collect.Lists;
 import com.tzld.piaoquan.recommend.server.model.Video;
 import com.tzld.piaoquan.recommend.server.service.filter.FilterParam;
@@ -11,7 +10,6 @@ import com.tzld.piaoquan.recommend.server.service.recall.RecallParam;
 import com.tzld.piaoquan.recommend.server.service.recall.RecallStrategy;
 import com.tzld.piaoquan.recommend.server.service.score.ScorerUtils;
 import com.tzld.piaoquan.recommend.server.service.score4recall.ScorerPipeline4Recall;
-import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.lang3.tuple.Pair;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -23,7 +21,6 @@ import java.util.*;
 /**
  * @author zhangbo
  */
-@Slf4j
 @Component
 public class BlessRecallStrategy implements RecallStrategy {
 
@@ -34,14 +31,15 @@ public class BlessRecallStrategy implements RecallStrategy {
     private String dailyBlessTimeRange;
     @Autowired
     private RegionFilterService filterService;
+
     @Override
     public List<Video> recall(RecallParam param) {
 
         // 1 获取省份key 放入参数map中
         String provinceCn = param.getProvince();
-        if (provinceCn == null){
+        if (provinceCn == null) {
             provinceCn = "中国";
-        }else{
+        } else {
             provinceCn = provinceCn.replaceAll("省$", "");
         }
         Map<String, String> param4Model = new HashMap<>(1);
@@ -53,27 +51,20 @@ public class BlessRecallStrategy implements RecallStrategy {
         ScorerPipeline4Recall pipeline = ScorerUtils.getScorerPipeline4Recall("feeds_score_config_bless.conf");
         List<List<Pair<Long, Double>>> results = pipeline.recall(param4Model);
         List<Pair<Long, Double>> result = results.get(0);
-        for (int i=1; i<results.size(); ++i){
+        for (int i = 1; i < results.size(); ++i) {
             result.addAll(results.get(i));
         }
         Map<Long, Double> videoMap = new LinkedHashMap<>();
-        for (Pair<Long, Double> v: result){
+        for (Pair<Long, Double> v : result) {
             videoMap.put(v.getLeft(), v.getRight());
         }
-        long t1 = new Long(System.currentTimeMillis());
         FilterParam filterParam = FilterParamFactory.create(param, Lists.newArrayList(videoMap.keySet()));
         filterParam.setForceTruncation(10000);
         filterParam.setConcurrent(true);
         filterParam.setNotUsePreView(false);
         FilterResult filterResult = filterService.filter(filterParam);
-        long t2 = new Long(System.currentTimeMillis());
-        JSONObject obj = new JSONObject();
-        obj.put("name", "FestivalRecallStrategyV1");
-        obj.put("filter_time", t2-t1);
-        obj.put("sizeOld", videoMap.size());
         List<Video> videosResult = new ArrayList<>();
         if (filterResult != null && CollectionUtils.isNotEmpty(filterResult.getVideoIds())) {
-            obj.put("sizeNew", filterResult.getVideoIds().size());
             filterResult.getVideoIds().stream().forEach(vid -> {
                 Video video = new Video();
                 video.setVideoId(vid);
@@ -83,13 +74,12 @@ public class BlessRecallStrategy implements RecallStrategy {
                 videosResult.add(video);
             });
         }
-        log.info(obj.toString());
         Collections.sort(videosResult, Comparator.comparingDouble(o -> -o.getRovScore()));
         return videosResult;
     }
 
     @Override
-    public String pushFrom(){
+    public String pushFrom() {
         return PUSH_FORM;
     }
 

+ 6 - 14
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/recall/strategy/FestivalRecallStrategyV1.java

@@ -23,7 +23,6 @@ import java.util.*;
 /**
  * @author zhangbo
  */
-@Slf4j
 @Component
 public class FestivalRecallStrategyV1 implements RecallStrategy {
 
@@ -33,14 +32,15 @@ public class FestivalRecallStrategyV1 implements RecallStrategy {
     private String yearlyFestivalTimeRange;
     @Autowired
     private RegionFilterService filterService;
+
     @Override
     public List<Video> recall(RecallParam param) {
 
         // 1 获取省份key 放入参数map中
         String provinceCn = param.getProvince();
-        if (provinceCn == null){
+        if (provinceCn == null) {
             provinceCn = "中国";
-        }else{
+        } else {
             provinceCn = provinceCn.replaceAll("省$", "");
         }
         Map<String, String> param4Model = new HashMap<>(1);
@@ -50,27 +50,20 @@ public class FestivalRecallStrategyV1 implements RecallStrategy {
         ScorerPipeline4Recall pipeline = ScorerUtils.getScorerPipeline4Recall("feeds_score_config_festival.conf");
         List<List<Pair<Long, Double>>> results = pipeline.recall(param4Model);
         List<Pair<Long, Double>> result = results.get(0);
-        for (int i=1; i<results.size(); ++i){
+        for (int i = 1; i < results.size(); ++i) {
             result.addAll(results.get(i));
         }
         Map<Long, Double> videoMap = new LinkedHashMap<>();
-        for (Pair<Long, Double> v: result){
+        for (Pair<Long, Double> v : result) {
             videoMap.put(v.getLeft(), v.getRight());
         }
-        long t1 = new Long(System.currentTimeMillis());
         FilterParam filterParam = FilterParamFactory.create(param, Lists.newArrayList(videoMap.keySet()));
         filterParam.setForceTruncation(10000);
         filterParam.setConcurrent(true);
         filterParam.setNotUsePreView(false);
         FilterResult filterResult = filterService.filter(filterParam);
-        long t2 = new Long(System.currentTimeMillis());
-        JSONObject obj = new JSONObject();
-        obj.put("name", "FestivalRecallStrategyV1");
-        obj.put("filter_time", t2-t1);
-        obj.put("sizeOld", videoMap.size());
         List<Video> videosResult = new ArrayList<>();
         if (filterResult != null && CollectionUtils.isNotEmpty(filterResult.getVideoIds())) {
-            obj.put("sizeNew", filterResult.getVideoIds().size());
             filterResult.getVideoIds().stream().forEach(vid -> {
                 Video video = new Video();
                 video.setVideoId(vid);
@@ -80,13 +73,12 @@ public class FestivalRecallStrategyV1 implements RecallStrategy {
                 videosResult.add(video);
             });
         }
-        log.info(obj.toString());
         Collections.sort(videosResult, Comparator.comparingDouble(o -> -o.getRovScore()));
         return videosResult;
     }
 
     @Override
-    public String pushFrom(){
+    public String pushFrom() {
         return PUSH_FORM;
     }
 

+ 145 - 0
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/recall/strategy/FlowPoolWithLevelRecallStrategyFilterDigit.java

@@ -0,0 +1,145 @@
+package com.tzld.piaoquan.recommend.server.service.recall.strategy;
+
+import com.tzld.piaoquan.recommend.server.model.Video;
+import com.tzld.piaoquan.recommend.server.service.filter.FilterResult;
+import com.tzld.piaoquan.recommend.server.service.flowpool.FlowPoolConfigService;
+import com.tzld.piaoquan.recommend.server.service.flowpool.FlowPoolConstants;
+import com.tzld.piaoquan.recommend.server.service.recall.FilterParamFactory;
+import com.tzld.piaoquan.recommend.server.service.recall.RecallParam;
+import lombok.Data;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.lang3.RandomUtils;
+import org.apache.commons.lang3.math.NumberUtils;
+import org.apache.commons.lang3.tuple.Pair;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.util.*;
+import java.util.stream.Collectors;
+
+import static com.tzld.piaoquan.recommend.server.service.flowpool.FlowPoolConstants.KEY_WITH_LEVEL_FORMAT;
+
+/**
+ * @author dyp
+ */
+@Service
+@Slf4j
+public class FlowPoolWithLevelRecallStrategyFilterDigit extends AbstractFlowPoolWithLevelRecallStrategy {
+
+    @Autowired
+    private FlowPoolConfigService flowPoolConfigService;
+
+    @Override
+    Pair<String, String> flowPoolKeyAndLevel(RecallParam param) {
+        //# 1. 获取流量池各层级分发概率权重
+        Map<String, Double> levelWeightMap = flowPoolConfigService.getLevelWeight();
+
+        // 2. 判断各层级是否有视频需分发
+        List<LevelWeight> availableLevels = new ArrayList<>();
+        for (Map.Entry<String, Double> entry : levelWeightMap.entrySet()) {
+            String levelKey = String.format(KEY_WITH_LEVEL_FORMAT, param.getAppType(), entry.getKey());
+            if (Boolean.TRUE.equals(redisTemplate.hasKey(levelKey))) {
+                LevelWeight lw = new LevelWeight();
+                lw.setLevel(entry.getKey());
+                lw.setLevelKey(levelKey);
+                lw.setWeight(entry.getValue());
+                availableLevels.add(lw);
+            }
+        }
+        if (CollectionUtils.isEmpty(availableLevels)) {
+            return Pair.of("", "");
+        }
+        // 3. 根据可分发层级权重设置分发概率
+        availableLevels.sort(Comparator.comparingDouble(LevelWeight::getWeight));
+
+        double weightSum = availableLevels.stream().mapToDouble(LevelWeight::getWeight).sum();
+        BigDecimal weightSumBD = new BigDecimal(weightSum);
+        double level_p_low = 0;
+        double weight_temp = 0;
+        double level_p_up = 0;
+        Map<String, LevelP> level_p_mapping = new HashMap<>();
+        for (LevelWeight lw : availableLevels) {
+            BigDecimal bd = new BigDecimal(weight_temp + lw.getWeight());
+            level_p_up = bd.divide(weightSumBD, 2, RoundingMode.HALF_UP).doubleValue();
+            LevelP levelP = new LevelP();
+            levelP.setMin(level_p_low);
+            levelP.setMax(level_p_up);
+            levelP.setLevelKey(lw.getLevelKey());
+            level_p_mapping.put(lw.level, levelP);
+            level_p_low = level_p_up;
+
+            weight_temp += lw.getWeight();
+        }
+
+        // 4. 随机生成[0,1)之间数,返回相应概率区间的key
+        double random_p = RandomUtils.nextDouble(0, 1);
+        for (Map.Entry<String, LevelP> entry : level_p_mapping.entrySet()) {
+            if (random_p >= entry.getValue().getMin()
+                    && random_p <= entry.getValue().getMax()) {
+                return Pair.of(entry.getValue().getLevelKey(), entry.getKey());
+            }
+        }
+        return Pair.of("", "");
+    }
+
+    @Data
+    static class LevelWeight {
+        private String level;
+        private String levelKey;
+        private Double weight;
+    }
+
+    @Data
+    static class LevelP {
+        private String levelKey;
+        private double min;
+        private double max;
+    }
+
+    @Override
+    public String pushFrom() {
+        return FlowPoolConstants.PUSH_FORM;
+    }
+
+    @Override
+    public List<Video> recall(RecallParam param) {
+        Pair<String, String> flowPoolKeyAndLevel = flowPoolKeyAndLevel(param);
+        String flowPoolKey = flowPoolKeyAndLevel.getLeft();
+        String level = flowPoolKeyAndLevel.getRight();
+        int getSize = param.getSize() * 5;
+        List<Video> results = new ArrayList<>();
+        List<String> list = Objects.requireNonNull(redisTemplate.opsForSet().members(flowPoolKey)).stream().filter(o ->
+                NumberUtils.toLong(o.split("-")[0], 0) % 10 == param.getLastDigit()).distinct().collect(Collectors.toList());
+        Collections.shuffle(list);
+        List<String> data = list.subList(0, Math.min(getSize, list.size()));
+        if (CollectionUtils.isEmpty(data)) {
+            return null;
+        }
+        Map<Long, String> videoFlowPoolMap = new LinkedHashMap<>();
+        for (String value : data) {
+            String[] values = value.split("-");
+            videoFlowPoolMap.put(NumberUtils.toLong(values[0], 0), values[1]);
+        }
+
+        FilterResult filterResult = filterService.filter(FilterParamFactory.create(param, videoFlowPoolMap));
+
+        if (filterResult != null && CollectionUtils.isNotEmpty(filterResult.getVideoIds())) {
+            filterResult.getVideoIds().forEach(vid -> {
+                Video recallData = new Video();
+                recallData.setVideoId(vid);
+                recallData.setAbCode(param.getAbCode());
+                recallData.setRovScore(RandomUtils.nextDouble(0, 100));
+                recallData.setPushFrom(pushFrom());
+                recallData.setFlowPool(videoFlowPoolMap.get(vid));
+                recallData.setFlowPoolAbtestGroup(param.getFlowPoolAbtestGroup());
+                recallData.setLevel(level);
+                results.add(recallData);
+            });
+        }
+
+        return results.subList(0, Math.min(results.size(), param.getSize()));
+    }
+}

+ 164 - 0
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/recall/strategy/FlowPoolWithLevelRecallStrategyTomsonFilterDigit.java

@@ -0,0 +1,164 @@
+package com.tzld.piaoquan.recommend.server.service.recall.strategy;
+
+import com.tzld.piaoquan.recommend.server.model.Video;
+import com.tzld.piaoquan.recommend.server.service.filter.FilterParam;
+import com.tzld.piaoquan.recommend.server.service.filter.FilterResult;
+import com.tzld.piaoquan.recommend.server.service.flowpool.FlowPoolConfigService;
+import com.tzld.piaoquan.recommend.server.service.flowpool.FlowPoolConstants;
+import com.tzld.piaoquan.recommend.server.service.recall.FilterParamFactory;
+import com.tzld.piaoquan.recommend.server.service.recall.RecallParam;
+import com.tzld.piaoquan.recommend.server.service.score.ScorerUtils;
+import com.tzld.piaoquan.recommend.server.service.score4recall.ScorerPipeline4Recall;
+import lombok.Data;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.lang3.RandomUtils;
+import org.apache.commons.lang3.math.NumberUtils;
+import org.apache.commons.lang3.tuple.Pair;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.util.*;
+import java.util.stream.Collectors;
+
+import static com.tzld.piaoquan.recommend.server.service.flowpool.FlowPoolConstants.KEY_WITH_LEVEL_FORMAT;
+
+/**
+ * @author zhangbo
+ */
+@Service
+@Slf4j
+public class FlowPoolWithLevelRecallStrategyTomsonFilterDigit extends AbstractFlowPoolWithLevelRecallStrategy {
+
+    @Autowired
+    private FlowPoolConfigService flowPoolConfigService;
+
+    @Override
+    Pair<String, String> flowPoolKeyAndLevel(RecallParam param) {
+        //# 1. 获取流量池各层级分发概率权重
+        Map<String, Double> levelWeightMap = flowPoolConfigService.getLevelWeight();
+
+        // 2. 判断各层级是否有视频需分发
+        List<LevelWeight> availableLevels = new ArrayList<>();
+        for (Map.Entry<String, Double> entry : levelWeightMap.entrySet()) {
+            String levelKey = String.format(KEY_WITH_LEVEL_FORMAT, param.getAppType(), entry.getKey());
+            if (Boolean.TRUE.equals(redisTemplate.hasKey(levelKey))) {
+                LevelWeight lw = new LevelWeight();
+                lw.setLevel(entry.getKey());
+                lw.setLevelKey(levelKey);
+                lw.setWeight(entry.getValue());
+                availableLevels.add(lw);
+            }
+        }
+        if (CollectionUtils.isEmpty(availableLevels)) {
+            return Pair.of("", "");
+        }
+
+        // 3. 根据可分发层级权重设置分发概率
+        availableLevels.sort(Comparator.comparingDouble(LevelWeight::getWeight));
+
+        double weightSum = availableLevels.stream().mapToDouble(o -> o.getWeight()).sum();
+        BigDecimal weightSumBD = new BigDecimal(weightSum);
+        double level_p_low = 0;
+        double weight_temp = 0;
+        double level_p_up = 0;
+        Map<String, LevelP> level_p_mapping = new HashMap<>();
+        for (LevelWeight lw : availableLevels) {
+            BigDecimal bd = new BigDecimal(weight_temp + lw.getWeight());
+            level_p_up = bd.divide(weightSumBD, 2, RoundingMode.HALF_UP).doubleValue();
+            LevelP levelP = new LevelP();
+            levelP.setMin(level_p_low);
+            levelP.setMax(level_p_up);
+            levelP.setLevelKey(lw.getLevelKey());
+            level_p_mapping.put(lw.level, levelP);
+            level_p_low = level_p_up;
+
+            weight_temp += lw.getWeight();
+        }
+
+        // 4. 随机生成[0,1)之间数,返回相应概率区间的key
+        double random_p = RandomUtils.nextDouble(0, 1);
+        for (Map.Entry<String, LevelP> entry : level_p_mapping.entrySet()) {
+            if (random_p >= entry.getValue().getMin()
+                    && random_p <= entry.getValue().getMax()) {
+                return Pair.of(entry.getValue().getLevelKey(), entry.getKey());
+            }
+        }
+        return Pair.of("", "");
+    }
+
+    @Data
+    static class LevelWeight {
+        private String level;
+        private String levelKey;
+        private Double weight;
+    }
+
+    @Data
+    static class LevelP {
+        private String levelKey;
+        private double min;
+        private double max;
+    }
+
+    @Override
+    public String pushFrom() {
+        return FlowPoolConstants.PUSH_FORM;
+    }
+
+    @Override
+    public List<Video> recall(RecallParam param) {
+        Pair<String, String> flowPoolKeyAndLevel = flowPoolKeyAndLevel(param);
+        String flowPoolKey = flowPoolKeyAndLevel.getLeft();
+        String level = flowPoolKeyAndLevel.getRight();
+        List<String> data = Objects.requireNonNull(redisTemplate.opsForSet().members(flowPoolKey)).stream().filter(o ->
+                NumberUtils.toLong(o.split("-")[0], 0) % 10 == param.getLastDigit()).distinct().collect(Collectors.toList());
+
+        if (CollectionUtils.isEmpty(data)) {
+            return null;
+        }
+        Map<String, String> videoFlowPoolMap = new LinkedHashMap<>();
+        Map<Long, String> videoFlowPoolMap_ = new LinkedHashMap<>();
+        for (String value : data) {
+            String[] values = value.split("-");
+            videoFlowPoolMap.put(values[0], values[1]);
+            videoFlowPoolMap_.put(NumberUtils.toLong(values[0], 0), values[1]);
+        }
+        ScorerPipeline4Recall pipeline = ScorerUtils.getScorerPipeline4Recall("feeds_recall_config_tomson.conf");
+        List<List<Pair<Long, Double>>> results = pipeline.recall(videoFlowPoolMap);
+        List<Pair<Long, Double>> result = results.get(0);
+        Map<Long, Double> resultmap = result.stream()
+                .collect(Collectors.toMap(
+                        Pair::getLeft, // 键是Pair的left值
+                        Pair::getRight, // 值是Pair的right值
+                        (existingValue, newValue) -> existingValue, // 如果键冲突,选择保留现有的值(或者你可以根据需要定义其他合并策略)
+                        LinkedHashMap::new // 使用LinkedHashMap来保持插入顺序(如果需要的话)
+                ));
+        // 3 召回内部过滤
+        FilterParam filterParam = FilterParamFactory.create(param, result.stream()
+                .map(Pair::getLeft)
+                .collect(Collectors.toList()));
+        filterParam.setForceTruncation(10000);
+        filterParam.setConcurrent(true);
+        filterParam.setNotUsePreView(false);
+        FilterResult filterResult = filterService.filter(filterParam);
+        List<Video> videosResult = new ArrayList<>();
+        if (filterResult != null && CollectionUtils.isNotEmpty(filterResult.getVideoIds())) {
+            filterResult.getVideoIds().forEach(vid -> {
+                Video recallData = new Video();
+                recallData.setVideoId(vid);
+                recallData.setAbCode(param.getAbCode());
+                recallData.setRovScore(resultmap.getOrDefault(vid, 0.0));
+                recallData.setPushFrom(pushFrom());
+                recallData.setFlowPool(videoFlowPoolMap_.get(vid));
+                recallData.setFlowPoolAbtestGroup(param.getFlowPoolAbtestGroup());
+                recallData.setLevel(level);
+                videosResult.add(recallData);
+            });
+        }
+        videosResult.sort(Comparator.comparingDouble(o -> -o.getRovScore()));
+        return videosResult;
+    }
+}

+ 0 - 5
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/recall/strategy/FlowPoolWithLevelScoreRecallStrategy.java

@@ -3,9 +3,7 @@ package com.tzld.piaoquan.recommend.server.service.recall.strategy;
 import com.tzld.piaoquan.recommend.server.service.flowpool.FlowPoolConfigService;
 import com.tzld.piaoquan.recommend.server.service.flowpool.FlowPoolConstants;
 import com.tzld.piaoquan.recommend.server.service.recall.RecallParam;
-import com.tzld.piaoquan.recommend.server.util.JSONUtils;
 import lombok.Data;
-import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.lang3.RandomUtils;
 import org.apache.commons.lang3.tuple.Pair;
@@ -22,7 +20,6 @@ import static com.tzld.piaoquan.recommend.server.service.flowpool.FlowPoolConsta
  * @author dyp
  */
 @Service
-@Slf4j
 public class FlowPoolWithLevelScoreRecallStrategy extends AbstractFlowPoolWithLevelScoreRecallStrategy {
 
     @Autowired
@@ -44,14 +41,12 @@ public class FlowPoolWithLevelScoreRecallStrategy extends AbstractFlowPoolWithLe
                 availableLevels.add(lw);
             }
         }
-        // log.info("flowPoolKeyAndLevel availableLevels={}", JSONUtils.toJson(availableLevels));
         if (CollectionUtils.isEmpty(availableLevels)) {
             return Pair.of("", "");
         }
 
         // 3. 根据可分发层级权重设置分发概率
         Collections.sort(availableLevels, Comparator.comparingDouble(LevelWeight::getWeight));
-        // log.info("flowPoolKeyAndLevel sorted availableLevels={}", JSONUtils.toJson(availableLevels));
 
         double weightSum = availableLevels.stream().mapToDouble(o -> o.getWeight()).sum();
         BigDecimal weightSumBD = new BigDecimal(weightSum);

+ 11 - 33
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/recall/strategy/RegionRealtimeRecallStrategyV1.java

@@ -1,6 +1,5 @@
 package com.tzld.piaoquan.recommend.server.service.recall.strategy;
 
-import com.alibaba.fastjson.JSONObject;
 import com.google.common.collect.Lists;
 import com.tzld.piaoquan.recommend.server.model.Video;
 import com.tzld.piaoquan.recommend.server.service.filter.FilterParam;
@@ -10,33 +9,31 @@ import com.tzld.piaoquan.recommend.server.service.recall.FilterParamFactory;
 import com.tzld.piaoquan.recommend.server.service.recall.RecallParam;
 import com.tzld.piaoquan.recommend.server.service.recall.RecallStrategy;
 import com.tzld.piaoquan.recommend.server.service.score.ScorerUtils;
-import lombok.extern.slf4j.Slf4j;
+import com.tzld.piaoquan.recommend.server.service.score4recall.ScorerPipeline4Recall;
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.lang3.tuple.Pair;
 import org.springframework.beans.factory.annotation.Autowired;
-import java.util.stream.*;
-import java.util.*;
-
-import com.tzld.piaoquan.recommend.server.service.score4recall.ScorerPipeline4Recall;
 import org.springframework.stereotype.Component;
 
+import java.util.*;
+
 /**
  * @author zhangbo
  */
-@Slf4j
 @Component
 public class RegionRealtimeRecallStrategyV1 implements RecallStrategy {
     private final String CLASS_NAME = this.getClass().getSimpleName();
     @Autowired
     private RegionFilterService filterService;
+
     @Override
     public List<Video> recall(RecallParam param) {
         long t0 = System.currentTimeMillis();
         // 1 获取省份key 放入参数map中
         String provinceCn = param.getProvince();
-        if (provinceCn == null){
+        if (provinceCn == null) {
             provinceCn = "中国";
-        }else{
+        } else {
             provinceCn = provinceCn.replaceAll("省$", "");
         }
         Map<String, String> param4Model = new HashMap<>(1);
@@ -45,11 +42,11 @@ public class RegionRealtimeRecallStrategyV1 implements RecallStrategy {
         ScorerPipeline4Recall pipeline = ScorerUtils.getScorerPipeline4Recall("feeds_recall_config_region_v1.conf");
         List<List<Pair<Long, Double>>> results = pipeline.recall(param4Model);
         List<Pair<Long, Double>> result = results.get(0);
-        for (int i=1; i<results.size(); ++i){
+        for (int i = 1; i < results.size(); ++i) {
             result.addAll(results.get(i));
         }
         Map<Long, Double> videoMap = new LinkedHashMap<>();
-        for (Pair<Long, Double> v: result){
+        for (Pair<Long, Double> v : result) {
             videoMap.put(v.getLeft(), v.getRight());
         }
         long t1 = System.currentTimeMillis();
@@ -59,18 +56,6 @@ public class RegionRealtimeRecallStrategyV1 implements RecallStrategy {
         filterParam.setConcurrent(true);
         filterParam.setNotUsePreView(false);
         FilterResult filterResult = filterService.filter(filterParam);
-        long t2 = System.currentTimeMillis();
-        JSONObject obj = new JSONObject();
-        obj.put("name", this.CLASS_NAME);
-        obj.put("filter_time", t2-t1);
-        obj.put("recall_time", t1-t0);
-        obj.put("provinceCn", provinceCn);
-        obj.put("sizeOld", videoMap.size());
-        obj.put("mid", param.getMid());
-        obj.put("regionCode", param.getRegionCode());
-        obj.put("video_input", result.stream()
-                .map(pair -> String.valueOf(pair.getLeft()))
-                .collect(Collectors.joining(",")));
         List<Video> videosResult = new ArrayList<>();
         List<Long> videosResultId = new ArrayList<>();
         if (filterResult != null && CollectionUtils.isNotEmpty(filterResult.getVideoIds())) {
@@ -85,20 +70,13 @@ public class RegionRealtimeRecallStrategyV1 implements RecallStrategy {
             });
         }
         videosResult.sort(Comparator.comparingDouble(o -> -o.getRovScore()));
-//        obj.put("video_output", videosResult.stream()
-//                .map(v -> String.valueOf(v.getVideoId()))
-//                .collect(Collectors.joining(",")));
-        obj.put("video_filter", result.stream()
-                .filter(v -> !videosResultId.contains(v.getLeft()))
-                .map(v -> String.valueOf(v.getLeft()))
-                .collect(Collectors.joining(",")));
-        obj.put("sizeNew", videosResult.size());
-        log.info(obj.toString());
         return videosResult;
     }
+
     public static final String PUSH_FORM = "recall_strategy_region_1h";
+
     @Override
-    public String pushFrom(){
+    public String pushFrom() {
         return PUSH_FORM;
     }
 

+ 9 - 31
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/recall/strategy/RegionRealtimeRecallStrategyV1_default.java

@@ -1,6 +1,5 @@
 package com.tzld.piaoquan.recommend.server.service.recall.strategy;
 
-import com.alibaba.fastjson.JSONObject;
 import com.google.common.collect.Lists;
 import com.tzld.piaoquan.recommend.server.model.Video;
 import com.tzld.piaoquan.recommend.server.service.filter.FilterParam;
@@ -11,33 +10,31 @@ import com.tzld.piaoquan.recommend.server.service.recall.RecallParam;
 import com.tzld.piaoquan.recommend.server.service.recall.RecallStrategy;
 import com.tzld.piaoquan.recommend.server.service.score.ScorerUtils;
 import com.tzld.piaoquan.recommend.server.service.score4recall.ScorerPipeline4Recall;
-import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.lang3.tuple.Pair;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
 import java.util.*;
-import java.util.stream.Collectors;
 
 /**
  * @author zhangbo
  */
-@Slf4j
 @Component
 public class RegionRealtimeRecallStrategyV1_default implements RecallStrategy {
     private final String CLASS_NAME = this.getClass().getSimpleName();
     @Autowired
     private RegionFilterService filterService;
+
     @Override
     public List<Video> recall(RecallParam param) {
         long t0 = System.currentTimeMillis();
         // 1 获取省份key 放入参数map中
         String provinceCn = param.getProvince();
-        if (provinceCn == null){
+        if (provinceCn == null) {
             // provinceCn = "中国";
             return new ArrayList<>();
-        }else{
+        } else {
             provinceCn = provinceCn.replaceAll("省$", "");
         }
         final Set<String> provinceCns = new HashSet<>(Arrays.asList(
@@ -47,7 +44,7 @@ public class RegionRealtimeRecallStrategyV1_default implements RecallStrategy {
                 "重庆", "四川", "贵州", "云南", "西藏", "陕西", "甘肃",
                 "青海", "宁夏", "新疆", "台湾", "香港", "澳门", "中国"
         ));
-        if (!provinceCns.contains(provinceCn)){
+        if (!provinceCns.contains(provinceCn)) {
             return new ArrayList<>();
         }
         Map<String, String> param4Model = new HashMap<>(1);
@@ -56,11 +53,11 @@ public class RegionRealtimeRecallStrategyV1_default implements RecallStrategy {
         ScorerPipeline4Recall pipeline = ScorerUtils.getScorerPipeline4Recall("feeds_recall_config_region_v1.conf");
         List<List<Pair<Long, Double>>> results = pipeline.recall(param4Model);
         List<Pair<Long, Double>> result = results.get(0);
-        for (int i=1; i<results.size(); ++i){
+        for (int i = 1; i < results.size(); ++i) {
             result.addAll(results.get(i));
         }
         Map<Long, Double> videoMap = new LinkedHashMap<>();
-        for (Pair<Long, Double> v: result){
+        for (Pair<Long, Double> v : result) {
             videoMap.put(v.getLeft(), v.getRight());
         }
         long t1 = System.currentTimeMillis();
@@ -70,18 +67,6 @@ public class RegionRealtimeRecallStrategyV1_default implements RecallStrategy {
         filterParam.setConcurrent(true);
         filterParam.setNotUsePreView(false);
         FilterResult filterResult = filterService.filter(filterParam);
-        long t2 = System.currentTimeMillis();
-        JSONObject obj = new JSONObject();
-        obj.put("name", this.CLASS_NAME);
-        obj.put("filter_time", t2-t1);
-        obj.put("recall_time", t1-t0);
-        obj.put("provinceCn", provinceCn);
-        obj.put("sizeOld", videoMap.size());
-        obj.put("mid", param.getMid());
-        obj.put("regionCode", param.getRegionCode());
-        obj.put("video_input", result.stream()
-                .map(pair -> String.valueOf(pair.getLeft()))
-                .collect(Collectors.joining(",")));
         List<Video> videosResult = new ArrayList<>();
         List<Long> videosResultId = new ArrayList<>();
         if (filterResult != null && CollectionUtils.isNotEmpty(filterResult.getVideoIds())) {
@@ -96,20 +81,13 @@ public class RegionRealtimeRecallStrategyV1_default implements RecallStrategy {
             });
         }
         videosResult.sort(Comparator.comparingDouble(o -> -o.getRovScore()));
-//        obj.put("video_output", videosResult.stream()
-//                .map(v -> String.valueOf(v.getVideoId()))
-//                .collect(Collectors.joining(",")));
-        obj.put("video_filter", result.stream()
-                .filter(v -> !videosResultId.contains(v.getLeft()))
-                .map(v -> String.valueOf(v.getLeft()))
-                .collect(Collectors.joining(",")));
-        obj.put("sizeNew", videosResult.size());
-        log.info(obj.toString());
         return videosResult;
     }
+
     public static final String PUSH_FORM = "recall_strategy_region_1h";
+
     @Override
-    public String pushFrom(){
+    public String pushFrom() {
         return PUSH_FORM;
     }
 

+ 63 - 66
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/score4recall/strategy/BlessRecallScore.java

@@ -1,17 +1,16 @@
 package com.tzld.piaoquan.recommend.server.service.score4recall.strategy;
 
-import com.alibaba.fastjson.JSONArray;
-import com.alibaba.fastjson.JSONObject;
 import com.tzld.piaoquan.recommend.server.service.score.ScorerConfigInfo;
 import com.tzld.piaoquan.recommend.server.service.score4recall.AbstractScorer4Recall;
 import com.tzld.piaoquan.recommend.server.service.score4recall.model4recall.Model4RecallKeyValue;
-import com.tzld.piaoquan.recommend.server.util.ListMerger;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.tuple.Pair;
 
 import java.time.LocalDateTime;
 import java.time.format.DateTimeFormatter;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
 import java.util.stream.Collectors;
 
 
@@ -33,76 +32,74 @@ public class BlessRecallScore extends AbstractScorer4Recall {
         if (model == null || model.kv == null) {
             return new ArrayList<>();
         }
-        LocalDateTime now = LocalDateTime.now();
-        // 节日祝福-每年
-        List<Pair<Long, Double>> yearResult = new ArrayList<>();
-        String yearlyFestivalTimeRange = params.get("yearly_festival_time_range");
-        if (StringUtils.isBlank(yearlyFestivalTimeRange)) {
-            return new ArrayList<>();
-        }
-        JSONObject jsonObject = JSONObject.parseObject(yearlyFestivalTimeRange);
-        for (String festival : jsonObject.keySet()) {
-            try {
-                JSONArray jsonArray = jsonObject.getJSONArray(festival);
-                if (jsonArray == null) {
-                    continue;
-                }
-                List<String> timeRangeList = jsonArray.toJavaList(String.class);
-                if (isFestivalTime(now, timeRangeList)) {
-                    Pair<LocalDateTime, LocalDateTime> startTimeAndEndTime = getStartTimeAndEndTime(timeRangeList.get(0));
-                    if (startTimeAndEndTime == null) {
-                        continue;
-                    }
-                    // 节日峰值设置为结束时间的当天的7点
-                    double weight = DynamicGaussianFunction.calculateValue(LocalDateTime.now(), startTimeAndEndTime.getLeft(),
-                            startTimeAndEndTime.getRight(), startTimeAndEndTime.getRight().withHour(7));
-                    List<Pair<Long, Double>> festivalLists = model.kv.getOrDefault(festival, new ArrayList<>());
-                    if (festivalLists.isEmpty()) {
-                        continue;
-                    }
-                    festivalLists = festivalLists.stream().map(pair -> Pair.of(pair.getLeft(), weight))
-                            .limit(Math.min(50, festivalLists.size()))
-                            .collect(Collectors.toList());
-                    yearResult.addAll(festivalLists);
-                }
-            } catch (Exception e) {
-                e.printStackTrace();
-            }
-        }
-        List<Pair<Long, Double>> dayResult = new ArrayList<>();
-        // 每日祝福-每天固定时间段
-        String dailyFestivalTimeRange = params.get("daily_bless_time_range");
-        if (StringUtils.isBlank(dailyFestivalTimeRange)) {
-            return new ArrayList<>();
-        }
-        JSONObject dailyFestivalTimeRangeJson = JSONObject.parseObject(dailyFestivalTimeRange);
-        for (String bless : dailyFestivalTimeRangeJson.keySet()) {
-            try {
-                String timeRange = dailyFestivalTimeRangeJson.getString(bless);
-                if (isFestivalTime(now, Collections.singletonList(timeRange))) {
-                    List<Pair<Long, Double>> festivalLists = model.kv.getOrDefault(bless, new ArrayList<>());
-                    if (festivalLists.isEmpty()) {
-                        continue;
-                    }
-                    festivalLists = festivalLists.stream().map(pair -> Pair.of(pair.getLeft(), 0.0))
-                            .limit(Math.min(50, festivalLists.size()))
-                            .collect(Collectors.toList());
-                    dayResult.addAll(festivalLists);
-                }
-            } catch (Exception e) {
-                e.printStackTrace();
-            }
-        }
+//        LocalDateTime now = LocalDateTime.now();
+//        // 节日祝福-每年
+//        List<Pair<Long, Double>> yearResult = new ArrayList<>();
+//        String yearlyFestivalTimeRange = params.get("yearly_festival_time_range");
+//        if (StringUtils.isBlank(yearlyFestivalTimeRange)) {
+//            return new ArrayList<>();
+//        }
+//        JSONObject jsonObject = JSONObject.parseObject(yearlyFestivalTimeRange);
+//        for (String festival : jsonObject.keySet()) {
+//            try {
+//                JSONArray jsonArray = jsonObject.getJSONArray(festival);
+//                if (jsonArray == null) {
+//                    continue;
+//                }
+//                //                if (isFestivalTime(now, timeRangeList)) {
+////                    Pair<LocalDateTime, LocalDateTime> startTimeAndEndTime = getStartTimeAndEndTime(timeRangeList.get(0));
+////                    if (startTimeAndEndTime == null) {
+////                        continue;
+////                    }
+//                    // 节日峰值设置为结束时间的当天的7点
+////                    double weight = DynamicGaussianFunction.calculateValue(LocalDateTime.now(), startTimeAndEndTime.getLeft(),
+////                            startTimeAndEndTime.getRight(), startTimeAndEndTime.getRight().withHour(7));
+//                    List<Pair<Long, Double>> festivalLists = model.kv.getOrDefault(festival, new ArrayList<>());
+//                    if (festivalLists.isEmpty()) {
+//                        continue;
+//                    }
+//                    festivalLists = festivalLists.stream().map(pair -> Pair.of(pair.getLeft(), 0.0))
+//                            .limit(Math.min(200, festivalLists.size()))
+//                            .collect(Collectors.toList());
+//                    yearResult.addAll(festivalLists);
+////                }
+//            } catch (Exception e) {
+//                e.printStackTrace();
+//            }
+//        }
+//        List<Pair<Long, Double>> dayResult = new ArrayList<>();
+//        // 每日祝福-每天固定时间段
+//        String dailyFestivalTimeRange = params.get("daily_bless_time_range");
+//        if (StringUtils.isBlank(dailyFestivalTimeRange)) {
+//            return new ArrayList<>();
+//        }
+//        JSONObject dailyFestivalTimeRangeJson = JSONObject.parseObject(dailyFestivalTimeRange);
+//        for (String bless : dailyFestivalTimeRangeJson.keySet()) {
+//            try {
+//                String timeRange = dailyFestivalTimeRangeJson.getString(bless);
+//                if (isFestivalTime(now, Collections.singletonList(timeRange))) {
+//                    List<Pair<Long, Double>> festivalLists = model.kv.getOrDefault(bless, new ArrayList<>());
+//                    if (festivalLists.isEmpty()) {
+//                        continue;
+//                    }
+//                    festivalLists = festivalLists.stream().map(pair -> Pair.of(pair.getLeft(), 0.0))
+//                            .limit(Math.min(50, festivalLists.size()))
+//                            .collect(Collectors.toList());
+//                    dayResult.addAll(festivalLists);
+//                }
+//            } catch (Exception e) {
+//                e.printStackTrace();
+//            }
+//        }
         // 常规祝福类的小程序-任意时间
         List<Pair<Long, Double>> anyResult = new ArrayList<>();
         List<Pair<Long, Double>> festivalLists = model.kv.getOrDefault("祝福", new ArrayList<>());
         if (!festivalLists.isEmpty()) {
             festivalLists = festivalLists.stream().map(pair -> Pair.of(pair.getLeft(), 0.0))
-                    .limit(Math.min(50, festivalLists.size()))
                     .collect(Collectors.toList());
             anyResult.addAll(festivalLists);
         }
-        return ListMerger.mergeLists(yearResult, dayResult, anyResult);
+        return anyResult;
     }
 
     public Pair<LocalDateTime, LocalDateTime> getStartTimeAndEndTime(String timeRangeList) {

+ 0 - 40
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/util/HttpClientFactory.java

@@ -58,46 +58,6 @@ public class HttpClientFactory {
         return requestInterceptor;
     }
 
-//    public String request(HttpRequestBase request) {
-//
-//        HttpEntity entity = null;
-//        try {
-//            log.info("request={}", JSONUtils.toJson(request));
-//            CloseableHttpResponse chr = request((HttpUriRequest) request);
-//            log.info("response={}", JSONUtils.toJson(chr));
-//            if (chr == null
-//                    || chr.getStatusLine() == null
-//                    || chr.getStatusLine().getStatusCode() != 200) {
-//                log.error("request failed http status exception!");
-//                return Strings.EMPTY;
-//            }
-//            entity = chr.getEntity();
-//            if (entity == null) {
-//                return Strings.EMPTY;
-//            }
-//            String content = EntityUtils.toString(entity, "UTF-8");
-//            log.info("response entity={}", JSONUtils.toJson(content));
-//        } catch (Exception e) {
-//            log.error("request error url={}", request.getURI().getPath(), e);
-//        } finally {
-//            if (request != null) {
-//                request.abort();
-//            }
-//            EntityUtils.consumeQuietly(entity);
-//        }
-//    }
-//
-//
-//    public CloseableHttpResponse request(HttpUriRequest request) {
-//        try {
-//            CloseableHttpResponse execute = closeableHttpClient.execute(request);
-//            return execute;
-//        } catch (Exception e) {
-//            log.error(String.format("http timeout request url = %s .", request.getURI().getPath()));
-//            throw new RuntimeException(e);
-//        }
-//    }
-
     /**
      * @param connectTimeout 连接超时时间 ms
      * @param socketTimeout  读超时时间(等待数据超时时间)ms