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

优化推荐系数

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