Browse Source

流量池已发布 降权修改

wangyunpeng 11 months ago
parent
commit
f3163d4870

+ 1 - 1
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/repository/crawler/PublishSortLogRepository.java

@@ -9,7 +9,7 @@ import java.util.List;
 @Repository
 public interface PublishSortLogRepository extends JpaRepository<PublishSortLog, Long> {
 
-    List<PublishSortLog> findByDateStr(String dateStr);
+    List<PublishSortLog> findByDateStrAndTitleIn(String dateStr, List<String> titles);
 
     List<PublishSortLog> findByCrawlerChannelContentIdIn(List<String> crawlerChannelContentIds);
 }

+ 1 - 1
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/repository/entity/crawler/Article.java

@@ -14,7 +14,7 @@ import java.io.Serializable;
 @AllArgsConstructor
 @NoArgsConstructor
 @Entity
-@Table(name = "official_articles")
+@Table(name = "official_articles_v2")
 public class Article implements Serializable {
 
     @Column(name = "ghId")

+ 2 - 2
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/RecommendService.java

@@ -161,7 +161,7 @@ public class RecommendService {
         publishContentSortLogRepository.save(log);
         // 仅记录3-8条 冷启层内容
         List<PublishSortLog> publishSortLogSaveList = new ArrayList<>();
-        for (int i = 3; i < rankResult.getContents().size() + 1; i++) {
+        for (int i = 1; i < rankResult.getContents().size() + 1; i++) {
             Content content = rankResult.getContents().get(i - 1);
 
             PublishSortLog sortLog = new PublishSortLog();
@@ -169,7 +169,7 @@ public class RecommendService {
             sortLog.setGhId(param.getGhId());
             sortLog.setAccountName(param.getAccountName());
             sortLog.setCrawlerChannelContentId(content.getCrawlerChannelContentId());
-            sortLog.setTitle(content.getCrawlerTitle());
+            sortLog.setTitle(content.getTitle());
             sortLog.setIndex(i);
             sortLog.setIndexAvgCount(accountIndexAvgViewCountService.getAvgReadCount(param.getGhId(), i));
             sortLog.setCategory(content.getCategory());

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

@@ -60,7 +60,7 @@ public class RankV3Strategy implements RankStrategy {
                 score = item.getScore(SimilarityStrategy.class.getSimpleName())
                         + item.getScore(CategoryStrategy.class.getSimpleName())
                         + item.getScore(AccountPreDistributeStrategy.class.getSimpleName())
-                        + item.getScore(ColdStartDecreaseStrategy.class.getSimpleName());
+                        + item.getScore(FlowCtlDecreaseStrategy.class.getSimpleName());
             }
             item.setScore(score);
             return item;

+ 1 - 1
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/score/ScoreService.java

@@ -90,7 +90,7 @@ public class ScoreService implements ApplicationContextAware {
             strategies.add(strategyMap.get(ViewMultiplierStrategy.class.getSimpleName()));
             strategies.add(strategyMap.get(CategoryStrategy.class.getSimpleName()));
             strategies.add(strategyMap.get(AccountPreDistributeStrategy.class.getSimpleName()));
-            strategies.add(strategyMap.get(ColdStartDecreaseStrategy.class.getSimpleName()));
+            strategies.add(strategyMap.get(FlowCtlDecreaseStrategy.class.getSimpleName()));
             strategies.add(strategyMap.get(ViewCountRateStrategy.class.getSimpleName()));
         }
 

+ 34 - 26
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/score/strategy/ColdStartDecreaseStrategy.java → long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/score/strategy/FlowCtlDecreaseStrategy.java

@@ -9,20 +9,19 @@ import com.tzld.longarticle.recommend.server.service.AccountContentPoolConfigSer
 import com.tzld.longarticle.recommend.server.service.score.Score;
 import com.tzld.longarticle.recommend.server.service.score.ScoreParam;
 import com.tzld.longarticle.recommend.server.service.score.ScoreStrategy;
+import com.tzld.longarticle.recommend.server.util.DateUtils;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 import org.springframework.util.CollectionUtils;
 
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.stream.Collectors;
 
 
 @Component
 @Slf4j
-public class ColdStartDecreaseStrategy implements ScoreStrategy {
+public class FlowCtlDecreaseStrategy implements ScoreStrategy {
 
     @Autowired
     private AccountContentPoolConfigService accountContentPoolConfigService;
@@ -30,12 +29,12 @@ public class ColdStartDecreaseStrategy implements ScoreStrategy {
     private PublishSortLogRepository publishSortLogRepository;
 
     // 账号score减少
-    @ApolloJsonValue("${accountColdStartScoreDecreaseConfig:{\"default\":-100}}")
-    private Map<String, Integer> accountColdStartScoreDecreaseMap;
+    @ApolloJsonValue("${accountColdStartScoreDecreaseConfig:{\"default\":{\"3\":-100,\"1\":-100,\"2\":-100}}}")
+    private Map<String, Map<String, Integer>> accountColdStartScoreDecreaseMap;
 
     // 计算阅读均值base
-    @ApolloJsonValue("${totalAvgReadCountBase:{\"default\":100}}")
-    private Map<String, Integer> totalAvgReadCountBaseMap;
+    @ApolloJsonValue("${totalAvgReadCountBase:{\"default\":{\"3\":100,\"1\":100,\"2\":100}}}")
+    private Map<String, Map<String, Integer>> totalAvgReadCountBaseMap;
 
     @Override
     public List<Score> score(ScoreParam param) {
@@ -43,16 +42,12 @@ public class ColdStartDecreaseStrategy implements ScoreStrategy {
         if (CollectionUtils.isEmpty(param.getContents())) {
             return scores;
         }
-        String[] contentPools = accountContentPoolConfigService.getContentPools(param.getAccountName());
-        List<String> crawlerChannelContentIds = param.getContents().stream().map(Content::getCrawlerChannelContentId).collect(Collectors.toList());
-        // 获取历史已发布内容
-        List<PublishSortLog> hisPublishContentList = publishSortLogRepository.findByCrawlerChannelContentIdIn(crawlerChannelContentIds);
-        Map<String, List<PublishSortLog>> hisPublishedContentMap = hisPublishContentList.stream().collect(Collectors.groupingBy(PublishSortLog::getCrawlerChannelContentId));
+        String dateStr = DateUtils.getCurrentDateStr("yyyy-MM-dd");
+        List<String> titles = param.getContents().stream().map(Content::getTitle).collect(Collectors.toList());
+        // 获取今日已发布内容
+        List<PublishSortLog> hisPublishContentList = publishSortLogRepository.findByDateStrAndTitleIn(dateStr, titles);
+        Map<String, List<PublishSortLog>> hisPublishedContentMap = hisPublishContentList.stream().collect(Collectors.groupingBy(PublishSortLog::getTitle));
         for (Content content : param.getContents()) {
-            // 仅判断3-8条 冷启层
-            if (!contentPools[2].equals(content.getContentPoolType())) {
-                continue;
-            }
             Score score = new Score();
             score.setStrategy(this);
             score.setContentId(content.getId());
@@ -69,31 +64,44 @@ public class ColdStartDecreaseStrategy implements ScoreStrategy {
     private Integer getContentScore(String accountName,
                                     Map<String, List<PublishSortLog>> hisPublishedContentMap,
                                     Content content) {
-        Integer weight = getColdStartScoreDecreaseWeight(accountName);
-        Integer totalAvgReadCountBase = getAvgReadCountBase(accountName);
-        if (hisPublishedContentMap.containsKey(content.getCrawlerChannelContentId())) {
-            List<PublishSortLog> publishContents = hisPublishedContentMap.get(content.getCrawlerChannelContentId());
-            double sumViewCount = publishContents.stream().mapToDouble(PublishSortLog::getIndexAvgCount).sum();
+        String[] contentPools = accountContentPoolConfigService.getContentPools(accountName);
+        int index = 3;
+        for (int i = 0; i < contentPools.length; i++) {
+            if (contentPools[i].equals(content.getContentPoolType())) {
+                index = i + 1;
+                break;
+            }
+        }
+        Map<String, Integer> indexWeight = getColdStartScoreDecreaseWeight(accountName);
+        Map<String, Integer> indexTotalAvgReadCountBase = getAvgReadCountBase(accountName);
+        if (Objects.isNull(indexWeight) || Objects.isNull(indexTotalAvgReadCountBase)) {
+            return 0;
+        }
+        if (hisPublishedContentMap.containsKey(content.getTitle())) {
+            List<PublishSortLog> publishContents = hisPublishedContentMap.get(content.getTitle());
+            int finalIndex = index;
+            double sumViewCount = publishContents.stream().filter(o -> (o.getIndex() / 3) == (finalIndex / 3)).mapToDouble(PublishSortLog::getIndexAvgCount).sum();
             int hisViewCountSum = content.getHisPublishArticleList().stream().filter(ContentHisPublishArticle::isInnerAccount)
                     .mapToInt(ContentHisPublishArticle::getAvgViewCount).sum();
-            if ((sumViewCount + hisViewCountSum) > totalAvgReadCountBase) {
-                return weight;
+            if ((sumViewCount + hisViewCountSum) > indexTotalAvgReadCountBase.get(String.valueOf(index))) {
+                return indexWeight.get(String.valueOf(index));
             }
         }
         return 0;
     }
 
-    public Integer getColdStartScoreDecreaseWeight(String accountName) {
+    public Map<String, Integer> getColdStartScoreDecreaseWeight(String accountName) {
         if (accountColdStartScoreDecreaseMap.containsKey(accountName)) {
             return accountColdStartScoreDecreaseMap.get(accountName);
         }
         return accountColdStartScoreDecreaseMap.get("default");
     }
 
-    public Integer getAvgReadCountBase(String accountName) {
+    public Map<String, Integer> getAvgReadCountBase(String accountName) {
         if (totalAvgReadCountBaseMap.containsKey(accountName)) {
             return totalAvgReadCountBaseMap.get(accountName);
         }
         return totalAvgReadCountBaseMap.get("default");
     }
+
 }