package cn.com.qmth.stmms.biz.report.utils.unit;

import java.util.Arrays;

import cn.com.qmth.stmms.biz.exam.model.ExamQuestion;

/**
 * 将小题按照等级归类统计的工具类
 * 
 * @author luoshi
 *
 */
public class QuestionCounter {

    // 与预设等级数量一样的计数结果
    public int[] totalCount;

    // 与预设等级数量一样的合计分值
    public double[] totalScore;

    // 预设置的等级集合
    public LevelRange[] levels;

    public int levelCount;

    public QuestionCounter(LevelRange[] levels) {
        this.levels = levels;
        this.levelCount = levels.length;
        this.totalCount = new int[levelCount];
        this.totalScore = new double[levelCount];
        Arrays.fill(totalCount, 0);
        Arrays.fill(totalScore, 0d);
    }

    public void process(ExamQuestion question, double value) {
        for (int i = 0; i < levels.length; i++) {
            if (levels[i].match(value)) {
                totalCount[i]++;
                totalScore[i] += question.getTotalScore();
                return;
            }
        }
    }

    public int[] getTotalCount() {
        return totalCount;
    }

    public double[] getTotalScore() {
        return totalScore;
    }
}
