package com.rf.psychological.scale.resultBusiness.cognitiveResult;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.rf.psychological.dao.model.ANTEntity;
import com.rf.psychological.file.excel.ExcelClass;
import com.rf.psychological.scale.resultBusiness.scaleResult.BaseScale;
import com.rf.psychological.utils.Constant;
import com.rf.psychological.utils.ExcelUtil;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * @author zsy
 * @description:ANT测试（亚太）
 * @date 2021/7/20 15:55
 */
public class ANTYATAICognize extends BaseScale {

    public ANTYATAICognize(JSONArray jsonArray, JSONObject resultJson) {
        super(jsonArray, resultJson);
    }

    public  JSONObject scaleCalculate() throws Exception {
        List<Map<String, String>> resultMapList = new ArrayList<>();
        JSONObject jsonObject = resultJson.getJSONObject("jsonObject");
        String fileName;
        String name;

        JSONObject resultDBJson = new JSONObject(true);

        JSONArray jsonArray = jsonObject.getJSONArray("data");
        //准确率
        String rightRate = jsonObject.getString("rightRate");
        //总反应时长
        String totalResponseTime = jsonObject.getString("totalResponseTime");

        fileName = resultJson.getString("fileName") + "-" + Constant.SHEET_NAME_ANT_YATAI + ".xlsx";
        name = Constant.SHEET_NAME_ANT_YATAI;

        Map<String, String> resultMap = new LinkedHashMap<>();
        resultMap.put("准确率", rightRate);
        resultDBJson.put("准确率", rightRate);
        resultMap.put("总反应时长", totalResponseTime);
        resultDBJson.put("总反应时长", totalResponseTime);
        resultMapList.add(resultMap);

        JSONObject result = jsonObject.getJSONObject("result");
        Map<String, String> resultMap1 = new LinkedHashMap<>();
        resultMap1.put("总命中次数", String.valueOf(result.get("hitsAll")));
        resultDBJson.put("总命中次数", String.valueOf(result.get("hitsAll")));
        resultMap1.put("一致性命中次数", String.valueOf(result.get("hitscongruent")));
        resultDBJson.put("一致性命中次数", String.valueOf(result.get("hitscongruent")));
        resultMap1.put("不一致性命中次数", String.valueOf(result.get("hitsincongruent")));
        resultDBJson.put("不一致性命中次数", String.valueOf(result.get("hitsincongruent")));
        resultMap1.put("NoCue命中次数", String.valueOf(result.get("hitsNoCue")));
        resultDBJson.put("NoCue命中次数", String.valueOf(result.get("hitsNoCue")));
        resultMap1.put("NeutralCue命中次数", String.valueOf(result.get("hitsNeutralCue")));
        resultDBJson.put("NeutralCue命中次数", String.valueOf(result.get("hitsNeutralCue")));
        resultMap1.put("SpatialCue命中次数", String.valueOf(result.get("hitsSpatialCue")));
        resultDBJson.put("SpatialCue命中次数", String.valueOf(result.get("hitsSpatialCue")));
        resultMap1.put("命中率", String.valueOf(result.get("hitRate")));
        resultDBJson.put("命中率", String.valueOf(result.get("hitRate")));
        resultMap1.put("一致性命中率", String.valueOf(result.get("congruentHitRate")));
        resultDBJson.put("一致性命中率", String.valueOf(result.get("congruentHitRate")));
        resultMap1.put("不一致性命中率", String.valueOf(result.get("incongruentHitRate")));
        resultDBJson.put("不一致性命中率", String.valueOf(result.get("incongruentHitRate")));
        resultMap1.put("NoCue命中率", String.valueOf(result.get("noCueHitRate")));
        resultDBJson.put("NoCue命中率", String.valueOf(result.get("noCueHitRate")));
        resultMap1.put("NeutralCue命中率", String.valueOf(result.get("neutralCueHitRate")));
        resultDBJson.put("NeutralCue命中率", String.valueOf(result.get("neutralCueHitRate")));
        resultMap1.put("SpatialCue命中率", String.valueOf(result.get("spatialCueHitRate")));
        resultDBJson.put("SpatialCue命中率", String.valueOf(result.get("spatialCueHitRate")));
        resultMap1.put("反应时", String.valueOf(result.get("responseTimeAll")));
        resultDBJson.put("反应时", String.valueOf(result.get("responseTimeAll")));
        resultMap1.put("一致性反应时", String.valueOf(result.get("responseTimeCongruent")));
        resultDBJson.put("一致性反应时", String.valueOf(result.get("responseTimeCongruent")));
        resultMap1.put("不一致性反应时", String.valueOf(result.get("responseTimeIncongruent")));
        resultDBJson.put("不一致性反应时", String.valueOf(result.get("responseTimeIncongruent")));
        resultMap1.put("NoCue反应时", String.valueOf(result.get("responseTimeNoCue")));
        resultDBJson.put("NoCue反应时", String.valueOf(result.get("responseTimeNoCue")));
        resultMap1.put("NeutralCue反应时", String.valueOf(result.get("responseTimeNeutralCue")));
        resultDBJson.put("NeutralCue反应时", String.valueOf(result.get("responseTimeNeutralCue")));
        resultMap1.put("SpatialCue反应时", String.valueOf(result.get("responseTimeSpatialCue")));
        resultDBJson.put("SpatialCue反应时", String.valueOf(result.get("responseTimeSpatialCue")));
        resultMap1.put("警觉分数", String.valueOf(result.get("warnScore")));
        resultDBJson.put("警觉分数", String.valueOf(result.get("warnScore")));
        resultMap1.put("定向分数", String.valueOf(result.get("directionScore")));
        resultDBJson.put("定向分数", String.valueOf(result.get("directionScore")));
        resultMap1.put("冲突分数", String.valueOf(result.get("conflictScore")));
        resultDBJson.put("冲突分数", String.valueOf(result.get("conflictScore")));
        resultMapList.add(resultMap1);
        String datas = jsonArray.toString();
        ExcelUtil.createExcelFile(ANTEntity.class, jsonArray.toJavaList(ANTEntity.class), resultMapList, new ExcelClass().contentExcel(Constant.QUEST_TYPE_ANT), fileName, Constant.SHEET_NAME_ANT_YATAI);

        JSONObject returnJson = new JSONObject(true);
        returnJson.put("fileName",fileName);
        returnJson.put("name", name);
        returnJson.put("resultJson",resultDBJson);
        returnJson.put("datas",datas);

        return returnJson;
    }


}
