Commit ca40b021 authored by 刘基明's avatar 刘基明

排序落库

parent 0fa259a9
......@@ -49,14 +49,17 @@ public class ThemeAnalysDO {
@ApiModelProperty(value = "用户质量")
private Double userWeight = 0.0;
private Double score;
public Double calcScore() {
//质量=帖子质量+用户质量
// 质量=帖子质量+用户质量
double w = (double) (viewCount * 0.1 + forwardCount * 3 + commentCount * 2 + likeCount * 1 + collectCount * 3) + userWeight;
double i = 1;//初试权重
double t = Double.valueOf(minuteTillNow) / 60;
double g = 0.1;//时间系数
double rank = (w + i) / Math.pow(t + 1, g);
this.score = score;
return rank;
}
......
......@@ -36,21 +36,25 @@ public class TopicRankQo {
private Integer viewCntAdjust;
@ApiModelProperty(value = "话题下的帖子权重")
private Integer themeWeight;
private Double themeWeight;
private Integer hoursTillNow;
private Double score;
/**
* 热度计算算法
*
* @return
*/
public Integer getRank() {
public Double getRank() {
double g = 0.3;//时间系数
//顶置话题
if (isTop > 0) {
return Integer.MAX_VALUE;
return Double.MAX_VALUE;
}
return (int)((disscussCount * 3 + viewCount)/ Math.pow(hoursTillNow + 1, g)) + themeWeight;
Double socre = ((disscussCount * 3 + viewCount) / Math.pow(hoursTillNow + 1, g)) + themeWeight;
this.score = socre;
return socre;
}
}
......@@ -102,7 +102,7 @@ public class RankService {
.sorted(Map.Entry.comparingByValue(Comparator.reverseOrder()))
.map(e -> e.getKey()).collect(Collectors.toList());
//落库
rankLogService.logThemeRank(hotestThemes,start, TimeUtils.calMillisTillNow(start));
rankLogService.logThemeRank(hotestThemes, start, TimeUtils.calMillisTillNow(start));
}
......@@ -125,7 +125,7 @@ public class RankService {
if (CollectionUtils.isEmpty(themeIds)) {
topic.setViewCount(topicViewMap.getOrDefault(topic.getTopicId(), 0));
topic.setDisscussCount(0);
topic.setThemeWeight(0);
topic.setThemeWeight(0.0);
topic.setFormatViewCount(BizUtils.formatCountNumber(topic.getViewCount()));
topic.setFormatDisscussCount(BizUtils.formatCountNumber(topic.getDisscussCount()));
continue;
......@@ -141,12 +141,12 @@ public class RankService {
double themeSum = getHotestThemes().stream().filter(o -> topic.getTopicId().equals(o.getTopicId()))
.mapToDouble(ThemeAnalysDO::calcScore)
.sum();
topic.setThemeWeight((int) themeSum);
topic.setThemeWeight(themeSum);
//格式化浏览量、讨论量
topic.setFormatViewCount(BizUtils.formatCountNumber(topic.getViewCount()));
topic.setFormatDisscussCount(BizUtils.formatCountNumber(topic.getDisscussCount()));
}
Map<TopicRankQo, Integer> map = topicRankQos.stream().collect(Collectors.toMap(o -> o, TopicRankQo::getRank));
Map<TopicRankQo, Double> map = topicRankQos.stream().collect(Collectors.toMap(o -> o, TopicRankQo::getRank));
List<TopicRankQo> rankList = map.entrySet().stream()
.sorted(Map.Entry.comparingByValue(Comparator.reverseOrder()))
.map(Map.Entry::getKey)
......@@ -156,7 +156,7 @@ public class RankService {
this.rankTopicListTop4 = rankList.stream().limit(4).collect(Collectors.toList());
//落库
rankLogService.logTopicRank(rankList,start, TimeUtils.calMillisTillNow(start));
rankLogService.logTopicRank(rankList, start, TimeUtils.calMillisTillNow(start));
return;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment