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

热度算法优化-加大时间因子

parent da281864
...@@ -42,7 +42,7 @@ public class ThemeAnalysDO { ...@@ -42,7 +42,7 @@ public class ThemeAnalysDO {
private Integer viewCount; private Integer viewCount;
@ApiModelProperty(value = "距今时间") @ApiModelProperty(value = "距今时间")
private Long hoursTillNow; private Long minutesTillNow;
@ApiModelProperty(value = "用户质量") @ApiModelProperty(value = "用户质量")
private Double userWeight = 0.0; private Double userWeight = 0.0;
......
...@@ -38,7 +38,7 @@ public class TopicRankQo { ...@@ -38,7 +38,7 @@ public class TopicRankQo {
@ApiModelProperty(value = "话题下的帖子权重") @ApiModelProperty(value = "话题下的帖子权重")
private Double themeWeight; private Double themeWeight;
private Integer hoursTillNow; private Integer minutesTillNow;
private Double score; private Double score;
} }
...@@ -260,7 +260,7 @@ public class RankService { ...@@ -260,7 +260,7 @@ public class RankService {
+ theme.getLikeCount() * likeRaten + theme.getLikeCount() * likeRaten
+ theme.getCollectCount() * collectRate + theme.getCollectCount() * collectRate
+ Math.pow(theme.getUserWeight(), userWeightRate); + Math.pow(theme.getUserWeight(), userWeightRate);
double score = (w + initialWeight) / Math.pow(theme.getHoursTillNow() + 1, timeRate); double score = (w + initialWeight) / Math.pow(theme.getMinutesTillNow() + 1, timeRate);
theme.setScore(score); theme.setScore(score);
} }
...@@ -271,7 +271,7 @@ public class RankService { ...@@ -271,7 +271,7 @@ public class RankService {
topic.setScore(Double.MAX_VALUE); topic.setScore(Double.MAX_VALUE);
} }
Double socre = ((topic.getDisscussCount() * topicDiscussRate + topic.getViewCount() * topicViewRate) Double socre = ((topic.getDisscussCount() * topicDiscussRate + topic.getViewCount() * topicViewRate)
/ Math.pow(topic.getHoursTillNow() + 1, topicTimeRate)) / Math.pow(topic.getMinutesTillNow() + 1, topicTimeRate))
+ topic.getThemeWeight() * topicThemeRate; + topic.getThemeWeight() * topicThemeRate;
topic.setScore(socre); topic.setScore(socre);
} }
......
...@@ -47,7 +47,7 @@ public class ConvertUtil { ...@@ -47,7 +47,7 @@ public class ConvertUtil {
} }
ThemeAnalysDO themeAnalysDO = new ThemeAnalysDO(); ThemeAnalysDO themeAnalysDO = new ThemeAnalysDO();
BeanUtils.copyProperties(themeEntity, themeAnalysDO); BeanUtils.copyProperties(themeEntity, themeAnalysDO);
themeAnalysDO.setHoursTillNow(TimeUtils.calHoursTillNow(themeEntity.getCreateTime())); themeAnalysDO.setMinutesTillNow(TimeUtils.calMinuteTillNow(themeEntity.getCreateTime()));
return themeAnalysDO; return themeAnalysDO;
} }
...@@ -64,7 +64,8 @@ public class ConvertUtil { ...@@ -64,7 +64,8 @@ public class ConvertUtil {
BeanUtils.copyProperties(entity, qo); BeanUtils.copyProperties(entity, qo);
// 抽取文本内容 // 抽取文本内容
List<ThemeContentQo> themeContentQos = JsonUtil.toBean(entity.getContent(), new TypeReference<List<ThemeContentQo>>() {}); List<ThemeContentQo> themeContentQos = JsonUtil.toBean(entity.getContent(), new TypeReference<List<ThemeContentQo>>() {
});
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
themeContentQos.stream().filter(q -> RelTypeEnum.TEXT.type.equals(q.getType())).forEach(q -> { themeContentQos.stream().filter(q -> RelTypeEnum.TEXT.type.equals(q.getType())).forEach(q -> {
sb.append(q.getValue()); sb.append(q.getValue());
...@@ -88,15 +89,15 @@ public class ConvertUtil { ...@@ -88,15 +89,15 @@ public class ConvertUtil {
TopicRankQo topicRankQo = new TopicRankQo(); TopicRankQo topicRankQo = new TopicRankQo();
BeanUtils.copyProperties(topicEntity, topicRankQo); BeanUtils.copyProperties(topicEntity, topicRankQo);
//2小时内发帖,添加新话题标签 //2小时内发帖,添加新话题标签
if(TimeUtils.calMinuteTillNow(topicEntity.getCreateTime())<120){ if (TimeUtils.calMinuteTillNow(topicEntity.getCreateTime()) < 120) {
topicRankQo.setType(TopicStatusEnum.NEWEST.getCode()); topicRankQo.setType(TopicStatusEnum.NEWEST.getCode());
} }
topicRankQo.setHoursTillNow((int) TimeUtils.calHoursTillNow(topicEntity.getCreateTime())); topicRankQo.setMinutesTillNow((int) TimeUtils.calMinuteTillNow(topicEntity.getCreateTime()));
return topicRankQo; return topicRankQo;
} }
public static List<TopicRankQo> topicEntityToHotQos(List<TopicEntity> topicEntities) { public static List<TopicRankQo> topicEntityToHotQos(List<TopicEntity> topicEntities) {
if (topicEntities==null){ if (topicEntities == null) {
return Collections.emptyList(); return Collections.emptyList();
} }
return topicEntities.stream().map(ConvertUtil::topicEntityToHotQo).collect(Collectors.toList()); return topicEntities.stream().map(ConvertUtil::topicEntityToHotQo).collect(Collectors.toList());
...@@ -153,13 +154,13 @@ public class ConvertUtil { ...@@ -153,13 +154,13 @@ public class ConvertUtil {
.build()); .build());
} }
} else if ((content.getType().equals(RelTypeEnum.SINGLE_IMG.type))) { } else if ((content.getType().equals(RelTypeEnum.SINGLE_IMG.type))) {
if (StringUtils.isEmpty(content.getValue())){ if (StringUtils.isEmpty(content.getValue())) {
list.add(ThemeAttachmentEntity.builder() list.add(ThemeAttachmentEntity.builder()
.attachType(Integer.valueOf(content.getType())) .attachType(Integer.valueOf(content.getType()))
.attachId(content.getValue()) .attachId(content.getValue())
.themeId(themeId) .themeId(themeId)
.build()); .build());
}else { } else {
List<ImagesDTO> imgList = content.getImgList(); List<ImagesDTO> imgList = content.getImgList();
for (ImagesDTO imagesDTO : imgList) { for (ImagesDTO imagesDTO : imgList) {
list.add(ThemeAttachmentEntity.builder() list.add(ThemeAttachmentEntity.builder()
...@@ -211,9 +212,9 @@ public class ConvertUtil { ...@@ -211,9 +212,9 @@ public class ConvertUtil {
.build(); .build();
} }
public static FileUploadResp fileRecordEntity2Resp(FileRecordEntity entity){ public static FileUploadResp fileRecordEntity2Resp(FileRecordEntity entity) {
FileUploadResp resp = new FileUploadResp(); FileUploadResp resp = new FileUploadResp();
BeanUtils.copyProperties(entity,resp); BeanUtils.copyProperties(entity, resp);
String extInfo = entity.getExtInfo(); String extInfo = entity.getExtInfo();
if (!StringUtils.isEmpty(extInfo)) { if (!StringUtils.isEmpty(extInfo)) {
Map<String, Object> extMap = JsonUtil.toMap(extInfo); Map<String, Object> extMap = JsonUtil.toMap(extInfo);
...@@ -224,5 +225,4 @@ public class ConvertUtil { ...@@ -224,5 +225,4 @@ public class ConvertUtil {
} }
} }
...@@ -60,7 +60,7 @@ public class TimeUtils { ...@@ -60,7 +60,7 @@ public class TimeUtils {
return between.toDays(); return between.toDays();
} }
//计算迄今 //计算迄今小时
public static long calHoursTillNow(LocalDateTime start) { public static long calHoursTillNow(LocalDateTime start) {
Duration between = Duration.between(start, LocalDateTime.now()); Duration between = Duration.between(start, LocalDateTime.now());
return between.toHours(); return between.toHours();
......
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