Merge remote-tracking branch 'origin/test-training2' into test-training2

# Conflicts:
#	src/main/java/club/joylink/rtss/simulation/cbtc/discriminate/ExtractRule.java
This commit is contained in:
tiger_zhou 2023-04-10 13:52:29 +08:00
commit c7e13aebe9
5 changed files with 138 additions and 59 deletions

View File

@ -66,12 +66,11 @@ public class OperateParseServiceImpl implements VoiceTransactionalService {
// 成员解析 // 成员解析
MemberRule memberRule = operateRule.getMemberRule(); MemberRule memberRule = operateRule.getMemberRule();
if (memberRule != null) { if (memberRule != null) {
List<String> groupList = result.getMatchGroupList();
List<SimulationMember> simulationMemberList = null; List<SimulationMember> simulationMemberList = null;
if (memberRule.getIndex() == null) { if (memberRule.getIndex() == null) {
simulationMemberList = memberRule.getParseRule().matchMember(simulation, null); simulationMemberList = memberRule.getParseRule().matchMember(simulation, null);
} else if (memberRule.getIndex() < paramExtractResults.size()) { } else if (memberRule.getIndex() < paramExtractResults.size()) {
simulationMemberList = memberRule.getParseRule().matchMember(simulation, groupList.get(memberRule.getIndex())); simulationMemberList = memberRule.getParseRule().matchMember(simulation, paramExtractResults.get(memberRule.getIndex()));
} else { } else {
return; return;
} }

View File

@ -53,12 +53,11 @@ public class ReplyParseServiceImpl implements VoiceTransactionalService {
// 匹配回复人员 // 匹配回复人员
MemberRule memberRule = replyRule.getMemberRule(); MemberRule memberRule = replyRule.getMemberRule();
if (memberRule != null) { if (memberRule != null) {
List<String> groupList = result.getMatchGroupList();
List<SimulationMember> simulationMemberList = null; List<SimulationMember> simulationMemberList = null;
if (memberRule.getIndex() == null) { if (memberRule.getIndex() == null) {
simulationMemberList = memberRule.getParseRule().matchMember(simulation, null); simulationMemberList = memberRule.getParseRule().matchMember(simulation, null);
} else if (memberRule.getIndex() < paramExtractResults.size()) { } else if (memberRule.getIndex() < paramExtractResults.size()) {
simulationMemberList = memberRule.getParseRule().matchMember(simulation, groupList.get(memberRule.getIndex())); simulationMemberList = memberRule.getParseRule().matchMember(simulation, paramExtractResults.get(memberRule.getIndex()));
} else { } else {
return; return;
} }

View File

@ -1,6 +1,7 @@
package club.joylink.rtss.simulation.cbtc.discriminate; package club.joylink.rtss.simulation.cbtc.discriminate;
import club.joylink.rtss.simulation.cbtc.Simulation; import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.data.map.MapElement;
import lombok.Getter; import lombok.Getter;
/** /**
@ -9,13 +10,35 @@ import lombok.Getter;
@Getter @Getter
public enum CommandParamParseRule { public enum CommandParamParseRule {
STATION_NAME { MAP_ELEMENT_CODE("获取地图元素Code") {
@Override @Override
public Object extractParam(Simulation simulation, ParamExtractResult... extractResult) { public Object extractParam(Simulation simulation, ParamExtractResult... extractResults) {
if (extractResults == null || extractResults.length ==0) {
return null; throw new IllegalArgumentException("执行方法参数为空");
}
ParamExtractResult paramResult = extractResults[0];
if (paramResult.getValue() instanceof MapElement) {
return ((MapElement) paramResult.getValue()).getCode();
}
throw new IllegalArgumentException("参数类型【MAP_ELEMENT_CODE】不匹配");
} }
}; },
PARAM_VALUE("获取参数值") { // 像限速上下行等已经处理后的参数可直接使用
@Override
public Object extractParam(Simulation simulation, ParamExtractResult... extractResults) {
if (extractResults == null || extractResults.length ==0) {
throw new IllegalArgumentException("执行方法参数为空");
}
return extractResults[0].getValue();
}
}
;
public abstract Object extractParam(Simulation simulation, ParamExtractResult... extractResult); private String description;
CommandParamParseRule(String description) {
this.description = description;
}
public abstract Object extractParam(Simulation simulation, ParamExtractResult... extractResults);
} }

View File

@ -5,6 +5,9 @@ import club.joylink.rtss.simulation.cbtc.data.map.*;
import club.joylink.rtss.util.PinYinUtil; import club.joylink.rtss.util.PinYinUtil;
import club.joylink.rtss.util.StrUtils; import club.joylink.rtss.util.StrUtils;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import club.joylink.rtss.simulation.cbtc.data.map.Route;
import club.joylink.rtss.simulation.cbtc.data.map.Station;
import club.joylink.rtss.util.PinYinUtil;
import lombok.Getter; import lombok.Getter;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.commons.text.similarity.JaroWinklerSimilarity; import org.apache.commons.text.similarity.JaroWinklerSimilarity;
@ -13,68 +16,95 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.Objects;
import java.util.Optional;
/** /**
* 参数的提取规则 * 参数的提取规则
*/ */
@Getter @Getter
public enum ExtractRule { public enum ExtractRule {
//车站名称 STATION_NAME_EXTRACT("根据车站名称匹配车站") {
STATION_NAME {
@Override @Override
public Object matchParam(Simulation simulation, String... sourceStr) { public Object matchParam(Simulation simulation, String... sourceStr) {
return ExtractRule.findDevice(simulation, MapElement.DeviceType.STATION, Station.class,sourceStr[0]); if (sourceStr == null || sourceStr.length == 0) {
} throw new IllegalArgumentException("定位参数不缺失");
},
// 道岔名称
SWITCH_NAME{
@Override
public Object matchParam(Simulation simulation, String... sourceStr) {
return ExtractRule.findDevice(simulation, MapElement.DeviceType.SWITCH, Switch.class,sourceStr[0]);
}
},
//上下行
UP_DOWN_WAY {
@Override
public Object matchParam(Simulation simulation, String... sourceStr) {
if(StringUtils.containsAnyIgnoreCase(sourceStr[0],"shangxing","shang")){
return true;
}else if(StringUtils.containsAnyIgnoreCase(sourceStr[0],"xiaxing","xia")){
return false;
}else{
return null;
} }
// 这里可能需要做对入参做一些处理
String stationName = sourceStr[0];
Optional<Station> stationOptional = simulation.getRepository().getStationList().stream()
.filter(station -> Objects.equals(stationName, PinYinUtil.toPinYin(station.getName())))
.findFirst();
if (stationOptional.isPresent()) {
return stationOptional.get();
}
throw new IllegalArgumentException("未找到【" + stationName + "】车站");
} }
},SIGNAL_NAME{ },
ROUTE_NAME_EXTRACT("根据进路名称匹配进路") {
@Override @Override
public Object matchParam(Simulation simulation, String... sourceStr) { public Object matchParam(Simulation simulation, String... sourceStr) {
return ExtractRule.findDevice(simulation, MapElement.DeviceType.SIGNAL, Signal.class,sourceStr[0]); if (sourceStr == null || sourceStr.length == 0) {
throw new IllegalArgumentException("定位参数不缺失");
}
// 这里可能对XS做处理
String routeName = sourceStr[0];
Optional<Route> routeOptional = simulation.getRepository().getRouteList().stream()
.filter(route -> Objects.equals(route.getName(), routeName))
.findFirst();
if (routeOptional.isPresent()) {
return routeOptional.get();
}
throw new IllegalArgumentException("未找到【" + routeName + "】进路");
} }
},STAND_NAME{ },
ROUTE_SIGNAL_EXTRACT("根据起始、终点信号机匹配进路") {
@Override @Override
public Object matchParam(Simulation simulation, String... sourceStr) { public Object matchParam(Simulation simulation, String... sourceStr) {
return null; if (sourceStr == null || sourceStr.length < 2) {
} throw new IllegalArgumentException("定位参数缺失");
}; }
String startSignalName = sourceStr[0], endSignalName = sourceStr[1];
Optional<Route> routeOptional = simulation.getRepository().getRouteList().stream()
public abstract Object matchParam(Simulation simulation, String... sourceStr); .filter(route -> {
if (route.getStart() == null || route.getDestination() == null) {
return false;
private static MapNamedElement findDevice(Simulation simulation, MapElement.DeviceType dt, Class<? extends MapNamedElement> eleClass,String matchVal){ }
List<? extends MapNamedElement> eleList = simulation.getRepository().getListByType(dt,eleClass); return Objects.equals(startSignalName, route.getStart().getShowName())
Map<Double,MapNamedElement> elementMap = Maps.newHashMap(); || Objects.equals(endSignalName, route.getDestination().getShowName());
for (MapNamedElement ele : eleList) { }).findFirst();
String namePinYin = PinYinUtil.toPinYin(ele.getName()); if (routeOptional.isPresent()) {
double ratio = StrUtils.getJaroWinklerSimilarityRatio(namePinYin,matchVal); return routeOptional.get();
elementMap.put(ratio,ele); }
throw new IllegalArgumentException("未找到【" + startSignalName + "-" + endSignalName + "】进路");
} }
Double d = elementMap.keySet().stream().mapToDouble(k->k).max().orElse(0D); },
MapNamedElement nameEle = elementMap.get(d); STAND_STATION_UP_DOWN_EXTRACT("根据车站、上下行匹配站台") {
if(Objects.isNull(nameEle)){ @Override
return null; public Object matchParam(Simulation simulation, String... sourceStr) {
if (sourceStr == null || sourceStr.length < 2) {
throw new IllegalArgumentException("定位参数缺失");
}
String stationName = sourceStr[0], upDown = sourceStr[1];
Station station = (Station) STATION_NAME_EXTRACT.matchParam(simulation, stationName);
boolean right = "SHANG".equals(upDown);
return station.getStandOf(right);
} }
return nameEle; },
;
/**
* 规则描述
*/
private String description;
ExtractRule(String description) {
this.description = description;
} }
public abstract Object matchParam(Simulation simulation, String... sourceStr);
} }

View File

@ -1,23 +1,51 @@
package club.joylink.rtss.simulation.cbtc.discriminate; package club.joylink.rtss.simulation.cbtc.discriminate;
import club.joylink.rtss.simulation.cbtc.Simulation; import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.data.map.MapElement;
import club.joylink.rtss.simulation.cbtc.data.map.Station;
import club.joylink.rtss.simulation.cbtc.member.SimulationMember; import club.joylink.rtss.simulation.cbtc.member.SimulationMember;
import org.springframework.util.StringUtils;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
/** /**
* 人员匹配规则 * 人员匹配规则
*/ */
public enum MemberParseRule { public enum MemberParseRule {
STATION_SUPERVISOR { STATION_SUPERVISOR("获取指定车站值班员") {
@Override @Override
public List<SimulationMember> matchMember(Simulation simulation, String sourceStr) { public List<SimulationMember> matchMember(Simulation simulation, ParamExtractResult extractResult) {
return null; if (extractResult != null && (extractResult.getValue() instanceof Station)) {
throw new IllegalArgumentException("人员匹配入参为空");
}
SimulationMember member =
simulation.getSimulationMember((MapElement) extractResult.getValue(), SimulationMember.Type.STATION_SUPERVISOR);
return Arrays.asList(member);
}
},
ALL_STATION_SUPERVISOR("全体车站值班员") {
@Override
public List<SimulationMember> matchMember(Simulation simulation, ParamExtractResult extractResult) {
List<SimulationMember> simulationMemberList = simulation.getSimulationMembers().stream()
.filter(simulationMember -> Objects.equals(SimulationMember.Type.STATION_SUPERVISOR, simulationMember.getType()))
.collect(Collectors.toList());
return simulationMemberList;
} }
}; };
/**
* 规则描述
*/
private String description;
public abstract List<SimulationMember> matchMember(Simulation simulation, String sourceStr); MemberParseRule(String description) {
this.description = description;
}
public abstract List<SimulationMember> matchMember(Simulation simulation, ParamExtractResult extractResult);
} }