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

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.rf.psychological.utils.Constant;

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

/**
 * @author lhl
 * @description:危险知觉能力自我评估量表
 * @date 2021/10/39 15:55
 */
public class SRHPScale extends BaseScale {
    public SRHPScale(JSONArray jsonArray, JSONObject resultJson) {
        super(jsonArray, resultJson);
    }

    public  JSONObject scaleCalculate() throws Exception {
        double score1 = 0;
        List<Map<String, String>> resultMapList = new ArrayList<>();
        for (int i = 0; i < jsonArray.size(); i++) {
            JSONObject jsonObject1 = jsonArray.getJSONObject(i);
            if (jsonObject1.getString("checkItems").equals("更差")) {
                score1 += 1;
            } else if (jsonObject1.getString("checkItems").equals("差")) {
                score1 += 2;
            } else if (jsonObject1.getString("checkItems").equals("比较差")) {
                score1 += 3;
            } else if (jsonObject1.getString("checkItems").equals("相同")) {
                score1 += 4;
            }else if (jsonObject1.getString("checkItems").equals("比较好")) {
                score1 += 5;
            } else if (jsonObject1.getString("checkItems").equals("好")) {
                score1 += 6;
            } else if (jsonObject1.getString("checkItems").equals("更好")) {
                score1 += 7;
            }
        }
        score1=score1/6.0;
        DecimalFormat df   = new DecimalFormat("######0.00");
        //得分列表
        Map<String, String> resultMap = new LinkedHashMap<>();
        resultMap.put("SRHP总得分", String.valueOf(Double.parseDouble(df.format(score1))));
        resultJson.put("SRHP总得分", String.valueOf(Double.parseDouble(df.format(score1))));

        resultMapList.add(resultMap);

        JSONObject returnJson = new JSONObject(true);
        returnJson.put("resultMapList",resultMapList);
        returnJson.put("scaleName", Constant.SHEET_NAME_TTT);
        returnJson.put("resultJson",resultJson);

        return returnJson;

    }

}
