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

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

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/11/01
 */
public class DASScale extends BaseScale {
    public DASScale(JSONArray jsonArray, JSONObject resultJson) {
        super(jsonArray, resultJson);
    }

    public  JSONObject scaleCalculate() throws Exception {

        //敌意手势
        double a = 0.0;
        //缓慢驾驶
        double score2 = 0.0;
        //无礼驾驶
        double score3 = 0.0;
        //交堵通拥
        double d = 0.0;


        for (int i = 0; i < jsonArray.size(); i++) {
            JSONObject jsonObject1 = jsonArray.getJSONObject(i);

            if (i == 0 || i == 7 || i == 8 || i == 13 || i == 16 || i == 18) {
                if (jsonObject1.getString("checkItems").equals("不生气")) {
                    a += 1.0;
                } else if (jsonObject1.getString("checkItems").equals("有点儿生气")) {
                    a += 2.0;
                } else if (jsonObject1.getString("checkItems").equals("生气")) {
                    a += 3.0;
                } else if (jsonObject1.getString("checkItems").equals("很生气")) {
                    a += 4.0;
                } else if (jsonObject1.getString("checkItems").equals("非常生气")) {
                    a += 5.0;
                }
                System.out.println(i+">>>>>>>>>>>>>"+a);
            }else if (i == 1 || i == 4 || i == 5 || i == 6 || i == 10) {
                if (jsonObject1.getString("checkItems").equals("不生气")) {
                    score2 += 1.0;
                } else if (jsonObject1.getString("checkItems").equals("有点儿生气")) {
                    score2 += 2.0;
                } else if (jsonObject1.getString("checkItems").equals("生气")) {
                    score2 += 3.0;
                } else if (jsonObject1.getString("checkItems").equals("很生气")) {
                    score2 += 4.0;
                } else if (jsonObject1.getString("checkItems").equals("非常生气")) {
                    score2 += 5.0;
                }
                System.out.println(i+"..............."+score2);
            } else if (i == 2 || i == 3 || i == 9 || i == 12 || i == 17 || i == 20) {
                if (jsonObject1.getString("checkItems").equals("不生气")) {
                    score3 += 1.0;
                } else if (jsonObject1.getString("checkItems").equals("有点儿生气")) {
                    score3 += 2.0;
                } else if (jsonObject1.getString("checkItems").equals("生气")) {
                    score3 += 3.0;
                } else if (jsonObject1.getString("checkItems").equals("很生气")) {
                    score3 += 4.0;
                } else if (jsonObject1.getString("checkItems").equals("非常生气")) {
                    score3 += 5.0;
                }
                System.out.println(i+"<<<<<<<<<<<<"+score3);
            } else if (i == 11 || i == 14 || i == 15 || i == 19 || i == 21) {
                if (jsonObject1.getString("checkItems").equals("不生气")) {
                    d += 1.0;
                } else if (jsonObject1.getString("checkItems").equals("有点儿生气")) {
                    d += 2.0;
                } else if (jsonObject1.getString("checkItems").equals("生气")) {
                    d += 3.0;
                } else if (jsonObject1.getString("checkItems").equals("很生气")) {
                    d += 4.0;
                } else if (jsonObject1.getString("checkItems").equals("非常生气")) {
                    d += 5.0;
                }
                System.out.println(i+",,,,,,,,,,,,,,,,,,"+d);
            }

            }
        System.out.println(a+"........."+d+">>>>>>"+jsonArray.size());
            DecimalFormat df = new DecimalFormat("######0.00");
        a= Double.parseDouble(df.format(a/6.0));

        score2= Double.parseDouble(df.format(score2/5.0));

        score3= Double.parseDouble(df.format(score3/6.0));
        d= Double.parseDouble(df.format(d/5.0));



            Map<String, String> resultMap = new LinkedHashMap<>();
            resultMap.put("敌意手势", String.valueOf(a));
            resultMap.put("缓慢驾驶", String.valueOf(score2));
            resultMap.put("无礼驾驶", String.valueOf(score3));
            resultMap.put("交堵通拥", String.valueOf(d));
            resultJson.put("敌意手势", String.valueOf(a));
            resultJson.put("缓慢驾驶", String.valueOf(score2));
            resultJson.put("无礼驾驶", String.valueOf(score3));
            resultJson.put("交堵通拥", String.valueOf(d));



            List<Map<String, String>> resultMapList = new ArrayList<>();
            resultMapList.add(resultMap);

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

            return returnJson;


        }

    }