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

import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.rf.psychological.dao.model.ObjectEntity;
import com.rf.psychological.file.excel.ExcelClass;
import com.rf.psychological.scale.resultBusiness.scaleResult.BaseScale;
import com.rf.psychological.user.dao.model.UserEntity;
import com.rf.psychological.utils.AgeUtil;
import com.rf.psychological.utils.Constant;
import com.rf.psychological.utils.ExcelUtil;
import org.apache.commons.lang.StringUtils;

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

/**
 * @author zsy
 * @description:瑞文测试
 * @date 2021/7/20 15:55
 */
public class RIVENCognize extends BaseScale {

    public RIVENCognize(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") + "-" + Constant.SHEET_NAME_RIVEN + ".xlsx";
        UserEntity userEntity = (UserEntity) resultJson.get("userEntity");
        JSONArray jsonArray = jsonObject.getJSONArray("data");
        int score = jsonObject.getInteger("userScore");
        String name = Constant.SHEET_NAME_RIVEN;
        int resultScore = RIVENScore(userEntity.getBirthday(), score);

        JSONObject resultDBJson = new JSONObject(true);
        resultDBJson.put("versionNo", "2.0");
        //知觉辨别能力得分
        int A = 0;
        //雷同比较能力得分
        int B = 0;
        //比较推理能力得分
        int C = 0;
        //系列关系能力得分
        int D = 0;
        //抽象推理能力得分
        int E = 0;
        for (int i = 0; i < jsonArray.size(); i++) {
            JSONObject jsonObject1 = jsonArray.getJSONObject(i);
            if (i <= 11){
                A += Integer.valueOf(jsonObject1.getInteger("score"));
            }else if (i >= 12 && i <= 23){
                B += Integer.valueOf(jsonObject1.getInteger("score"));
            }else if (i >= 24&& i <= 35){
                C += Integer.valueOf(jsonObject1.getInteger("score"));
            }else if (i >= 36 && i <= 47){
                D += Integer.valueOf(jsonObject1.getInteger("score"));
            }else {
                E += Integer.valueOf(jsonObject1.getInteger("score"));
            }
        }
        //总分模块
        JSONArray totalScores = new JSONArray();
        JSONObject totalScoreObject = new JSONObject(true);
        totalScoreObject.put("totalScore",score);
        if (resultScore < 5) {
            totalScoreObject.put("totalScoreDesc","智力水平低下");
        } else if (resultScore >= 5 && resultScore <= 24) {
            totalScoreObject.put("totalScoreDesc","智力水平中下");
        } else if (resultScore >= 25 && resultScore <= 74) {
            totalScoreObject.put("totalScoreDesc","智力水平中等");
        } else if (resultScore >= 75 && resultScore <= 94) {
            totalScoreObject.put("totalScoreDesc","智力水平良好");
        } else {
            totalScoreObject.put("totalScoreDesc","智力水平优秀");
        }

        totalScores.add(totalScoreObject);
        resultDBJson.put("totalScore", totalScores);

        //表格数据
        JSONArray tableModule = new JSONArray();
        JSONObject table1 = new JSONObject(true);
        JSONArray columnName = new JSONArray();
        columnName.add("评估指标");
        columnName.add("我的");
        JSONArray columnValue = new JSONArray();
        columnValue.add("知觉辨别能力;雷同比较能力;比较推理能力;系列关系能力;抽象推理能力");
        columnValue.add(A+";"+B+";"+C+";"+D+";"+E);
        table1.put("tableName","table1");
        table1.put("columnName",columnName);
        table1.put("columnValue",columnValue);
        tableModule.add(table1);
        resultDBJson.put("tableModule", tableModule);

        //图表模块
        JSONObject chartModule = new JSONObject(true);
        chartModule.put("chartType","radar");
        JSONObject chartBody = new JSONObject(true);
        JSONArray indicator = new JSONArray();
        JSONObject indicatorA = new JSONObject(true);
        indicatorA.put("name","知觉辨别能力");
        indicatorA.put("max",12);
        indicator.add(indicatorA);
        JSONObject indicatorB = new JSONObject(true);
        indicatorB.put("name","雷同比较能力");
        indicatorB.put("max",12);
        indicator.add(indicatorB);
        JSONObject indicatorC = new JSONObject(true);
        indicatorC.put("name","比较推理能力");
        indicatorC.put("max",12);
        indicator.add(indicatorC);
        JSONObject indicatorD = new JSONObject(true);
        indicatorD.put("name","系列关系能力");
        indicatorD.put("max",12);
        indicator.add(indicatorD);
        JSONObject indicatorE = new JSONObject(true);
        indicatorE.put("name","抽象推理能力");
        indicatorE.put("max",12);
        indicator.add(indicatorE);
        chartBody.put("indicator",indicator);
        JSONArray groupData = new JSONArray();
        JSONObject group1 = new JSONObject(true);
        JSONArray group1Value = new JSONArray();
        group1Value.add(A);
        group1Value.add(B);
        group1Value.add(C);
        group1Value.add(D);
        group1Value.add(E);
        group1.put("index",1);
        group1.put("value",group1Value);
        group1.put("name","group1");
        groupData.add(group1);
        chartBody.put("groupData",groupData);
        chartModule.put("chartBody",chartBody);
        resultDBJson.put("chartModule", chartModule);

        //维度得分及结论模块
        JSONArray dimensions = new JSONArray();
        JSONObject scoreA = new JSONObject(true);
        scoreA.put("name","知觉辨别能力");
        scoreA.put("score",A);
        scoreA.put("Describe","知觉辨认能力是指对外界感官信息做出整体性辨别的能力，比如万花丛中一点绿，在视力水平相等情况下，知觉辨认能力强的人会马上察觉到这点绿，而知觉辨认能力弱的人则不能。\n" +
                "在知觉辨认能力维度得分高的受测者对外界环境各种感觉的组织整合能力较强，看待问题更有全局观，往往能耳听八方、眼观六路。\n" +
                "而在该维度得分较低的受测者则对外界环境各种感觉信息的组织整合能力较差，看待问题时可能忽略对整体的把控或处理失误。\n" +
                "对于在该维度得分较低的受测者，建议可以后续在心灵照相机平台加强感知觉整体性的辨别训练。");
        scoreA.put("maximum","12");
        scoreA.put("groupName","第一组");
        dimensions.add(scoreA);
        JSONObject scoreB = new JSONObject(true);
        scoreB.put("name","雷同比较能力");
        scoreB.put("score",B);
        scoreB.put("Describe","类同比较能力跟比较推理能力差不多，不同的是类同比较能力只强调个体将同类事物进行比较并从中提取出共同要素即可，而不强调举一反三将其用于其他同类问题的解决。因此简单地说，类同比较能力就相当于找不同。\n" +
                "该维度得分高的受测者在同类现象中发觉共同规律的能力较强，归纳总结能力较强。而在该维度得分低的受测者这类能力较差。\n" +
                "该维度得分较低的受测者可以后续加强类同比较能力训练。");
        scoreB.put("maximum","12");
        scoreB.put("groupName","第一组");
        dimensions.add(scoreB);
        JSONObject scoreC = new JSONObject(true);
        scoreC.put("name","比较推理能力");
        scoreC.put("score",C);
        scoreC.put("Describe","比较推理能力是指个体从同类现象或问题中提取出共性因素，举一反三，并应用于其他同类问题的解决中去的能力，比如鲁班根据茅草发明了锯子，人类根据鸟的模型发明了飞机等。\n" +
                "在比较推理能力维度得分高的受测者，其举一反三能力更优秀，迁移学习能力更好，且将会获得更好的创造力。\n" +
                "而在该维度得分低的受测者，其举一反三的能力较差，迁移学习的能力和解决问题的能力也有待提高\n" +
                "对于在该维度得分较低的受测者，建议可以在平台坚持类比迁移能力的训练和创造力训练，且在平时生活实践中要打破常规惯性思维，提高解决实际问题的能力。");
        scoreC.put("maximum","12");
        scoreC.put("groupName","第一组");
        dimensions.add(scoreC);
        JSONObject scoreD = new JSONObject(true);
        scoreD.put("name","系列关系能力");
        scoreD.put("score",D);
        scoreD.put("Describe","系列关系能力指个体对情景中若干信息之间的联系的觉察能力，该能力高的个体偏向场依存的认知模式，更能觉察到情景中的变化，更关注外界，该能力低的个体偏向场独立的认知模式，更关注内在。但需要注意的是，场依存和场独立的认知模式是中性的，无好坏之分，而系列关系能力作为一种认知能力是有高低好坏之分的，高肯定比低好。\n" +
                "因此，该维度得分高的受测者拥有更好的对场景动态的敏感性，换位思考、交际能力更好，更能体会到别人的内心。\n" +
                "而该维度得分低的受测者这方面能力较差，不太能够换位思考，更多活在自己的世界，但从另一个角度来讲，这部分受测者内心更加深邃，思维能力更强。\n" +
                "低分受测者也可以通过场依存认知训练等来弥补缺陷。");
        scoreD.put("maximum","12");
        scoreD.put("groupName","第一组");
        dimensions.add(scoreD);
        JSONObject scoreE = new JSONObject(true);
        scoreE.put("name","抽象推理能力");
        scoreE.put("score",E);
        scoreE.put("Describe","抽象推理能力是一种高级思维能力，小孩在7岁左右开始萌芽，12岁左右青春期开始较快发展。\n" +
                "抽象推理能力指不仅能把握事物的表面，更能揭露事物的深层本质，即透过现象看本质的能力。该维度得分高的受测者拥有世俗认为的高智商水平，认知灵活性强，其创造力想象力都较高，适合做科学家发明家工作。而得分低的个体则这方面能力较低。作为一种一般能力，抽象推理能力越早培养越好，若受测者年龄较小，可以尽快培养起来。");
        scoreE.put("maximum","12");
        scoreE.put("groupName","第一组");
        dimensions.add(scoreE);
        resultDBJson.put("dimensions", dimensions);

        //注意事项模块
            /*JSONArray notes = new JSONArray();
            JSONObject noteObject = new JSONObject(true);
            noteObject.put("totalScore",score);
            noteObject.put("scoreDes","通过五个方面得分的结构，一定程度上有助于了解被测者智力结构。 \n" +
                    "对分数作解释时注意，由于瑞文测验强调推理方面的能力，并非完全的智力，目前仅用于智力方面的筛选。因此不能绝对化。\n" +
                    "该测验根据斯皮尔曼智力二因素理论编制，所测量的均为一般智力，而不是某方面的特殊技能。\n" +
                    "本报告不具有临床诊断意义，仅供专业人员参考。\n" +
                    "智力不是一成不变的，会随着年龄变化和受教育以及环境等因素变化而变化，所以以上维度智力得分低的受测者可以通专业训练提升。");
            notes.add(noteObject);*/
        resultDBJson.put("note", "通过五个方面得分的结构，一定程度上有助于了解被测者智力结构。 \n" +
                "对分数作解释时注意，由于瑞文测验强调推理方面的能力，并非完全的智力，目前仅用于智力方面的筛选。因此不能绝对化。\n" +
                "该测验根据斯皮尔曼智力二因素理论编制，所测量的均为一般智力，而不是某方面的特殊技能。\n" +
                "本报告不具有临床诊断意义，仅供专业人员参考。\n" +
                "智力不是一成不变的，会随着年龄变化和受教育以及环境等因素变化而变化，所以以上维度智力得分低的受测者可以通专业训练提升。");
        //显示模块
        JSONObject ifShow = new JSONObject(true);
        ifShow.put("totalScore",true);
        ifShow.put("dimensions",true);
        ifShow.put("note",true);
        ifShow.put("radar",true);
        ifShow.put("table",true);
        resultDBJson.put("ifShow", ifShow);

        Map<String, String> resultMap = new LinkedHashMap<>();
        resultMap.put("知觉辨别能力", String.valueOf(A));
        resultDBJson.put("知觉辨别能力", String.valueOf(A));
        resultMap.put("雷同比较能力", String.valueOf(B));
        resultDBJson.put("雷同比较能力", String.valueOf(B));
        resultMap.put("比较推理能力", String.valueOf(C));
        resultDBJson.put("比较推理能力", String.valueOf(C));
        resultMap.put("系列关系能力", String.valueOf(D));
        resultDBJson.put("系列关系能力", String.valueOf(D));
        resultMap.put("抽象推理能力", String.valueOf(E));
        resultDBJson.put("抽象推理能力", String.valueOf(E));
        //第一版计分规则
        /*resultMap.put("总分", String.valueOf(score));
        resultDBJson.put("总分", String.valueOf(score));
        resultMap.put("结论", "智力水平大于" + resultScore + "%的同龄人");
        resultDBJson.put("结论", "智力水平大于" + resultScore + "%的同龄人");
        if (resultScore < 5) {
            resultMap.put("智力水平", "低下");
            resultDBJson.put("智力水平", "低下");
        } else if (resultScore >= 5 && resultScore <= 24) {
            resultMap.put("智力水平", "中下");
            resultDBJson.put("智力水平", "中下");
        } else if (resultScore >= 25 && resultScore <= 74) {
            resultMap.put("智力水平", "中等");
            resultDBJson.put("智力水平", "中等");
        } else if (resultScore >= 75 && resultScore <= 94) {
            resultMap.put("智力水平", "良好");
            resultDBJson.put("智力水平", "良好");
        } else {
            resultMap.put("智力水平", "优秀");
            resultDBJson.put("智力水平", "优秀");
        }*/
        resultMapList.add(resultMap);

        String datas = jsonArray.toString();
        ExcelUtil.createExcelFile(ObjectEntity.class, jsonArray.toJavaList(ObjectEntity.class), resultMapList, new ExcelClass().contentExcel(Constant.QUEST_TYPE_RIVEN), fileName, Constant.SHEET_NAME_RIVEN);
        
        JSONObject returnJson = new JSONObject(true);
        returnJson.put("fileName",fileName);
        returnJson.put("name", name);
        returnJson.put("resultJson",resultDBJson);
        returnJson.put("datas",datas);

        return returnJson;
    }

