Skip to content

Commit

Permalink
新增对评分因子处理的工具类,目前的例子包括日期和金额
Browse files Browse the repository at this point in the history
  • Loading branch information
qindongliang committed May 18, 2016
1 parent fe242e9 commit 15ef97f
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions src/main/java/com/easy/custom/tools/ScoreTools.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.easy.custom.tools;

import org.joda.time.DateTime;
import org.joda.time.Years;

/**
* Created by qindongliang on 2016/5/17.
*/
public class ScoreTools {


/***
*
* @param time 传入当前计算的日期毫秒数
* @param maxYears 设置加权因子的最大年份上限
* @return 该日期的一个动态加权评分
*/
public static float getYearScore(long time,int maxYears){
if(time==0){//没有日期的数据,不做加权操作
return 1;
}
DateTime now=new DateTime();
DateTime varTime=new DateTime(time);
int year= Years.yearsBetween(varTime,now).getYears();
float score=1;
if(year>0&&year<=maxYears){
return year*score;
}else if(year>maxYears){ //超过上限者,统一按上限值乘以1.5倍算
return score*maxYears*1.5f;
}
return score;

}


/***
*
* @param money 传入需要计算的注册资金
* @param maxTimes 设置加权因子的最大倍数上限
* @param money_base 注册资金基数
* @return 该资金的一个动态评分值
*/
public static float getMoneyScore(Double money,int maxTimes,int money_base){
if(money==0){//没有注册资金的数据,不做加权操作
return 1;
}
int mtimes=(int)(money/money_base);
float score=1;
if(mtimes>0&&mtimes<=maxTimes){
return mtimes*score;
}else if(mtimes>maxTimes){//超过上限者,统一按上限值乘以1.5倍算
return score*maxTimes*1.5f;
}
return score;

}



}

0 comments on commit 15ef97f

Please sign in to comment.