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.DataBeansJobVo;
import org.matrix.util.ReporterUtils;

import java.util.List;

/**
 * @author MRY
 */
public class ReporterDataJob {
    /**
     * 模板公共部分
     *
     * @return 补全了的所有报告信息
     */
    public DataBean testDataBean() {
        DataBeansJobVo dataBeansJobVo = ReporterUtils.jobMap.get("dataBeansJobVo");
        int passNum = 0;
        int failNum = 0;
        // 测试结果汇总数据
        DataBean dataBean = dataBeansJobVo.getDataBean();
        List<DataBeans> dataBeanLists = dataBeansJobVo.getDataBeansList();
        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 List<DataBeanMove> testDataBeanMove() {
        return ReporterUtils.jobMap.get("dataBeansJobVo").getDataBeanMoveList();
    }

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