试卷场景分数调整

This commit is contained in:
tiger_zhou 2023-02-15 13:43:16 +08:00
parent be8c515eea
commit db0ba127ed
4 changed files with 58 additions and 32 deletions

View File

@ -24,8 +24,13 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.util.SocketUtils;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.time.Duration; import java.time.Duration;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.*; import java.util.*;
@ -172,6 +177,7 @@ public class PaperUserService {
long paperTime = Duration.between(paper.getStartTime(), now).toMinutes();//实际做题时长min long paperTime = Duration.between(paper.getStartTime(), now).toMinutes();//实际做题时长min
for (PaperUserQuestion uq : userQuestionList) { for (PaperUserQuestion uq : userQuestionList) {
PaperRule rule = ruleIdMap.get(uq.getRuleId()); PaperRule rule = ruleIdMap.get(uq.getRuleId());
switch (PaperQType.GroupType.getItem(uq.getType())) { switch (PaperQType.GroupType.getItem(uq.getType())) {
case Common: case Common:
scoreCommon += calculateCommonScore(uq, rule);break; scoreCommon += calculateCommonScore(uq, rule);break;
@ -204,16 +210,26 @@ public class PaperUserService {
* 获取题的最终得分 * 获取题的最终得分
*/ */
private int calculateCommonScore(PaperUserQuestion puq, PaperRule rule) { private int calculateCommonScore(PaperUserQuestion puq, PaperRule rule) {
// PaperQuestionExample example = new PaperQuestionExample();
// example.createCriteria().andIdEqualTo(puq.getQuestionId());
// PaperQuestion question = pagerQuestionDAO.selectByExample(example).get(0);
if (PaperQuestionState.Right.equals(PaperQuestionState.getItem(puq.getState()))) {//题答对时 if (PaperQuestionState.Right.equals(PaperQuestionState.getItem(puq.getState()))) {//题答对时
// PaperRule rule = ruleMap.get(this.getPaperQuestionType(question));
return rule.getScore(); return rule.getScore();
} }
return 0; return 0;
} }
public static int getPercentage(double score,int sumScore,int ruleScore) {
if(score >= sumScore){
return ruleScore;
}
int d = sumScore * 100;
if(sumScore >=10){
d = sumScore ;
}
double t = score / d;
if(t <=0.5){
return (int)Math.round(t * ruleScore);
}
return (int)Math.floor(t * ruleScore);
}
/** /**
* 获取题的最终得分 * 获取题的最终得分
@ -226,12 +242,9 @@ public class PaperUserService {
return 0; return 0;
} }
PaperSubmitAnswerReqVo.AnswerDetail answerDetail = JsonUtils.read(puq.getTmpAnswer(),PaperSubmitAnswerReqVo.AnswerDetail.class); PaperSubmitAnswerReqVo.AnswerDetail answerDetail = JsonUtils.read(puq.getTmpAnswer(),PaperSubmitAnswerReqVo.AnswerDetail.class);
double sumScore = answerDetail.getTrainDetail().stream().mapToDouble(PaperTrainAnswerDetail::getScore).sum(); int sumScore = answerDetail.getSumScore();
double dd = sumScore / (rule.getScore() * 100); double totalScore = answerDetail.getTrainDetail().stream().mapToDouble(PaperTrainAnswerDetail::getScore).sum();
if(dd > 0){ return getPercentage(totalScore,sumScore,rule.getScore());
return (int)Math.round(dd);
}
return 0;
} }
return 0; return 0;
} }

View File

@ -10,8 +10,6 @@ import club.joylink.rtss.entity.paper.PaperUserQuestion;
import club.joylink.rtss.entity.paper.PaperUserQuestionExample; import club.joylink.rtss.entity.paper.PaperUserQuestionExample;
import club.joylink.rtss.entity.paper.question.PaperQuestion; import club.joylink.rtss.entity.paper.question.PaperQuestion;
import club.joylink.rtss.entity.paper.question.PaperQuestionExample; import club.joylink.rtss.entity.paper.question.PaperQuestionExample;
import club.joylink.rtss.entity.training2.PublishedTraining2;
import club.joylink.rtss.exception.BusinessExceptionAssert;
import club.joylink.rtss.exception.BusinessExceptionAssertEnum; import club.joylink.rtss.exception.BusinessExceptionAssertEnum;
import club.joylink.rtss.exception.PaperExceptionAssert; import club.joylink.rtss.exception.PaperExceptionAssert;
import club.joylink.rtss.services.training2.Training2PublishService; import club.joylink.rtss.services.training2.Training2PublishService;
@ -21,10 +19,8 @@ import club.joylink.rtss.vo.client.training2.ScoringRuleVO;
import club.joylink.rtss.vo.client.training2.Step2VO; import club.joylink.rtss.vo.client.training2.Step2VO;
import club.joylink.rtss.vo.paper.*; import club.joylink.rtss.vo.paper.*;
import club.joylink.rtss.vo.training2.publish.PublishedTraining2DetailRspVo; import club.joylink.rtss.vo.training2.publish.PublishedTraining2DetailRspVo;
import com.google.common.base.Joiner;
import com.google.common.base.Splitter; import com.google.common.base.Splitter;
import com.google.common.base.Strings; import com.google.common.base.Strings;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -78,24 +74,22 @@ public class PaperUserSubmitAnswerService {
rsp.setPqId(req.getPqId()); rsp.setPqId(req.getPqId());
rsp.setType(req.getType()); rsp.setType(req.getType());
rsp.setSubType(req.getSubType()); rsp.setSubType(req.getSubType());
String tmpAnswer = null; TrainAnswerVO answerVO;
BusinessExceptionAssertEnum.DATA_INVALID.assertTrue(Objects.nonNull(req.getType()),"未知的考试类型");
//处理用户提交的答案 //处理用户提交的答案
if(req.getType() == PaperQType.GroupType.Common){ if(req.getType() == PaperQType.GroupType.Common){
rsp.setResult(submitCommonAnswer(puq, req)); answerVO = submitCommonAnswer(puq, req);
tmpAnswer = this.getAnswerFromSubmit(req); }else{
}else if(req.getType() == PaperQType.GroupType.Training){
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertNotTrue((req.getSubType() != PaperQType.SubType.Single && req.getSubType() != PaperQType.SubType.Scene),String.format("未知答题类型[%s]",req.getSubType())); BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertNotTrue((req.getSubType() != PaperQType.SubType.Single && req.getSubType() != PaperQType.SubType.Scene),String.format("未知答题类型[%s]",req.getSubType()));
TrainAnswerVO answerVO = this.submitTrainingAnswer(req,puq); answerVO = this.submitTrainingAnswer(req,puq);
rsp.setResult(answerVO.getState());
tmpAnswer = JsonUtils.writeValueAsString(answerVO.getDetail());
} }
rsp.setResult(answerVO.getState());
//记录用户答题情况 //记录用户答题情况
PaperUserQuestion record = new PaperUserQuestion(); PaperUserQuestion record = new PaperUserQuestion();
record.setId(puq.getId()); record.setId(puq.getId());
record.setState(rsp.getResult().getValue()); record.setState(rsp.getResult().getValue());
record.setTmpAnswer(tmpAnswer); record.setTmpAnswer(answerVO.getDetailStr());
paperUserQuestionDAO.updateByPrimaryKeySelective(record); paperUserQuestionDAO.updateByPrimaryKeySelective(record);
//
return rsp; return rsp;
} }
@ -112,7 +106,7 @@ public class PaperUserSubmitAnswerService {
// PaperExceptionAssert.PuqCanSubmit.assertTrue(PaperQuestionState.Undo.equals(PaperQuestionState.getItem(puq.getState())), "只有未做的题才能提交答案"); // PaperExceptionAssert.PuqCanSubmit.assertTrue(PaperQuestionState.Undo.equals(PaperQuestionState.getItem(puq.getState())), "只有未做的题才能提交答案");
} }
private TrainAnswerVO submitTrainingAnswer(PaperSubmitAnswerReqVo reqVo,PaperUserQuestion puq){ private TrainAnswerVO<PaperSubmitAnswerReqVo.AnswerDetail> submitTrainingAnswer(PaperSubmitAnswerReqVo reqVo,PaperUserQuestion puq){
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotTrue(Strings.isNullOrEmpty(reqVo.getTrainAnswerDetail().getCosplayMemberId()),"实训考试没有对应的角色"); BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotTrue(Strings.isNullOrEmpty(reqVo.getTrainAnswerDetail().getCosplayMemberId()),"实训考试没有对应的角色");
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotTrue(CollectionUtils.isEmpty(reqVo.getTrainAnswerDetail().getTrainDetail()),"实训考试没有对应的操作"); BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotTrue(CollectionUtils.isEmpty(reqVo.getTrainAnswerDetail().getTrainDetail()),"实训考试没有对应的操作");
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotTrue(reqVo.getTrainAnswerDetail().getTrainDetail().stream().anyMatch(d->Objects.isNull(d.getStepId())),"实训步骤id不能为空"); BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotTrue(reqVo.getTrainAnswerDetail().getTrainDetail().stream().anyMatch(d->Objects.isNull(d.getStepId())),"实训步骤id不能为空");
@ -126,7 +120,7 @@ public class PaperUserSubmitAnswerService {
}else if(reqVo.getSubType() == PaperQType.SubType.Scene){ }else if(reqVo.getSubType() == PaperQType.SubType.Scene){
return this.submitTrainingAnswerForScene(detailVO,reqVo); return this.submitTrainingAnswerForScene(detailVO,reqVo);
} }
return new TrainAnswerVO(PaperQuestionState.Wrong, null); return new TrainAnswerVO<PaperSubmitAnswerReqVo.AnswerDetail>(PaperQuestionState.Wrong, null);
} }
/** /**
@ -135,13 +129,13 @@ public class PaperUserSubmitAnswerService {
* *
* @return * @return
*/ */
private TrainAnswerVO submitTrainingAnswerForSingle(PaperSubmitAnswerReqVo req,PublishedTraining2DetailRspVo trainDetailVO/*List<Step2VO> allStepList,PaperUserQuestion puq*/) { private TrainAnswerVO submitTrainingAnswerForSingle(PaperSubmitAnswerReqVo req, PublishedTraining2DetailRspVo trainDetailVO/*List<Step2VO> allStepList,PaperUserQuestion puq*/) {
BusinessExceptionAssertEnum.DATA_ERROR.assertTrue(StringUtils.hasText(trainDetailVO.getStepJson()),"场景实训没有对应的操作步骤"); BusinessExceptionAssertEnum.DATA_ERROR.assertTrue(StringUtils.hasText(trainDetailVO.getStepJson()),"场景实训没有对应的操作步骤");
List<Step2VO> allStepList = JsonUtils.readCollection(trainDetailVO.getStepJson(),ArrayList.class, Step2VO.class); List<Step2VO> allStepList = JsonUtils.readCollection(trainDetailVO.getStepJson(),ArrayList.class, Step2VO.class);
List<Step2VO> cosplayStepList = allStepList.stream().filter(d->Objects.equals(d.getMemberId(),req.getTrainAnswerDetail().getCosplayMemberId())).collect(Collectors.toList()); List<Step2VO> cosplayStepList = allStepList.stream().filter(d->Objects.equals(d.getMemberId(),req.getTrainAnswerDetail().getCosplayMemberId())).collect(Collectors.toList());
if(req.getTrainAnswerDetail().getTrainDetail().size() != cosplayStepList.size()){ if(req.getTrainAnswerDetail().getTrainDetail().size() != cosplayStepList.size()){
return new TrainAnswerVO(PaperQuestionState.Wrong, req.getTrainAnswerDetail()); return new TrainAnswerVO<>(PaperQuestionState.Wrong, req.getTrainAnswerDetail());
} }
if(req.getTrainAnswerDetail().getTrainDetail().stream().allMatch(PaperTrainAnswerDetail::isSuccess)){ if(req.getTrainAnswerDetail().getTrainDetail().stream().allMatch(PaperTrainAnswerDetail::isSuccess)){
return new TrainAnswerVO(PaperQuestionState.Right, req.getTrainAnswerDetail()); return new TrainAnswerVO(PaperQuestionState.Right, req.getTrainAnswerDetail());
@ -162,12 +156,12 @@ public class PaperUserSubmitAnswerService {
Map<String,PaperTrainAnswerDetail> answerDetailMap = answerDetailList.stream().collect(Collectors.toMap(d->d.getStepId().toString(),Function.identity())); Map<String,PaperTrainAnswerDetail> answerDetailMap = answerDetailList.stream().collect(Collectors.toMap(d->d.getStepId().toString(),Function.identity()));
List<PaperTrainAnswerDetail> resultAnswerDetailList = new ArrayList<>(allDetailVOList.size()); List<PaperTrainAnswerDetail> resultAnswerDetailList = new ArrayList<>(allDetailVOList.size());
int sumScore = allDetailVOList.stream().mapToInt(d->(int)d.getScore()).sum();
for (ScoringRuleVO.DetailVO detailVO : allDetailVOList) { for (ScoringRuleVO.DetailVO detailVO : allDetailVOList) {
PaperTrainAnswerDetail answerDetail = answerDetailMap.get(detailVO.getElementId()); PaperTrainAnswerDetail answerDetail = answerDetailMap.get(detailVO.getElementId());
if(Objects.nonNull(answerDetail)){ if(Objects.nonNull(answerDetail)){
answerDetail.setScore(detailVO.getScore()); answerDetail.setScore(detailVO.getScore());
}else{ }else{
answerDetail = new PaperTrainAnswerDetail(); answerDetail = new PaperTrainAnswerDetail();
answerDetail.setScore(0F); answerDetail.setScore(0F);
@ -176,6 +170,7 @@ public class PaperUserSubmitAnswerService {
} }
resultAnswerDetailList.add(answerDetail); resultAnswerDetailList.add(answerDetail);
} }
req.getTrainAnswerDetail().setSumScore(sumScore);
req.getTrainAnswerDetail().setTrainDetail(resultAnswerDetailList); req.getTrainAnswerDetail().setTrainDetail(resultAnswerDetailList);
return new TrainAnswerVO(PaperQuestionState.SECEN_CUL,req.getTrainAnswerDetail()); return new TrainAnswerVO(PaperQuestionState.SECEN_CUL,req.getTrainAnswerDetail());
@ -183,7 +178,7 @@ public class PaperUserSubmitAnswerService {
/** /**
* 处理理论题答案 * 处理理论题答案
*/ */
private PaperQuestionState submitCommonAnswer(PaperUserQuestion puq, PaperSubmitAnswerReqVo req) { private TrainAnswerVO<String> submitCommonAnswer(PaperUserQuestion puq, PaperSubmitAnswerReqVo req) {
//题目 //题目
PaperQuestionExample pqExample = new PaperQuestionExample(); PaperQuestionExample pqExample = new PaperQuestionExample();
pqExample.createCriteria().andIdEqualTo(puq.getQuestionId()); pqExample.createCriteria().andIdEqualTo(puq.getQuestionId());
@ -192,7 +187,12 @@ public class PaperUserSubmitAnswerService {
final String qAn = this.getAnswerFromQuestion(pq); final String qAn = this.getAnswerFromQuestion(pq);
final String sAn = this.getAnswerFromSubmit(req); final String sAn = this.getAnswerFromSubmit(req);
// //
return qAn.equals(sAn) ? PaperQuestionState.Right : PaperQuestionState.Wrong; PaperQuestionState qState = PaperQuestionState.Wrong;
if(qAn.equals(sAn)){
qState = PaperQuestionState.Right;
}
TrainAnswerVO vo = new TrainAnswerVO(qState,sAn);
return vo;
} }
private String getAnswerFromQuestion(PaperQuestion pq) { private String getAnswerFromQuestion(PaperQuestion pq) {

View File

@ -51,6 +51,7 @@ public class PaperSubmitAnswerReqVo {
@Data @Data
public static class AnswerDetail{ public static class AnswerDetail{
private String cosplayMemberId; private String cosplayMemberId;
private int sumScore;
private List<PaperTrainAnswerDetail> trainDetail; private List<PaperTrainAnswerDetail> trainDetail;
} }
} }

View File

@ -1,15 +1,27 @@
package club.joylink.rtss.vo.paper; package club.joylink.rtss.vo.paper;
import club.joylink.rtss.util.JsonUtils;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import java.util.List; import java.util.List;
import java.util.Objects;
@Data @Data
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
public class TrainAnswerVO { public class TrainAnswerVO<V> {
private PaperQuestionState state; private PaperQuestionState state;
private PaperSubmitAnswerReqVo.AnswerDetail detail; private V detail;
public String getDetailStr(){
if(Objects.isNull(detail)){
return null;
}
if(this.detail instanceof String){
return this.detail.toString();
}
return JsonUtils.writeValueAsString(this.detail);
}
} }