武汉8号线列车位置显示功能

This commit is contained in:
tiger_zhou 2022-09-07 10:01:58 +08:00
parent 7065625895
commit 753c314292
2 changed files with 47 additions and 14 deletions

View File

@ -7,6 +7,8 @@ import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.build.SimulationBuildParams;
import club.joylink.rtss.simulation.cbtc.data.map.Section;
import club.joylink.rtss.vo.ws.TrainPosition;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
@ -14,10 +16,7 @@ import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import javax.annotation.Resource;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
@ -28,9 +27,9 @@ public class TrainPositionService {
AtsTrainLoadService atsTrainLoadService;
@Resource
SimulationManager simulationManager;
final Map<Section.SectionRoadType,List<Section>> map = new ConcurrentHashMap<>();
private final static Cache<Section.SectionRoadType,List<Section>> ROAD_TYPE_CACHE = CacheBuilder.newBuilder().build();
public void initTrainOrUpdate(String mapName,TrainPosition tp){
// this.simulationManager.getSimulationList().stream().filter(d->d.getb)
List<Simulation> simulationList = this.findSimulationList(mapName);
if(Objects.equals(true, CollectionUtils.isEmpty(simulationList))){
@ -38,21 +37,40 @@ public class TrainPositionService {
return;
}
List<Section> sectionList = findDirectionAllSection(simulationList.get(0),tp.getRoadType());
for (Simulation sim : simulationList) {
}
}
private void findSection(Simulation sim,TrainPosition tp,Section.SectionRoadType roadType){
/* Section.SectionRoadType roadType = Section.SectionRoadType.LEFT;
if(tp.getDirection() == 1){
roadType = Section.SectionRoadType.RIGHT;
}*/
List<Section> list = sim.getRepository().getSectionList();
list.stream().filter(d->d.getRoadType() == roadType).sorted((o1, o2) -> Integer.compare(1,2)).collect(Collectors.toList());
private void findSecion(List<Section> sectionList,TrainPosition tp){
int i = 0;
Section findSection;
for (Section section : sectionList) {
if(tp.isRight()){
if(tp.getLocation() <= section.getKmMax()){
findSection = section;
break;
}
}else{
}
i++;
}
}
private static synchronized List<Section> findDirectionAllSection(Simulation sim,Section.SectionRoadType roadType){
List<Section> list = ROAD_TYPE_CACHE.getIfPresent(roadType);
if(Objects.equals(true,CollectionUtils.isEmpty(list))){
list = sim.getRepository().getSectionList();
list = list.stream().filter(d->d.getRoadType() == roadType)
.sorted(Comparator.comparing(Section::getKmMin)/*.reversed()*/).collect(Collectors.toList());
ROAD_TYPE_CACHE.put(roadType,list);
}
return list;
}
private List<Simulation> findSimulationList(String mapName){
return this.simulationManager.getSimulationList().stream().filter(d->{
if(d instanceof Simulation){

View File

@ -1,5 +1,6 @@
package club.joylink.rtss.vo.ws;
import club.joylink.rtss.simulation.cbtc.data.map.Section;
import lombok.Data;
import lombok.NoArgsConstructor;
@ -7,6 +8,20 @@ import lombok.NoArgsConstructor;
@NoArgsConstructor
public class TrainPosition {
private String trainTripNum;
/**
* 方向1=上行向右0=下行(向左)
*/
private int direction;
private float location;
public Section.SectionRoadType getRoadType(){
Section.SectionRoadType type = Section.SectionRoadType.LEFT;
if(this.direction == 1){
return Section.SectionRoadType.RIGHT;
}
return type;
}
public boolean isRight(){
return this.direction == 1;
}
}