From 6a0a8477f208b322507838e114c370fc1a60addf Mon Sep 17 00:00:00 2001 From: tiger_zhou <123456> Date: Tue, 14 Feb 2023 17:43:32 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BA=94=E6=80=A5ws=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ATS/service/TrainPositionService.java | 2 +- .../rtss/services/ws/EnvLoggerFileTest.java | 7 +++++- .../joylink/rtss/services/ws/StompTest.java | 25 ++++++++++--------- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/TrainPositionService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/TrainPositionService.java index 43fd6986c..2cdd98b1c 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/TrainPositionService.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/TrainPositionService.java @@ -30,7 +30,7 @@ public class TrainPositionService { public void initTrainOrUpdate(String mapName,String json){ TrainPosition tp = JsonUtils.read(json, TrainPosition.class); tp.setReceiveTime(System.currentTimeMillis()); - log.info(json); + log.debug(json); // SocketMessageVO vo = SocketMessageFactory.buildBasic(WebSocketMessageType.YJDDZH_TRAIN_POSITION,tp); // this.messageService.send(vo); this.timeOverService.addTrainAccept(mapName,tp); diff --git a/src/test/java/club/joylink/rtss/services/ws/EnvLoggerFileTest.java b/src/test/java/club/joylink/rtss/services/ws/EnvLoggerFileTest.java index 76ff0d90a..3b54a6faf 100644 --- a/src/test/java/club/joylink/rtss/services/ws/EnvLoggerFileTest.java +++ b/src/test/java/club/joylink/rtss/services/ws/EnvLoggerFileTest.java @@ -44,17 +44,22 @@ public class EnvLoggerFileTest { } }); } + public List query(List list, List groups){ + List newList = list.stream().filter(d->groups.contains(d.getGroupNum()) ).collect(Collectors.toList()); + return newList; + } public List query(List list, List groups, Section.SectionRoadType roadType){ List newList = list.stream().filter(d->groups.contains(d.getGroupNum()) && d.getRoadType() == roadType ).sorted(Comparator.comparing(TrainPosition::getReceiveTime)).collect(Collectors.toList()); return newList; } + public List query(List list, String groupNum, Section.SectionRoadType roadType){ List newList = list.stream().filter(d-> Objects.equals(d.getGroupNum(),groupNum) && d.getRoadType() == roadType ).sorted(Comparator.comparing(TrainPosition::getReceiveTime)).collect(Collectors.toList()); return newList; } public List query(List list,String groupNum){ - List newList = list.stream().filter(d->Objects.equals(d.getGroupNum(),groupNum)).sorted(Comparator.comparing(TrainPosition::getReceiveTime)).collect(Collectors.toList()); + List newList = list.stream().filter(d->Objects.equals(d.getGroupNum(),groupNum)).collect(Collectors.toList()); return newList; } diff --git a/src/test/java/club/joylink/rtss/services/ws/StompTest.java b/src/test/java/club/joylink/rtss/services/ws/StompTest.java index af4eec62d..d1f54383a 100644 --- a/src/test/java/club/joylink/rtss/services/ws/StompTest.java +++ b/src/test/java/club/joylink/rtss/services/ws/StompTest.java @@ -40,10 +40,11 @@ public class StompTest { e.printStackTrace(); } EnvLoggerFileTest lt = new EnvLoggerFileTest(); - List list = lt.readFile("d:\\spring.log2"); + List list = lt.readFile("d:\\spring.log"); // List list = lt.readSource("d:\\t.txt"); // runToLeft(stompSession,"001"); // runToRight(stompSession,"002"); +// list = lt.query(list,"031"); // list = lt.query(list,"004", Section.SectionRoadType.LEFT); // list = lt.query(list, Lists.newArrayList("015","037"), Section.SectionRoadType.RIGHT); send(stompSession,list); @@ -87,7 +88,7 @@ public class StompTest { } public static void send(StompSession stompSession,List list){ - for (int i = 25; i < list.size(); i++) { + for (int i = 0; i < list.size(); i++) { // for (int i = 22; i < 23; i++) { TrainPosition tp = list.get(i); tp.setCloseDoor(false); @@ -95,21 +96,21 @@ public class StompTest { tp.setSpeed(Float.valueOf(i)); // tp.setLocation(tp.getLocation() - 500); String val = JsonUtils.writeValueNullableFieldAsString(tp); - Instant instant = Instant.ofEpochMilli(tp.getReceiveTime()); - ZoneId zone = ZoneId.systemDefault(); - String d = LocalDateTime.ofInstant(instant, zone).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); - System.out.println(d + " ->" + i +" ->" + val); +// Instant instant = Instant.ofEpochMilli(tp.getReceiveTime()); +// ZoneId zone = ZoneId.systemDefault(); +// String d = LocalDateTime.ofInstant(instant, zone).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); + System.out.println(i +" ->" + val); stompSession.send("/app/武汉8号线/trainPosition",val.getBytes(StandardCharsets.UTF_8)); if(i > 0){ TrainPosition old = list.get(i - 1); try { - long sleepTime = (tp.getReceiveTime() - old.getReceiveTime()); - if(sleepTime > 10000){ - sleepTime = sleepTime / 1000; - } - System.out.println("index:" + i + "sleep:"+sleepTime); - TimeUnit.MILLISECONDS.sleep(sleepTime); +// long sleepTime = (tp.getReceiveTime() - old.getReceiveTime()); +// if(sleepTime > 10000){ +// sleepTime = sleepTime / 1000; +// } +// System.out.println("index:" + i + "sleep:"+sleepTime); + TimeUnit.MILLISECONDS.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); }