|
@@ -1,5 +1,6 @@
|
|
|
package edu.math.diagnosis.service;
|
|
|
|
|
|
+import edu.math.diagnosis.config.Constants;
|
|
|
import edu.math.diagnosis.dao.PaperCommitRepo;
|
|
|
import edu.math.diagnosis.dao.PaperResultRepo;
|
|
|
import edu.math.diagnosis.entity.*;
|
|
@@ -10,14 +11,13 @@ import edu.math.diagnosis.util.ObjectUtil;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.security.core.parameters.P;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.LinkedHashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
|
public class PaperResultService {
|
|
@@ -31,6 +31,10 @@ public class PaperResultService {
|
|
|
private PaperService paperService;
|
|
|
@Resource
|
|
|
private KnowledgeService knowledgeService;
|
|
|
+ @Resource
|
|
|
+ private AbilityScoreService abilityScoreService;
|
|
|
+ @Resource
|
|
|
+ private SubjectAbilityService subjectAbilityService;
|
|
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(PaperResultService.class);
|
|
|
|
|
@@ -51,7 +55,7 @@ public class PaperResultService {
|
|
|
Map<String, Double> pData = ObjectUtil.json2Object(paper.getJsonScore(), Map.class);
|
|
|
//清空value为0
|
|
|
pData.keySet().forEach(d -> pData.put(d, 0d));
|
|
|
- final Double[] score = {0d};
|
|
|
+ double score = 0d;
|
|
|
for (Question q : questions) {
|
|
|
String ans = q.getAnswer();
|
|
|
if (StringUtils.isBlank(ans)) {
|
|
@@ -68,19 +72,20 @@ public class PaperResultService {
|
|
|
collectQuestion.add(q.getNumber());
|
|
|
String jsonScore = q.getJsonScore();
|
|
|
Map<String, Double> qData = ObjectUtil.json2Object(jsonScore, Map.class);
|
|
|
- pData.keySet().forEach(d -> {
|
|
|
+ //计算分数
|
|
|
+ for (String d : pData.keySet()) {
|
|
|
Double pData0 = qData.getOrDefault(d, 0d) + pData.get(d);
|
|
|
- score[0] += qData.getOrDefault(d, 0d);
|
|
|
+ score += qData.getOrDefault(d, 0d);
|
|
|
pData.put(d, pData0);
|
|
|
- });
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
result.setCollectQuestion(StringUtils.join(collectQuestion, ","));
|
|
|
result.setJsonScore(ObjectUtil.object2Json(pData));
|
|
|
//转换分数为百分制
|
|
|
double totalScore = paper.getTotalScore();
|
|
|
- double s = Double.parseDouble(NumberUtil.formatDouble(score[0] * 100 / totalScore));
|
|
|
- result.setScore(totalScore == 0 ? score[0] : s);
|
|
|
+ double s = NumberUtil.format(score * 100 / totalScore);
|
|
|
+ result.setScore(totalScore == 0 ? score : s);
|
|
|
result.setTotalScore(totalScore);
|
|
|
paperResultRepo.save(result);
|
|
|
logger.info("答案分析保存成功");
|
|
@@ -114,30 +119,188 @@ public class PaperResultService {
|
|
|
PaperCommit commit = paperCommitRepo.findByPidAndUid(r.getPid(), r.getUid());
|
|
|
Paper paper = paperService.getOnePaper(r.getPid());
|
|
|
//知识点掌握率
|
|
|
- r.setKnowledgeRate(88.88);
|
|
|
- r.setAbilityScore("{}");
|
|
|
+ r.setKnowledgeRate(knowledgeRate(r, paper));
|
|
|
+ r.setAbilityScore(abilityScore(r, paper));
|
|
|
+
|
|
|
}
|
|
|
|
|
|
- public Double knowledgeRate(PaperResult result,PaperCommit commit, Paper paper) {
|
|
|
+ /**
|
|
|
+ * 知识点掌握率 = 各知识点掌握数总和 / 总知识点数
|
|
|
+ * 知识点掌握 为 该知识点对应的题目都做对了
|
|
|
+ *
|
|
|
+ * @param result 试卷答题
|
|
|
+ * @param paper 试卷
|
|
|
+ * @return 知识点掌握率
|
|
|
+ */
|
|
|
+ public Double knowledgeRate(PaperResult result, Paper paper) {
|
|
|
+
|
|
|
+// Map<qid,tag> 定义为一对一 题目与知识点对应关系
|
|
|
+// Map<Long, String> tags = new LinkedHashMap<>();
|
|
|
+
|
|
|
+// Map<tag,num> 每个知识点的数量
|
|
|
+// Map<String, Integer> tagNum = new LinkedHashMap<>();
|
|
|
+// List<QuestionOption> options = questions.stream().map(Question::getOptions).flatMap(Collection::stream).collect(Collectors.toList());
|
|
|
+// questions.forEach(q -> tags.put(q.getId(), q.getTag()));
|
|
|
+
|
|
|
+ List<Integer> collects = convertCollectQuestion(result.getCollectQuestion());
|
|
|
+
|
|
|
+ //Map<tag,Set<number>> 知识点与题目对应
|
|
|
+ Map<String, Set<Integer>> tagNumbers = tagNumbers(paper);
|
|
|
+ //Map<tag,keep> 每个知识点的掌握情况
|
|
|
+ Map<String, Integer> tagKeep = tagKeep(collects, tagNumbers);
|
|
|
+
|
|
|
+ if (tagKeep.size() == 0) {
|
|
|
+ return 0D;
|
|
|
+ }
|
|
|
+ long count = tagKeep.values().stream().filter(t -> t == Constants.KNOWLEDGE_MASTER).count();
|
|
|
+
|
|
|
+ return NumberUtil.format(count * 100.0 / tagKeep.size());
|
|
|
+
|
|
|
+ //试卷的所有知识点
|
|
|
+// Set<String> tag = new HashSet<>(tags.values());
|
|
|
+
|
|
|
+ //
|
|
|
+// for (String c : collect) {
|
|
|
+// Question q = questionMap.get(Integer.valueOf(c));
|
|
|
+// }
|
|
|
+//
|
|
|
+// for (SubjectKnowledge k : knowledge) {
|
|
|
+// //每个知识点的能力标签
|
|
|
+// String abilityCodes = k.getAbilityCodes();
|
|
|
+// String[] codes = abilityCodes.split(",");
|
|
|
+// }
|
|
|
+// return 0d;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 能力分数
|
|
|
+ *
|
|
|
+ * @param result 提交的试卷
|
|
|
+ * @param paper 试卷
|
|
|
+ * @return {"计算能力":4.22,"转化能力":2.1}
|
|
|
+ */
|
|
|
+ public String abilityScore(PaperResult result, Paper paper) {
|
|
|
+
|
|
|
+ Map<String, String> abilityCodes = subjectAbilityService.map(paper.getSubjectId());
|
|
|
+ List<Integer> collectQuestion = convertCollectQuestion(result.getCollectQuestion());
|
|
|
+ //各能力分数 Map<code,Set<number>> 能力与题目编号
|
|
|
+// Map<String, Set<Integer>> codeNumber = new HashMap<>();
|
|
|
+
|
|
|
+ //Map<code,score> 各能力分数
|
|
|
+ Map<String, Double> codeScore = new HashMap<>();
|
|
|
+ //初始化能力分数
|
|
|
+ abilityCodes.keySet().forEach(e -> codeScore.put(e, 0d));
|
|
|
+
|
|
|
+ paper.getQuestions().forEach(q -> {
|
|
|
+ String jsonScore = q.getJsonScore();
|
|
|
+ Map<String, Double> scores = ObjectUtil.json2Map(jsonScore);
|
|
|
+// scores.forEach((code, score) -> {
|
|
|
+// if (score > 0) {
|
|
|
+// Set<Integer> number = codeNumber.getOrDefault(code, new HashSet<>());
|
|
|
+// number.add(q.getNumber());
|
|
|
+// codeNumber.put(code, number);
|
|
|
+// }
|
|
|
+// });
|
|
|
+ //如果这题做对了 分数累加
|
|
|
+ if (collectQuestion.contains(q.getNumber())) {
|
|
|
+ for (Map.Entry<String, Double> e : codeScore.entrySet()) {
|
|
|
+ e.setValue(e.getValue() + scores.get(e.getKey()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ //获取试卷的分数
|
|
|
+ Map<String, Double> paperJsonScore = ObjectUtil.json2Map(paper.getJsonScore());
|
|
|
+ Map<String, Double> d = new HashMap<>();
|
|
|
+ //将分数转化为最大值为5
|
|
|
+ for (Map.Entry<String, Double> e : codeScore.entrySet()) {
|
|
|
+ double s = e.getValue();
|
|
|
+ double score = NumberUtil.format(5 * s * 100.0 / paperJsonScore.get(e.getKey()));
|
|
|
+ d.put(abilityCodes.get(e.getKey()), score);
|
|
|
+ }
|
|
|
+ return ObjectUtil.object2Json(d);
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
- //知识点掌握率 = 各知识点掌握数总和 / 总知识点数
|
|
|
- //知识点掌握 为 该知识点对应的题目都做对了
|
|
|
+ /**
|
|
|
+ * 章节掌握情况
|
|
|
+ *
|
|
|
+ * @param result 提交的试卷
|
|
|
+ * @param paper 试卷
|
|
|
+ * @return [[1, 2, 0], [0, 0, 1]]
|
|
|
+ */
|
|
|
+ public String keepStatus(PaperResult result, Paper paper) {
|
|
|
+ List<List<Integer>> keepStatus = new ArrayList<>();
|
|
|
Long subjectId = paper.getSubjectId();
|
|
|
String grade = paper.getGrade();
|
|
|
List<SubjectKnowledge> knowledge = knowledgeService.list(subjectId, grade);
|
|
|
- //Map<qid,tag> 定义为一对一
|
|
|
- Map<Long, String> tags = new LinkedHashMap<>();
|
|
|
- List<Question> questions = paper.getQuestions();
|
|
|
- String collectOption = result.getCollectQuestion();
|
|
|
- String[] options = collectOption.split(",");
|
|
|
-// List<QuestionOption> options = questions.stream().map(Question::getOptions).flatMap(Collection::stream).collect(Collectors.toList());
|
|
|
- questions.forEach(q -> tags.put(q.getId(), q.getTag()));
|
|
|
+ //根据章节分组 Map<chapter,...>
|
|
|
+ Map<String, List<SubjectKnowledge>> group = knowledge.stream().collect(Collectors.groupingBy(SubjectKnowledge::getChapter));
|
|
|
+ List<Integer> collects = convertCollectQuestion(result.getCollectQuestion());
|
|
|
|
|
|
- for (SubjectKnowledge k : knowledge) {
|
|
|
- String abilityCodes = k.getAbilityCodes();
|
|
|
- String[]codes = abilityCodes.split(",");
|
|
|
- }
|
|
|
- return 0d;
|
|
|
+ //Map<tag,Set<number>> 知识点与题目对应
|
|
|
+ Map<String, Set<Integer>> tagNumbers = tagNumbers(paper);
|
|
|
+ //Map<tag,keep> 每个知识点的掌握情况
|
|
|
+ Map<String, Integer> tagKeep = tagKeep(collects, tagNumbers);
|
|
|
+ group.forEach((chapter, list) -> {
|
|
|
+ List<Integer> chapterKeep = new ArrayList<>();
|
|
|
+ list.forEach(k -> {
|
|
|
+ //找到知识点的掌握情况
|
|
|
+ int keep = tagKeep.getOrDefault(k.getCode(), 0);
|
|
|
+ chapterKeep.add(keep);
|
|
|
+ });
|
|
|
+ keepStatus.add(chapterKeep);
|
|
|
+ });
|
|
|
+ return ObjectUtil.object2Json(keepStatus);
|
|
|
}
|
|
|
|
|
|
+ public String chapterKeepRate(PaperResult result,Paper paper){
|
|
|
+ Map<String,Double> chapterKeepRate = new LinkedHashMap<>();
|
|
|
+ List<SubjectKnowledge> knowledge = knowledgeService.list(paper.getSubjectId(), paper.getGrade());
|
|
|
+ //根据章节分组 Map<chapter,...>
|
|
|
+ Map<String, List<SubjectKnowledge>> group = knowledge.stream().collect(Collectors.groupingBy(SubjectKnowledge::getChapter));
|
|
|
+ List<Integer> collects = convertCollectQuestion(result.getCollectQuestion());
|
|
|
+ //Map<tag,Set<number>> 知识点与题目对应
|
|
|
+ Map<String, Set<Integer>> tagNumbers = tagNumbers(paper);
|
|
|
+ //Map<tag,keep> 每个知识点的掌握情况
|
|
|
+ Map<String, Integer> tagKeep = tagKeep(collects, tagNumbers);
|
|
|
+
|
|
|
+ return "{}";
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private List<Integer> convertCollectQuestion(String collectQuestion) {
|
|
|
+ //获取答对的题目
|
|
|
+ String[] collect = collectQuestion.split(",");
|
|
|
+ //转换成整型
|
|
|
+ return Arrays.stream(collect).map(Integer::valueOf).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ private Map<String, Set<Integer>> tagNumbers(Paper paper) {
|
|
|
+ Map<String, Set<Integer>> tagNumbers = new LinkedHashMap<>();
|
|
|
+ paper.getQuestions().forEach(q -> {
|
|
|
+ String tag = q.getTag();
|
|
|
+// tagNum.put(tag, tagNum.getOrDefault(tag, 0) + 1);
|
|
|
+ Set<Integer> number = tagNumbers.getOrDefault(tag, new HashSet<>());
|
|
|
+ number.add(q.getNumber());
|
|
|
+ tagNumbers.put(tag, number);
|
|
|
+ });
|
|
|
+ return tagNumbers;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Map<String, Integer> tagKeep(List<Integer> collects, Map<String, Set<Integer>> tagNumbers) {
|
|
|
+ Map<String, Integer> tagKeep = new LinkedHashMap<>();
|
|
|
+ for (Map.Entry<String, Set<Integer>> entry : tagNumbers.entrySet()) {
|
|
|
+ Set<Integer> number = entry.getValue();
|
|
|
+ int right = Constants.KNOWLEDGE_NOT_MASTER;
|
|
|
+ if (collects.containsAll(number)) {
|
|
|
+ right = Constants.KNOWLEDGE_MASTER;
|
|
|
+ } else if (number.stream().anyMatch(collects::contains)) {
|
|
|
+ right = Constants.KNOWLEDGE_LACK;
|
|
|
+ }
|
|
|
+ tagKeep.put(entry.getKey(), right);
|
|
|
+ }
|
|
|
+ return tagKeep;
|
|
|
+ }
|
|
|
}
|