|
@@ -14,6 +14,8 @@ import java.text.DecimalFormat;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
+import static com.rf.psychological.scale.resultBusiness.scaleResult.NEWCOMMONScale.commonComputeDimensionScore;
|
|
|
+
|
|
|
/**
|
|
|
* @Author: GaoYiXuan
|
|
|
* @Description:卡特尔16PF测试
|
|
@@ -27,7 +29,7 @@ public class C16PFTScale extends BaseScale {
|
|
|
super(jsonArray, resultJson);
|
|
|
}
|
|
|
|
|
|
- public JSONObject scaleCalculate() throws Exception {
|
|
|
+ /*public JSONObject scaleCalculate() throws Exception {
|
|
|
//总分
|
|
|
double score = 0;
|
|
|
DecimalFormat df = new DecimalFormat("######0.00");
|
|
@@ -216,16 +218,139 @@ public class C16PFTScale extends BaseScale {
|
|
|
returnJson.put(ScaleConstant.ResultEnum.RESULT_NEW_FIELD.getKeyword(), newResult);
|
|
|
|
|
|
return returnJson;
|
|
|
- }
|
|
|
+ }*/
|
|
|
+
|
|
|
+ public JSONObject scaleCalculate() throws Exception {
|
|
|
+ //总分
|
|
|
+ double score = 0;
|
|
|
+ DecimalFormat df = new DecimalFormat("######0.00");
|
|
|
+
|
|
|
+ Map<String, String> resultMap0 = new LinkedHashMap<>();
|
|
|
+ List<Map<String, String>> resultMapList = new ArrayList<>();
|
|
|
+ //新版本数据格式
|
|
|
+ Map<String, Object> newResult = new LinkedHashMap<>();
|
|
|
|
|
|
- private static void putDimResult(Map<String, String> resultMap0, JSONObject resultJson, DimensionEntity dimensionEntity, NewResultDto newResultDto1, ScaleMarksEntity scaleMarksEntity) {
|
|
|
- resultMap0.put(dimensionEntity.getName() + "常模参考值", scaleMarksEntity.getReference());
|
|
|
- resultMap0.put(dimensionEntity.getName() + "症状", scaleMarksEntity.getSymptom());
|
|
|
- resultJson.put(dimensionEntity.getName() + "结论", scaleMarksEntity.getSymptom());
|
|
|
- resultMap0.put(dimensionEntity.getName() + "因子解释", scaleMarksEntity.getNameExplain());
|
|
|
- resultMap0.put(dimensionEntity.getName() + "指导语", scaleMarksEntity.getImprovementSuggestions());
|
|
|
- resultJson.put(dimensionEntity.getName() + "指导语", scaleMarksEntity.getImprovementSuggestions());
|
|
|
- resultMap0.put(dimensionEntity.getName() + "建议", scaleMarksEntity.getSuggestion());
|
|
|
- BeanUtils.copyProperties(scaleMarksEntity, newResultDto1);
|
|
|
+ //获取答案列表
|
|
|
+ List<AnswerEntity> answerEntities = (List<AnswerEntity>) resultJson.get("answerEntities");
|
|
|
+ //获取评分规则列表
|
|
|
+ List<ScaleMarksEntity> scaleMarksEntities = (List<ScaleMarksEntity>) resultJson.get("scaleMarksEntities");
|
|
|
+ //获取维度信息列表
|
|
|
+ List<DimensionEntity> dimensionEntities = (List<DimensionEntity>) resultJson.get("dimensionEntities");
|
|
|
+ //计算每个维度得分dimensionEntities
|
|
|
+ double[] dimensionScore = new double[dimensionEntities.size()];
|
|
|
+ Map<String,Double> dimensionScoreMap = new HashMap<>();
|
|
|
+ //jsonArray:用户自己选择的题目选项
|
|
|
+ for (int i = 0; i < jsonArray.size(); i++) {
|
|
|
+ JSONObject jsonObject1 = jsonArray.getJSONObject(i);
|
|
|
+ //计算总分
|
|
|
+ for (AnswerEntity answerEntity : answerEntities) {
|
|
|
+ if (answerEntity.getQuestionNo().equals(jsonObject1.getString("questionNo"))) {
|
|
|
+ if (answerEntity.getName().replaceAll("\\s", "").equals(jsonObject1.getString("checkItems").replaceAll("\\s", ""))) {
|
|
|
+ score += Double.parseDouble(answerEntity.getScore());
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //计算维度分数
|
|
|
+ for (int y = 0; y < dimensionEntities.size(); y++) {
|
|
|
+ //获取维度信息
|
|
|
+ DimensionEntity dimensionEntity = dimensionEntities.get(y);
|
|
|
+ //获取该维度下有哪些选项
|
|
|
+ String questionNos = dimensionEntity.getQuestionNo();
|
|
|
+ //删除空白字符后得到进行划分得到选择题号
|
|
|
+ String[] questionNo = questionNos.replaceAll("\\s", "").split(";");
|
|
|
+ //计算每道题的得分
|
|
|
+ for (String question : questionNo) {
|
|
|
+ if (question.equals(jsonObject1.getString("questionNo"))) {
|
|
|
+ //获取所有答案中本道题目的答案list数组
|
|
|
+ List<AnswerEntity> nowQuestionAnswerList = answerEntities.stream().filter(answerEntity -> answerEntity.getQuestionNo().equals(question)).collect(Collectors.toList());
|
|
|
+ //本题目的正确答案与自己的选项进行对比,正确的话相应分数进行相加
|
|
|
+ for (AnswerEntity answerEntity : nowQuestionAnswerList) {
|
|
|
+ if (answerEntity.getName().replaceAll("\\s", "").equals(jsonObject1.getString("checkItems").replaceAll("\\s", ""))) {
|
|
|
+ dimensionScoreMap.put(dimensionEntity.getId(),dimensionScoreMap.get(dimensionEntity.getId())==null?Double.parseDouble(answerEntity.getScore()):(dimensionScoreMap.get(dimensionEntity.getId()) +Double.parseDouble(answerEntity.getScore())));
|
|
|
+ dimensionScore[y] += Double.parseDouble(answerEntity.getScore());
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ resultJson.put("dimensionScoreMap",dimensionScoreMap);
|
|
|
+ }
|
|
|
+ //计算标准分
|
|
|
+ for (int y = 0; y < dimensionEntities.size(); y++) {
|
|
|
+ for (int i = 0; i < scaleMarksEntities.size(); i++) {
|
|
|
+ if (dimensionEntities.get(y).getName().equals(scaleMarksEntities.get(i).getName())) {
|
|
|
+ String[] splits = scaleMarksEntities.get(i).getReference().split("±");
|
|
|
+ double a = Double.valueOf(splits[0]);
|
|
|
+ double b = Double.valueOf(splits[1]);
|
|
|
+ dimensionScore[y] = Math.floor(((dimensionScore[y] - a)/b)*1.5 + 5.5);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //返回值以及存数据库格式
|
|
|
+ List<NewResultDto> newResultDtos = new ArrayList<>();
|
|
|
+
|
|
|
+ //判断最高分
|
|
|
+ double[] dimensionScores = new double[dimensionScore.length];
|
|
|
+ for (int y = 0; y < dimensionScore.length; y++) {
|
|
|
+ dimensionScores[y] = dimensionScore[y];
|
|
|
+ }
|
|
|
+ Arrays.sort(dimensionScores);
|
|
|
+ JSONObject jsonObject = new JSONObject(true);
|
|
|
+ for (int y = 0; y < dimensionScore.length; y++) {
|
|
|
+ if (dimensionScore[y] == dimensionScores[dimensionScores.length-1]){
|
|
|
+ jsonObject.put(dimensionEntities.get(y).getName(),dimensionScores[dimensionScores.length-1]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Set<String> keys = jsonObject.keySet();
|
|
|
+ List<DimensionEntity> dimensionEntitieList = new ArrayList<>();
|
|
|
+ int b = 0;
|
|
|
+ for (String key : keys) {
|
|
|
+ for (DimensionEntity dimensionEntity : dimensionEntities) {
|
|
|
+ if (dimensionEntity.getName().equals(key)){
|
|
|
+ dimensionEntitieList.add(dimensionEntity);
|
|
|
+ dimensionScore[b] = jsonObject.getInteger(key);
|
|
|
+ b++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //将量表总维度根据维度名称进行分组
|
|
|
+ Map<String, List<ScaleMarksEntity>> scaleMarksMap = scaleMarksEntities.stream().collect(Collectors.groupingBy(ScaleMarksEntity::getName));
|
|
|
+ JSONObject iconInfo = new JSONObject();
|
|
|
+ //雷达图需要的维度以及最大值
|
|
|
+ List<Map<String, Object>> indicator = new LinkedList<>();
|
|
|
+ //雷达图所需要的常模参考值
|
|
|
+ LinkedList<String> reference = new LinkedList<>();
|
|
|
+ //雷达图需要的分数
|
|
|
+ LinkedList<String> scoreList = new LinkedList<>();
|
|
|
+ //计算维度所在评分区间
|
|
|
+ commonComputeDimensionScore(df, resultMap0, resultJson, dimensionEntitieList, dimensionScore, scaleMarksMap, newResultDtos, indicator, reference, scoreList);
|
|
|
+ //需要图表展示的
|
|
|
+ iconInfo.put("indicator", indicator);
|
|
|
+ //判断是否有常模参考值,即reference的内容如果全为0,则不进行返回
|
|
|
+ if (!reference.stream().allMatch("0"::equals)) {
|
|
|
+ iconInfo.put("reference", reference);
|
|
|
+ }
|
|
|
+ iconInfo.put("scoreList", scoreList);
|
|
|
+ if (indicator.size() == 0 && reference.size() == 0) {
|
|
|
+ newResult.put("iconInfo", "");
|
|
|
+ } else {
|
|
|
+ newResult.put("iconInfo", iconInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ newResult.put("result", newResultDtos);
|
|
|
+ resultMapList.add(resultMap0);
|
|
|
+ JSONObject returnJson = new JSONObject(true);
|
|
|
+ returnJson.put("resultMapList", resultMapList);
|
|
|
+ returnJson.put("resultJson", resultJson);
|
|
|
+ returnJson.put(ScaleConstant.ResultEnum.RESULT_NEW_FIELD.getKeyword(), newResult);
|
|
|
+
|
|
|
+
|
|
|
+ return returnJson;
|
|
|
}
|
|
|
}
|