Commit 41834a1e authored by 刘基明's avatar 刘基明

优化推荐系数

parent a546391f
......@@ -50,11 +50,23 @@ public class ThemeAnalysDO {
private Double userWeight = 0.0;
public Double getRank() {
double viewRatio = 0.1;
double forwardRatio = 3;
double commentRatio = 2;
double likeRation = 1;
double collectRatio = 3;
double userWeightRatio = 0.8;
double initialWeight = 1.0;
double timeRation = 0.3;
// 质量=帖子质量+用户质量
double w = (double) (viewCount * 0.1 + forwardCount * 3 + commentCount * 2 + likeCount * 1 + collectCount * 3) + userWeight;
double i = 1; // 初始权重
double w = viewCount * viewRatio + forwardCount * forwardRatio + commentCount * commentRatio
+ likeCount * likeRation + collectCount * collectRatio
+ Math.pow(userWeight, userWeightRatio);
double i = initialWeight; // 初始权重
double t = Double.valueOf(minuteTillNow) / 60;
double g = 0.1; // 时间系数
double g = timeRation; // 时间系数
return (w + i) / Math.pow(t + 1, g);
}
......
......@@ -40,10 +40,17 @@ public class ConJobManager {
/**
* 定时统计主题、话题排行
*/
@Scheduled(cron = "0 */1 * * * ?")
@Scheduled(cron = "*/30 * * * * ?")
public void themeRank() {
rankService.rankThemes();
rankService.rankTopics();
}
/**
* 定时统计主题、话题排行
*/
@Scheduled(cron = "*/5 * * * * ?")
public void getThemeNewest() {
recommendService.refreshNewestThemes();
}
}
......@@ -129,26 +129,28 @@ public class RecommendService {
int newTimes = newRatio;
int recTimes = pythonRatio;
String id;
while (hotTimes > 0 && hotThemeIds.size() > hotIdx) {
id = hotThemeIds.get(hotIdx);
while (newTimes > 0 && newThemeIds.size() > newIdx) {
id = newThemeIds.get(newIdx);
if (!set.contains(id)) {
result.add(id);
set.add(id);
}
hotIdx++;
hotTimes--;
newIdx++;
newTimes--;
}
while (newTimes > 0 && newThemeIds.size() > newIdx) {
id = newThemeIds.get(newIdx);
while (hotTimes > 0 && hotThemeIds.size() > hotIdx) {
id = hotThemeIds.get(hotIdx);
if (!set.contains(id)) {
result.add(id);
set.add(id);
}
newIdx++;
newTimes--;
hotIdx++;
hotTimes--;
}
while (recTimes > 0 && recThemeIds.size() > recIdx) {
id = recThemeIds.get(recIdx);
if (!set.contains(id)) {
......@@ -170,15 +172,14 @@ public class RecommendService {
int round = 0;
while (true) {
int hotStart = round * 6;
int newestStart = round * 3;
int hotStart = round * 3;
int newestStart = round * 6;
int recmdStart = round;
if (hotStart >= hotIds.size() && newestStart >= newestIds.size() && recmdStart >= recmdIds.size()) {
break;
}
retList.addAll(BizUtils.subList(hotIds, hotStart, hotStart + 6));
retList.addAll(BizUtils.subList(newestIds, newestStart, newestStart + 3));
retList.addAll(BizUtils.subList(hotIds, hotStart, hotStart + 6));
retList.addAll(BizUtils.subList(recmdIds, recmdStart, recmdStart + 1));
round++;
......
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