From 3b486e90160f071089c17b612c4b74086c3edcb0 Mon Sep 17 00:00:00 2001 From: joylink_zhangsai <1021828630@qq.com> Date: Mon, 29 Aug 2022 10:32:29 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E8=AF=84=E5=88=86=E8=A7=84?= =?UTF-8?q?=E5=88=99=E6=95=B0=E6=8D=AE=E7=BB=93=E6=9E=84=E5=92=8C=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E9=80=BB=E8=BE=91=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../services/training2/Training2Service.java | 28 +----- .../cbtc/training2/ScoringRule2.java | 98 +++++++------------ .../vo/client/training2/ScoringRuleVO.java | 17 ++-- 3 files changed, 42 insertions(+), 101 deletions(-) diff --git a/src/main/java/club/joylink/rtss/services/training2/Training2Service.java b/src/main/java/club/joylink/rtss/services/training2/Training2Service.java index cf4700f52..f89c28ade 100644 --- a/src/main/java/club/joylink/rtss/services/training2/Training2Service.java +++ b/src/main/java/club/joylink/rtss/services/training2/Training2Service.java @@ -14,7 +14,9 @@ import club.joylink.rtss.simulation.cbtc.exception.SimulationException; import club.joylink.rtss.simulation.cbtc.exception.SimulationExceptionType; import club.joylink.rtss.simulation.cbtc.member.MemberManager; import club.joylink.rtss.simulation.cbtc.script.ScriptBO; -import club.joylink.rtss.simulation.cbtc.training2.*; +import club.joylink.rtss.simulation.cbtc.training2.Operation2; +import club.joylink.rtss.simulation.cbtc.training2.Step2; +import club.joylink.rtss.simulation.cbtc.training2.Training2; import club.joylink.rtss.util.JsonUtils; import club.joylink.rtss.vo.AccountVO; import club.joylink.rtss.vo.LoginUserInfoVO; @@ -31,7 +33,6 @@ import org.springframework.util.StringUtils; import java.time.LocalDateTime; import java.time.temporal.ChronoUnit; -import java.util.List; import java.util.Objects; import java.util.function.Consumer; @@ -134,28 +135,6 @@ public class Training2Service { atsOperationDispatcher.execute(simulation, step.getSimulationMember(), simOperation2.getOperationType().name(), simOperation2.getParams()); } - /** - * 评分监视 - */ - public void scoringMonitor(Simulation simulation) { - Training2 training2 = simulation.getTraining2(); - List scoringRules = training2.getScoringRules(); - if (CollectionUtils.isEmpty(scoringRules)) - return; - for (ScoringRule2 scoringRule : scoringRules) { - for (ScoringRule2.Detail durativeDetail : scoringRule.getDurativeDetails()) { - if (durativeDetail.getDeduct() != null) //已经被判定的不用再监视 - continue; - Expression condition = durativeDetail.getCondition(); - if (condition != null) { - if (condition.getValue(boolean.class)) { - durativeDetail.setDeduct(true); - } - } - } - } - } - /** * 预览实训草稿 */ @@ -243,7 +222,6 @@ public class Training2Service { simulation.removeJob(EXECUTE_JOB_NAME); } simulation.addJobIfAbsent(EXECUTE_JOB_NAME, () -> this.run(simulation), RATE); - simulation.addJobIfAbsent(SCORING_JOB_NAME, () -> this.scoringMonitor(simulation), RATE); training2.start(mode); simulationLifeCycleService.resume(simulation); } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/training2/ScoringRule2.java b/src/main/java/club/joylink/rtss/simulation/cbtc/training2/ScoringRule2.java index 9cb7c37fa..25d80f5f8 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/training2/ScoringRule2.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/training2/ScoringRule2.java @@ -1,9 +1,8 @@ package club.joylink.rtss.simulation.cbtc.training2; +import club.joylink.rtss.exception.BusinessExceptionAssertEnum; import club.joylink.rtss.simulation.cbtc.member.SimulationMember; -import lombok.AllArgsConstructor; import lombok.Getter; -import lombok.Setter; import org.springframework.util.CollectionUtils; import java.util.ArrayList; @@ -30,11 +29,6 @@ public class ScoringRule2 { */ private List details; - /** - * 最终得分 - */ - private Float finalScore; - public ScoringRule2(SimulationMember member, Float fullMarks, List details) { this.member = member; this.fullMarks = fullMarks; @@ -52,75 +46,45 @@ public class ScoringRule2 { } public float mark(boolean allStepCompletion) { - if (finalScore != null) - return finalScore; - if (CollectionUtils.isEmpty(details)) { //没有打分细则,则实训完成给满分,否则0分 return allStepCompletion ? fullMarks : 0f; } else { double deductedPoints = details.stream() - .peek(detail -> { - if (detail.getDeduct() == null) { //未作出判定 - if (detail.isDurative()) { - detail.setDeduct(false); - } else { - if (detail.getCondition() != null) { - detail.setDeduct(detail.getCondition().getValue(boolean.class)); - } else { - detail.setDeduct(!detail.isCompletion()); - } - } + .mapToDouble(detail -> { + if (detail.isDurative()) { + throw BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.exception("暂不支持该类型评分规则"); + } else { + return !detail.isCompletion() ? detail.getScore() : 0; } }) - .mapToDouble(detail -> Boolean.TRUE.equals(detail.getDeduct()) ? detail.getScore() : 0) - .sum(); + .sum(); //统计扣分分值 float finalScore = (float) (fullMarks - deductedPoints); - this.finalScore = finalScore < 0 ? 0 : finalScore; - return finalScore; + return finalScore < 0 ? 0 : finalScore; } } @Getter - @AllArgsConstructor - public static class Detail { + public static abstract class Detail { private Type type; private ElementType elementType; /** - * 扣分分值 + * 分值 */ private float score; - /** - * 满足该条件则扣分 - */ - private Expression condition; - - /** - * null 未判定;true 扣分;false 不扣分; - */ - @Setter - private Boolean deduct; - - public Detail(Type type, ElementType elementType, float score, Expression condition) { + public Detail(Type type, ElementType elementType, float score) { this.type = type; this.elementType = elementType; this.score = score; - this.condition = condition; - } - - public Object getElement() { - return null; } public boolean isDurative() { return Type.DURATIVE.equals(type); } - public boolean isCompletion() { - return true; - } + public abstract boolean isCompletion(); public enum Type { /** @@ -150,40 +114,44 @@ public class ScoringRule2 { } public static class Operation2Detail extends Detail { - private Operation2 element; + private Operation2 operation2; - public Operation2Detail(Type type, ElementType elementType, Operation2 element, float score, Expression condition) { - super(type, elementType, score, condition); - this.element = element; - } - - @Override - public Object getElement() { - return element; + public Operation2Detail(Type type, ElementType elementType, float score, Operation2 operation2) { + super(type, elementType, score); + this.operation2 = operation2; } @Override public boolean isCompletion() { - return element.isCompletion(); + return operation2.isCompletion(); } } public static class Step2Detail extends Detail { private Step2 step; - public Step2Detail(Type type, ElementType elementType, Step2 step, float score, Expression condition) { - super(type, elementType, score, condition); + public Step2Detail(Type type, ElementType elementType, float score, Step2 step) { + super(type, elementType, score); this.step = step; } - @Override - public Object getElement() { - return step; - } - @Override public boolean isCompletion() { return step.isCompletion(); } } + + public static class Training2Detail extends Detail { + private List steps; + + public Training2Detail(Type type, ElementType elementType, float score, List steps) { + super(type, elementType, score); + this.steps = steps; + } + + @Override + public boolean isCompletion() { + return steps.stream().allMatch(Step2::isCompletion); + } + } } diff --git a/src/main/java/club/joylink/rtss/vo/client/training2/ScoringRuleVO.java b/src/main/java/club/joylink/rtss/vo/client/training2/ScoringRuleVO.java index e49ef8bbf..84fa6c201 100644 --- a/src/main/java/club/joylink/rtss/vo/client/training2/ScoringRuleVO.java +++ b/src/main/java/club/joylink/rtss/vo/client/training2/ScoringRuleVO.java @@ -1,7 +1,6 @@ package club.joylink.rtss.vo.client.training2; import club.joylink.rtss.simulation.cbtc.Simulation; -import club.joylink.rtss.simulation.cbtc.data.SimulationDataRepository; import club.joylink.rtss.simulation.cbtc.member.SimulationMember; import club.joylink.rtss.simulation.cbtc.training2.Operation2; import club.joylink.rtss.simulation.cbtc.training2.ScoringRule2; @@ -44,8 +43,9 @@ public class ScoringRuleVO { simulationMember = simulation.getSimulationMemberById(memberId); } if (!CollectionUtils.isEmpty(this.details)) { + SimulationMember finalSimulationMember = simulationMember; details = this.details.stream() - .map(vo -> vo.convert2BO(training2, simulation.getRepository())) + .map(vo -> vo.convert2BO(training2, finalSimulationMember)) .collect(Collectors.toList()); } return new ScoringRule2(simulationMember, fullMarks, details); @@ -69,21 +69,16 @@ public class ScoringRuleVO { */ private float score; - /** - * 扣分条件 - */ - private ExpressionVO condition; - - public ScoringRule2.Detail convert2BO(Training2 training2, SimulationDataRepository repository) { + public ScoringRule2.Detail convert2BO(Training2 training2, SimulationMember simulationMember) { switch (elementType) { case O: Operation2 operation2 = training2.getOperation(Integer.parseInt(elementId)); - return new ScoringRule2.Operation2Detail(type, elementType, operation2, score, ExpressionVO.convert2BO(condition, repository)); + return new ScoringRule2.Operation2Detail(type, elementType, score, operation2); case S: Step2 step2 = training2.getStep(Integer.parseInt(elementId)); - return new ScoringRule2.Step2Detail(type, elementType, step2, score, ExpressionVO.convert2BO(condition, repository)); + return new ScoringRule2.Step2Detail(type, elementType, score, step2); case T: - return new ScoringRule2.Detail(type, elementType, score, ExpressionVO.convert2BO(condition, repository)); + return new ScoringRule2.Training2Detail(type, elementType, score, training2.getSteps(simulationMember)); default: throw new IllegalStateException("Unexpected value: " + elementType); }