|
@@ -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);
|
|
|
|
|
|
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) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ List<Integer> collects = convertCollectQuestion(result.getCollectQuestion());
|
|
|
+
|
|
|
+
|
|
|
+ Map<String, Set<Integer>> tagNumbers = tagNumbers(paper);
|
|
|
+
|
|
|
+ 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());
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ * 能力分数
|
|
|
+ *
|
|
|
+ * @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<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);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ 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<>();
|
|
|
+
|
|
|
+ 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<Long, String> tags = new LinkedHashMap<>();
|
|
|
- List<Question> questions = paper.getQuestions();
|
|
|
- String collectOption = result.getCollectQuestion();
|
|
|
- String[] options = collectOption.split(",");
|
|
|
-
|
|
|
- questions.forEach(q -> tags.put(q.getId(), q.getTag()));
|
|
|
+
|
|
|
+ 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<String, Set<Integer>> tagNumbers = tagNumbers(paper);
|
|
|
+
|
|
|
+ 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<String, List<SubjectKnowledge>> group = knowledge.stream().collect(Collectors.groupingBy(SubjectKnowledge::getChapter));
|
|
|
+ List<Integer> collects = convertCollectQuestion(result.getCollectQuestion());
|
|
|
+
|
|
|
+ Map<String, Set<Integer>> tagNumbers = tagNumbers(paper);
|
|
|
+
|
|
|
+ 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();
|
|
|
+
|
|
|
+ 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;
|
|
|
+ }
|
|
|
}
|