From 5fb422d3d0e9729d53292c7211c7114993783b90 Mon Sep 17 00:00:00 2001 From: tiger_zhou <123456> Date: Sun, 23 Apr 2023 18:04:14 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=97=E8=BD=A6=E5=9B=BE=E4=BE=8B=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E4=BD=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cbtc/ATS/ATSTrainMessageDiagram.java | 185 ++++++++++-------- .../cbtc/ATS/data/StationDiagram.java | 12 +- .../ATS/service/diagram/CalculateDiagram.java | 11 ++ .../simulation/cbtc/data/map/Section.java | 11 +- .../simulation/cbtc/data/vo/TrainInfo.java | 4 +- .../cbtc/data/vr/VirtualRealityTrain.java | 4 +- .../message/SimulationSubscribeTopic.java | 3 +- .../work/MetroSimulationWorkServiceImpl.java | 3 +- .../client/factory/SocketMessageFactory.java | 5 +- 9 files changed, 145 insertions(+), 93 deletions(-) create mode 100644 src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/diagram/CalculateDiagram.java diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/ATSTrainMessageDiagram.java b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/ATSTrainMessageDiagram.java index feaf15ba9..e67479473 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/ATSTrainMessageDiagram.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/ATSTrainMessageDiagram.java @@ -1,11 +1,14 @@ package club.joylink.rtss.simulation.cbtc.ATS; import club.joylink.rtss.simulation.cbtc.ATS.data.StationDiagram; +import club.joylink.rtss.simulation.cbtc.CTC.data.CtcStationRunPlanLog; import club.joylink.rtss.simulation.cbtc.Simulation; import club.joylink.rtss.simulation.cbtc.constant.SimulationConstants; import club.joylink.rtss.simulation.cbtc.constant.SimulationModule; import club.joylink.rtss.simulation.cbtc.data.CalculateService; -import club.joylink.rtss.simulation.cbtc.data.map.Section; +import club.joylink.rtss.simulation.cbtc.data.map.*; +import club.joylink.rtss.simulation.cbtc.data.plan.StationPlan; +import club.joylink.rtss.simulation.cbtc.data.plan.TripPlan; import club.joylink.rtss.simulation.cbtc.data.support.SectionPosition; import club.joylink.rtss.simulation.cbtc.data.vo.TrainInfo; import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityTrain; @@ -17,14 +20,14 @@ import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.ObjectUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -import org.springframework.util.CollectionUtils; +import java.io.BufferedReader; +import java.io.FileReader; import java.math.BigDecimal; import java.math.RoundingMode; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; +import java.util.*; +import java.util.stream.Collectors; +import java.util.stream.IntStream; /** * 收集列车相关信息 @@ -36,110 +39,96 @@ public class ATSTrainMessageDiagram { private StompMessageService stompMessageService; public void collect(Simulation simulation){ - List stationDiagramList = Lists.newArrayList(); + + KmStation kmStation = new KmStation(simulation); + List stationDiagramList = Lists.newArrayList(); for (VirtualRealityTrain train : simulation.getRepository().getOnlineTrainList()) { + Section target = train.getTarget(); if(ObjectUtils.anyNull(target,train.getNextStation(),train.getTerminalStation())){ + StationDiagram sd = new StationDiagram(train,0F,false); + stationDiagramList.add(sd); continue; } TrainInfo trainInfo = simulation.getRepository().getSupervisedTrainByGroup(train.getGroupNumber()); if(Objects.nonNull(trainInfo) && trainInfo.isInbound()){ + StationDiagram sd = new StationDiagram(train,0F,false); + stationDiagramList.add(sd); continue; } + Station nextStation = train.getNextStation(); + SectionPosition tailPos = train.getTailPosition(); + if(nextStation.isDepot() && !tailPos.getSection().isStandTrack()){ + //出站 + StationDiagram sd = new StationDiagram(train,0F,false); + stationDiagramList.add(sd); + }else if(trainInfo.isTurnBack()){ + //列车正在折返 + StationDiagram sd = new StationDiagram(train,0F,true); + sd.setStartStation(train.getNextStation()); + sd.setTurnBack(true); + stationDiagramList.add(sd); + }else{ + Optional optionalDiagram = this.calculateRuning2(simulation,train,trainInfo,kmStation); + optionalDiagram.ifPresent(stationDiagramList::add); - Optional optionalDiagram = this.calculate(train); - optionalDiagram.ifPresent(stationDiagramList::add); + } } SocketMessageVO> messageVO = SocketMessageFactory.buildAtsStationDiagram(simulation.getId(), stationDiagramList); Set sessions = simulation.getSimulationUserIds(); stompMessageService.sendToUser(sessions, messageVO); - } - /*public void collect(Simulation simulation){ - for (VirtualRealityTrain train : simulation.getRepository().getOnlineTrainList()) { - Section target = train.getTarget(); - if(ObjectUtils.anyNull(target,train.getNextStation(),train.getTerminalStation())){ - continue; - } - TrainInfo trainInfo = simulation.getRepository().getSupervisedTrainByGroup(train.getGroupNumber()); - if(Objects.nonNull(trainInfo) && trainInfo.isInbound()){ - continue; - } - if(train.isParkingAt()){ - trainInfo.setStationDiagramRatio(1F); - }else { - Section endSeciont = target; - if(!Objects.equals(train.getNextStation().getCode(),train.getTerminalStation().getCode())) { - //车辆的下一站不是终点站,获取下一站的停车位置 - SectionPosition sp = train.calculateNextStandStopPosition(); - endSeciont = sp.getSection(); - } - SectionPosition tailSP = train.getTailPosition(); - Section tailSection = tailSP.getSection(); - Section parent = tailSection; - if(!tailSection.isPhysical()){ - parent = tailSection.getParent(); - } - //如果车尾所在的区段是逻辑区段那么就查找车辆后方的车站 - if(Objects.isNull(parent.getStation())){ - SectionPosition sp1 = train.calculateBackStandStopPosition(); - if(Objects.isNull(sp1)){ - //未找到列车后面的车站 - continue; - } - tailSection = sp1.getSection(); - } - Float complateDis = this.calculateStationRatio(tailSection,endSeciont,train); - trainInfo.setStationDiagramRatio(complateDis); + + private Optional calculateRuning2(Simulation simulation,VirtualRealityTrain train,TrainInfo trainInfo,KmStation kmStation){ + + + Section leaveSeaction = simulation.getRepository().getByCode(Objects.isNull(trainInfo.getEstimatedLeaveStandTrack()) ? trainInfo.getActualLeaveStandTrack() : trainInfo.getEstimatedLeaveStandTrack(),Section.class); + Section trainSection = train.getHeadPosition().getSection(); + + if(train.isParkingAt()){ + if(trainSection.isStandTrack() && Objects.equals(trainSection.getStation().getCode(),trainInfo.getStartStation())){ + //到达始发站 + StationDiagram sd = new StationDiagram(train,true,0F,false); + sd.setStartStation(trainSection.getStation()); + Station nextStation = kmStation.findNext(trainSection.getStation(),train.isRight()); + + sd.setEndStation(nextStation); + return Optional.of(sd); + }else if(trainSection.isStandTrack() || (trainSection.isStandTrack() && Objects.equals(trainSection.getStation().getCode(),trainInfo.getEndStation()))){ + //列车停靠车站或到终点站 + + StationDiagram sd = new StationDiagram(train,true,1F,true); + Station preStation = kmStation.findPre(trainSection.getStation(),train.isRight()); + sd.setStartStation(preStation); + sd.setEndStation(trainSection.getStation()); + + return Optional.of(sd); } } - }*/ - - - private Optional calculate(VirtualRealityTrain train){ - boolean finalStation = true; - Section targetSecion = train.getTarget(); - Section tailSection = train.getTailPosition().getSection(); - - if(!Objects.equals(train.getNextStation().getCode(),train.getTerminalStation().getCode())) { + Section targetStand = train.getTerminalStation().getStandOf(train.isRight()).get(0).getSection(); + if(!Objects.equals(train.getNextStation().getCode(),trainInfo.getEndStation())) { //车辆的下一站不是终点站,获取下一站的停车位置 finalStation = false; - SectionPosition sp = train.calculateNextStandStopPosition(); - if(Objects.isNull(sp)){ - StationDiagram sd = new StationDiagram(train,false); - return Optional.of(sd); - } - targetSecion = sp.getSection(); - } + targetStand = train.getNextStation().getStandOf(train.isRight()).get(0).getSection(); - if(!tailSection.isStandTrack()){ - //如果车尾所在的区段是逻辑区段那么就查找车辆后方的车站 - SectionPosition sp1 = train.calculateBackStandStopPosition(); - if(Objects.isNull(sp1)){ - //未找到列车后面的车站,可能还未进始发站 - StationDiagram sd = new StationDiagram(train,false); - return Optional.of(sd); - } - tailSection = sp1.getSection(); } + Float complateDis = this.calculateStationRatio(leaveSeaction,targetStand,train); - Float complateDis = 1F; - if(!train.isParkingAt()){ - complateDis = this.calculateStationRatio(tailSection,targetSecion,train); - } StationDiagram stationDiagram = new StationDiagram(train,true,complateDis,finalStation); - stationDiagram.setStartStation(tailSection.getStation()); - stationDiagram.setEndStation(train.getNextStation()); + stationDiagram.setStartStation(leaveSeaction.getStation()); + stationDiagram.setEndStation(targetStand.getStation()); return Optional.of(stationDiagram); + } + private Float calculateStationRatio(Section begin,Section end,VirtualRealityTrain train){ float totalDis = CalculateService.calculateDistance(begin,end,train.isRight()); if(totalDis == 0F){ @@ -151,19 +140,53 @@ public class ATSTrainMessageDiagram { if(runDis > 0){ t = runDis / totalDis;; } - float d = new BigDecimal(t + "") - .setScale(3, RoundingMode.HALF_UP).floatValue(); + float d = new BigDecimal(t).setScale(3, RoundingMode.HALF_UP).floatValue(); log.debug("车次[{}] 方向[{}] 车头区段[{}] 车尾区段[{}] 是否停靠[{}] 查找开始区段[{}] 结束区段[{}] 距离总长[{}] 剩余距离[{}] 行驶完成度[{}]" ,train.getGroupNumber(),train.isRight(),train.getHeadPosition().getSection().getCode() ,train.getTailPosition().getSection().getCode(),train.isParkingAt(),begin.getCode(),end.getCode() , totalDis ,train.getTargetDistance() ,d); - d = Math.abs(d); - return d; + return Math.abs(d); }catch (Exception e){ log.error("计算失败 groupNum:{},isRight:{},begin:{},end:{},totalDis:{},targetDis:{}",train.getGroupNumber() ,train.isRight(),begin.getCode() ,end.getCode() ,totalDis , train.getTargetDistance()); return null; } } + public static class KmStation{ + private List stationList; + public KmStation(Simulation simulation){ + List list = simulation.getRepository().getListByType(MapElement.DeviceType.STATION,Station.class); + stationList = list.stream().sorted((o1, o2) -> Float.compare(o1.getKmPostVal(),o2.getKmPostVal())).filter(d->!d.isDepot()).collect(Collectors.toList()); + } + + public int findIndex(Station station){ + return IntStream.range(0,stationList.size()).filter(d->Objects.equals(stationList.get(d).getCode(),station.getCode())).findFirst().getAsInt(); + } + public Station findNext(Station station,boolean isRight){ + int index = this.findIndex(station); + if(isRight){ + return stationList.get(index + 1); + }else{ + + return stationList.get(index - 1); + } + + } + public Station findPre(Station station,boolean isRight){ + int index = this.findIndex(station); + if(isRight){ + return stationList.get(index - 1); + }else{ + return stationList.get(index + 1); + + } + } + public Station find(Station station){ + int index = this.findIndex(station); + return stationList.get(index); + } + + } + public void addJobs(Simulation simulation){ simulation.addFixedRateJob(SimulationModule.TRAIN_DIAGRAM.name(), () -> collect(simulation), SimulationConstants.TRAIN_DIAGRAM_RATE); } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/data/StationDiagram.java b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/data/StationDiagram.java index 4f8e0aa0e..fa99ea8df 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/data/StationDiagram.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/data/StationDiagram.java @@ -4,12 +4,14 @@ import club.joylink.rtss.simulation.cbtc.data.map.Station; import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityTrain; import lombok.Data; import lombok.NoArgsConstructor; +import lombok.ToString; /** * ncc车站运行图例消息 */ @Data @NoArgsConstructor +@ToString public class StationDiagram { @@ -60,21 +62,23 @@ public class StationDiagram { /** * 运行开始车站 */ - private String startStation; +// private String startStation; private String startStationCode; /** * 到达车站 */ - private String targetStation; +// private String targetStation; private String targetStationCode; + private boolean turnBack; + public void setStartStation(Station station){ - this.startStation = station.getName(); +// this.startStation = station.getName(); this.startStationCode = station.getCode(); } public void setEndStation(Station station){ - this.targetStation = station.getName(); +// this.targetStation = station.getName(); this.targetStationCode = station.getCode(); } } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/diagram/CalculateDiagram.java b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/diagram/CalculateDiagram.java new file mode 100644 index 000000000..a2ef2dfd4 --- /dev/null +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/diagram/CalculateDiagram.java @@ -0,0 +1,11 @@ +package club.joylink.rtss.simulation.cbtc.ATS.service.diagram; + +import club.joylink.rtss.simulation.cbtc.ATS.data.StationDiagram; +import club.joylink.rtss.simulation.cbtc.data.plan.TripPlan; +import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityTrain; + +import java.util.Optional; + +public interface CalculateDiagram { + Optional calculate(VirtualRealityTrain train, TripPlan tripPlan); +} diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/data/map/Section.java b/src/main/java/club/joylink/rtss/simulation/cbtc/data/map/Section.java index 09261a881..7fe7c7e13 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/data/map/Section.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/data/map/Section.java @@ -465,7 +465,16 @@ public class Section extends DelayUnlockDevice { } return null; } - + public Section findBackRunningSectionBaseRealSwitch(boolean right) { + if (right && Objects.nonNull(this.leftSection)) { + return this.leftSection; + } else if (!right && Objects.nonNull(this.rightSection)) { + return this.rightSection; + } else if (this.isSwitchTrack()) { + return this.getRelSwitch().getNextSectionBaseRealSwitch(this); + } + return null; + } /** * 获取左/右向关联的区段 * diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/data/vo/TrainInfo.java b/src/main/java/club/joylink/rtss/simulation/cbtc/data/vo/TrainInfo.java index bf90c5c08..b758d40c7 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/data/vo/TrainInfo.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/data/vo/TrainInfo.java @@ -310,8 +310,8 @@ public class TrainInfo extends MapElement { /** * 车站之间的运行比例 */ - @Setter - private Float stationDiagramRatio; +// @Setter +// private Float stationDiagramRatio; public TrainInfo(String groupNumber) { super(groupNumber, DeviceType.TRAIN); this.groupNumber = groupNumber; diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/data/vr/VirtualRealityTrain.java b/src/main/java/club/joylink/rtss/simulation/cbtc/data/vr/VirtualRealityTrain.java index ece2183b3..ef0476882 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/data/vr/VirtualRealityTrain.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/data/vr/VirtualRealityTrain.java @@ -851,10 +851,10 @@ public class VirtualRealityTrain extends VirtualRealityDevice { */ public SectionPosition calculateBackStandStopPosition(){ SectionPosition tailPosition = this.tailPosition; - boolean right = !this.right; + boolean right = this.right; Section section = tailPosition.getSection(); for (int i = 0; i < 100; i++) { - section = section.findNextRunningSectionBaseRealSwitch(right); + section = section.findBackRunningSectionBaseRealSwitch(right); if (section == null) { break; } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/message/SimulationSubscribeTopic.java b/src/main/java/club/joylink/rtss/simulation/cbtc/message/SimulationSubscribeTopic.java index 82c063590..118385d86 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/message/SimulationSubscribeTopic.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/message/SimulationSubscribeTopic.java @@ -20,7 +20,8 @@ public enum SimulationSubscribeTopic { Room("/queue/room/{id}"), Wgu3d("/topic/simulation/wgu3d/{id}"), YJDDZH_TRAIN_POSITION("/topic/yjddzh/trainPosition/simulation/{id}"), - RUN_FACT("/queue/simulation/{id}/runFact") + RUN_FACT("/queue/simulation/{id}/runFact"), + NCC_DIAGRAM("/queue/diagram/simulation/{id}") ; private String destPattern; diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/work/MetroSimulationWorkServiceImpl.java b/src/main/java/club/joylink/rtss/simulation/cbtc/work/MetroSimulationWorkServiceImpl.java index 82c730b40..d38d75951 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/work/MetroSimulationWorkServiceImpl.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/work/MetroSimulationWorkServiceImpl.java @@ -213,7 +213,7 @@ public class MetroSimulationWorkServiceImpl implements SimulationWorkService { atsLogicLoop.addJobs(simulation); simulationRobotService.addJobs(simulation); vrTrainRunningService.addJobs(simulation); - trainMessageDiagram.addJobs(simulation); + vrDeviceLogicLoop.addJobs(simulation); ciLogic.addJobs(simulation); @@ -221,6 +221,7 @@ public class MetroSimulationWorkServiceImpl implements SimulationWorkService { faultGenerator.addJobs(simulation); atsMessageCollectAndDispatcher.addJobs(simulation); nccAlarmService.addJobs(simulation); + trainMessageDiagram.addJobs(simulation); } @Override diff --git a/src/main/java/club/joylink/rtss/vo/client/factory/SocketMessageFactory.java b/src/main/java/club/joylink/rtss/vo/client/factory/SocketMessageFactory.java index 2750e0cfc..79b70ec3c 100644 --- a/src/main/java/club/joylink/rtss/vo/client/factory/SocketMessageFactory.java +++ b/src/main/java/club/joylink/rtss/vo/client/factory/SocketMessageFactory.java @@ -71,6 +71,10 @@ public class SocketMessageFactory { private static List getTopicsBy(WebSocketMessageType messageType, String group) { List topicList = new ArrayList<>(); switch (messageType) { + case SIMULATION_NCC_STATION_DIAGRAM:{ + topicList.add(SimulationSubscribeTopic.NCC_DIAGRAM.buildDestination(group)); + break; + } case YJDDZH_TRAIN_POSITION: { topicList.add(SimulationSubscribeTopic.YJDDZH_TRAIN_POSITION.buildDestination(group)); @@ -105,7 +109,6 @@ public class SocketMessageFactory { case SIMULATION_RAIL_TICKET: case Simulation_Alarm: case Simulation_Operation_Mode_Apply: - case SIMULATION_NCC_STATION_DIAGRAM: case Simulation_Conversation_Group: { topicList.add(SimulationSubscribeTopic.Main.buildDestination(group)); break;