Created
April 20, 2016 14:48
-
-
Save hellokaton/4788a970f80a9d18c4bca1cb1e07a3b6 to your computer and use it in GitHub Desktop.
Java排名算法
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import blade.kit.DateKit; | |
public class TopicRank { | |
/** | |
* 计算帖子权重 | |
* @param stars 点赞数 | |
* @param comments 评论数 | |
* @param sink 下沉数 | |
* @param create 创建时间 | |
* @return 返回帖子得分 | |
*/ | |
public static double getScore(int stars, int comments, int sink, long create){ | |
int score = Math.max(stars - 1, 0) + comments - sink; | |
// 投票方向 | |
int sign = (score == 0) ? 0 : (score > 0 ? 1 : -1); | |
// 帖子争议度 | |
double order = Math.log10(Math.max(Math.abs(score), 1)); | |
// 1459440000是项目创建时间 | |
double seconds = create - 1459440000; | |
return Double.parseDouble(String.format("%.2f",order + sign * seconds / 45000)); | |
} | |
public static void main(String[] args) { | |
System.out.println(getScore(0, 0, 0, DateKit.getUnixTimeByDate(DateKit.dateFormat("201604192000","yyyyMMddHHmm")))); | |
System.out.println(getScore(0, 0, -1, DateKit.getUnixTimeByDate(DateKit.dateFormat("201604202000","yyyyMMddHHmm")))); | |
System.out.println(getScore(10, 2, 0, DateKit.getUnixTimeByDate(DateKit.dateFormat("201604202000","yyyyMMddHHmm")))); | |
System.out.println(getScore(0, 2, 0, DateKit.getUnixTimeByDate(DateKit.dateFormat("201604202000","yyyyMMddHHmm")))); | |
System.out.println(getScore(20, 0, 0, DateKit.getUnixTimeByDate(DateKit.dateFormat("201604202000","yyyyMMddHHmm")))); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
这个下沉数是什么意思?