|
@@ -2,17 +2,26 @@ 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.data.UploadRecordDTO;
|
|
|
|
+import cn.iselab.mooctest.site.models.UploadRecord;
|
|
import cn.iselab.mooctest.site.service.*;
|
|
import cn.iselab.mooctest.site.service.*;
|
|
|
|
+import cn.iselab.mooctest.site.util.BeanFactory;
|
|
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;
|
|
import cn.iselab.mooctest.site.web.data.forMongo.NodeCatch.CaughtNodeDTO;
|
|
import cn.iselab.mooctest.site.web.data.forMongo.NodeCatch.CaughtNodeDTO;
|
|
import cn.iselab.mooctest.site.web.data.forMongo.NodeCatch.UserCatchDTO;
|
|
import cn.iselab.mooctest.site.web.data.forMongo.NodeCatch.UserCatchDTO;
|
|
import cn.iselab.mooctest.site.web.data.forMongo.graph.Node;
|
|
import cn.iselab.mooctest.site.web.data.forMongo.graph.Node;
|
|
|
|
+import cn.iselab.mooctest.site.web.data.response.ServerCode;
|
|
|
|
+import cn.iselab.mooctest.site.web.exception.ServerException;
|
|
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 lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.context.ApplicationContext;
|
|
|
|
+import org.springframework.context.annotation.Scope;
|
|
import org.springframework.scheduling.annotation.Async;
|
|
import org.springframework.scheduling.annotation.Async;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
@@ -30,9 +39,10 @@ import java.util.Map;
|
|
* @create 2018-03-14 11:18
|
|
* @create 2018-03-14 11:18
|
|
*/
|
|
*/
|
|
@Component
|
|
@Component
|
|
|
|
+@Slf4j
|
|
public class GeneralCalculateScoreComponent {
|
|
public class GeneralCalculateScoreComponent {
|
|
|
|
|
|
- //获取元node服务
|
|
|
|
|
|
+// 获取元node服务
|
|
@Autowired
|
|
@Autowired
|
|
CaseGraphService caseGraphService;
|
|
CaseGraphService caseGraphService;
|
|
//获取被命中nodes的服务
|
|
//获取被命中nodes的服务
|
|
@@ -55,8 +65,11 @@ public class GeneralCalculateScoreComponent {
|
|
@Autowired
|
|
@Autowired
|
|
CatchService catchService;
|
|
CatchService catchService;
|
|
|
|
|
|
- public void calculateGrade(long examId, long caseId, Long userId, String source) throws Exception {
|
|
|
|
- recordTypeScore(examId, caseId, userId, source);
|
|
|
|
|
|
+ private static Map<Long, CaseGraphDTO> basicNodeMap = new HashMap<>();
|
|
|
|
+
|
|
|
|
+ public void calculateGrade(long examId, long caseId, Long userId) throws
|
|
|
|
+ Exception {
|
|
|
|
+ recordTypeScore(examId, caseId, userId);
|
|
if (userId != null) {
|
|
if (userId != null) {
|
|
calculateCaseScore(examId, caseId, userId);
|
|
calculateCaseScore(examId, caseId, userId);
|
|
} else { //计算所有人的分数
|
|
} else { //计算所有人的分数
|
|
@@ -66,8 +79,32 @@ public class GeneralCalculateScoreComponent {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- private void recordTypeScore(long examId, long caseId, Long userId, String
|
|
|
|
- source) throws Exception {
|
|
|
|
|
|
+ //计算当即提交的node的得分
|
|
|
|
+ public void calculateGradeCurrent(Long uploadId, long examId, long caseId, long userId,
|
|
|
|
+ List<CaughtNodeDTO> caughtNodeDTOS)
|
|
|
|
+ throws Exception {
|
|
|
|
+
|
|
|
|
+ //过滤没有catch的node,并将catch住的node转换为CatchDTO
|
|
|
|
+ List<CatchDTO> catchDTOS = caughtNodeDTOS.stream().filter
|
|
|
|
+ (CaughtNodeDTO::getIfCatch).map(x -> new CatchDTO(x.getNodeName(),x.getCategory()
|
|
|
|
+ ,null)).collect(Collectors.toList());
|
|
|
|
+
|
|
|
|
+ //通过元node和CatchDTOs计算每种类型的得分
|
|
|
|
+ CaseGraphDTO basicNode = getBasicNode(caseId);
|
|
|
|
+ Map<String, Double> typeScoreMap = calculateTypeScore(basicNode,catchDTOS);
|
|
|
|
+ List<GeneralGradeDTO> gradeDTOList = new ArrayList<>();
|
|
|
|
+ typeScoreMap.forEach((type,score) -> gradeDTOList.add(new GeneralGradeDTO(type,score,uploadId)));
|
|
|
|
+
|
|
|
|
+ //记录每种类型的得分
|
|
|
|
+ generalCalculateScoreService.updateTypeGrade(gradeDTOList);
|
|
|
|
+
|
|
|
|
+ //计算该case的得分
|
|
|
|
+ calculateCaseScore(examId, caseId, userId);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //非当即分数记录
|
|
|
|
+ private void recordTypeScore(long examId, long caseId, Long userId) throws
|
|
|
|
+ Exception {
|
|
|
|
|
|
List<UserCatchDTO> userCatchDTOList;
|
|
List<UserCatchDTO> userCatchDTOList;
|
|
if (userId == null) {
|
|
if (userId == null) {
|
|
@@ -75,10 +112,8 @@ public class GeneralCalculateScoreComponent {
|
|
} else {
|
|
} else {
|
|
userCatchDTOList = userCatchService.getUserCatchDTOs(userId, examId, caseId);
|
|
userCatchDTOList = userCatchService.getUserCatchDTOs(userId, examId, caseId);
|
|
}
|
|
}
|
|
-
|
|
|
|
List<GeneralGradeDTO> gradeDTOList = calculateTypeScore(caseId, userCatchDTOList);
|
|
List<GeneralGradeDTO> gradeDTOList = calculateTypeScore(caseId, userCatchDTOList);
|
|
if (gradeDTOList != null) {
|
|
if (gradeDTOList != null) {
|
|
- gradeDTOList.forEach(x -> x.setSource(source));
|
|
|
|
generalCalculateScoreService.updateTypeGrade(gradeDTOList);
|
|
generalCalculateScoreService.updateTypeGrade(gradeDTOList);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -97,49 +132,53 @@ public class GeneralCalculateScoreComponent {
|
|
List<UserCatchDTO> userCatchDTOS) throws Exception {
|
|
List<UserCatchDTO> userCatchDTOS) throws Exception {
|
|
|
|
|
|
List<GeneralGradeDTO> generalGradeDTOList = new ArrayList<>();
|
|
List<GeneralGradeDTO> generalGradeDTOList = new ArrayList<>();
|
|
|
|
+
|
|
//元node数据
|
|
//元node数据
|
|
- CaseGraphDTO basicNode = caseGraphService.getCaseGraph(caseId);
|
|
|
|
|
|
+ CaseGraphDTO basicNode = getBasicNode(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);
|
|
|
|
+ UploadRecordDTO uploadRecordDTO = generalCalculateScoreService.getUploadRecord
|
|
|
|
+ (userCatchDTO.getUserId(),userCatchDTO.getExamId(),userCatchDTO.getCaseId
|
|
|
|
+ (),catchDTOs.get(0).getUploadTime());
|
|
|
|
+ if(uploadRecordDTO == null){
|
|
|
|
+ throw new ServerException(ServerCode.SYSTEM_ERROR.getCode(),"上传记录不存在");
|
|
}
|
|
}
|
|
-
|
|
|
|
for (String key : typeScoreMap.keySet()) {
|
|
for (String key : typeScoreMap.keySet()) {
|
|
- String uploadTime = catchDTOs.get(0).getUploadTime();
|
|
|
|
- GeneralGradeDTO generalGradeDTO = new GeneralGradeDTO(userCatchDTO.getUserId
|
|
|
|
- (), userCatchDTO.getExamId(), userCatchDTO.getCaseId(), key, typeScoreMap
|
|
|
|
- .get(key), uploadTime, "");
|
|
|
|
|
|
+ GeneralGradeDTO generalGradeDTO = new GeneralGradeDTO(key,typeScoreMap.get
|
|
|
|
+ (key),uploadRecordDTO.getId());
|
|
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){
|
|
|
|
+ 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节点的权重
|
|
@@ -203,48 +242,61 @@ public class GeneralCalculateScoreComponent {
|
|
|
|
|
|
|
|
|
|
@Async("calculateGradeAsync")
|
|
@Async("calculateGradeAsync")
|
|
- 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);
|
|
|
|
- }
|
|
|
|
|
|
+ public void saveCaughtDetails(long uploadId, Long examId, Long caseId, Long userId,
|
|
|
|
+ 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);
|
|
|
|
+// }
|
|
|
|
+
|
|
|
|
+ calculateGradeCurrent(uploadId,examId,caseId,userId,caughtNodeDTOs);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private CaseGraphDTO getBasicNode(long caseId){
|
|
|
|
+ CaseGraphDTO basicNode = basicNodeMap.get(caseId);
|
|
|
|
+ if(basicNode == null){
|
|
|
|
+ basicNode = caseGraphService.getCaseGraph(caseId);
|
|
|
|
+ if(basicNode == null){
|
|
|
|
+ throw new ServerException(ServerCode.META_NODE_NOT_EXIST);
|
|
}
|
|
}
|
|
- caughtNodeService.bulkUpdateCaughtNodes(examId, caseId, nodeNameList, userId);
|
|
|
|
|
|
+ basicNodeMap.put(caseId,basicNode);
|
|
}
|
|
}
|
|
- calculateGrade(examId, caseId, userId, source);
|
|
|
|
-
|
|
|
|
|
|
+ return basicNode;
|
|
}
|
|
}
|
|
}
|
|
}
|