diff --git a/zc-business/src/main/java/com/zc/business/constant/StakeMarkConstant.java b/zc-business/src/main/java/com/zc/business/constant/StakeMarkConstant.java index 614a2978..45d5e654 100644 --- a/zc-business/src/main/java/com/zc/business/constant/StakeMarkConstant.java +++ b/zc-business/src/main/java/com/zc/business/constant/StakeMarkConstant.java @@ -13,6 +13,9 @@ public class StakeMarkConstant { // 定义最小桩号常量 public static final int MIN_STAKE_MARK = 54394; + // 定义毫米波雷达最大测量间隔 + public static final int MAX_INTERVAL_MILLIMETER_WAVE_RADAR = 12030; + /** * 计算道路长度 * @return 道路长度(单位:米) diff --git a/zc-business/src/main/java/com/zc/business/domain/DcTrafficMetricsData.java b/zc-business/src/main/java/com/zc/business/domain/DcTrafficMetricsData.java index 199561fd..29e180af 100644 --- a/zc-business/src/main/java/com/zc/business/domain/DcTrafficMetricsData.java +++ b/zc-business/src/main/java/com/zc/business/domain/DcTrafficMetricsData.java @@ -56,4 +56,14 @@ public class DcTrafficMetricsData { * 交通量 */ private Integer trafficVolume; + + /** + * 拥堵路段数量 + */ + private Integer congestedSectionQuantity; + + /** + * 拥堵里程 + */ + private Integer congestedDistance; } diff --git a/zc-business/src/main/java/com/zc/business/statistics/handler/TrafficAnalysis.java b/zc-business/src/main/java/com/zc/business/statistics/handler/TrafficAnalysis.java index e8df68e9..657927ac 100644 --- a/zc-business/src/main/java/com/zc/business/statistics/handler/TrafficAnalysis.java +++ b/zc-business/src/main/java/com/zc/business/statistics/handler/TrafficAnalysis.java @@ -154,8 +154,14 @@ public class TrafficAnalysis { metricsData.setSaturationLevel(calculateFullSaturationDegree(sectionDataList, direction, periodType)); // 计算通道拥挤度 metricsData.setChannelCongestionLevel(calculateSectionChannelCongestionLevel(sectionDataList)); + // 计算路网整体拥堵的方法 + DcTrafficMetricsData trafficMetricsData = calculateRoadNetworkCongestion(sectionDataList); + // 拥堵路段数量 + metricsData.setCongestedSectionQuantity(trafficMetricsData.getCongestedSectionQuantity()); + // 返回拥堵里程 + metricsData.setCongestedDistance(trafficMetricsData.getCongestedDistance()); // 计算路网拥堵指数 - metricsData.setRoadNetworkCongestionLevel(calculateRoadNetworkCongestionLevel(sectionDataList)); + metricsData.setRoadNetworkCongestionLevel(trafficMetricsData.getRoadNetworkCongestionLevel()); result.add(metricsData); }); @@ -369,13 +375,18 @@ public class TrafficAnalysis { } /** - * 计算路网拥堵指数 - * @param trafficSectionDataList 交通路段数据列表,包含各个路段的拥堵情况和里程等信息 - * @return 返回路网整体的拥堵指数,如果输入列表为空则返回null + * 计算路网整体拥堵的方法。 + * + * @param trafficSectionDataList 交通路段数据列表,包含各个路段的交通状况和里程信息。 + * @return DcTrafficMetricsData 包含路网整体拥堵指数、拥堵路段数量和拥堵里程的数据对象。 */ - public Integer calculateRoadNetworkCongestionLevel(List trafficSectionDataList) { + public DcTrafficMetricsData calculateRoadNetworkCongestion(List trafficSectionDataList) { + + DcTrafficMetricsData metricsData = new DcTrafficMetricsData(); + + // 如果输入的交通路段数据为空或为空列表,直接返回一个不含数据的metricsData对象 if (trafficSectionDataList == null || trafficSectionDataList.isEmpty()) { - return null; // 列表为空时返回null + return metricsData; } // 根据行驶方向对交通数据进行分组,以便分别计算每个方向的拥堵情况 @@ -386,6 +397,8 @@ public class TrafficAnalysis { int totalDistance = StakeMarkConstant.calculateRoadLength() * groupedByDirection.size(); // 总拥堵里程,使用AtomicInteger以支持在并发环境中进行累加操作 AtomicInteger totalCongestionDistance = new AtomicInteger(); + // 拥堵路段数量 + AtomicInteger congestedSectionQuantity = new AtomicInteger(); // 遍历每个方向的数据,计算总拥堵里程 groupedByDirection.forEach((directionData, trafficSectionList) -> { @@ -427,7 +440,12 @@ public class TrafficAnalysis { // 如果之前已经有路段被计算过,则根据两个路段之间的距离和默认拥堵距离,计算实际应累加的拥堵距离 if (previousAverageSpeed != 0) { int congestionDistance = Math.abs(stakeMark - previousStakeMark); - totalCongestionDistance.addAndGet(Math.min(congestionDistance, defaultCongestionDistance)); + if (congestionDistance > StakeMarkConstant.MAX_INTERVAL_MILLIMETER_WAVE_RADAR) { + totalCongestionDistance.addAndGet(defaultCongestionDistance); + } else { + totalCongestionDistance.addAndGet(congestionDistance); + congestedSectionQuantity.addAndGet(1); + } } // 更新辅助变量以备后续计算 @@ -437,10 +455,17 @@ public class TrafficAnalysis { }); // 计算并返回路网整体的拥堵指数 - return Math.round((float) totalCongestionDistance.get() / totalDistance * 100); + metricsData.setRoadNetworkCongestionLevel(Math.round((float) totalCongestionDistance.get() / totalDistance * 100)); + // 返回拥堵路段数量 + metricsData.setCongestedSectionQuantity(congestedSectionQuantity.get()); + // 返回拥堵里程 + metricsData.setCongestedDistance(totalCongestionDistance.get()); + + return metricsData; } + /** * 计算路段交通量 *