luojunhui 2 месяцев назад
Родитель
Сommit
6c95831c45

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

@@ -26,6 +26,11 @@ import org.springframework.beans.factory.InitializingBean;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
@@ -114,7 +119,7 @@ public class RankService implements InitializingBean {
         if (CollectionUtil.isEmpty(contentList)) {
             return;
         }
-        contentList = contentList.subList(0, Math.min(contentList.size(), 200));
+        contentList = contentList.subList(0, Math.min(contentList.size(), 500));
         for (Content content : contentList) {
             JSONObject obj = new JSONObject();
             obj.put("id", content.getId());
@@ -123,7 +128,32 @@ public class RankService implements InitializingBean {
             obj.put("scoreMap", content.getScoreMap());
             jsonArray.add(obj);
         }
-        log.info("{} 账号名称 {} {}评分结果 {}", strategy, accountName, position, JSONObject.toJSONString(jsonArray));
+//        log.info("{} 账号名称 {} {}评分结果 {}", strategy, accountName, position, JSONObject.toJSONString(jsonArray));
+//        String result = String.format(
+//                "%s 账号名称 %s %s 评分结果 %s%n",
+//                strategy,
+//                accountName,
+//                position,
+//                JSONObject.toJSONString(jsonArray)
+//        );
+        System.out.println(strategy);
+        if ("头条".equals(position)){
+            writeToFile(jsonArray);
+        }
+    }
+
+    private static void writeToFile(JSONArray jsonArray) {
+        try {
+            // 文件路径可按需调整
+            Path path = Paths.get("Rank_V19_2.json");
+
+            Files.write(
+                    path,
+                    JSONObject.toJSONString(jsonArray, true).getBytes(StandardCharsets.UTF_8)
+            );
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
     }
 
     public static void commonAddSecondContent(RankParam param, List<Content> result,

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

@@ -143,7 +143,17 @@ public class ViewCountRateStrategy implements ScoreStrategy {
                     viewCountRate = showViewCountSum / readAvgCiUpperSum;
                 }
                 // 置信度
-                double viewCountRateW = MathUtils.sigmoid(readAvgCiUpperSum, 0.002, avgViewCountPos);
+//                double viewCountRateW = MathUtils.sigmoid(readAvgCiUpperSum, 0.002, avgViewCountPos);
+                double viewCountRateW = MathUtils.sigmoid(readAvgCiUpperSum, 0.002, 200);
+                if (i == 0){
+                    System.out.printf(
+                            "指标统计 | readAvgCiUpperSum: %s; viewCountRateW: %s; ori_view_score: %s; avg_view_pos: %s%n",
+                            readAvgCiUpperSum,
+                            viewCountRateW,
+                            viewCountRate,
+                            avgViewCountPos
+                    );
+                }
                 double viewCountRateScore = 0;
 
                 if (viewCountRate > 0) {

+ 6 - 6
long-article-recommend-service/src/main/resources/application-dev.yml

@@ -1,5 +1,5 @@
 server:
-  port: 80
+  port: 8080
 
 spring:
   redis:
@@ -15,13 +15,13 @@ spring:
         min-idle: 0
   datasource:
     crawler:
-#      jdbc-url: jdbc:mysql://rm-bp1159bu17li9hi94.mysql.rds.aliyuncs.com:3306/piaoquan-crawler?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useSSL=false
-#      username: crawler
-#      password: crawler123456@
-      # 测试库
-      jdbc-url: jdbc:mysql://rm-bp1k5853td1r25g3n690.mysql.rds.aliyuncs.com:3306/piaoquan-crawler?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useSSL=false
+      jdbc-url: jdbc:mysql://rm-bp1159bu17li9hi94.mysql.rds.aliyuncs.com:3306/piaoquan-crawler?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useSSL=false
       username: crawler
       password: crawler123456@
+#       测试库
+#      jdbc-url: jdbc:mysql://rm-bp1k5853td1r25g3n690.mysql.rds.aliyuncs.com:3306/piaoquan-crawler?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useSSL=false
+#      username: crawler
+#      password: crawler123456@
       driver-class-name: com.mysql.jdbc.Driver
       hikari:
         connection-timeout: 30000