浏览代码

修复次条

yangxiaohui 8 月之前
父节点
当前提交
8874da3a78

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

@@ -36,9 +36,13 @@ public class ViewCountRateStrategy implements ScoreStrategy {
         String[] contentPools = accountContentPoolConfigService.getContentPools(param.getAccountName());
         List<AccountAvgInfo> avgInfoList = accountAvgInfoRepository.getAllByGhIdEqualsAndStatusEquals(param.getGhId(), 1);
         double avgViewCountFirst = accountIndexAvgViewCountService.getAvgReadCountByDB(avgInfoList, param.getGhId(), 1);
-        // 缺省头条均值设置为2w
+        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++) {
@@ -52,19 +56,39 @@ public class ViewCountRateStrategy implements ScoreStrategy {
                 double avgViewCountSumFirst = 0D;
                 double showViewCountSumSecond = 0D;
                 double avgViewCountSumSecond = 0D;
+                double maxAvgViewCount = 0D;
                 for (ContentHisPublishArticle hisItem : content.getHisPublishArticleList()) {
                     if (hisItem.isInnerAccount() && Objects.nonNull(hisItem.getViewCount())
                             && hisItem.getViewCount() > 0 && Objects.nonNull(hisItem.getAvgViewCount())
                             && hisItem.getAvgViewCount() > 0) {
+                        maxAvgViewCount = Math.max(maxAvgViewCount, hisItem.getAvgViewCount());
                         if (hisItem.getItemIndex() == 1) {
                             showViewCountSumFirst += hisItem.getViewCount();
                             avgViewCountSumFirst += hisItem.getAvgViewCount();
                         } else if (hisItem.getItemIndex() == 2) {
-                            showViewCountSumSecond += hisItem.getViewCount();
-                            avgViewCountSumSecond += hisItem.getAvgViewCount();
+                            if (Objects.nonNull(hisItem.getFirstViewCount()) &&  hisItem.getFirstViewCount() > 0 &&
+                                    Objects.nonNull(hisItem.getFirstViewCountRate()) && hisItem.getFirstViewCountRate() > 0) {
+                                showViewCountSumSecond += hisItem.getViewCount();
+                                if (hisItem.getFirstViewCountRate() > 1) {
+                                    // 对于头条均值倍数大于1的情况,次条均值线性增加,用于debias;
+                                    // TODO: 对于小于1的情况,是否要减去?
+                                    avgViewCountSumSecond += hisItem.getAvgViewCount() * hisItem.getFirstViewCountRate();
+                                } else {
+                                    avgViewCountSumSecond += hisItem.getAvgViewCount();
+                                }
+                            }
                         } else {
-                            showViewCountSum += hisItem.getViewCount();
-                            avgViewCountSum += hisItem.getAvgViewCount();
+                            if (Objects.nonNull(hisItem.getFirstViewCount()) && hisItem.getFirstViewCount() > 0
+                                    && Objects.nonNull(hisItem.getFirstViewCountRate()) && hisItem.getFirstViewCountRate() > 0) {
+                                showViewCountSum += hisItem.getViewCount();
+                                if (hisItem.getFirstViewCountRate() > 1) {
+                                    // 对于头条均值倍数大于1的情况,次条均值线性增加,用于debias;
+                                    // TODO: 对于小于1的情况,是否要减去?
+                                    avgViewCountSum += hisItem.getAvgViewCount() * hisItem.getFirstViewCountRate();
+                                } else {
+                                    avgViewCountSum += hisItem.getAvgViewCount();
+                                }
+                            }
                         }
                     }
                 }
@@ -74,23 +98,26 @@ public class ViewCountRateStrategy implements ScoreStrategy {
                 if (showViewCountSumFirst > 0) {
                     showViewCountSum = showViewCountSumFirst;
                     avgViewCountSum = avgViewCountSumFirst;
-                    avgViewCountPos = avgViewCountFirst;
                 } else if (showViewCountSumSecond > 0) {
                     showViewCountSum = showViewCountSumSecond;
                     avgViewCountSum = avgViewCountSumSecond;
-                    avgViewCountPos = avgViewCountFirst;
                     // 如果是大号头条,则降权
-                    if (avgViewCountFirst >= 2000 && i == 0) {
-                        minRate = 1.001D;
-                    }
+//                    if (avgViewCountFirst >= 2000 && i == 0) {
+//                        minRate = 1.001D;
+//                    }
                 }
+                // 均值倍数
                 if (avgViewCountSum > 0) {
                     viewCountRate = showViewCountSum / avgViewCountSum;
                 }
+                // 置信度
                 double viewCountRateW = MathUtils.sigmoid(avgViewCountSum, 0.0005, avgViewCountPos);
                 double viewCountRateScore = 0;
+
                 if (viewCountRate > 0) {
-                    viewCountRateScore = (Math.min(viewCountRate, minRate) - 1D) * viewCountRateW;
+                    // 最终分数 = 置信度 * 均值倍数
+                    viewCountRateScore = viewCountRateW * viewCountRate;
+//                    viewCountRateScore = (Math.min(viewCountRate, minRate) - 1D) * viewCountRateW;
                 }
                 Score score = new Score();
                 score.setStrategy(this);