Skip to content

Commit 13bede6

Browse files
committedNov 22, 2024
获取大屏参数
1 parent 40ffe4b commit 13bede6

File tree

7 files changed

+150
-59
lines changed

7 files changed

+150
-59
lines changed
 

‎ruoyi-simulation/src/main/java/com/ruoyi/simulation/config/TrafficIndirectionListener.java

+55-22
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22

33
import com.alibaba.fastjson2.JSON;
44
import com.alibaba.fastjson2.JSONObject;
5+
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
56
import com.ruoyi.common.utils.StringUtils;
67
import com.ruoyi.simulation.call.CallUE4Engine;
8+
import com.ruoyi.simulation.dao.JunctionMapper;
9+
import com.ruoyi.simulation.dao.RoadMapper;
710
import com.ruoyi.simulation.dao.SpeedMapper;
811
import com.ruoyi.simulation.domain.Junction;
912
import com.ruoyi.simulation.domain.Road;
@@ -35,21 +38,25 @@ public class TrafficIndirectionListener implements ApplicationListener<Applicati
3538
public RedisTemplate<String,String> redisTemplate;
3639
@Resource
3740
public SpeedMapper speedMapper;
41+
@Resource
42+
public RoadMapper roadMapper;
43+
@Resource
44+
public JunctionMapper junctionMapper;
3845
//每天定时获取历史平均速度
3946
private Map<String,Double> speedMap = new HashMap<>();
4047
//一天内的平均速度
4148
private Map<String, List<Double>> daySpeedMap = new HashMap<>();
4249
private Map<String, Double> hourSpeedMap = new HashMap<>();
4350
private Map<String, Double> indirectionTrendMap = new HashMap<>();
44-
private Map<String, Double> mileageTrendMap = new HashMap<>();
51+
private Map<Integer, Double> mileageTrendMap = new HashMap<>();
4552
private Map<String, Double> trafficTrendMap = new HashMap<>();
4653
private int acquiredCount = 0;
4754
private List<Road> roadList = new ArrayList<>();
4855
private List<Junction> junctionList = new ArrayList<>();
4956
@Override
5057
public void onApplicationEvent(ApplicationStartedEvent e) {
5158
executionIndirectionScript();
52-
getJunctionRoad();
59+
getMapBasicData();
5360
new Thread(new Runnable() {
5461
@Override
5562
public void run() {
@@ -71,17 +78,28 @@ private void executionIndirectionScript(){
7178
//获得总拥堵里程
7279
this.callUE4Engine.getTrafficIndirection("congestion_mileage.py");
7380
//获得不同道路的拥堵里程
74-
this.callUE4Engine.getTrafficIndirection("road_congestion_mileage.py");
81+
this.callUE4Engine.getTrafficIndirection("junction_congestion_mileage.py");
7582
//获得服务车次
7683
this.callUE4Engine.getTrafficIndirection("serviced_vehicle.py");
7784
//获得路网车辆
7885
this.callUE4Engine.getTrafficIndirection("total_vehicle.py");
7986
}
8087

8188
/**
82-
* 获取道路及路口的字典信息
89+
* 获取道路及路口的地图基础数据信息
8390
*/
84-
private void getJunctionRoad(){
91+
private void getMapBasicData(){
92+
this.roadList = this.roadMapper.selectList(new QueryWrapper<>());
93+
Map<Integer,Integer> roadMap = new HashMap<>();
94+
//设置carla中roadId与道路主键之间的对应关系
95+
for(Road road: this.roadList){
96+
List<String> relatedList = Arrays.asList(road.getRelatedRoadId().split(","));
97+
for(String related: relatedList){
98+
roadMap.put(Integer.parseInt(related), road.getRoadId());
99+
}
100+
}
101+
this.redisTemplate.opsForValue().set("roadMap", JSON.toJSONString(roadMap));
102+
this.junctionList = this.junctionMapper.selectList(new QueryWrapper<>());
85103
}
86104
/**
87105
* 每天零点整执行读取数据和写入数据的操作
@@ -125,6 +143,8 @@ public void getRedisIndirection(){
125143
LoggerUtil.printLoggerStace(e);
126144
}
127145
Map<String,Object> indirectionMap = new HashMap<>();
146+
//设置交通趋势变化数据
147+
this.setTrafficTrend();
128148
//获取实时的平均车速
129149
double averageSpeed = this.getAverageSpeed();
130150
indirectionMap.put("averageSpeed", averageSpeed);
@@ -139,13 +159,11 @@ public void getRedisIndirection(){
139159
double congestionMileage = this.getCongestionMileage();
140160
indirectionMap.put("congestionMileage", congestionMileage);
141161
//获取不同路口的拥堵里程
142-
this.setJunctionCongestionMileage(indirectionMap);
162+
this.setJunctionIndirection(indirectionMap);
143163
//获取服务车次
144164
this.setServicedVehicle(indirectionMap);
145165
//获取路网车辆
146166
this.setTotalVehicle(indirectionMap);
147-
//设置交通趋势变化数据
148-
this.setTrafficTrend();
149167
for(String sessionId: WebSocketServer.webSocketMap.keySet()){
150168
SendResponseUtil.sendIndirectionResponse(indirectionMap, sessionId);
151169
}
@@ -199,6 +217,13 @@ public void setRoadAverageSpeed(String roadId, double averageSpeed) {
199217
road.setAverageSpeed(averageSpeed);
200218
double congestionIndirection = speedMap.get(roadId)/averageSpeed;
201219
road.setCongestionIndirection(congestionIndirection);
220+
double trend = indirectionTrendMap.get(roadId);
221+
//计算拥堵指数趋势变化
222+
double trendRate = 1d;
223+
if(trend!=0){
224+
trendRate = (congestionIndirection-trend)/trend;
225+
}
226+
road.setCongestionIndirectionTrend(trendRate);
202227
}
203228
}.getRoadAverageSpeed();
204229
indirectionMap.put("roadIndirection", this.roadList);
@@ -234,10 +259,10 @@ public double getCongestionMileage(){
234259
* 设置不同路口的拥堵里程
235260
* @param indirectionMap
236261
*/
237-
public void setJunctionCongestionMileage(Map<String,Object> indirectionMap){
238-
Map<String, Junction> junctionMap = new HashMap<>();
262+
public void setJunctionIndirection(Map<String,Object> indirectionMap){
263+
Map<Integer, Junction> junctionMap = new HashMap<>();
239264
for(Junction junction: this.junctionList){
240-
junctionMap.put(String.valueOf(junction.getJunctionRoadId()), junction);
265+
junctionMap.put(junction.getTrafficLightId(), junction);
241266
//初始化所有的道路拥堵里程
242267
junction.setCongestionMileage(0d);
243268
//初始化拥堵里程趋势变化
@@ -246,10 +271,17 @@ public void setJunctionCongestionMileage(Map<String,Object> indirectionMap){
246271
//保存不同路口拥堵里程数据
247272
new ParseJunctionIndirection(){
248273
@Override
249-
protected void setJunctionCongestionMileage(String junctionRoadId, double congestionMileage) {
250-
Junction junction = junctionMap.get(junctionRoadId);
274+
protected void setJunctionCongestionMileage(int trafficLightId, double congestionMileage) {
275+
Junction junction = junctionMap.get(trafficLightId);
251276
//设置拥堵里程
252277
junction.setCongestionMileage(congestionMileage);
278+
double trend = mileageTrendMap.get(trafficLightId);
279+
//计算拥堵里程趋势变化
280+
double trendRate = 1d;
281+
if(trend!=0){
282+
trendRate = (congestionMileage-trend)/trend;
283+
}
284+
junction.setCongestionMileageTrend(trendRate);
253285
}
254286
}.getJunctionCongestionMileage();
255287
indirectionMap.put("junctionCongestionMileage", junctionList);
@@ -265,7 +297,7 @@ private void setTrafficTrend(){
265297
this.indirectionTrendMap.put(String.valueOf(road.getRoadId()), 1d);
266298
}
267299
for(Junction junction: this.junctionList){
268-
this.mileageTrendMap.put(String.valueOf(junction.getJunctionRoadId()), 0d);
300+
this.mileageTrendMap.put(junction.getTrafficLightId(), 0d);
269301
}
270302
//保存不同道路的拥堵指数变化趋势
271303
new ParseRoadIndirection(){
@@ -281,11 +313,10 @@ public void setRoadAverageSpeed(String roadId, double averageSpeed) {
281313
//保存不同路口的拥堵里程变化趋势
282314
new ParseJunctionIndirection(){
283315
@Override
284-
public void setJunctionCongestionMileage(String junctionRoadId, double congestionMileage) {
285-
mileageTrendMap.put(junctionRoadId, congestionMileage);
316+
public void setJunctionCongestionMileage(int trafficLightId, double congestionMileage) {
317+
mileageTrendMap.put(trafficLightId, congestionMileage);
286318
}
287319
}.getJunctionCongestionMileage();
288-
289320
//保存平均延误时间变化趋势
290321
trafficTrendMap.put("averageDelay", this.getAverageDelay());
291322
//保存总拥堵里程变化趋势
@@ -392,18 +423,20 @@ public void getJunctionCongestionMileage(){
392423
String roadCongestionMileageStr = redisTemplate.opsForValue().get("road_congestion_mileage");
393424
if(!StringUtils.isEmpty(roadCongestionMileageStr)) {
394425
JSONObject jsonObject = JSON.parseObject(roadCongestionMileageStr);
395-
for (String junctionRoadId : jsonObject.keySet()) {
426+
for (String identity : jsonObject.keySet()) {
427+
int trafficLightId = Integer.parseInt(identity.split("_")[0]);
428+
System.out.println(identity);
396429
//获取不同路口的拥堵里程
397-
double congestionMileage = Double.valueOf(String.valueOf(jsonObject.get(junctionRoadId)));
398-
this.setJunctionCongestionMileage(junctionRoadId, congestionMileage);
430+
double congestionMileage = Double.valueOf(String.valueOf(jsonObject.get(identity)));
431+
this.setJunctionCongestionMileage(trafficLightId, congestionMileage);
399432
}
400433
}
401434
}
402435
/**
403436
* 设置实时拥堵里程数据
404-
* @param junctionRoadId
437+
* @param trafficLightId
405438
* @param congestionMileage
406439
*/
407-
protected abstract void setJunctionCongestionMileage(String junctionRoadId, double congestionMileage);
440+
protected abstract void setJunctionCongestionMileage(int trafficLightId, double congestionMileage);
408441
}
409442
}
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package com.ruoyi.simulation.dao;
22

33
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4+
import com.ruoyi.simulation.domain.Junction;
45
import com.ruoyi.simulation.domain.Speed;
56

67
/**
78
* 路口信息数据库访问层
89
*/
9-
public interface JunctionMapper extends BaseMapper<Speed> {
10+
public interface JunctionMapper extends BaseMapper<Junction> {
1011
}
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package com.ruoyi.simulation.dao;
22

33
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4+
import com.ruoyi.simulation.domain.Road;
45
import com.ruoyi.simulation.domain.Speed;
56

67
/**
78
* 道路信息数据访问层
89
*/
9-
public interface RoadMapper extends BaseMapper<Speed> {
10+
public interface RoadMapper extends BaseMapper<Road> {
1011
}
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,28 @@
11
package com.ruoyi.simulation.domain;
22

3+
import com.baomidou.mybatisplus.annotation.TableName;
4+
import com.fasterxml.jackson.annotation.JsonIgnore;
35
import lombok.Data;
46

57
/**
68
* 路口指标信息实体类
79
*/
810
@Data
11+
@TableName("simulation_junction")
912
public class Junction {
1013
/**
1114
* 路口方向id
1215
*/
13-
private Integer junctionRoadId;
16+
private Integer junctionId;
1417
/**
1518
* 路口方向名称
1619
*/
17-
private String junctionRoadName;
20+
private String junctionName;
21+
/**
22+
* 交通灯id
23+
*/
24+
@JsonIgnore
25+
private Integer trafficLightId;
1826
/**
1927
* 拥堵里程
2028
*/
@@ -23,36 +31,4 @@ public class Junction {
2331
* 拥堵里程趋势变化
2432
*/
2533
private Double congestionMileageTrend;
26-
27-
public Integer getJunctionRoadId() {
28-
return junctionRoadId;
29-
}
30-
31-
public void setJunctionRoadId(Integer junctionRoadId) {
32-
this.junctionRoadId = junctionRoadId;
33-
}
34-
35-
public String getJunctionRoadName() {
36-
return junctionRoadName;
37-
}
38-
39-
public void setJunctionRoadName(String junctionRoadName) {
40-
this.junctionRoadName = junctionRoadName;
41-
}
42-
43-
public Double getCongestionMileage() {
44-
return congestionMileage;
45-
}
46-
47-
public void setCongestionMileage(Double congestionMileage) {
48-
this.congestionMileage = congestionMileage;
49-
}
50-
51-
public Double getCongestionMileageTrend() {
52-
return congestionMileageTrend;
53-
}
54-
55-
public void setCongestionMileageTrend(Double congestionMileageTrend) {
56-
this.congestionMileageTrend = congestionMileageTrend;
57-
}
5834
}

‎ruoyi-simulation/src/main/java/com/ruoyi/simulation/domain/Road.java

+7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package com.ruoyi.simulation.domain;
22

33
import com.baomidou.mybatisplus.annotation.TableName;
4+
import com.fasterxml.jackson.annotation.JsonIgnore;
45
import lombok.Data;
56

67
/**
78
* 道路指标信息实体类
89
*/
910
@Data
11+
@TableName("simulation_road")
1012
public class Road {
1113
/**
1214
* 道路id
@@ -16,6 +18,11 @@ public class Road {
1618
* 道路名称
1719
*/
1820
private String roadName;
21+
/**
22+
* 地图中相关联的roadId
23+
*/
24+
@JsonIgnore
25+
private String relatedRoadId;
1926
/**
2027
* 平均速度
2128
*/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package com.ruoyi.simulation.domain;
2+
3+
import lombok.Data;
4+
5+
import java.sql.Timestamp;
6+
import java.util.Date;
7+
8+
/**
9+
* 信号控制信息实体类
10+
*/
11+
@Data
12+
public class SignalControl {
13+
/**
14+
* 用于区分不同的路口(如序号1表示尖山路-望青路)
15+
*/
16+
private String intersectionId;
17+
private String intersectionName;
18+
/**
19+
* 用于区分同一路口的不同红绿灯控制方案(如1表示方案1,2表示方案2)
20+
*/
21+
private Integer schemeId;
22+
/**
23+
* 周期ID,用于标识一个完整的周期(现在用1表示,以后可拓展)。
24+
*/
25+
private Integer cycleId;
26+
/**
27+
* 车辆大方向阶段,以车辆在路口开始行驶方向为准划分,分为"North-South"和"East-West"(表示车辆开始时的南北走向和东西走向),North-South(B)后面括号加了(B)标识的时非机动车道。
28+
*/
29+
private String Direction;
30+
/**
31+
* 一个红绿灯周期又四个阶段变化,分别用1、2、3、4代替
32+
*/
33+
private Integer DirectionPhase;
34+
/**
35+
* 起始方向(如 "South")
36+
*/
37+
private String FromDirection;
38+
/**
39+
* 目的方向(如 "East") (起始方向和目的方向就决定了车辆形式的方向)
40+
*/
41+
private String ToDirection;
42+
/**
43+
* 机动车道信号灯状态,表示该方向阶段内的绿灯、黄灯、红灯变化。
44+
*/
45+
private String LightStatus;
46+
/**
47+
* 每个阶段的开始时间。
48+
*/
49+
private Timestamp StartTime;
50+
/**
51+
* 每个阶段的结束时间。
52+
*/
53+
private Timestamp EndTime;
54+
/**
55+
* 机动车道的阶段持续时间(以秒为单位)
56+
*/
57+
private Long Duration;
58+
/**
59+
* 表示南北方向人行道的信号灯状态
60+
*/
61+
private String PedestrianNSLightStatus;
62+
/**
63+
* 表示南北方向人行道的信号灯持续时间
64+
*/
65+
private Long PedestrianNSDuration;
66+
/**
67+
* 表示东西方向人行道的信号灯状态及其持续时间。
68+
*/
69+
private String PedestrianEWLightStatus;
70+
/**
71+
* 表示东西方向人行道的信号灯持续时间。
72+
*/
73+
private Long PedestrianEWDuration;
74+
}

‎ruoyi-system/pom.xml

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
</description>
1515

1616
<dependencies>
17-
1817
<!-- 通用工具-->
1918
<dependency>
2019
<groupId>com.ruoyi</groupId>

0 commit comments

Comments
 (0)
Please sign in to comment.