#509 rankV19

Unito
wangyunpeng ha unito 1 commit da Server/wyp/20250918-rankV19 a Server/master 13 ore fa
22 ha cambiato i file con 213 aggiunte e 87 eliminazioni
  1. 0 3
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/DefaultRankStrategy.java
  2. 0 3
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/FwhColdStartRankStrategy.java
  3. 0 3
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/RankV10Strategy.java
  4. 0 3
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/RankV11Strategy.java
  5. 0 3
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/RankV12Strategy.java
  6. 0 3
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/RankV13Strategy.java
  7. 0 3
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/RankV14Strategy.java
  8. 0 3
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/RankV15Strategy.java
  9. 0 3
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/RankV16Strategy.java
  10. 0 3
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/RankV17Strategy.java
  11. 0 3
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/RankV18Strategy.java
  12. 176 0
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/RankV19Strategy.java
  13. 0 3
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/RankV2Strategy.java
  14. 0 3
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/RankV3Strategy.java
  15. 0 3
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/RankV4Strategy.java
  16. 0 3
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/RankV5Strategy.java
  17. 0 3
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/RankV7Strategy.java
  18. 0 3
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/RankV8Strategy.java
  19. 0 3
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/RankV9Strategy.java
  20. 0 5
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/score/strategy/ViewCountRateCorrelationStrategy.java
  21. 37 23
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/score/strategy/ViewCountRateStrategy.java
  22. 0 5
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/score/strategy/ViewCountRateV2Strategy.java

+ 0 - 3
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/DefaultRankStrategy.java

@@ -19,9 +19,6 @@ import org.springframework.stereotype.Service;
 
 import java.util.*;
 
