Browse Source

断面交通统计添加大型车车流量字段统计

develop
xiepufeng 8 months ago
parent
commit
59bda7d6e9
  1. 5
      zc-business/src/main/java/com/zc/business/domain/DcTrafficSectionData.java
  2. 39
      zc-business/src/main/java/com/zc/business/service/impl/DcTrafficSectionDataServiceImpl.java
  3. 9
      zc-business/src/main/java/com/zc/business/statistics/handler/RealtimeTrafficStatistics.java
  4. 3
      zc-business/src/main/resources/mapper/business/DcTrafficSectionDataMapper.xml

5
zc-business/src/main/java/com/zc/business/domain/DcTrafficSectionData.java

@ -29,6 +29,11 @@ public class DcTrafficSectionData {
*/ */
private Integer trafficVolume; private Integer trafficVolume;
/**
* 大型车车流量
*/
private Integer largeTrafficVolume;
/** /**
* 平均速度 * 平均速度
*/ */

39
zc-business/src/main/java/com/zc/business/service/impl/DcTrafficSectionDataServiceImpl.java

@ -369,8 +369,11 @@ public class DcTrafficSectionDataServiceImpl
initializeTrafficSectionData(upwardData, dcDevice, reportTime, LaneDirection.UPWARD); initializeTrafficSectionData(upwardData, dcDevice, reportTime, LaneDirection.UPWARD);
initializeTrafficSectionData(downwardData, dcDevice, reportTime, LaneDirection.DOWNWARD); initializeTrafficSectionData(downwardData, dcDevice, reportTime, LaneDirection.DOWNWARD);
// 初始化上行和下行的车流量和累计平均速度 // 初始化上行和下行的车流量
int upwardTrafficVolume = 0, downwardTrafficVolume = 0; int upwardTrafficVolume = 0, downwardTrafficVolume = 0;
// 初始化上行和下行的累计大车流量
int upwardLargeTrafficVolume = 0, downwardLargeTrafficVolume = 0;
// 初始化上行和下行的累计平均速度
double upwardCumulativeAverageSpeed = 0.0, downwardCumulativeAverageSpeed = 0.0; double upwardCumulativeAverageSpeed = 0.0, downwardCumulativeAverageSpeed = 0.0;
// 遍历车道信息,计算上行和下行的车流量和累计平均速度 // 遍历车道信息,计算上行和下行的车流量和累计平均速度
@ -383,20 +386,23 @@ public class DcTrafficSectionDataServiceImpl
// 根据车道方向累加车流量和累计平均速度 // 根据车道方向累加车流量和累计平均速度
int totalTrafficFlow = laneData.getInteger("totalTrafficFlow"); int totalTrafficFlow = laneData.getInteger("totalTrafficFlow");
double cumulativeAverageSpeed = calculateCumulativeAverageSpeed(laneData); int cumulativeAverageSpeed = calculateCumulativeAverageSpeed(laneData);
int cumulativeLargeTrafficVolume = calculateCumulativeLargeTrafficVolume(laneData);
if (isDownward) { if (isDownward) {
downwardTrafficVolume += totalTrafficFlow; downwardTrafficVolume += totalTrafficFlow;
downwardCumulativeAverageSpeed += cumulativeAverageSpeed; downwardCumulativeAverageSpeed += cumulativeAverageSpeed;
downwardLargeTrafficVolume += cumulativeLargeTrafficVolume;
} else { } else {
upwardTrafficVolume += totalTrafficFlow; upwardTrafficVolume += totalTrafficFlow;
upwardCumulativeAverageSpeed += cumulativeAverageSpeed; upwardCumulativeAverageSpeed += cumulativeAverageSpeed;
upwardLargeTrafficVolume += cumulativeLargeTrafficVolume;
} }
} }
// 设置上行和下行的车流量和累计平均速度 // 设置上行和下行的车流量和累计平均速度
setUpTrafficSectionData(upwardData, upwardTrafficVolume, upwardCumulativeAverageSpeed); setTrafficSectionData(upwardData, upwardTrafficVolume, upwardCumulativeAverageSpeed, upwardLargeTrafficVolume);
setUpTrafficSectionData(downwardData, downwardTrafficVolume, downwardCumulativeAverageSpeed); setTrafficSectionData(downwardData, downwardTrafficVolume, downwardCumulativeAverageSpeed, downwardLargeTrafficVolume);
// 将上行和下行的交通段数据放入结果映射中 // 将上行和下行的交通段数据放入结果映射中
resultMap.put(LaneDirection.UPWARD, upwardData); resultMap.put(LaneDirection.UPWARD, upwardData);
@ -437,9 +443,11 @@ public class DcTrafficSectionDataServiceImpl
* @param data 交通路段数据对象用于存储交通路段的相关信息 * @param data 交通路段数据对象用于存储交通路段的相关信息
* @param trafficVolume 该路段的交通量单位通常为车辆数 * @param trafficVolume 该路段的交通量单位通常为车辆数
* @param cumulativeAverageSpeed 该路段的累积平均速度单位通常为千米/小时 * @param cumulativeAverageSpeed 该路段的累积平均速度单位通常为千米/小时
* @param largeTrafficVolume 大型车交通量
*/ */
private void setUpTrafficSectionData(DcTrafficSectionData data, int trafficVolume, double cumulativeAverageSpeed) { private void setTrafficSectionData(DcTrafficSectionData data, int trafficVolume, double cumulativeAverageSpeed, int largeTrafficVolume) {
data.setTrafficVolume(trafficVolume); // 设置交通量 data.setTrafficVolume(trafficVolume); // 设置交通量
data.setLargeTrafficVolume(largeTrafficVolume); // 设置大车流量
data.setAverageSpeed(0); data.setAverageSpeed(0);
if (trafficVolume != 0) { // 当交通量不为0时,计算并设置平均速度 if (trafficVolume != 0) { // 当交通量不为0时,计算并设置平均速度
data.setAverageSpeed((int) Math.round(cumulativeAverageSpeed / trafficVolume)); // 平均速度 = 累积平均速度 / 交通量 data.setAverageSpeed((int) Math.round(cumulativeAverageSpeed / trafficVolume)); // 平均速度 = 累积平均速度 / 交通量
@ -475,6 +483,27 @@ public class DcTrafficSectionDataServiceImpl
laneData.getInteger("motorcycleTrafficVolume") * laneData.getInteger("averageSpeedOfMotorcycle"); laneData.getInteger("motorcycleTrafficVolume") * laneData.getInteger("averageSpeedOfMotorcycle");
} }
/**
* 计算累积大型交通流量
* 该方法用于根据给定的车道数据计算出特定类型的车辆包括公共汽车中型货车大型货车特大型货车和集装箱车的交通量总和
*
* @param laneData 包含车道交通量数据的JSONObject对象该对象应包含以下键
* - "busTrafficVolume"公共汽车交通量
* - "mediumTruckTrafficVolume"中型货车交通量
* - "largeTruckTrafficVolume"大型货车交通量
* - "extraLargeTrucksTrafficVolume"特大型货车交通量
* - "containerTruckTrafficVolume"集装箱车交通量
* @return 返回各种类型大型车辆交通量的总和类型为int
*/
private int calculateCumulativeLargeTrafficVolume(JSONObject laneData) {
// 计算各种类型大型车辆的交通量总和
return laneData.getInteger("busTrafficVolume") +
laneData.getInteger("mediumTruckTrafficVolume") +
laneData.getInteger("largeTruckTrafficVolume") +
laneData.getInteger("extraLargeTrucksTrafficVolume") +
laneData.getInteger("containerTruckTrafficVolume");
}
/** /**
* 将缓存中的数据统计后保存至数据库 * 将缓存中的数据统计后保存至数据库
*/ */

9
zc-business/src/main/java/com/zc/business/statistics/handler/RealtimeTrafficStatistics.java

@ -26,14 +26,19 @@ public class RealtimeTrafficStatistics {
// 创建一个汇总统计用的对象 // 创建一个汇总统计用的对象
DcTrafficSectionData aggregatedData = new DcTrafficSectionData(); DcTrafficSectionData aggregatedData = new DcTrafficSectionData();
// 初始化车流量总和和计算平均车速所需的分子部分 // 初始化车流量总和
int trafficVolume = 0; int trafficVolume = 0;
// 初始化最大车流量
int largeTrafficVolume = 0;
// 初始化计算平均车速所需的分子部分
double numerator = 0; double numerator = 0;
// 遍历原始数据列表,累加车流量并计算平均车速 // 遍历原始数据列表,累加车流量并计算平均车速
for (DcTrafficSectionData data: dataCollection) { for (DcTrafficSectionData data: dataCollection) {
// 累加车流量 // 累加车流量
trafficVolume += data.getTrafficVolume(); trafficVolume += data.getTrafficVolume();
// 累加最大车流量
largeTrafficVolume += data.getLargeTrafficVolume();
// 计算分子部分 // 计算分子部分
numerator += data.getAverageSpeed() * data.getTrafficVolume(); numerator += data.getAverageSpeed() * data.getTrafficVolume();
} }
@ -62,6 +67,8 @@ public class RealtimeTrafficStatistics {
aggregatedData.setStatisticalDate(firstDcTrafficSectionData.getStatisticalDate(), trafficDataPeriodType); aggregatedData.setStatisticalDate(firstDcTrafficSectionData.getStatisticalDate(), trafficDataPeriodType);
// 车流量 // 车流量
aggregatedData.setTrafficVolume(trafficVolume); aggregatedData.setTrafficVolume(trafficVolume);
// 大型车车流量
aggregatedData.setLargeTrafficVolume(largeTrafficVolume);
// 更新或插入操作 // 更新或插入操作
aggregatedData.setUpdateTime(DateUtils.getNowDate()); aggregatedData.setUpdateTime(DateUtils.getNowDate());
// 生成主键 // 生成主键

3
zc-business/src/main/resources/mapper/business/DcTrafficSectionDataMapper.xml

@ -11,6 +11,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
( (
id, id,
traffic_volume, traffic_volume,
large_traffic_volume,
average_speed, average_speed,
device_id, device_id,
statistical_date, statistical_date,
@ -23,6 +24,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
( (
#{id}, #{id},
#{trafficVolume}, #{trafficVolume},
#{largeTrafficVolume},
#{averageSpeed}, #{averageSpeed},
#{deviceId}, #{deviceId},
#{statisticalDate}, #{statisticalDate},
@ -32,6 +34,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
NOW()) NOW())
ON DUPLICATE KEY UPDATE ON DUPLICATE KEY UPDATE
traffic_volume = VALUES(traffic_volume), traffic_volume = VALUES(traffic_volume),
large_traffic_volume = VALUES(large_traffic_volume),
average_speed = VALUES(average_speed), average_speed = VALUES(average_speed),
device_id = VALUES(device_id), device_id = VALUES(device_id),
statistical_date = VALUES(statistical_date), statistical_date = VALUES(statistical_date),

Loading…
Cancel
Save