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

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

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