-/**
- * @author dyp
- */
 @Service
 @Slf4j
 public class DefaultRankStrategy implements RankStrategy {

+ 0 - 3
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/FwhColdStartRankStrategy.java

@@ -14,9 +14,6 @@ import org.springframework.stereotype.Service;
 
 import java.util.*;
 
-/**
- * @author dyp
- */
 @Service
 @Slf4j
 public class FwhColdStartRankStrategy implements RankStrategy {

+ 0 - 3
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/RankV10Strategy.java

@@ -19,9 +19,6 @@ import org.springframework.stereotype.Service;
 
 import java.util.*;
 
-/**
- * @author dyp
- */
 @Service
 @Slf4j
 public class RankV10Strategy implements RankStrategy {

+ 0 - 3
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/RankV11Strategy.java

@@ -19,9 +19,6 @@ import org.springframework.stereotype.Service;
 
 import java.util.*;
 
-/**
- * @author dyp
- */
 @Service
 @Slf4j
 public class RankV11Strategy implements RankStrategy {

+ 0 - 3
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/RankV12Strategy.java

@@ -19,9 +19,6 @@ import org.springframework.stereotype.Service;
 
 import java.util.*;
 
-/**
- * @author dyp
- */
 @Service
 @Slf4j
 public class RankV12Strategy implements RankStrategy {

+ 0 - 3
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/RankV13Strategy.java

@@ -19,9 +19,6 @@ import org.springframework.stereotype.Service;
 
 import java.util.*;
 
-/**
- * @author dyp
- */
 @Service
 @Slf4j
 public class RankV13Strategy implements RankStrategy {

+ 0 - 3
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/RankV14Strategy.java

@@ -19,9 +19,6 @@ import org.springframework.stereotype.Service;
 
 import java.util.*;
 
-/**
- * @author dyp
- */
 @Service
 @Slf4j
 public class RankV14Strategy implements RankStrategy {

+ 0 - 3
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/RankV15Strategy.java

@@ -22,9 +22,6 @@ import org.springframework.stereotype.Service;
 import java.util.*;
 import java.util.stream.Collectors;
 
-/**
- * @author dyp
- */
 @Service
 @Slf4j
 public class RankV15Strategy implements RankStrategy {

+ 0 - 3
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/RankV16Strategy.java

@@ -24,9 +24,6 @@ import org.springframework.stereotype.Service;
 import java.util.*;
 import java.util.stream.Collectors;
 
-/**
- * @author dyp
- */
 @Service
 @Slf4j
 public class RankV16Strategy implements RankStrategy {

+ 0 - 3
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/RankV17Strategy.java

@@ -24,9 +24,6 @@ import org.springframework.stereotype.Service;
 import java.util.*;
 import java.util.stream.Collectors;
 
-/**
- * @author dyp
- */
 @Service
 @Slf4j
 public class RankV17Strategy implements RankStrategy {

+ 0 - 3
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/RankV18Strategy.java

@@ -24,9 +24,6 @@ import org.springframework.stereotype.Service;
 import java.util.*;
 import java.util.stream.Collectors;
 
-/**
- * @author dyp
- */
 @Service
 @Slf4j
 public class RankV18Strategy implements RankStrategy {

+ 176 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/RankV19Strategy.java

@@ -0,0 +1,176 @@
+package com.tzld.longarticle.recommend.server.service.recommend.rank.strategy;
+
+
+import com.ctrip.framework.apollo.spring.annotation.ApolloJsonValue;
+import com.tzld.longarticle.recommend.server.common.enums.aigc.PublishPlanInputSourceTypesEnum;
+import com.tzld.longarticle.recommend.server.common.enums.recommend.ScoreStrategyEnum;
+import com.tzld.longarticle.recommend.server.model.dto.Content;
+import com.tzld.longarticle.recommend.server.model.entity.crawler.Article;
+import com.tzld.longarticle.recommend.server.repository.crawler.ArticleRepository;
+import com.tzld.longarticle.recommend.server.service.recommend.config.AccountContentPoolConfigService;
+import com.tzld.longarticle.recommend.server.service.recommend.config.StrategyIndexScoreWeightService;
+import com.tzld.longarticle.recommend.server.service.recommend.rank.*;
+import com.tzld.longarticle.recommend.server.service.recommend.score.AccountIndexReplacePoolConfig;
+import com.tzld.longarticle.recommend.server.service.recommend.score.ScoreResult;
+import com.tzld.longarticle.recommend.server.service.recommend.score.ScoreService;
+import com.tzld.longarticle.recommend.server.util.CommonCollectionUtils;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.lang3.RandomUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Service;
+
+import java.util.*;
+import java.util.stream.Collectors;
+
+@Service
+@Slf4j
+public class RankV19Strategy implements RankStrategy {
+
+    @Autowired
+    private ScoreService scoreService;
+    @Autowired
+    private RankService rankService;
+    @Autowired
+    private AccountContentPoolConfigService accountContentPoolConfigService;
+    @Autowired
+    private ArticleRepository articleRepository;
+    @Autowired
+    private StrategyIndexScoreWeightService weightService;
+
+    @ApolloJsonValue("${touliu.account.ghIds:[\"gh_93e00e187787\", \"gh_ac43e43b253b\", \"gh_68e7fdc09fe4\",\"gh_77f36c109fb1\", \"gh_b181786a6c8c\", \"gh_1ee2e1b39ccf\"]}")
+    private List<String> touliuAccountGhIds;
+    @Value("${topProducePlanId:}")
+    private String topProducePlanId;
+
+    public RankResult rank(RankParam param) {
+        List<Content> result = new ArrayList<>();
+
+        ScoreResult scoreResult = scoreService.score(RankStrategy.convertToScoreParam(param));
+
+        Map<String, Map<String, Double>> scoreMap = scoreResult.getScoreMap();
+        String[] contentPools = accountContentPoolConfigService.getContentPools(param.getAccountName());
+        Map<Integer, AccountIndexReplacePoolConfig> indexReplacePoolConfigMap = accountContentPoolConfigService.getContentReplacePools(param.getAccountName());
+
+        List<RankItem> items = CommonCollectionUtils.toList(param.getContents(), c -> {
+            RankItem item = new RankItem();
+            item.setContent(c);
+            c.setScoreMap(scoreMap.get(c.getId()));
+            item.setScoreMap(scoreMap.get(c.getId()));
+            double score;
+            int index = weightService.getIndex(item.getContent().getContentPoolType(), contentPools);
+            if (contentPools[0].equals(item.getContent().getContentPoolType())
+                    || contentPools[1].equals(item.getContent().getContentPoolType())) {
+                score = item.getScore(ScoreStrategyEnum.SIMILARITY.value())
+                        * weightService.getWeight(param.getStrategy(), param.getGhId(), index,
+                        ScoreStrategyEnum.SIMILARITY.value())
+                        + item.getScore(ScoreStrategyEnum.CATEGORY.value())
+                        * weightService.getWeight(param.getStrategy(), param.getGhId(), index,
+                        ScoreStrategyEnum.CATEGORY.value())
+                        + item.getScore(ScoreStrategyEnum.HIS_FISSION_OPEN_RATE.value())
+                        * weightService.getWeight(param.getStrategy(), param.getGhId(), index,
+                        ScoreStrategyEnum.HIS_FISSION_OPEN_RATE.value())
+                        + item.getScore(ScoreStrategyEnum.FLOW_CTL_DECREASE.value())
+                        + item.getScore(ScoreStrategyEnum.CRAWLER_DAYS_DECREASE_STRATEGY.value());
+                if (item.getScore(ScoreStrategyEnum.PUBLISH_TIMES.value()) >= 0) {
+                    score += item.getScore(ScoreStrategyEnum.VIEW_COUNT_RATE.value())
+                            * weightService.getWeight(param.getStrategy(), param.getGhId(), index,
+                            ScoreStrategyEnum.VIEW_COUNT_RATE.value());
+                }
+            } else {
+                score = item.getScore(ScoreStrategyEnum.SIMILARITY.value())
+                        * weightService.getWeight(param.getStrategy(), param.getGhId(), index,
+                        ScoreStrategyEnum.SIMILARITY.value())
+                        + item.getScore(ScoreStrategyEnum.CATEGORY.value())
+                        * weightService.getWeight(param.getStrategy(), param.getGhId(), index,
+                        ScoreStrategyEnum.CATEGORY.value())
+                        + item.getScore(ScoreStrategyEnum.ACCOUNT_PRE_DISTRIBUTE.value())
+                        + item.getScore(ScoreStrategyEnum.PUBLISH_TIMES.value())
+                        + item.getScore(ScoreStrategyEnum.CRAWLER_DAYS_DECREASE_STRATEGY.value())
+                        + item.getScore(ScoreStrategyEnum.FLOW_CTL_DECREASE.value());
+            }
+            c.setScore(score);
+            item.setScore(score);
+            return item;
+        });
+        // 相似度评分为0 报警返回
+        List<Article> hisPublishFirstArticleList = articleRepository.getByGhIdAndItemIndexAndTypeEqualsAndStatusEquals(
+                param.getGhId(), 1, param.getType(), 1);
+        if (RankStrategy.SimilarityScoreZero(items, param, hisPublishFirstArticleList)) {
+            return new RankResult(result);
+        }
+        // 安全分降权
+        RankService.safeScoreDecrease(items);
+
+        // 1 排序
+        Collections.sort(items, (o1, o2) -> -Double.compare(o1.getScore(), o2.getScore()));
+        // 2 相似去重
+        List<Content> contents = CommonCollectionUtils.toList(items, RankItem::getContent);
+
+        // 3 文章按照内容池分组
+        Map<String, List<Content>> contentMap = new HashMap<>();
+        for (Content c : contents) {
+            List<Content> data = contentMap.computeIfAbsent(c.getContentPoolType(), k -> new ArrayList<>());
+            data.add(c);
+        }
+        // 4 选文章
+        String[] publishPool = Arrays.copyOf(contentPools, contentPools.length);
+
+        // 头
+        List<Content> pool1 = contentMap.get(contentPools[0]);
+        if (CollectionUtils.isNotEmpty(pool1)) {
+            pool1 = RankService.contentSourceTypeFilter(param.getStrategy(), pool1, 1);
+        }
+        RankService.printSortLog(param.getStrategy(), param.getAccountName(), "头条", pool1);
+        if (CollectionUtils.isNotEmpty(pool1)) {
+            if (topProducePlanId.equals(pool1.get(0).getProducePlanId())) {
+                int i = RandomUtils.nextInt(0, 2);
+                if (i == 0) {
+                    for (Content content : pool1) {
+                        if (!topProducePlanId.equals(content.getProducePlanId())) {
+                            result.add(content);
+                            break;
+                        }
+                    }
+                }
+            }
+            if (CollectionUtils.isEmpty(result)) {
+                result.add(pool1.get(0));
+            }
+        } else {
+            RankStrategy.sendFeishuFirstPoolEmpty(param, contentPools[0]);
+            return new RankResult(result);
+        }
+
+        // 次
+        RankService.commonAddSecondContent(param, result, publishPool, contentPools, contentMap,
+                indexReplacePoolConfigMap, param.getStrategy());
+
+        // 3-8
+        // RankService.commonAdd38Content(param, result, contentPools, contentMap, param.getStrategy());
+        List<Content> pool = contentMap.get(contentPools[2]);
+        RankService.printSortLog(param.getStrategy(), param.getAccountName(), "3-8", pool);
+        if (CollectionUtils.isNotEmpty(pool)) {
+            Integer videoSourceType = PublishPlanInputSourceTypesEnum.longArticleVideoPoolSource.getVal();
+            Queue<Content> videoPoolQueue = pool.stream().filter(o -> Objects.equals(o.getSourceType(), videoSourceType))
+                    .collect(Collectors.toCollection(LinkedList::new));
+            Queue<Content> otherPoolQueue = pool.stream().filter(o -> !Objects.equals(o.getSourceType(), videoSourceType))
+                    .collect(Collectors.toCollection(LinkedList::new));
+            for (int i = 3; i < param.getSize() + 1; i++) {
+                Integer sourceType = RankService.getStrategyPoolSourceType(param.getStrategy(), i);
+                if (Objects.equals(sourceType, videoSourceType) && !videoPoolQueue.isEmpty()) {
+                    result.add(videoPoolQueue.poll());
+                } else if (!otherPoolQueue.isEmpty()) {
+                    result.add(otherPoolQueue.poll());
+                }
+            }
+        }
+
+        rankService.checkPublishContentStatus(result, contentMap, publishPool);
+        RankStrategy.deduplication(result, contentMap, publishPool);
+
+        return new RankResult(result);
+    }
+
+}

+ 0 - 3
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/RankV2Strategy.java

@@ -20,9 +20,6 @@ import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 
-/**
- * @author dyp
- */
 @Service
 @Slf4j
 public class RankV2Strategy implements RankStrategy {

+ 0 - 3
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/RankV3Strategy.java

@@ -19,9 +19,6 @@ import org.springframework.stereotype.Service;
 
 import java.util.*;
 
-/**
- * @author dyp
- */
 @Service
 @Slf4j
 public class RankV3Strategy implements RankStrategy {

+ 0 - 3
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/RankV4Strategy.java

@@ -18,9 +18,6 @@ import org.springframework.stereotype.Service;
 
 import java.util.*;
 
-/**
- * @author dyp
- */
 @Service
 @Slf4j
 public class RankV4Strategy implements RankStrategy {

+ 0 - 3
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/RankV5Strategy.java

@@ -20,9 +20,6 @@ import org.springframework.stereotype.Service;
 
 import java.util.*;
 
-/**
- * @author dyp
- */
 @Service
 @Slf4j
 public class RankV5Strategy implements RankStrategy {

+ 0 - 3
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/RankV7Strategy.java

@@ -18,9 +18,6 @@ import org.springframework.stereotype.Service;
 
 import java.util.*;
 
-/**
- * @author dyp
- */
 @Service
 @Slf4j
 public class RankV7Strategy implements RankStrategy {

+ 0 - 3
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/RankV8Strategy.java

@@ -19,9 +19,6 @@ import org.springframework.stereotype.Service;
 
 import java.util.*;
 
-/**
- * @author dyp
- */
 @Service
 @Slf4j
 public class RankV8Strategy implements RankStrategy {

+ 0 - 3
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/RankV9Strategy.java

@@ -18,9 +18,6 @@ import org.springframework.stereotype.Service;
 
 import java.util.*;
 
-/**
- * @author dyp
- */
 @Service
 @Slf4j
 public class RankV9Strategy implements RankStrategy {

+ 0 - 5
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/score/strategy/ViewCountRateCorrelationStrategy.java

@@ -32,18 +32,13 @@ public class ViewCountRateCorrelationStrategy implements ScoreStrategy {
 
     @Override
     public List<Score> score(ScoreParam param) {
-        long start = System.currentTimeMillis();
         List<Score> scores = new ArrayList<>();
         String[] contentPools = accountContentPoolConfigService.getContentPools(param.getAccountName());
         List<AccountAvgInfo> avgInfoList = accountAvgInfoRepository.getAllByGhIdEqualsAndStatusEquals(param.getGhId(), 1);
         double avgViewCountFirst = accountIndexAvgViewCountService.getAvgReadCountByDB(avgInfoList, param.getGhId(), 1);
-        double avgViewCountSecond = accountIndexAvgViewCountService.getAvgReadCountByDB(avgInfoList, param.getGhId(), 2);
-        double avgViewCountThird = accountIndexAvgViewCountService.getAvgReadCountByDB(avgInfoList, param.getGhId(), 3);
         // 缺省头条均值设置为2w,次条为1w
         if (avgViewCountFirst < 10) {
             avgViewCountFirst = 20000D;
-            avgViewCountSecond = 10000D;
-            avgViewCountThird = 400D;
         }
         for (Content content : param.getContents()) {
             for (int i = 0; i < contentPools.length; i++) {

+ 37 - 23
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/score/strategy/ViewCountRateStrategy.java

@@ -13,6 +13,7 @@ import com.tzld.longarticle.recommend.server.util.MathUtils;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections4.CollectionUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Component;
 
 import java.util.ArrayList;
@@ -30,20 +31,18 @@ public class ViewCountRateStrategy implements ScoreStrategy {
     @Autowired
     AccountAvgInfoRepository accountAvgInfoRepository;
 
+    @Value("view.count.rate.his.first.publish.time.config:5")
+    private int hisFirstPublishTimeConfig;
+
     @Override
     public List<Score> score(ScoreParam param) {
-        long start = System.currentTimeMillis();
         List<Score> scores = new ArrayList<>();
         String[] contentPools = accountContentPoolConfigService.getContentPools(param.getAccountName());
         List<AccountAvgInfo> avgInfoList = accountAvgInfoRepository.getAllByGhIdEqualsAndStatusEquals(param.getGhId(), 1);
         double avgViewCountFirst = accountIndexAvgViewCountService.getAvgReadCountByDB(avgInfoList, param.getGhId(), 1);
-        double avgViewCountSecond = accountIndexAvgViewCountService.getAvgReadCountByDB(avgInfoList, param.getGhId(), 2);
-        double avgViewCountThird = accountIndexAvgViewCountService.getAvgReadCountByDB(avgInfoList, param.getGhId(), 3);
         // 缺省头条均值设置为2w,次条为1w
         if (avgViewCountFirst < 10) {
             avgViewCountFirst = 20000D;
-            avgViewCountSecond = 10000D;
-            avgViewCountThird = 400D;
         }
         for (Content content : param.getContents()) {
             for (int i = 0; i < contentPools.length; i++) {
@@ -61,28 +60,37 @@ public class ViewCountRateStrategy implements ScoreStrategy {
                         avgViewCountPos = 400D;
                     }
                 }
+                // 阅读量之和
                 double showViewCountSum = 0D;
-                double avgViewCountSum = 0D;
+                // 阅读均值置信区间上限之和
+                double readAvgCiUpperSum = 0D;
+                // 头条阅读量之和
                 double showViewCountSumFirst = 0D;
-                double avgViewCountSumFirst = 0D;
+                // 头条阅读均值置信区间上限之和
+                double readAvgCiUpperSumFirst = 0D;
+                // 次条阅读量之和
                 double showViewCountSumSecond = 0D;
-                double avgViewCountSumSecond = 0D;
-                double maxAvgViewCount = 0D;
+                // 次条阅读均值置信区间上限之和
+                double readAvgCiUpperSumSecond = 0D;
+                // 最大阅读均值置信区间上限
+                double maxReadAvgCiUpper = 0D;
                 if (CollectionUtils.isEmpty(content.getHisPublishArticleList())) {
                     continue;
                 }
+                int hisFirstPublishTime = 0;
                 for (ContentHisPublishArticle hisItem : content.getHisPublishArticleList()) {
                     // 过滤掉发布时间晚于19点数据
                     if (ScoreStrategy.hisContentLateFilter(hisItem.getPublishTimestamp())) {
                         continue;
                     }
                     if (hisItem.isInnerAccount() && Objects.nonNull(hisItem.getViewCount())
-                            && hisItem.getViewCount() > 0 && Objects.nonNull(hisItem.getAvgViewCount())
-                            && hisItem.getAvgViewCount() > 0) {
-                        maxAvgViewCount = Math.max(maxAvgViewCount, hisItem.getAvgViewCount());
+                            && hisItem.getViewCount() > 0 && Objects.nonNull(hisItem.getReadAvgCiUpper())
+                            && hisItem.getReadAvgCiUpper() > 0) {
+                        maxReadAvgCiUpper = Math.max(maxReadAvgCiUpper, hisItem.getReadAvgCiUpper());
                         if (hisItem.getItemIndex() == 1) {
                             showViewCountSumFirst += hisItem.getViewCount();
-                            avgViewCountSumFirst += hisItem.getAvgViewCount();
+                            readAvgCiUpperSumFirst += hisItem.getReadAvgCiUpper();
+                            hisFirstPublishTime++;
                         } else if (hisItem.getItemIndex() == 2) {
                             if (Objects.nonNull(hisItem.getFirstViewCount()) && hisItem.getFirstViewCount() > 0 &&
                                     Objects.nonNull(hisItem.getFirstViewCountRate()) && hisItem.getFirstViewCountRate() > 0) {
@@ -90,9 +98,9 @@ public class ViewCountRateStrategy implements ScoreStrategy {
                                 if (hisItem.getFirstViewCountRate() > 1) {
                                     // 对于头条均值倍数大于1的情况,次条均值线性增加,用于debias;
                                     // TODO: 对于小于1的情况,是否要减去?
-                                    avgViewCountSumSecond += hisItem.getAvgViewCount() * hisItem.getFirstViewCountRate();
+                                    readAvgCiUpperSumSecond += hisItem.getReadAvgCiUpper() * hisItem.getFirstViewCountRate();
                                 } else {
-                                    avgViewCountSumSecond += hisItem.getAvgViewCount();
+                                    readAvgCiUpperSumSecond += hisItem.getReadAvgCiUpper();
                                 }
                             }
                         } else {
@@ -102,9 +110,9 @@ public class ViewCountRateStrategy implements ScoreStrategy {
                                 if (hisItem.getFirstViewCountRate() > 1) {
                                     // 对于头条均值倍数大于1的情况,次条均值线性增加,用于debias;
                                     // TODO: 对于小于1的情况,是否要减去?
-                                    avgViewCountSum += hisItem.getAvgViewCount() * hisItem.getFirstViewCountRate();
+                                    readAvgCiUpperSum += hisItem.getReadAvgCiUpper() * hisItem.getFirstViewCountRate();
                                 } else {
-                                    avgViewCountSum += hisItem.getAvgViewCount();
+                                    readAvgCiUpperSum += hisItem.getReadAvgCiUpper();
                                 }
                             }
                         }
@@ -114,22 +122,28 @@ public class ViewCountRateStrategy implements ScoreStrategy {
                 double bigRateW = 1D;
                 // 如果有头条反馈数据,优先选取头条反馈数据;
                 if (showViewCountSumFirst > 0) {
-                    showViewCountSum = showViewCountSumFirst;
-                    avgViewCountSum = avgViewCountSumFirst;
+                    // 如果历史头条发布次数小于x次,将次条数据也加入计算
+                    if (hisFirstPublishTime < hisFirstPublishTimeConfig) {
+                        showViewCountSum = showViewCountSumFirst + showViewCountSumSecond;
+                        readAvgCiUpperSum = readAvgCiUpperSumFirst + readAvgCiUpperSumSecond;
+                    } else {
+                        showViewCountSum = showViewCountSumFirst;
+                        readAvgCiUpperSum = readAvgCiUpperSumFirst;
+                    }
                 } else if (showViewCountSumSecond > 0) {
                     showViewCountSum = showViewCountSumSecond;
-                    avgViewCountSum = avgViewCountSumSecond;
+                    readAvgCiUpperSum = readAvgCiUpperSumSecond;
                     // 如果是大号头条,则降权
                     if (avgViewCountFirst >= 3000 && i == 0) {
                         bigRateW = 0.001D;
                     }
                 }
                 // 均值倍数
-                if (avgViewCountSum > 0) {
-                    viewCountRate = showViewCountSum / avgViewCountSum;
+                if (readAvgCiUpperSum > 0) {
+                    viewCountRate = showViewCountSum / readAvgCiUpperSum;
                 }
                 // 置信度
-                double viewCountRateW = MathUtils.sigmoid(avgViewCountSum, 0.0005, avgViewCountPos);
+                double viewCountRateW = MathUtils.sigmoid(readAvgCiUpperSum, 0.0002, avgViewCountPos);
                 double viewCountRateScore = 0;
 
                 if (viewCountRate > 0) {

+ 0 - 5
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/score/strategy/ViewCountRateV2Strategy.java

@@ -32,18 +32,13 @@ public class ViewCountRateV2Strategy implements ScoreStrategy {
 
     @Override
     public List<Score> score(ScoreParam param) {
-        long start = System.currentTimeMillis();
         List<Score> scores = new ArrayList<>();
         String[] contentPools = accountContentPoolConfigService.getContentPools(param.getAccountName());
         List<AccountAvgInfo> avgInfoList = accountAvgInfoRepository.getAllByGhIdEqualsAndStatusEquals(param.getGhId(), 1);
         double avgViewCountFirst = accountIndexAvgViewCountService.getAvgReadCountByDB(avgInfoList, param.getGhId(), 1);
-        double avgViewCountSecond = accountIndexAvgViewCountService.getAvgReadCountByDB(avgInfoList, param.getGhId(), 2);
-        double avgViewCountThird = accountIndexAvgViewCountService.getAvgReadCountByDB(avgInfoList, param.getGhId(), 3);
         // 缺省头条均值设置为2w,次条为1w
         if (avgViewCountFirst < 10) {
             avgViewCountFirst = 20000D;
-            avgViewCountSecond = 10000D;
-            avgViewCountThird = 400D;
         }
         for (Content content : param.getContents()) {
             for (int i = 0; i < contentPools.length; i++) {