Bladeren bron

2025-04-15 冷启动晋级优化

luojunhui 1 week geleden
bovenliggende
commit
fb94fa9c8a

+ 21 - 8
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/ArticlePromotionService.java

@@ -61,6 +61,7 @@ import java.util.stream.Stream;
 @Slf4j
 public class ArticlePromotionService {
 
+    private final List<String> contentPoolType = Arrays.asList("autoArticlePoolLevel1", "autoArticlePoolLevel3", "autoArticlePoolLevel4");
     @Autowired
     LongArticleBaseMapper longArticleBaseMapper;
     @Autowired
@@ -91,13 +92,12 @@ public class ArticlePromotionService {
     AigcBaseMapper aigcBaseMapper;
     @Autowired
     VideoTitleReWriteRepository videoTitleReWriteRepository;
-
     @ApolloJsonValue("${articlePromotionProduceConfig:{}}")
     private Map<String, Map<String, Map<String, String>>> produceConfig;
     @Value("${topProducePlanId:}")
     private String topProducePlanId;
 
-    public static boolean abZTestCorrected(double readAvg, int fansA , double viewCount, int fansB, double confidence) {
+    public static boolean abZTestCorrected(double readAvg, int fansA, double viewCount, int fansB, double confidence) {
         // 检查基础参数合法性
         if (fansA <= 0 || fansB <= 0) {
             throw new IllegalArgumentException("样本量必须大于零");
@@ -131,8 +131,6 @@ public class ArticlePromotionService {
         // 判断是否拒绝原假设
         return ciLow > 0;
     }
-    
-    private final List<String> contentPoolType = Arrays.asList("autoArticlePoolLevel1", "autoArticlePoolLevel3", "autoArticlePoolLevel4");
 
     public void articlePromotion(String pos, String way, String accountNickName, String tag,
                                  Integer viewCountFilter, Double viewCountRateFilter, List<Integer> positionFilter) {
@@ -150,14 +148,29 @@ public class ArticlePromotionService {
 
             // 使用显著性检验晋级
             List<DatastatSortStrategy> listStrategy2 = list.stream()
-                    .filter(o -> abZTestCorrected(
-                            o.getAvgViewCount() * 1.1 * 30, o.getFans() * 30, o.getViewCount(), o.getFans(), 0.95))
+                    .filter(o -> {
+                        try {
+                            return abZTestCorrected(
+                                    o.getAvgViewCount() * 1.1 * 30,
+                                    o.getFans() * 30,
+                                    o.getViewCount(),
+                                    o.getFans(),
+                                    0.95
+                            );
+                        } catch (IllegalArgumentException e) {
+                            // 记录异常日志(包含对象标识)
+                            log.error("显著性检验,传入数值错误: {}", e.getMessage());
+                            return false; // 异常时过滤掉该对象
+                        } catch (Exception e) {
+                            // 捕获其他未预期异常
+                            log.error("显著性检验, 其他异常: {}", e.getMessage());
+                            return false;
+                        }
+                    })
                     .collect(Collectors.toList());
 
             // merge 两个 list, 通过wx_sn去重
             // 临时用 Map 存储去重(保留第一个出现的元素)
-            // 冲突时保留已有元素
-            // 从 Map 的 values 中提取结果
             list = Stream.concat(listStrategy1.stream(), listStrategy2.stream())
                     // 使用标题作为去重标识
                     .collect(Collectors.collectingAndThen(