【实训加载时,增加指令时间控制;实训加载时过滤不必要指令】

This commit is contained in:
weizhihong 2022-11-18 13:51:42 +08:00
parent 9e1448b053
commit da4cd76c2a
5 changed files with 345 additions and 322 deletions

View File

@ -243,25 +243,14 @@ public class Training2Service {
if (simulation == null) {
throw new SimulationException(SimulationExceptionType.Invalid_Operation, "仿真不存在");
}
// boolean participant = simulation.getSimulationMembers().stream().anyMatch(m -> String.valueOf(user.getId()).equals(m.getUserId()));
Training2 training2 = simulation.getTraining2();
Map<String, Float> scoreMap = new HashMap<>();
if (training2 != null) {
// 创建者退出则清理实训
if (simulation.getCreator().getId().equals(user.getId())) {
training2.finish();
removeTrainingJob(simulation);
}
// if (participant || simulation.getCreator().getId().equals(user.getId())) {
// scoreMap = training2.mark();
// }
}
// if (participant) {
// SimulationMember member = simulation.getSimulationMemberByUserId(user.getId());
// return scoreMap.get(member.getId());
// } else {
// return 0f;
// }
if (CollectionUtils.isEmpty(scoreList)) {
return 0f;
} else {
@ -377,12 +366,18 @@ public class Training2Service {
return;
}
// 为会话操作
if (CONVERSATION_LIST.contains(simCommand2.getOperationType().name())
&& CONVERSATION_LIST.contains(event.getOperate())) {
boolean startFlag = Boolean.FALSE;
if (CONVERSATION_LIST.contains(simCommand2.getOperationType().name()) && CONVERSATION_LIST.contains(event.getOperate())) {
checkSimOperationConversation(simCommand2, simulation, step);
} else if (simCommand2.getOperationType().name().equals(event.getOperate())
&& compareParams(event.getParams(), simCommand2.getParams())) {
startFlag = Boolean.TRUE;
} else if (simCommand2.getOperationType().name().equals(event.getOperate()) && compareParams(event.getParams(), simCommand2.getParams())) {
simCommand2.doOperated(); // 标识已操作过
startFlag = Boolean.TRUE;
}
// 指令执行后启动仿真
if (simulation.isPause() && startFlag) {
simulation.start();
}
// 检查是否要计算指标
if (!CollectionUtils.isEmpty(training2.getIndexList())) {
@ -585,6 +580,14 @@ public class Training2Service {
, operation2.getParams());
return true;
} else { // 非机器人暂停仿真等待用户操作
if (operation2.getSimTime() != null) {
long maxTime = operation2.getSimTime() + 1000;
long simCurTime = simulation.getCorrectSystemTimeStamp();
// 如果时间到达操作时间或者在1s内则暂停仿真
if (simCurTime == operation2.getSimTime() || maxTime > simCurTime) {
simulation.pause();
}
}
return false;
}
}

View File

@ -132,10 +132,16 @@ public abstract class Operation2 {
private Map<String, Object> params;
/**
* 仿真指令执行时间
*/
private Long simTime;
public SimCommand2(Operation2VO.SimCommand2VO vo, Simulation simulation) {
super(vo.getId());
this.operationType = vo.getOperationType();
this.params = vo.getParams();
this.simTime = vo.getSimTime();
if (vo.getTriggerCondition() != null) {
this.setTriggerCondition(vo.getTriggerCondition().convert2BO(simulation.getRepository()));
}

View File

@ -83,7 +83,8 @@ public class Step2 {
this.operations = Collections.EMPTY_LIST;
}
if (!CollectionUtils.isEmpty(vo.getSimCommands())) {
this.simCommands = vo.getSimCommands().stream().map(o -> new Operation2.SimCommand2(o, simulation))
this.simCommands = vo.getSimCommands().stream().filter(o -> o.getOperationType().isStatusType())
.map(o -> new Operation2.SimCommand2(o, simulation))
.collect(Collectors.toList());
} else {
this.simCommands = Collections.EMPTY_LIST;

View File

@ -7,6 +7,7 @@ import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import java.time.LocalDateTime;
import java.util.Map;
/**
@ -46,6 +47,11 @@ public abstract class Operation2VO {
private Map<String, Object> params;
/**
* 仿真指令执行时间
*/
private Long simTime;
@Override
public Operation2 convert2BO(Simulation simulation) {
return new Operation2.SimCommand2(this, simulation);