package com.ruoyi.common.utils;

public class BeerRatingUtils {

//    private static final double C = 100; // 虚拟评价数量,（例如，所有商品的平均评价数）。
//    private static final double m = 3.5; // 全局平均评分
    private static final double z = 1.96; // 95%置信水平的Z值

    public static double calculateBayesianScore(double C,double m,double sumOfScores, int n) {
        return (C * m + sumOfScores) / (C + n);
    }

    public static double calculateWilsonScore(double p, int n) {
        return (p + z * z / (2 * n) - z * Math.sqrt((p * (1 - p) + z * z / (4 * n)) / n)) / (1 + z * z / n);
    }

//    public static void main(String[] args) {
//        double aromaScore = 4.0;
//        double tasteScore = 4.5;
//        double colorScore = 4.2;
//
//        double singleScore = aromaScore * 0.1 + tasteScore * 0.3 + colorScore * 0.6;
//        System.out.println(singleScore);
//        int n = 5; // 当前评价数量
//        double sumOfScores = singleScore * n; // 假设所有评价的总分
//
//        double bayesianScore = calculateBayesianScore(50, 3.5, sumOfScores, n);
//        double wilsonScore = calculateWilsonScore(singleScore / 5, n);
//
//        System.out.println("Bayesian Score: " + bayesianScore);
//        System.out.println("Wilson Score: " + wilsonScore);
//    }
}
