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 75d9d214b..4b44a53ab 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,20 +1,13 @@ package club.joylink.rtss.simulation.cbtc.ATS; import club.joylink.rtss.services.cache.ICacheService; -import club.joylink.rtss.simulation.SimulationManager; import club.joylink.rtss.simulation.cbtc.ATS.data.SortDiagramStation; import club.joylink.rtss.simulation.cbtc.ATS.data.StationDiagram; import club.joylink.rtss.simulation.cbtc.ATS.service.diagram.*; -import club.joylink.rtss.simulation.cbtc.CTC.data.CtcStationRunPlanLog; -import club.joylink.rtss.simulation.cbtc.GroupSimulationCache; 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.*; -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.map.Section; import club.joylink.rtss.simulation.cbtc.data.vo.TrainInfo; import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityTrain; import club.joylink.rtss.vo.client.SocketMessageVO; @@ -25,17 +18,13 @@ 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 javax.annotation.PostConstruct; -import java.io.BufferedReader; -import java.io.FileReader; -import java.math.BigDecimal; -import java.math.RoundingMode; -import java.util.*; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; import java.util.concurrent.TimeUnit; -import java.util.stream.Collectors; -import java.util.stream.IntStream; /** * 收集列车相关信息 @@ -53,8 +42,8 @@ public class ATSTrainMessageDiagram { @PostConstruct private void init(){ - CALCULATE_DIAGRAM_LIST.add(new InOutBoundService()); CALCULATE_DIAGRAM_LIST.add(new TurnBackService()); + CALCULATE_DIAGRAM_LIST.add(new InOutBoundService()); CALCULATE_DIAGRAM_LIST.add(new PackingService()); CALCULATE_DIAGRAM_LIST.add(new RuningService()); } @@ -100,6 +89,6 @@ public class ATSTrainMessageDiagram { public void addJobs(Simulation simulation){ - simulation.addFixedRateJob(SimulationModule.TRAIN_DIAGRAM.name(), () -> collect(simulation), SimulationConstants.TRAIN_DIAGRAM_RATE); + simulation.addJob(SimulationModule.TRAIN_DIAGRAM.name(), () -> collect(simulation), SimulationConstants.TRAIN_DIAGRAM_RATE); } } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/ATSTrainMessageDiagram2.java b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/ATSTrainMessageDiagram2.java deleted file mode 100644 index a6e916b72..000000000 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/ATSTrainMessageDiagram2.java +++ /dev/null @@ -1,208 +0,0 @@ -/* -package club.joylink.rtss.simulation.cbtc.ATS; - -import club.joylink.rtss.simulation.cbtc.ATS.data.StationDiagram; -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.MapElement; -import club.joylink.rtss.simulation.cbtc.data.map.Section; -import club.joylink.rtss.simulation.cbtc.data.map.Station; -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; -import club.joylink.rtss.vo.client.SocketMessageVO; -import club.joylink.rtss.vo.client.factory.SocketMessageFactory; -import club.joylink.rtss.websocket.StompMessageService; -import com.google.common.collect.Lists; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.ObjectUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -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.stream.Collectors; -import java.util.stream.IntStream; - -*/ -/** - * 收集列车相关信息 - *//* - -@Component -@Slf4j -public class ATSTrainMessageDiagram2 { - @Autowired - private StompMessageService stompMessageService; - - public void collect(Simulation simulation){ - - KmStation kmStation = new KmStation(simulation); - List stationDiagramList = Lists.newArrayList(); - for (VirtualRealityTrain train : simulation.getRepository().getOnlineTrainList()) { - TrainInfo trainInfo = simulation.getRepository().findSupervisedTrainByGroup(train.getGroupNumber()); - Section target = train.getTarget(); - if(ObjectUtils.anyNull(trainInfo,target,train.getNextStation(),train.getTerminalStation())){ - StationDiagram sd = new StationDiagram(train,0F,false); - stationDiagramList.add(sd); - continue; - } - 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); - } - } - SocketMessageVO> messageVO = - SocketMessageFactory.buildAtsStationDiagram(simulation.getId(), stationDiagramList); - Set sessions = simulation.getSimulationUserIds(); - stompMessageService.sendToUser(sessions, messageVO); - } - - - - - private Optional calculateRuning2(Simulation simulation,VirtualRealityTrain train,TrainInfo trainInfo,KmStation kmStation){ - - Section trainSection = train.getHeadPosition().getSection(); - - Section arttiveSection = simulation.getRepository().getByCode(trainInfo.getEstimatedArriveStandTrack(),Section.class); - - 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); - } - } - - if(Objects.equals(train.getNextStation().getCode(),trainInfo.getStartStation())){ - StationDiagram sd = new StationDiagram(train,true,0F,false); - sd.setStartStation(train.getNextStation()); - Station nextStation = kmStation.findNext(train.getNextStation(),train.isRight()); - sd.setEndStation(nextStation); - return Optional.of(sd); - } - - String d = Objects.isNull(trainInfo.getEstimatedLeaveStandTrack()) ? trainInfo.getActualLeaveStandTrack() : trainInfo.getEstimatedLeaveStandTrack(); - Section leaveSeaction = simulation.getRepository().getByCode(d,Section.class); - Station endStation = simulation.getRepository().getByCode(trainInfo.getEndStation(),Station.class); - if(Objects.equals(leaveSeaction.getStation().getCode(),trainInfo.getEndStation())){ - StationDiagram sd = new StationDiagram(train,true,1F,true); - Station preStation = kmStation.findPre(leaveSeaction.getStation(),train.isRight()); - sd.setStartStation(preStation); - sd.setEndStation(endStation); - return Optional.of(sd); - }else{ - Station targetStation = kmStation.findNext(leaveSeaction.getStation(),train.isRight()); - Section targetStand = targetStation.getStandOf(train.isRight()).get(0).getSection(); - Float complateDis = this.calculateStationRatio(leaveSeaction,targetStand,train); - StationDiagram stationDiagram = new StationDiagram(train,true,complateDis,false); - 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){ - return 1F; - } - try{ - float runDis = totalDis - train.getTargetDistance(); - double t = 0D; - if(runDis > 0){ - t = runDis / totalDis;; - } - 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); - 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/SortDiagramStation.java b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/data/SortDiagramStation.java index adcc21a9f..cf0caa362 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/data/SortDiagramStation.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/data/SortDiagramStation.java @@ -13,12 +13,17 @@ public class SortDiagramStation { private List stationList; public SortDiagramStation(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()); + 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){ 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 fa99ea8df..29a2a2026 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 @@ -14,6 +14,12 @@ import lombok.ToString; @ToString public class StationDiagram { + public StationDiagram(VirtualRealityTrain train){ + this.groupNum = train.getGroupNumber(); + this.right = train.isRight(); + this.stationComplateRatio = 0F; + this.finalStation = false; + } public StationDiagram(VirtualRealityTrain train,Float stationComplateRatio, Boolean finalStation){ this.groupNum = train.getGroupNumber(); @@ -22,12 +28,6 @@ public class StationDiagram { this.finalStation = finalStation; } - public StationDiagram(VirtualRealityTrain train,boolean showTrainDiagram){ - this.groupNum = train.getGroupNumber(); - this.right = train.isRight(); - this.showTrainDiagram = showTrainDiagram; - } - public StationDiagram(VirtualRealityTrain train,boolean showTrainDiagram,Float stationComplateRatio, Boolean finalStation){ this.groupNum = train.getGroupNumber(); this.right = train.isRight(); diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/diagram/InOutBoundService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/diagram/InOutBoundService.java index a6f7418bb..b0c95d34f 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/diagram/InOutBoundService.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/diagram/InOutBoundService.java @@ -7,6 +7,8 @@ import club.joylink.rtss.simulation.cbtc.data.map.Station; 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; +import lombok.extern.slf4j.Slf4j; +import org.springframework.util.StringUtils; import java.util.Objects; import java.util.Optional; @@ -14,28 +16,34 @@ import java.util.Optional; /** * 车辆出入库 */ +@Slf4j public class InOutBoundService implements CalculateDiagram{ @Override public Optional calculate(Simulation simulation, TrainInfo trainInfo, VirtualRealityTrain train, SortDiagramStation diagramStation){ if(trainInfo.isInbound()){ - StationDiagram sd = new StationDiagram(train,0F,false); + StationDiagram sd = new StationDiagram(train); + sd.setShowTrainDiagram(false); return Optional.of(sd); } Station nextStation = train.getNextStation(); SectionPosition tailPos = train.getTailPosition(); if(nextStation.isDepot() && !tailPos.getSection().isStandTrack()) { - //入库 - StationDiagram sd = new StationDiagram(train, 0F, false); + //列车入库,车尾离开站台轨 + StationDiagram sd = new StationDiagram(train); + sd.setShowTrainDiagram(false); + log.debug("列车[{}] 入库 即将驶向[{}] 方向[{}]",train.getGroupNumber(),nextStation.getCode(),train.isRight()); return Optional.of(sd); } - if(Objects.equals(nextStation.getCode(),trainInfo.getStartStation())){ + if(Objects.equals(nextStation.getCode(),trainInfo.getStartStation()) || StringUtils.isEmpty(trainInfo.getStartStation())){ //出库 - StationDiagram sd = new StationDiagram(train,true,0F,false); + StationDiagram sd = new StationDiagram(train); sd.setStartStation(train.getNextStation()); Station nextStopStation = diagramStation.findNext(nextStation,train.isRight()); sd.setEndStation(nextStopStation); + sd.setShowTrainDiagram(true); + log.debug("列车[{}] 出库 前站[{}] 方向[{}]",train.getGroupNumber(),nextStation.getCode(),train.isRight()); return Optional.of(sd); } return Optional.empty(); diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/diagram/PackingService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/diagram/PackingService.java index 3d9f11de2..020692876 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/diagram/PackingService.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/diagram/PackingService.java @@ -7,6 +7,7 @@ import club.joylink.rtss.simulation.cbtc.data.map.Section; import club.joylink.rtss.simulation.cbtc.data.map.Station; import club.joylink.rtss.simulation.cbtc.data.vo.TrainInfo; import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityTrain; +import lombok.extern.slf4j.Slf4j; import java.util.Objects; import java.util.Optional; @@ -14,25 +15,35 @@ import java.util.Optional; /** * 车辆停靠站 */ +@Slf4j public class PackingService implements CalculateDiagram{ @Override public Optional calculate(Simulation simulation, TrainInfo trainInfo, VirtualRealityTrain train, SortDiagramStation diagramStation){ Section trainSection = train.getHeadPosition().getSection(); + Station endStation = train.getTerminalStation(); + if(endStation.isDepot()){ + endStation = diagramStation.findPre(endStation,train.isRight()); + } if(train.isParkingAt()){ + if(trainSection.isStandTrack() && Objects.equals(trainSection.getStation().getCode(),trainInfo.getStartStation())){ //停留在始发站 - StationDiagram sd = new StationDiagram(train,true,0F,false); + StationDiagram sd = new StationDiagram(train); sd.setStartStation(trainSection.getStation()); Station nextStation = diagramStation.findNext(trainSection.getStation(),train.isRight()); sd.setEndStation(nextStation); + sd.setShowTrainDiagram(true); + log.debug("列车[{}] 方向[{}] 停靠车站[{}] 查找前方车站[{}]",train.getGroupNumber(),train.isRight(),trainSection.getStation().getCode(),nextStation.getCode()); return Optional.of(sd); - }else if(trainSection.isStandTrack() || (trainSection.isStandTrack() && Objects.equals(trainSection.getStation().getCode(),trainInfo.getEndStation()))){ + }else if(trainSection.isStandTrack() || (trainSection.isStandTrack() && Objects.equals(trainSection.getStation().getCode(),endStation.getCode()))){ //列车停靠车站或到终点站 StationDiagram sd = new StationDiagram(train,true,1F,true); + Station preStation = diagramStation.findPre(trainSection.getStation(),train.isRight()); sd.setStartStation(preStation); sd.setEndStation(trainSection.getStation()); + log.debug("列车[{}] 方向[{}] 停靠车站[{}] 查找前方车站[{}]",train.getGroupNumber(),train.isRight(),trainSection.getStation().getCode(),preStation.getCode()); return Optional.of(sd); } //中途停靠站不处理 diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/diagram/RuningService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/diagram/RuningService.java index 0836382a7..917d2b7b6 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/diagram/RuningService.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/diagram/RuningService.java @@ -25,8 +25,13 @@ public class RuningService implements CalculateDiagram{ public Optional calculate(Simulation simulation, TrainInfo trainInfo, VirtualRealityTrain train, SortDiagramStation diagramStation){ String d = Objects.isNull(trainInfo.getEstimatedLeaveStandTrack()) ? trainInfo.getActualLeaveStandTrack() : trainInfo.getEstimatedLeaveStandTrack(); Section leaveSeaction = simulation.getRepository().getByCode(d,Section.class); - Station endStation = simulation.getRepository().getByCode(trainInfo.getEndStation(),Station.class); - if(Objects.equals(leaveSeaction.getStation().getCode(),trainInfo.getEndStation())){ + Station endStation = train.getTerminalStation(); + if(endStation.isDepot()){ + endStation = diagramStation.findPre(endStation,train.isRight()); + } + + if(Objects.equals(leaveSeaction.getStation().getCode(),endStation.getCode())){ + //列车即将驶离终点站 StationDiagram sd = new StationDiagram(train,true,1F,true); Station preStation = diagramStation.findPre(leaveSeaction.getStation(),train.isRight()); sd.setStartStation(preStation);