|
@@ -3,6 +3,7 @@ package cn.iselab.mooctest.site.web.logic.impl;
|
|
import cn.iselab.mooctest.site.data.GeneralGradeDTO;
|
|
import cn.iselab.mooctest.site.data.GeneralGradeDTO;
|
|
import cn.iselab.mooctest.site.data.NodeExtends;
|
|
import cn.iselab.mooctest.site.data.NodeExtends;
|
|
import cn.iselab.mooctest.site.service.*;
|
|
import cn.iselab.mooctest.site.service.*;
|
|
|
|
+import cn.iselab.mooctest.site.util.data.CacheUtil;
|
|
import cn.iselab.mooctest.site.util.data.JSONUtil;
|
|
import cn.iselab.mooctest.site.util.data.JSONUtil;
|
|
import cn.iselab.mooctest.site.web.data.forMongo.CaseGraphDTO;
|
|
import cn.iselab.mooctest.site.web.data.forMongo.CaseGraphDTO;
|
|
import cn.iselab.mooctest.site.web.data.forMongo.NodeCatch.CatchDTO;
|
|
import cn.iselab.mooctest.site.web.data.forMongo.NodeCatch.CatchDTO;
|
|
@@ -12,6 +13,7 @@ import cn.iselab.mooctest.site.web.data.forMongo.graph.Node;
|
|
import cn.iselab.mooctest.site.web.logic.strategy.HighestStrategy;
|
|
import cn.iselab.mooctest.site.web.logic.strategy.HighestStrategy;
|
|
import cn.iselab.mooctest.site.web.logic.strategy.LatestStrategy;
|
|
import cn.iselab.mooctest.site.web.logic.strategy.LatestStrategy;
|
|
import cn.iselab.mooctest.site.web.logic.strategy.ScoreStrategy;
|
|
import cn.iselab.mooctest.site.web.logic.strategy.ScoreStrategy;
|
|
|
|
+import java.util.stream.Collectors;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.scheduling.annotation.Async;
|
|
import org.springframework.scheduling.annotation.Async;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
@@ -32,9 +34,6 @@ import java.util.Map;
|
|
@Component
|
|
@Component
|
|
public class GeneralCalculateScoreComponent {
|
|
public class GeneralCalculateScoreComponent {
|
|
|
|
|
|
- //获取元node服务
|
|
|
|
- @Autowired
|
|
|
|
- CaseGraphService caseGraphService;
|
|
|
|
//获取被命中nodes的服务
|
|
//获取被命中nodes的服务
|
|
@Autowired
|
|
@Autowired
|
|
CaughtNodeService caughtNodeService;
|
|
CaughtNodeService caughtNodeService;
|
|
@@ -54,6 +53,8 @@ public class GeneralCalculateScoreComponent {
|
|
HighestStrategy highestStrategy;
|
|
HighestStrategy highestStrategy;
|
|
@Autowired
|
|
@Autowired
|
|
CatchService catchService;
|
|
CatchService catchService;
|
|
|
|
+ @Autowired
|
|
|
|
+ CacheUtil cacheUtil;
|
|
|
|
|
|
public void calculateGrade(long examId, long caseId, Long userId, String source) throws Exception {
|
|
public void calculateGrade(long examId, long caseId, Long userId, String source) throws Exception {
|
|
recordTypeScore(examId, caseId, userId, source);
|
|
recordTypeScore(examId, caseId, userId, source);
|
|
@@ -66,6 +67,23 @@ public class GeneralCalculateScoreComponent {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private void calculateGradeCurrent(long examId, long caseId, long userId, String source, String
|
|
|
|
+ uploadTime, List<CaughtNodeDTO> caughtNodeDTOS) throws Exception {
|
|
|
|
+
|
|
|
|
+ CaseGraphDTO basicNode = cacheUtil.getMetaNode(caseId);
|
|
|
|
+ List<CatchDTO> catchDTOS = caughtNodeDTOS.stream().filter
|
|
|
|
+ (CaughtNodeDTO::getIfCatch).map(x -> new CatchDTO(x.getNodeName(),x.getCategory()
|
|
|
|
+ ,null)).collect(Collectors.toList());
|
|
|
|
+ Map<String, Double> typeScoreMap = calculateTypeScore(basicNode,catchDTOS);
|
|
|
|
+ List<GeneralGradeDTO> gradeDTOList = new ArrayList<>();
|
|
|
|
+ typeScoreMap.forEach((type,score) -> gradeDTOList.add(new GeneralGradeDTO(userId,examId,
|
|
|
|
+ caseId,type,score,uploadTime,source)));
|
|
|
|
+
|
|
|
|
+ generalCalculateScoreService.updateTypeGrade(gradeDTOList);
|
|
|
|
+
|
|
|
|
+ calculateCaseScore(examId, caseId, userId);
|
|
|
|
+ }
|
|
|
|
+
|
|
private void recordTypeScore(long examId, long caseId, Long userId, String
|
|
private void recordTypeScore(long examId, long caseId, Long userId, String
|
|
source) throws Exception {
|
|
source) throws Exception {
|
|
|
|
|
|
@@ -98,28 +116,14 @@ public class GeneralCalculateScoreComponent {
|
|
|
|
|
|
List<GeneralGradeDTO> generalGradeDTOList = new ArrayList<>();
|
|
List<GeneralGradeDTO> generalGradeDTOList = new ArrayList<>();
|
|
//元node数据
|
|
//元node数据
|
|
- CaseGraphDTO basicNode = caseGraphService.getCaseGraph(caseId);
|
|
|
|
|
|
+ CaseGraphDTO basicNode = cacheUtil.getMetaNode(caseId);
|
|
|
|
|
|
if (basicNode != null && userCatchDTOS != null && userCatchDTOS.size() != 0) {
|
|
if (basicNode != null && userCatchDTOS != null && userCatchDTOS.size() != 0) {
|
|
for (UserCatchDTO userCatchDTO : userCatchDTOS) {
|
|
for (UserCatchDTO userCatchDTO : userCatchDTOS) {
|
|
String id = userCatchDTO.getLatestId();
|
|
String id = userCatchDTO.getLatestId();
|
|
List<CatchDTO> catchDTOs = catchService.findById(id);
|
|
List<CatchDTO> catchDTOs = catchService.findById(id);
|
|
- Map<String, Double> typeScoreMap = new HashMap<>();
|
|
|
|
- for (Node node : basicNode.getNodes()) {
|
|
|
|
- for (CatchDTO catchDTO : catchDTOs) {
|
|
|
|
- if (node.getName().equals(catchDTO.getNodeName())) {//用户命中了该node
|
|
|
|
- double scoreGot = 0;
|
|
|
|
- String key = node.getCategory();
|
|
|
|
- if (typeScoreMap.containsKey(key)) {
|
|
|
|
- scoreGot = typeScoreMap.get(key);
|
|
|
|
- }
|
|
|
|
- //获取权重
|
|
|
|
- double singleNodeWeight = getNodeWeight(basicNode, node);
|
|
|
|
- typeScoreMap.put(key, scoreGot + singleNodeWeight);
|
|
|
|
- break;//一旦找到命中node则跳出,无需继续遍历
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+
|
|
|
|
+ Map<String, Double> typeScoreMap = calculateTypeScore(basicNode,catchDTOs);
|
|
|
|
|
|
for (String key : typeScoreMap.keySet()) {
|
|
for (String key : typeScoreMap.keySet()) {
|
|
String uploadTime = catchDTOs.get(0).getUploadTime();
|
|
String uploadTime = catchDTOs.get(0).getUploadTime();
|
|
@@ -128,18 +132,38 @@ public class GeneralCalculateScoreComponent {
|
|
.get(key), uploadTime, "");
|
|
.get(key), uploadTime, "");
|
|
generalGradeDTOList.add(generalGradeDTO);
|
|
generalGradeDTOList.add(generalGradeDTO);
|
|
}
|
|
}
|
|
-
|
|
|
|
-// typeScoreMap.keySet().forEach(type -> {
|
|
|
|
-// GeneralGradeDTO generalGradeDTO = new GeneralGradeDTO(userCatchDTO.getUserId
|
|
|
|
-// (), userCatchDTO.getExamId(), userCatchDTO.getCaseId(), type, typeScoreMap
|
|
|
|
-// .get(type), userCatchDTO.getLatestDTOS().get(0).getUploadTime(), "");
|
|
|
|
-// generalGradeDTOList.add(generalGradeDTO);
|
|
|
|
-// });
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return generalGradeDTOList;
|
|
return generalGradeDTOList;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private Map<String, Double> calculateTypeScore(CaseGraphDTO basicNode, List<CatchDTO>
|
|
|
|
+ catchDTOS){
|
|
|
|
+ if(basicNode ==null || catchDTOS == null){
|
|
|
|
+ return new HashMap<>();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Map<String, Double> typeScoreMap = new HashMap<>();
|
|
|
|
+ for (Node node : basicNode.getNodes()) {
|
|
|
|
+ for (CatchDTO catchDTO : catchDTOS) {
|
|
|
|
+ if (node.getName().equals(catchDTO.getNodeName())) {//用户命中了该node
|
|
|
|
+ double scoreGot = 0;
|
|
|
|
+ String key = node.getCategory();
|
|
|
|
+ if (typeScoreMap.containsKey(key)) {
|
|
|
|
+ scoreGot = typeScoreMap.get(key);
|
|
|
|
+ }
|
|
|
|
+ //获取权重
|
|
|
|
+ double singleNodeWeight = getNodeWeight(basicNode, node);
|
|
|
|
+ typeScoreMap.put(key, scoreGot + singleNodeWeight);
|
|
|
|
+ break;//一旦找到命中node则跳出,无需继续遍历
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return typeScoreMap;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
|
|
/**
|
|
/**
|
|
* 获取node节点的权重
|
|
* 获取node节点的权重
|
|
@@ -204,47 +228,48 @@ public class GeneralCalculateScoreComponent {
|
|
|
|
|
|
@Async("calculateGradeAsync")
|
|
@Async("calculateGradeAsync")
|
|
public void saveCaughtDetails(Long examId, Long caseId, Long userId, String
|
|
public void saveCaughtDetails(Long examId, Long caseId, Long userId, String
|
|
- source, List<CaughtNodeDTO> caughtNodeDTOs) throws Exception {
|
|
|
|
-
|
|
|
|
- List<CaughtNodeDTO> caughtNodeDTOList = caughtNodeService.getCaughtNodeList(examId, caseId);
|
|
|
|
- if (caughtNodeDTOList == null) {
|
|
|
|
- List<CaughtNodeDTO> cns = new ArrayList<>();
|
|
|
|
- for (CaughtNodeDTO cn : caughtNodeDTOs) {
|
|
|
|
- List<Long> userIds = new ArrayList<>();
|
|
|
|
- userIds.add(userId);
|
|
|
|
-
|
|
|
|
- cn.setNodeName(cn.getNodeName());
|
|
|
|
- cn.setExamId(examId);
|
|
|
|
- cn.setCaseId(caseId);
|
|
|
|
- cn.setIfCatch(cn.getIfCatch());
|
|
|
|
-
|
|
|
|
- if (cn.getIfCatch().equals(Boolean.TRUE)) {
|
|
|
|
- cn.setCatchNum(1);
|
|
|
|
- cn.setUserIds(userIds);
|
|
|
|
- } else {
|
|
|
|
- cn.setCatchNum(0);
|
|
|
|
- cn.setUserIds(new ArrayList<>());
|
|
|
|
- }
|
|
|
|
- cn.setTotalNum(1);
|
|
|
|
- cn.setCategory(cn.getCategory());
|
|
|
|
- cns.add(cn);
|
|
|
|
- }
|
|
|
|
- caughtNodeService.bulkCreateCaughtNodeDTOs(cns);
|
|
|
|
- } else {
|
|
|
|
- //更新totalNum
|
|
|
|
- caughtNodeService.bulkUpdateAllCaughtNode(examId, caseId);
|
|
|
|
-
|
|
|
|
- //更新catch到的node
|
|
|
|
- List<String> nodeNameList = new ArrayList<>();
|
|
|
|
- for (CaughtNodeDTO caughtNodeDTO : caughtNodeDTOs) {
|
|
|
|
- if (caughtNodeDTO.getIfCatch().equals(Boolean.TRUE)) {
|
|
|
|
- String nodeName = caughtNodeDTO.getNodeName();
|
|
|
|
- nodeNameList.add(nodeName);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- caughtNodeService.bulkUpdateCaughtNodes(examId, caseId, nodeNameList, userId);
|
|
|
|
- }
|
|
|
|
- calculateGrade(examId, caseId, userId, source);
|
|
|
|
|
|
+ source,String uploadTime, List<CaughtNodeDTO> caughtNodeDTOs) throws Exception {
|
|
|
|
+
|
|
|
|
+// List<CaughtNodeDTO> caughtNodeDTOList = caughtNodeService.getCaughtNodeList(examId, caseId);
|
|
|
|
+// if (caughtNodeDTOList == null) {
|
|
|
|
+// List<CaughtNodeDTO> cns = new ArrayList<>();
|
|
|
|
+// for (CaughtNodeDTO cn : caughtNodeDTOs) {
|
|
|
|
+// List<Long> userIds = new ArrayList<>();
|
|
|
|
+// userIds.add(userId);
|
|
|
|
+//
|
|
|
|
+// cn.setNodeName(cn.getNodeName());
|
|
|
|
+// cn.setExamId(examId);
|
|
|
|
+// cn.setCaseId(caseId);
|
|
|
|
+// cn.setIfCatch(cn.getIfCatch());
|
|
|
|
+//
|
|
|
|
+// if (cn.getIfCatch().equals(Boolean.TRUE)) {
|
|
|
|
+// cn.setCatchNum(1);
|
|
|
|
+// cn.setUserIds(userIds);
|
|
|
|
+// } else {
|
|
|
|
+// cn.setCatchNum(0);
|
|
|
|
+// cn.setUserIds(new ArrayList<>());
|
|
|
|
+// }
|
|
|
|
+// cn.setTotalNum(1);
|
|
|
|
+// cn.setCategory(cn.getCategory());
|
|
|
|
+// cns.add(cn);
|
|
|
|
+// }
|
|
|
|
+// caughtNodeService.bulkCreateCaughtNodeDTOs(cns);
|
|
|
|
+// } else {
|
|
|
|
+// //更新totalNum
|
|
|
|
+// caughtNodeService.bulkUpdateAllCaughtNode(examId, caseId);
|
|
|
|
+//
|
|
|
|
+// //更新catch到的node
|
|
|
|
+// List<String> nodeNameList = new ArrayList<>();
|
|
|
|
+// for (CaughtNodeDTO caughtNodeDTO : caughtNodeDTOs) {
|
|
|
|
+// if (caughtNodeDTO.getIfCatch().equals(Boolean.TRUE)) {
|
|
|
|
+// String nodeName = caughtNodeDTO.getNodeName();
|
|
|
|
+// nodeNameList.add(nodeName);
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// caughtNodeService.bulkUpdateCaughtNodes(examId, caseId, nodeNameList, userId);
|
|
|
|
+// }
|
|
|
|
+// calculateGrade(examId, caseId, userId, source);
|
|
|
|
+ calculateGradeCurrent(examId,caseId,userId,source,uploadTime, caughtNodeDTOs);
|
|
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|