Explorar o código

Merge branch 'wyp/0926-score-list' of Server/long-article-recommend into master

fengzhoutian hai 9 meses
pai
achega
eed8caecc9

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

@@ -37,8 +37,12 @@ public class NLPRemoteService {
     private String chatId;
     @ApolloJsonValue("${score.interest.type:{}}")
     private Map<String, String> accountScoreInterestTypeMap;
+    @ApolloJsonValue("${score.sim.type:{}}")
+    private Map<String, String> accountScoreSimTypeMap;
     @ApolloJsonValue("${score.viewCount.filter:{}}")
     private Map<String, Integer> accountScoreViewCountFilterMap;
+    @ApolloJsonValue("${score.rate:{}}")
+    private Map<String, Double> accountScoreRaterMap;
     @ApolloJsonValue("${score.min.time:{}}")
     private Map<String, Long> accountScoreMinTimeMap;
 
@@ -55,8 +59,8 @@ public class NLPRemoteService {
         bodyParam.put("account_nickname_list", Collections.singletonList(accountName));
         bodyParam.put("text_list", titleList);
         bodyParam.put("interest_type", accountScoreInterestTypeMap.getOrDefault(accountName, "avg"));
-        bodyParam.put("sim_type", "mean");
-        bodyParam.put("rate", 0.1);
+        bodyParam.put("sim_type", accountScoreSimTypeMap.getOrDefault(accountName, "mean"));
+        bodyParam.put("rate", accountScoreRaterMap.getOrDefault(accountName, 0.1));
         if (accountScoreViewCountFilterMap.containsKey(accountName)) {
             bodyParam.put("view_count_filter", accountScoreViewCountFilterMap.get(accountName));
         }

+ 25 - 16
long-article-recommend-service/src/test/java/com/tzld/longarticle/recommend/server/RecommendTest.java

@@ -274,9 +274,9 @@ public class RecommendTest {
         sortLogList.sort(Comparator.comparing(PublishSortLog::getGhId).thenComparing(PublishSortLog::getDateStr));
         List<Article> articleList = articleRepository.getByGhIdInAndUpdateTimeGreaterThanAndTypeEquals(ghIds, 1725638400L, "9");
         articleList = articleList.stream().filter(o -> o.getItemIndex() == 1).collect(Collectors.toList());
-        Map<String, Article> articleMap = articleList.stream().collect(Collectors.toMap(
+        Map<String, Map<String, Article>> articleMap = articleList.stream().collect(Collectors.groupingBy(Article::getGhId, Collectors.toMap(
                 o -> DateUtils.timestampToYMDStr(o.getUpdateTime(),"yyyyMMdd"), o -> o,
-                (existing, replacement) -> replacement));
+                (existing, replacement) -> replacement)));
         List<AccountAvgInfo> accountAvgInfoList = accountAvgInfoRepository.getAllByGhIdIn(new HashSet<>(ghIds));
         Map<String, Map<String, AccountAvgInfo>> accountAvgInfoMap = accountAvgInfoList.stream()
                 .filter(o -> Objects.equals(o.getPosition(), "1")).collect(Collectors.groupingBy(AccountAvgInfo::getGhId,
@@ -328,7 +328,17 @@ public class RecommendTest {
         titleCell.setCellValue("阅读均值倍数");
 
         // 填充数据
+        String title = "";
         for (PublishSortLog publishSortLog : sortLogList) {
+            Map<String, Article> dateArticleMap = articleMap.get(publishSortLog.getGhId());
+            Article article = dateArticleMap.get(publishSortLog.getDateStr());
+            if (Objects.isNull(article) || !publishSortLog.getTitle().equals(article.getTitle())) {
+                continue;
+            }
+            if (publishSortLog.getTitle().equals(title)) {
+                continue;
+            }
+            title = publishSortLog.getTitle();
             rowNum++;
             Row row = sheet.createRow(rowNum);
             Cell cell = row.createCell(0);
@@ -366,22 +376,21 @@ public class RecommendTest {
             cell.setCellValue(String.format("%.3f", Optional.of(scoreMap.getDoubleValue("ViewCountRateStrategy")).orElse(0.0)));
             cell = row.createCell(16);
             cell.setCellValue(String.format("%.3f", Optional.of(scoreMap.getDoubleValue("HisFissionDeWeightAvgReadSumRateStrategy")).orElse(0.0)));
-            Article article = articleMap.get(publishSortLog.getDateStr());
-            if (Objects.nonNull(article)) {
-                cell = row.createCell(17);
-                cell.setCellValue(article.getShowViewCount());
-                cell = row.createCell(18);
-                Map<String, AccountAvgInfo> map = accountAvgInfoMap.get(article.getGhId());
-                if (Objects.nonNull(map)) {
-                    AccountAvgInfo accountAvgInfo = map.get(DateUtils.timestampToYMDStr(article.getUpdateTime(), "yyyy-MM-dd"));
-                    if (Objects.nonNull(accountAvgInfo)) {
-                        cell.setCellValue(accountAvgInfo.getReadAvg());
-                        cell = row.createCell(19);
-                        cell.setCellValue(String.format("%.3f", article.getShowViewCount() / (double) accountAvgInfo.getReadAvg()));
-                    }
+            cell = row.createCell(17);
+            cell.setCellValue(article.getShowViewCount());
+            cell = row.createCell(18);
+            Map<String, AccountAvgInfo> map = accountAvgInfoMap.get(article.getGhId());
+            if (Objects.nonNull(map)) {
+                List<String> avgMapDateList = new ArrayList<>(map.keySet());
+                String publishDate = DateUtils.findNearestDate(avgMapDateList,
+                        DateUtils.timestampToYMDStr(article.getUpdateTime(), "yyyy-MM-dd"), "yyyy-MM-dd");
+                AccountAvgInfo accountAvgInfo = map.get(publishDate);
+                if (Objects.nonNull(accountAvgInfo)) {
+                    cell.setCellValue(accountAvgInfo.getReadAvg());
+                    cell = row.createCell(19);
+                    cell.setCellValue(String.format("%.3f", article.getShowViewCount() / (double) accountAvgInfo.getReadAvg()));
                 }
             }
-
         }
 
         try (FileOutputStream outputStream = new FileOutputStream("/Users/wangyunpeng/Downloads/example.xlsx")) {