|
@@ -2,7 +2,14 @@ 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.data.UploadRecordDTO;
|
|
|
|
+import cn.iselab.mooctest.site.service.CatchService;
|
|
|
|
+import cn.iselab.mooctest.site.service.CaughtNodeService;
|
|
|
|
+import cn.iselab.mooctest.site.service.Exam2CaseService;
|
|
|
|
+import cn.iselab.mooctest.site.service.GeneralCalculateScoreService;
|
|
|
|
+import cn.iselab.mooctest.site.service.SubmitRecordService;
|
|
|
|
+import cn.iselab.mooctest.site.service.UserCatchService;
|
|
|
|
+import cn.iselab.mooctest.site.service.WeightGeneralService;
|
|
import cn.iselab.mooctest.site.util.data.CacheUtil;
|
|
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;
|
|
@@ -10,20 +17,22 @@ 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 org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
-import org.springframework.scheduling.annotation.Async;
|
|
|
|
-import org.springframework.stereotype.Component;
|
|
|
|
-
|
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
import java.math.RoundingMode;
|
|
import java.math.RoundingMode;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.scheduling.annotation.Async;
|
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
|
|
|
/**
|
|
/**
|
|
* asyncTask
|
|
* asyncTask
|
|
@@ -32,6 +41,7 @@ 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 {
|
|
|
|
|
|
//获取被命中nodes的服务
|
|
//获取被命中nodes的服务
|
|
@@ -56,8 +66,9 @@ public class GeneralCalculateScoreComponent {
|
|
@Autowired
|
|
@Autowired
|
|
CacheUtil cacheUtil;
|
|
CacheUtil cacheUtil;
|
|
|
|
|
|
- public void calculateGrade(long examId, long caseId, Long userId, String source) throws Exception {
|
|
|
|
- recordTypeScore(examId, caseId, userId, source);
|
|
|
|
|
|
+ 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 { //计算所有人的分数
|
|
@@ -67,25 +78,32 @@ public class GeneralCalculateScoreComponent {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- private void calculateGradeCurrent(long examId, long caseId, long userId, String source, String
|
|
|
|
- uploadTime, List<CaughtNodeDTO> caughtNodeDTOS) throws Exception {
|
|
|
|
|
|
+ //计算当即提交的node的得分
|
|
|
|
+ public void calculateGradeCurrent(Long uploadId, long examId, long caseId, long userId,
|
|
|
|
+ List<CaughtNodeDTO> caughtNodeDTOS)
|
|
|
|
+ throws Exception {
|
|
|
|
|
|
- CaseGraphDTO basicNode = cacheUtil.getMetaNode(caseId);
|
|
|
|
|
|
+ //过滤没有catch的node,并将catch住的node转换为CatchDTO
|
|
List<CatchDTO> catchDTOS = caughtNodeDTOS.stream().filter
|
|
List<CatchDTO> catchDTOS = caughtNodeDTOS.stream().filter
|
|
(CaughtNodeDTO::getIfCatch).map(x -> new CatchDTO(x.getNodeName(),x.getCategory()
|
|
(CaughtNodeDTO::getIfCatch).map(x -> new CatchDTO(x.getNodeName(),x.getCategory()
|
|
,null)).collect(Collectors.toList());
|
|
,null)).collect(Collectors.toList());
|
|
|
|
+
|
|
|
|
+ //通过元node和CatchDTOs计算每种类型的得分
|
|
|
|
+ CaseGraphDTO basicNode = cacheUtil.getMetaNode(caseId);
|
|
Map<String, Double> typeScoreMap = calculateTypeScore(basicNode,catchDTOS);
|
|
Map<String, Double> typeScoreMap = calculateTypeScore(basicNode,catchDTOS);
|
|
List<GeneralGradeDTO> gradeDTOList = new ArrayList<>();
|
|
List<GeneralGradeDTO> gradeDTOList = new ArrayList<>();
|
|
- typeScoreMap.forEach((type,score) -> gradeDTOList.add(new GeneralGradeDTO(userId,examId,
|
|
|
|
- caseId,type,score,uploadTime,source)));
|
|
|
|
|
|
+ typeScoreMap.forEach((type,score) -> gradeDTOList.add(new GeneralGradeDTO(type,score,uploadId)));
|
|
|
|
|
|
|
|
+ //记录每种类型的得分
|
|
generalCalculateScoreService.updateTypeGrade(gradeDTOList);
|
|
generalCalculateScoreService.updateTypeGrade(gradeDTOList);
|
|
|
|
|
|
|
|
+ //计算该case的得分
|
|
calculateCaseScore(examId, caseId, userId);
|
|
calculateCaseScore(examId, caseId, userId);
|
|
}
|
|
}
|
|
|
|
|
|
- private void recordTypeScore(long examId, long caseId, Long userId, String
|
|
|
|
- source) throws Exception {
|
|
|
|
|
|
+ //非当即分数记录
|
|
|
|
+ private void recordTypeScore(long examId, long caseId, Long userId) throws
|
|
|
|
+ Exception {
|
|
|
|
|
|
List<UserCatchDTO> userCatchDTOList;
|
|
List<UserCatchDTO> userCatchDTOList;
|
|
if (userId == null) {
|
|
if (userId == null) {
|
|
@@ -93,10 +111,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);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -115,6 +131,7 @@ 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 = cacheUtil.getMetaNode(caseId);
|
|
CaseGraphDTO basicNode = cacheUtil.getMetaNode(caseId);
|
|
|
|
|
|
@@ -122,14 +139,16 @@ public class GeneralCalculateScoreComponent {
|
|
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 = calculateTypeScore(basicNode,catchDTOs);
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -137,15 +156,14 @@ public class GeneralCalculateScoreComponent {
|
|
return generalGradeDTOList;
|
|
return generalGradeDTOList;
|
|
}
|
|
}
|
|
|
|
|
|
- private Map<String, Double> calculateTypeScore(CaseGraphDTO basicNode, List<CatchDTO>
|
|
|
|
- catchDTOS){
|
|
|
|
- if(basicNode ==null || catchDTOS == null){
|
|
|
|
- return new HashMap<>();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
+ private Map<String,Double> calculateTypeScore(CaseGraphDTO basicNode, List<CatchDTO>
|
|
|
|
+ catchDTOs){
|
|
Map<String, Double> typeScoreMap = new HashMap<>();
|
|
Map<String, Double> typeScoreMap = new HashMap<>();
|
|
|
|
+ if(basicNode == null || catchDTOs == null){
|
|
|
|
+ return typeScoreMap;
|
|
|
|
+ }
|
|
for (Node node : basicNode.getNodes()) {
|
|
for (Node node : basicNode.getNodes()) {
|
|
- for (CatchDTO catchDTO : catchDTOS) {
|
|
|
|
|
|
+ for (CatchDTO catchDTO : catchDTOs) {
|
|
if (node.getName().equals(catchDTO.getNodeName())) {//用户命中了该node
|
|
if (node.getName().equals(catchDTO.getNodeName())) {//用户命中了该node
|
|
double scoreGot = 0;
|
|
double scoreGot = 0;
|
|
String key = node.getCategory();
|
|
String key = node.getCategory();
|
|
@@ -161,7 +179,6 @@ public class GeneralCalculateScoreComponent {
|
|
}
|
|
}
|
|
|
|
|
|
return typeScoreMap;
|
|
return typeScoreMap;
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -227,8 +244,8 @@ public class GeneralCalculateScoreComponent {
|
|
|
|
|
|
|
|
|
|
@Async("calculateGradeAsync")
|
|
@Async("calculateGradeAsync")
|
|
- public void saveCaughtDetails(Long examId, Long caseId, Long userId, String
|
|
|
|
- source,String uploadTime, List<CaughtNodeDTO> caughtNodeDTOs) throws Exception {
|
|
|
|
|
|
+ public void saveCaughtDetails(long uploadId, Long examId, Long caseId, Long userId,
|
|
|
|
+ List<CaughtNodeDTO> caughtNodeDTOs) throws Exception {
|
|
|
|
|
|
// List<CaughtNodeDTO> caughtNodeDTOList = caughtNodeService.getCaughtNodeList(examId, caseId);
|
|
// List<CaughtNodeDTO> caughtNodeDTOList = caughtNodeService.getCaughtNodeList(examId, caseId);
|
|
// if (caughtNodeDTOList == null) {
|
|
// if (caughtNodeDTOList == null) {
|
|
@@ -268,8 +285,8 @@ public class GeneralCalculateScoreComponent {
|
|
// }
|
|
// }
|
|
// caughtNodeService.bulkUpdateCaughtNodes(examId, caseId, nodeNameList, userId);
|
|
// caughtNodeService.bulkUpdateCaughtNodes(examId, caseId, nodeNameList, userId);
|
|
// }
|
|
// }
|
|
-// calculateGrade(examId, caseId, userId, source);
|
|
|
|
- calculateGradeCurrent(examId,caseId,userId,source,uploadTime, caughtNodeDTOs);
|
|
|
|
|
|
+
|
|
|
|
+ calculateGradeCurrent(uploadId,examId,caseId,userId,caughtNodeDTOs);
|
|
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|