    //瑞文根据年龄分值转换
    private int RIVENScore(String userBirthday, int score) throws Exception {
        int resultScore = 0;
        if (StringUtils.isEmpty(userBirthday) || "-".equals(userBirthday)){
            userBirthday = DateUtil.now();
        }
        double age = AgeUtil.getAge(userBirthday);
        if (age <= 5.5) {
            if (score >= 9 && score < 12) {
                resultScore = 5;
            } else if (score >= 12 && score < 13) {
                resultScore = 10;
            } else if (score >= 13 && score < 16) {
                resultScore = 25;
            } else if (score >= 16 && score < 25) {
                resultScore = 50;
            } else if (score >= 25 && score < 29) {
                resultScore = 75;
            } else if (score >= 29 && score < 34) {
                resultScore = 90;
            } else if (score >= 34) {
                resultScore = 95;
            }
        } else if (age == 6) {
            if (score >= 9 && score < 12) {
                resultScore = 5;
            } else if (score >= 12 && score < 13) {
                resultScore = 10;
            } else if (score >= 13 && score < 17) {
                resultScore = 25;
            } else if (score >= 17 && score < 25) {
                resultScore = 50;
            } else if (score >= 25 && score < 31) {
                resultScore = 75;
            } else if (score >= 31 && score < 36) {
                resultScore = 90;
            } else if (score >= 36) {
                resultScore = 95;
            }
        } else if (age == 6.5) {
            if (score >= 10 && score < 12) {
                resultScore = 5;
            } else if (score >= 12 && score < 13) {
                resultScore = 10;
            } else if (score >= 13 && score < 18) {
                resultScore = 25;
            } else if (score >= 18 && score < 25) {
                resultScore = 50;
            } else if (score >= 25 && score < 31) {
                resultScore = 75;
            } else if (score >= 31 && score < 37) {
                resultScore = 90;
            } else if (score >= 37) {
                resultScore = 95;
            }
        } else if (age == 7) {
            if (score >= 10 && score < 12) {
                resultScore = 5;
            } else if (score >= 12 && score < 13) {
                resultScore = 10;
            } else if (score >= 13 && score < 19) {
                resultScore = 25;
            } else if (score >= 19 && score < 25) {
                resultScore = 50;
            } else if (score >= 25 && score < 36) {
                resultScore = 75;
            } else if (score >= 36 && score < 43) {
                resultScore = 90;
            } else if (score >= 43) {
                resultScore = 95;
            }
        } else if (age == 7.5) {
            if (score >= 10 && score < 12) {
                resultScore = 5;
            } else if (score >= 12 && score < 13) {
                resultScore = 10;
            } else if (score >= 13 && score < 21) {
                resultScore = 25;
            } else if (score >= 21 && score < 31) {
                resultScore = 50;
            } else if (score >= 31 && score < 38) {
                resultScore = 75;
            } else if (score >= 38 && score < 44) {
                resultScore = 90;
            } else if (score >= 44) {
                resultScore = 95;
            }
        } else if (age == 8) {
            if (score >= 10 && score < 13) {
                resultScore = 5;
            } else if (score >= 13 && score < 15) {
                resultScore = 10;
            } else if (score >= 15 && score < 23) {
                resultScore = 25;
            } else if (score >= 23 && score < 31) {
                resultScore = 50;
            } else if (score >= 31 && score < 39) {
                resultScore = 75;
            } else if (score >= 39 && score < 44) {
                resultScore = 90;
            } else if (score >= 44) {
                resultScore = 95;
            }
        } else if (age == 8.5) {
            if (score >= 12 && score < 14) {
                resultScore = 5;
            } else if (score >= 14 && score < 20) {
                resultScore = 10;
            } else if (score >= 20 && score < 29) {
                resultScore = 25;
            } else if (score >= 29 && score < 33) {
                resultScore = 50;
            } else if (score >= 33 && score < 40) {
                resultScore = 75;
            } else if (score >= 40 && score < 45) {
                resultScore = 90;
            } else if (score >= 45) {
                resultScore = 95;
            }

        } else if (age == 9) {
            if (score >= 12 && score < 14) {
                resultScore = 5;
            } else if (score >= 14 && score < 25) {
                resultScore = 10;
            } else if (score >= 25 && score < 33) {
                resultScore = 25;
            } else if (score >= 33 && score < 37) {
                resultScore = 50;
            } else if (score >= 37 && score < 43) {
                resultScore = 75;
            } else if (score >= 43 && score < 47) {
                resultScore = 90;
            } else if (score >= 47) {
                resultScore = 95;
            }

        } else if (age == 9.5) {
            if (score >= 13 && score < 17) {
                resultScore = 5;
            } else if (score >= 17 && score < 27) {
                resultScore = 10;
            } else if (score >= 27 && score < 35) {
                resultScore = 25;
            } else if (score >= 35 && score < 39) {
                resultScore = 50;
            } else if (score >= 39 && score < 47) {
                resultScore = 75;
            } else if (score >= 47 && score < 50) {
                resultScore = 90;
            } else if (score >= 50) {
                resultScore = 95;
            }

        } else if (age == 10) {
            if (score >= 13 && score < 17) {
                resultScore = 5;
            } else if (score >= 17 && score < 27) {
                resultScore = 10;
            } else if (score >= 27 && score < 35) {
                resultScore = 25;
            } else if (score >= 35 && score < 42) {
                resultScore = 50;
            } else if (score >= 42 && score < 48) {
                resultScore = 75;
            } else if (score >= 48 && score < 50) {
                resultScore = 90;
            } else if (score >= 50) {
                resultScore = 95;
            }

        } else if (age == 10.5) {
            if (score >= 18 && score < 25) {
                resultScore = 5;
            } else if (score >= 25 && score < 32) {
                resultScore = 10;
            } else if (score >= 32 && score < 39) {
                resultScore = 25;
            } else if (score >= 39 && score < 42) {
                resultScore = 50;
            } else if (score >= 42 && score < 49) {
                resultScore = 75;
            } else if (score >= 49 && score < 50) {
                resultScore = 90;
            } else if (score >= 50) {
                resultScore = 95;
            }

        } else if (age == 11) {
            if (score >= 19 && score < 25) {
                resultScore = 5;
            } else if (score >= 25 && score < 33) {
                resultScore = 10;
            } else if (score >= 33 && score < 39) {
                resultScore = 25;
            } else if (score >= 39 && score < 43) {
                resultScore = 50;
            } else if (score >= 43 && score < 50) {
                resultScore = 75;
            } else if (score >= 50 && score < 52) {
                resultScore = 90;
            } else if (score >= 52) {
                resultScore = 95;
            }

        } else if (age == 11.5) {
            if (score >= 19 && score < 25) {
                resultScore = 5;
            } else if (score >= 25 && score < 35) {
                resultScore = 10;
            } else if (score >= 35 && score < 42) {
                resultScore = 25;
            } else if (score >= 42 && score < 45) {
                resultScore = 50;
            } else if (score >= 45 && score < 50) {
                resultScore = 75;
            } else if (score >= 50 && score < 53) {
                resultScore = 90;
            } else if (score >= 53) {
                resultScore = 95;
            }

        } else if (age == 12) {
            if (score >= 21 && score < 27) {
                resultScore = 5;
            } else if (score >= 27 && score < 37) {
                resultScore = 10;
            } else if (score >= 37 && score < 42) {
                resultScore = 25;
            } else if (score >= 42 && score < 46) {
                resultScore = 50;
            } else if (score >= 46 && score < 50) {
                resultScore = 75;
            } else if (score >= 50 && score < 53) {
                resultScore = 90;
            } else if (score >= 53) {
                resultScore = 95;
            }

        } else if (age == 12.5) {
            if (score >= 28 && score < 33) {
                resultScore = 5;
            } else if (score >= 33 && score < 40) {
                resultScore = 10;
            } else if (score >= 40 && score < 45) {
                resultScore = 25;
            } else if (score >= 45 && score < 50) {
                resultScore = 50;
            } else if (score >= 50 && score < 52) {
                resultScore = 75;
            } else if (score >= 52 && score < 53) {
                resultScore = 90;
            } else if (score >= 53) {
                resultScore = 95;
            }

        } else if (age == 13) {
            if (score >= 30 && score < 35) {
                resultScore = 5;
            } else if (score >= 35 && score < 40) {
                resultScore = 10;
            } else if (score >= 40 && score < 45) {
                resultScore = 25;
            } else if (score >= 45 && score < 50) {
                resultScore = 50;
            } else if (score >= 50 && score < 52) {
                resultScore = 75;
            } else if (score >= 52 && score < 53) {
                resultScore = 90;
            } else if (score >= 53) {
                resultScore = 95;
            }

        } else if (age == 13.5) {
            if (score >= 32 && score < 35) {
                resultScore = 5;
            } else if (score >= 35 && score < 42) {
                resultScore = 10;
            } else if (score >= 42 && score < 46) {
                resultScore = 25;
            } else if (score >= 46 && score < 50) {
                resultScore = 50;
            } else if (score >= 50 && score < 52) {
                resultScore = 75;
            } else if (score >= 52 && score < 54) {
                resultScore = 90;
            } else if (score >= 54) {
                resultScore = 95;
            }

        } else if (age == 14) {
            if (score >= 34 && score < 36) {
                resultScore = 5;
            } else if (score >= 36 && score < 43) {
                resultScore = 10;
            } else if (score >= 43 && score < 48) {
                resultScore = 25;
            } else if (score >= 48 && score < 50) {
                resultScore = 50;
            } else if (score >= 50 && score < 52) {
                resultScore = 75;
            } else if (score >= 52 && score < 55) {
                resultScore = 90;
            } else if (score >= 55) {
                resultScore = 95;
            }

        } else if (age == 14.5) {
            if (score >= 34 && score < 36) {
                resultScore = 5;
            } else if (score >= 36 && score < 43) {
                resultScore = 10;
            } else if (score >= 43 && score < 48) {
                resultScore = 25;
            } else if (score >= 48 && score < 51) {
                resultScore = 50;
            } else if (score >= 51 && score < 53) {
                resultScore = 75;
            } else if (score >= 53 && score < 55) {
                resultScore = 90;
            } else if (score >= 55) {
                resultScore = 95;
            }

        } else if (age == 15) {
            if (score >= 34 && score < 36) {
                resultScore = 5;
            } else if (score >= 36 && score < 43) {
                resultScore = 10;
            } else if (score >= 43 && score < 48) {
                resultScore = 25;
            } else if (score >= 48 && score < 51) {
                resultScore = 50;
            } else if (score >= 51 && score < 54) {
                resultScore = 75;
            } else if (score >= 54 && score < 57) {
                resultScore = 90;
            } else if (score >= 57) {
                resultScore = 95;
            }

        } else if (age == 15.5) {
            if (score >= 34 && score < 41) {
                resultScore = 5;
            } else if (score >= 41 && score < 43) {
                resultScore = 10;
            } else if (score >= 43 && score < 49) {
                resultScore = 25;
            } else if (score >= 49 && score < 52) {
                resultScore = 50;
            } else if (score >= 52 && score < 55) {
                resultScore = 75;
            } else if (score >= 55 && score < 57) {
                resultScore = 90;
            } else if (score >= 57) {
                resultScore = 95;
            }

        } else if (age == 16) {
            if (score >= 36 && score < 41) {
                resultScore = 5;
            } else if (score >= 41 && score < 44) {
                resultScore = 10;
            } else if (score >= 44 && score < 49) {
                resultScore = 25;
            } else if (score >= 49 && score < 53) {
                resultScore = 50;
            } else if (score >= 53 && score < 56) {
                resultScore = 75;
            } else if (score >= 56 && score < 57) {
                resultScore = 90;
            } else if (score >= 57) {
                resultScore = 95;
            }

        } else if (age == 16.5) {
            if (score >= 37 && score < 41) {
                resultScore = 5;
            } else if (score >= 41 && score < 45) {
                resultScore = 10;
            } else if (score >= 45 && score < 49) {
                resultScore = 25;
            } else if (score >= 49 && score < 53) {
                resultScore = 50;
            } else if (score >= 53 && score < 56) {
                resultScore = 75;
            } else if (score >= 56 && score < 57) {
                resultScore = 90;
            } else if (score >= 57) {
                resultScore = 95;
            }

        } else if (age == 17) {
            if (score >= 37 && score < 40) {
                resultScore = 5;
            } else if (score >= 40 && score < 47) {
                resultScore = 10;
            } else if (score >= 47 && score < 52) {
                resultScore = 25;
            } else if (score >= 52 && score < 55) {
                resultScore = 50;
            } else if (score >= 55 && score < 57) {
                resultScore = 75;
            } else if (score >= 57 && score < 58) {
                resultScore = 90;
            } else if (score >= 58) {
                resultScore = 95;
            }

        } else if (age > 17 && age <= 24.5) {//20
            if (score >= 33 && score < 38) {
                resultScore = 5;
            } else if (score >= 38 && score < 44) {
                resultScore = 10;
            } else if (score >= 44 && score < 50) {
                resultScore = 25;
            } else if (score >= 50 && score < 54) {
                resultScore = 50;
            } else if (score >= 54 && score < 56) {
                resultScore = 75;
            } else if (score >= 56 && score < 57) {
                resultScore = 90;
            } else if (score >= 57) {
                resultScore = 95;
            }

        } else if (age >= 25 && age <= 34.5) {//30
            if (score >= 28 && score < 37) {
                resultScore = 5;
            } else if (score >= 37 && score < 43) {
                resultScore = 10;
            } else if (score >= 43 && score < 48) {
                resultScore = 25;
            } else if (score >= 48 && score < 52) {
                resultScore = 50;
            } else if (score >= 52 && score < 55) {
                resultScore = 75;
            } else if (score >= 55 && score < 57) {
                resultScore = 90;
            } else if (score >= 57) {
                resultScore = 95;
            }

        } else if (age >= 35 && age <= 44.5) {//40
            if (score >= 28 && score < 31) {
                resultScore = 5;
            } else if (score >= 31 && score < 41) {
                resultScore = 10;
            } else if (score >= 41 && score < 47) {
                resultScore = 25;
            } else if (score >= 47 && score < 50) {
                resultScore = 50;
            } else if (score >= 50 && score < 54) {
                resultScore = 75;
            } else if (score >= 54 && score < 57) {
                resultScore = 90;
            } else if (score >= 57) {
                resultScore = 95;
            }

        } else if (age >= 45 && age <= 54.5) {//50
            if (score >= 21 && score < 24) {
                resultScore = 5;
            } else if (score >= 24 && score < 34) {
                resultScore = 10;
            } else if (score >= 34 && score < 42) {
                resultScore = 25;
            } else if (score >= 42 && score < 48) {
                resultScore = 50;
            } else if (score >= 48 && score < 52) {
                resultScore = 75;
            } else if (score >= 52 && score < 54) {
                resultScore = 90;
            } else if (score >= 54) {
                resultScore = 95;
            }

        } else if (age >= 55 && age <= 64.5) {//60
            if (score >= 19 && score < 22) {
                resultScore = 5;
            } else if (score >= 22 && score < 30) {
                resultScore = 10;
            } else if (score >= 30 && score < 37) {
                resultScore = 25;
            } else if (score >= 37 && score < 46) {
                resultScore = 50;
            } else if (score >= 46 && score < 52) {
                resultScore = 75;
            } else if (score >= 52 && score < 54) {
                resultScore = 90;
            } else if (score >= 54) {
                resultScore = 95;
            }

        } else {//70
            if (score >= 17 && score < 18) {
                resultScore = 5;
            } else if (score >= 18 && score < 26) {
                resultScore = 10;
            } else if (score >= 26 && score < 33) {
                resultScore = 25;
            } else if (score >= 33 && score < 44) {
                resultScore = 50;
            } else if (score >= 44 && score < 49) {
                resultScore = 75;
            } else if (score >= 49 && score < 52) {
                resultScore = 90;
            } else if (score >= 52) {
                resultScore = 95;
            }
        }

        return resultScore;
    }

}
