import java.io.Serializable; import java.lang.ref.ReferenceQueue; import java.lang.ref.WeakReference; import java.math.BigDecimal; import java.math.RoundingMode; /** * 商品评价算法 * * @project icomment * @fileName ProductScore.java * @Description * @author light-zhang * @date 2018年1月15日下午4:44:40 * @version 1.0.0 */ public abstract class CommentUtils implements Serializable { private static final long serialVersionUID = 8143504152635422263L; /*************************** 方案一 *******************************************/ private static final double baby_ratio = 0.837;// 宝贝评价计算占比(0.837/千) private static final double merchant_ratio = 0.113;// 卖家态度计算占比(0.113/千) private static final double logistics_ratio = 0.0278;// 物流评价计算占比(0.0278/万) private static final double aplatfrom_ration = 0.0037;// 平台影响分A(0.0037/万) private static final double bplatfrom_ration = 0.0185; // 平台影响分B (0.0185/万) private static final double basic_score = 4.7463;// 最高分 /**************************************************************************/ /** * 方案一 宝贝占比较高,防止卖假货 宝贝评价 0.837(千分比) 5 卖家态度 0.113(千分比) 4 物流服务 0.0278(万分比) 3 平台影响 * 0.0037(万分比) 2 平台影响 0.0185(万分比) 1 * * @return */ public static BigDecimal babyScore(int baby, int merchant, int logistics) { double value = baby * baby_ratio + (merchant - 1) * merchant_ratio + (logistics - 2) * logistics_ratio + (2 * aplatfrom_ration) + (1 * bplatfrom_ration); final BigDecimal result = getTemp(new BigDecimal(value)); if (result.doubleValue() == basic_score) { return result.setScale(0, RoundingMode.HALF_UP); } return result.setScale(1, RoundingMode.HALF_UP); } /************************** * 方案二 ************************************************/ private static final double syn_baby_ratio = 0.35; private static final double syn_merchant_ratio = 0.25; private static final double syn_logistics_ratio = 0.35; private static final double syn_aplatfrom_ration = 0.3; private static final double syn_bplatfrom_ration = 0.2; private static final double syn_basic_score = 4.6; /**************************************************************************/ /** * 综合占比率 * @param baby * @param merchant * @param logistics * @return */ public static BigDecimal synthetical(int baby, int merchant, int logistics) { double value = baby * syn_baby_ratio + (merchant - 1) * syn_merchant_ratio + (logistics - 2) * syn_logistics_ratio + 2 * syn_aplatfrom_ration + 1 * syn_bplatfrom_ration; final BigDecimal result = getTemp(new BigDecimal(value)); if (result.doubleValue() == syn_basic_score) { return result.setScale(0, RoundingMode.HALF_UP); } return result.setScale(1, RoundingMode.HALF_UP); } /** * 宝贝梯度 梯度 0失望 1不满意 2一般 3满意 4惊喜 默认返回3满意 * * @param avgf * @return */ public static int grads(double avgf) { return (avgf <= 1.5) ? 0 : (avgf > 1.5 && avgf <= 2.3) ? 1 : (avgf > 2.3 && avgf <= 3.1) ? 2 : (avgf > 3.1 && avgf <= 4.0) ? 3 : (avgf > 4.0 && avgf <= 5.0) ? 4 : 3; } private static <T> T getTemp(T classOfType) { ReferenceQueue<T> queue = new ReferenceQueue<T>(); WeakReference<T> weakRef = new WeakReference<T>(classOfType, queue); if (null == weakRef.get()) { weakRef = new WeakReference<T>(classOfType); } return weakRef.get(); } public static void main(String[] args) { int baby = 2; int merchant = 2; int logistics = 5; System.out.println("评测1 " + babyScore(baby, merchant, logistics));// 方案一 防止卖假货采用方案 System.out.println("梯度1 >>>>> " + grads(babyScore(baby, merchant, logistics).doubleValue())); System.out.println("评测2 " + synthetical(baby, merchant, logistics));// 方案二 综合商家,宝贝,物流采用方案 System.out.println("梯度2 >>>>> " + grads(synthetical(baby, merchant, logistics).doubleValue())); } }