This commit is contained in:
weizhihong 2023-05-15 13:19:29 +08:00
commit 9e08c224ac
3 changed files with 24 additions and 26 deletions

View File

@ -21,18 +21,15 @@ public class StationDiagram {
this.finalStation = false; this.finalStation = false;
} }
public StationDiagram(VirtualRealityTrain train,Float stationComplateRatio, Boolean finalStation){ public StationDiagram(VirtualRealityTrain train,Float stationCompleteRatio, Boolean finalStation){
this.groupNum = train.getGroupNumber(); this.groupNum = train.getGroupNumber();
this.right = train.isRight(); this.right = train.isRight();
this.stationCompleteRatio = stationComplateRatio; this.stationCompleteRatio = stationCompleteRatio;
this.finalStation = finalStation; this.finalStation = finalStation;
} }
public StationDiagram(VirtualRealityTrain train,boolean showTrainDiagram,Float stationComplateRatio, Boolean finalStation){ public StationDiagram(VirtualRealityTrain train,boolean showTrainDiagram,Float stationCompleteRatio, Boolean finalStation){
this.groupNum = train.getGroupNumber(); this(train,stationCompleteRatio,finalStation);
this.right = train.isRight();
this.stationCompleteRatio = stationComplateRatio;
this.finalStation = finalStation;
this.showTrainDiagram = showTrainDiagram; this.showTrainDiagram = showTrainDiagram;
} }

View File

@ -61,29 +61,28 @@ public class RuningService implements CalculateDiagram{
private Float calculateStationRatio(Simulation simulation,Section begin,Section end,VirtualRealityTrain train){ private Float calculateStationRatio(Simulation simulation,Section begin,Section end,VirtualRealityTrain train){
Long mapId = simulation.getBuildParams().getMap().getId(); Long mapId = simulation.getBuildParams().getMap().getId();
LocalDateTime simulationDateTime = simulation.getCorrectSystemTime(); LocalDateTime simulationDateTime = simulation.getCorrectSystemTime();
Float totalDis =null;
Float runOffset =null;
try{ try{
totalDis = CalculateService.calculateDistance(begin,end,train.isRight()); Float totalDis = CalculateService.calculateDistance(begin,end,train.isRight());
if(totalDis == 0F){ Float runOffset = 0F;
//车辆已经到达站点 float stationCompleteRatio = 1F;
return 1F; if(totalDis != 0F){
} float off = begin.getStopPointByDirection(train.isRight());
float off = begin.getStopPointByDirection(train.isRight()); runOffset = CalculateService.calculateDistanceIgnoreSwitchFromStationToTrainHead(new SectionPosition(begin,off),train.getHeadPosition(),train.isRight());
runOffset = CalculateService.calculateDistanceIgnoreSwitchFromStationToTrainHead(new SectionPosition(begin,off),train.getHeadPosition(),train.isRight()); if(runOffset != 1F){
double t = runOffset / totalDis; stationCompleteRatio = new BigDecimal(runOffset / totalDis).setScale(3, RoundingMode.HALF_UP).floatValue();
float d = new BigDecimal(t).setScale(3, RoundingMode.HALF_UP).floatValue(); if(stationCompleteRatio >= 1F){
if(d >= 1F){ stationCompleteRatio = 1F;
d = 1F; }
}
} }
log.debug("线路id:{} 仿真时间:{} 车次[{}] 方向[{}] 车头区段[{}] 车头位置[{}] 车尾区段[{}] 查找开始区段[{}] 结束区段[{}] 距离总长[{}] 剩余距离[{}] 已行驶[{}] 行驶完成度[{}]" log.debug("线路id:{} 仿真时间:{} 车次[{}] 方向[{}] 车头区段[{}] 车头位置[{}] 车尾区段[{}] 查找开始区段[{}] 结束区段[{}] 距离总长[{}] 剩余距离[{}] 已行驶[{}] 行驶完成度[{}]"
,mapId,simulationDateTime ,mapId,simulationDateTime
,train.getGroupNumber(),train.isRight(),train.getHeadPosition().getSection().getCode(),train.getHeadPosition().getOffset() ,train.getGroupNumber(),train.isRight(),train.getHeadPosition().getSection().getCode(),train.getHeadPosition().getOffset()
,train.getTailPosition().getSection().getCode(), begin.getCode(),end.getCode() , totalDis ,(totalDis - runOffset),runOffset ,d); ,train.getTailPosition().getSection().getCode(), begin.getCode(),end.getCode() , totalDis ,(totalDis - runOffset),runOffset ,stationCompleteRatio);
return Math.abs(d); return Math.abs(stationCompleteRatio);
}catch (Exception e){ }catch (Exception e){
log.error("计算失败 线路id:{} 仿真时间:{} groupNum:{},isRight:{},begin:{},end:{},totalDis:{},targetDis:{} 错误信息:{}",mapId,simulationDateTime log.error("计算失败 线路id:{} 仿真时间:{} groupNum:{},isRight:{},begin:{},end:{}, 错误信息:{}",mapId,simulationDateTime
,train.getGroupNumber() ,train.isRight(),begin.getCode() ,end.getCode() ,totalDis , runOffset,e.getMessage(),e); ,train.getGroupNumber() ,train.isRight(),begin.getCode() ,end.getCode() ,e.getMessage(),e);
return null; return null;
} }
} }

View File

@ -1257,10 +1257,12 @@ public class CalculateService {
} else { } else {
offset = startPosition.getOffset() - endPosition.getOffset(); offset = startPosition.getOffset() - endPosition.getOffset();
} }
if (offset > 0) { if (offset >= 0) {
return offset; return offset;
} else { } else {
return null; return 1F;
// return Math.abs(offset);
// return null;
} }
} else { } else {
Float distance = recursiveCalculate(startPosition.getSection(), endPosition.getSection(), right, (byte) 51); Float distance = recursiveCalculate(startPosition.getSection(), endPosition.getSection(), right, (byte) 51);