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

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.rf.psychological.dao.cognizeModel.ECATEntity;
import com.rf.psychological.dao.model.SHAPE2Entity;
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.text.DecimalFormat;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * @author zsy
 * @description:ECAT::情绪分类任务
 * @date 2021/7/20 15:55
 */
public class ECATCognize extends BaseScale {

    public ECATCognize(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 = resultJson.getString("fileName");
        String name;

        JSONObject resultDBJson = new JSONObject(true);

        List<ECATEntity> ecatEntities = jsonObject.getJSONArray("data").toJavaList(ECATEntity.class);
        JSONObject result = jsonObject.getJSONObject("result");
        String posNum = result.getString("posNum");
        String negNum = result.getString("negNum");
        String posAverageTime = result.getString("posAverageTime");
        String negAverageTime = result.getString("negAverageTime");


        Map<String, String> resultMap = new LinkedHashMap<>();
        resultMap.put("积极词语个数", posNum);
        resultDBJson.put("积极词语个数", posNum);

        resultMap.put("消极词语个数", negNum);
        resultDBJson.put("消极词语个数", negNum);

        resultMap.put("积极词语平均反应时", posAverageTime);
        resultDBJson.put("积极词语平均反应时", posAverageTime);

        resultMap.put("消极词语平均反应时", negAverageTime);
        resultDBJson.put("消极词语平均反应时", negAverageTime);

        resultMapList = new ArrayList<>();
        resultMapList.add(resultMap);

        String datas = JSONArray.toJSONString(ecatEntities);
        fileName = fileName + "-" + Constant.SHEET_NAME_ECAT + ".xlsx";
        name = Constant.SHEET_NAME_ECAT;
        ExcelUtil.createExcelFile(ECATEntity.class, ecatEntities, resultMapList, new ExcelClass().contentExcel(Constant.QUEST_TYPE_ECAT), fileName, Constant.SHEET_NAME_ECAT);

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

        return returnJson;
    }


}
