package com.smppw.utils;

/**
 * @author Rain
 * @date 2023/5/15 19:13
 * @description
 */
public class QuartileUtil {

    /**
     * 根据相对排名计算 四分位
     *
     * @param absrank
     * @return
     */
    public static String handleQuartile(String absrank) {
        if (absrank != null && absrank.contains("/")) {
            String[] split = absrank.split("/");
            int rank = Integer.parseInt(split[0]);
            int total = Integer.parseInt(split[1]);
            return handleQuartile(rank, total);
        }
        return null;
    }

    public static String handleQuartile(Integer rank, Integer total) {
        if (rank == null || total == null) {
            return null;
        }
        int average = total / 4;
        if (rank <= average) {
            return "4";
        } else if (rank <= average * 2) {
            return "3";
        } else if (rank <= average * 3) {
            return "2";
        } else if (rank <= total) {
            return "1";
        } else {
            return null;
        }
    }
}
