package org.matrix.testNg.web.report;

import org.matrix.testNg.web.entity.DataBean;
import org.matrix.testNg.web.entity.DataBeanMove;
import org.matrix.testNg.web.entity.DataBeans;
import org.matrix.testNg.web.entity.DataBeansVo;
import org.matrix.util.ReporterUtils;

import java.util.List;

/**
 * @author mruny
 */
public class ReporterData {

    /**
     * 模板公共部分
     *
     * @return 补全了的所有报告信息
     */
    public DataBean testDataBean() {
        DataBeansVo dataBeansVo = ReporterUtils.map.get("dataBeansVo");
        int passNum = 0;
        int failNum = 0;
        // 测试结果汇总数据
        DataBean dataBean = dataBeansVo.getDataBean();
        List<DataBeans> dataBeanLists = dataBeansVo.getDataBeanLists();
        for (DataBeans dataBeanList : dataBeanLists) {
            if (dataBeanList.getResult()) {
                passNum += 1;
            } else {
                failNum += 1;
            }
        }
        //成功
        dataBean.setPassNum(passNum);
        //失败
        dataBean.setFailNum(failNum);
        //总数
        dataBean.setTotal(passNum + failNum);
        //通过率
        dataBean.setProbability(passNum / (passNum + failNum));
        // TODO 时间需要处理
        return dataBean;
    }

    /**
     * 动作部分
     */
    public DataBeanMove testDataBeanMove() {
        return ReporterUtils.map.get("dataBeansVo").getDataBeanMove();
    }

    /**
     * 模板的细节部分
     *
     * @return 报告中细节部分的信息
     */
    public List<DataBeans> testDataBeans() {
        return ReporterUtils.map.get("dataBeansVo").getDataBeanLists();
    }

}