Commit cbaabc92 authored by hanbing's avatar hanbing

[update] 运行评价-干线详细指标查询增加绿灯空放时长

parent 7e81b999
......@@ -123,7 +123,7 @@ public class MainlineEvaluateServiceImpl implements MainlineEvaluateService {
}
@Override
public List<MainlineEvaluateBottomCurveVO> bottomCurve(BottomCurveBO bo) throws Exception {
public List<MainlineEvaluateBottomCurveVO> bottomCurve(BottomCurveBO bo) {
String crossId = bo.getCrossId();
Integer scope = bo.getScope();
List<String> scopeList = bo.getScopeList();
......@@ -133,6 +133,15 @@ public class MainlineEvaluateServiceImpl implements MainlineEvaluateService {
Date startTime = bo.getStartTime();
Date endTime = bo.getEndTime();
// 从 Kafka 查询绿灯空放时长
KafkaConsumerUtil kafkaConsumerUtil = new KafkaConsumerUtil(bootstrapServers, "bottom-curve-empty-phase");
List<PhaseEmptyResult> phaseEmptyResults =
kafkaConsumerUtil.consumeEmptyPhaseForTimeRange(
emptyPhaseTopic, 0, startTime.getTime(), endTime.getTime());
List<PhaseEmptyResult> crossEmptyPhaseList = phaseEmptyResults.stream()
.filter(p -> crossId.equals(p.getCrossId()))
.collect(Collectors.toList());
String metricCode = StrategyAndMetricsEnum.Metrics.getCodeByName(metricName);
if (scope != 1 && Objects.equals(metricCode, StrategyAndMetricsEnum.Metrics.LOAD_BALANCE.getCode())) {
throw new RuntimeException("只有路口级别可选择负载均衡度");
......@@ -147,8 +156,24 @@ public class MainlineEvaluateServiceImpl implements MainlineEvaluateService {
if (scope == 0) { // 路口
// 查询路口该时段内的所有数据
List<CrossDataHistPO> crossPOList = crossDataHistMapper.selectByCrossIdAndStartEnd(
List<CrossDataHistPOExt> crossPOList = crossDataHistMapper.selectExtByCrossIdAndStartEnd(
crossId, startTimeStamp, endTimeStamp);
// 填充相位空放时长
for (CrossDataHistPOExt po : crossPOList) {
// 计算结束时间
Date endTime2 = new Date(po.getStartTime().getTime() + 5 * 60 * 1000); // 增加5分钟
// 遍历每个 PhaseEmptyResult 来查找和累加 duration
for (PhaseEmptyResult phaseEmptyResult : crossEmptyPhaseList) {
if (phaseEmptyResult.getDetectTime() * 1000 >= po.getStartTime().getTime()
&& phaseEmptyResult.getDetectTime() * 1000 <= endTime2.getTime()) {
// 累加 duration
po.setEmptyPhase(po.getEmptyPhase() + phaseEmptyResult.getDuration());
}
}
}
for (String timeStr : timeList) {
// 解析 timeStr 为 Calendar 对象
String[] timeParts = timeStr.split(":");
......@@ -166,7 +191,7 @@ public class MainlineEvaluateServiceImpl implements MainlineEvaluateService {
endTimeCal.add(Calendar.MINUTE, minutesSpan);
// 过滤 crossPOList 中的记录
List<CrossDataHistPO> filteredList = crossPOList.stream()
List<CrossDataHistPOExt> filteredList = crossPOList.stream()
.filter(crossPO -> {
// 将 batchTime 转换为小时和分钟
Calendar batchTimeCal = Calendar.getInstance();
......@@ -184,65 +209,78 @@ public class MainlineEvaluateServiceImpl implements MainlineEvaluateService {
if (Objects.equals(metricCode, StrategyAndMetricsEnum.Metrics.NO_STOP_RATE.getCode())) {
double v = filteredList.stream()
.mapToDouble(CrossDataHistPO::getNoStopRate)
.mapToDouble(CrossDataHistPOExt::getNoStopRate)
.average()
.orElse(0.0);
int round = (int) (Math.round(v * 100));
vo.setValue(round);
} else if (Objects.equals(metricCode, StrategyAndMetricsEnum.Metrics.STOP_RATE.getCode())) {
double v = filteredList.stream()
.mapToDouble(CrossDataHistPO::getOneStopRate)
.mapToDouble(CrossDataHistPOExt::getOneStopRate)
.average()
.orElse(0.0);
int round = (int) (Math.round(v * 100));
vo.setValue(round);
} else if (Objects.equals(metricCode, StrategyAndMetricsEnum.Metrics.AVERAGE_DELAY.getCode())) {
double v = filteredList.stream()
.mapToInt(CrossDataHistPO::getDelayTime)
.mapToInt(CrossDataHistPOExt::getDelayTime)
.average()
.orElse(0.0);
int round = (int) (Math.round(v));
vo.setValue(round);
} else if (Objects.equals(metricCode, StrategyAndMetricsEnum.Metrics.MAX_QUEUE_LENGTH.getCode())) {
double v = filteredList.stream()
.mapToDouble(CrossDataHistPO::getQueueLength)
.mapToDouble(CrossDataHistPOExt::getQueueLength)
.max()
.orElse(0.0);
int round = (int) (Math.round(v));
vo.setValue(round);
} else if (Objects.equals(metricCode, StrategyAndMetricsEnum.Metrics.STOP_TIMES.getCode())) {
double v = filteredList.stream()
.mapToDouble(CrossDataHistPO::getStopTimes)
.mapToDouble(CrossDataHistPOExt::getStopTimes)
.average()
.orElse(0.0);
int round = (int) (Math.round(v));
vo.setValue(round);
} else if (Objects.equals(metricCode, StrategyAndMetricsEnum.Metrics.AVERAGE_SPEED.getCode())) {
double v = filteredList.stream()
.mapToDouble(CrossDataHistPO::getSpeed)
.mapToDouble(CrossDataHistPOExt::getSpeed)
.average()
.orElse(0.0);
int round = (int) (Math.round(v));
vo.setValue(round);
} else if (Objects.equals(metricCode, StrategyAndMetricsEnum.Metrics.GREEN_LIGHT_EFFICIENCY.getCode())) {
double v = filteredList.stream()
.mapToDouble(CrossDataHistPO::getGreenLightEfficiency)
.mapToDouble(CrossDataHistPOExt::getGreenLightEfficiency)
.average()
.orElse(0.0);
int round = (int) (Math.round(v * 100));
vo.setValue(round);
} else if (Objects.equals(metricCode, StrategyAndMetricsEnum.Metrics.SATURATION.getCode())) {
double v = filteredList.stream()
.mapToDouble(CrossDataHistPO::getSturation)
.mapToDouble(CrossDataHistPOExt::getSturation)
.average()
.orElse(0.0);
int round = (int) (Math.round(v * 100));
vo.setValue(round);
} else if (Objects.equals(metricCode, StrategyAndMetricsEnum.Metrics.LOAD_BALANCE.getCode())) {
double v = filteredList.stream()
.mapToDouble(CrossDataHistPO::getLoadBalance)
.mapToDouble(CrossDataHistPOExt::getLoadBalance)
.average()
.orElse(0.0);
int round = (int) (Math.round(v));
vo.setValue(round);
} else if (Objects.equals(metricCode, StrategyAndMetricsEnum.Metrics.EFFUSION_RATE.getCode())) {
double v = filteredList.stream()
.mapToDouble(CrossDataHistPOExt::getEffusionRate)
.average()
.orElse(0.0);
int round = (int) (Math.round(v * 100));
vo.setValue(round);
} else if (Objects.equals(metricCode, StrategyAndMetricsEnum.Metrics.EMPTY_PHASE.getCode())) {
double v = filteredList.stream()
.mapToDouble(CrossDataHistPOExt::getEmptyPhase)
.sum();
int round = (int) (Math.round(v));
vo.setValue(round);
}
......@@ -884,7 +922,7 @@ public class MainlineEvaluateServiceImpl implements MainlineEvaluateService {
String boStartDayStr = dayFormat.format(startDate);
String boEndDayStr = dayFormat.format(endDate);
List<CrossDirDataHistPO> crossDirDataHistPOList = crossDirDataHistMapper.selectByTimeSection(
List<CrossDirDataHistPOExt> crossDirDataHistPOList = crossDirDataHistMapper.selectExtByTimeSection(
boStartDayStr, boEndDayStr, startHourMinute, endHourMinute);
List<BaseCrossDirInfoPO> baseCrossDirInfoPOList =
......@@ -959,7 +997,7 @@ public class MainlineEvaluateServiceImpl implements MainlineEvaluateService {
private List<String> buildCrossEvaluateList(
String crossId, List<BaseCrossDirInfoPO> baseCrossDirInfoPOList,
List<CrossDirDataHistPO> crossDirDataHistPOList) {
List<CrossDirDataHistPOExt> crossDirDataHistPOList) {
List<String> res = new ArrayList<>();
......@@ -973,18 +1011,18 @@ public class MainlineEvaluateServiceImpl implements MainlineEvaluateService {
for (Integer dirCode : dirCodeList) {
List<CrossDirDataHistPO> filteredList = crossDirDataHistPOList.stream()
List<CrossDirDataHistPOExt> filteredList = crossDirDataHistPOList.stream()
.filter(item -> crossId.equals(item.getCrossId()))
.filter(item -> 1 == item.getInOutType())
.filter(item -> dirCode.equals(item.getDirType()))
.collect(Collectors.toList());
Integer maxDelayTime = filteredList.stream()
.map(CrossDirDataHistPO::getDelayTime)
.map(CrossDirDataHistPOExt::getDelayTime)
.max(Integer::compareTo)
.orElse(0);
Double maxQueueLength = filteredList.stream()
.mapToDouble(CrossDirDataHistPO::getQueueLength)
.mapToDouble(CrossDirDataHistPOExt::getQueueLength)
.max()
.orElse(0.0);
......@@ -1005,7 +1043,7 @@ public class MainlineEvaluateServiceImpl implements MainlineEvaluateService {
private List<MainlineCrossEvaluateVO.DirElement> buildDirElementList(
String crossId, String metricName, List<BaseCrossDirInfoPO> baseCrossDirInfoPOList,
List<CrossDirDataHistPO> crossDirDataHistPOList, List<PhaseEmptyResult> crossEmptyPhaseList) {
List<CrossDirDataHistPOExt> crossDirDataHistPOList, List<PhaseEmptyResult> crossEmptyPhaseList) {
// 获取路口所有方向
List<BaseCrossDirInfoPO> collect = baseCrossDirInfoPOList.stream()
......@@ -1020,7 +1058,7 @@ public class MainlineEvaluateServiceImpl implements MainlineEvaluateService {
MainlineCrossEvaluateVO.DirElement dirElement = new MainlineCrossEvaluateVO.DirElement();
dirElement.setDir(dirCode);
List<CrossDirDataHistPO> filteredList = crossDirDataHistPOList.stream()
List<CrossDirDataHistPOExt> filteredList = crossDirDataHistPOList.stream()
.filter(item -> crossId.equals(item.getCrossId()))
.filter(item -> 1 == item.getInOutType())
.filter(item -> dirCode.equals(item.getDirType()))
......@@ -1037,47 +1075,47 @@ public class MainlineEvaluateServiceImpl implements MainlineEvaluateService {
return res;
}
private Integer calcDirValue(String metricName, List<CrossDirDataHistPO> crossDirDataHistPOList,
private Integer calcDirValue(String metricName, List<CrossDirDataHistPOExt> crossDirDataHistPOList,
List<PhaseEmptyResult> dirPhaseEmptyList) {
int dirValue = 0;
if (Objects.equals(metricName, StrategyAndMetricsEnum.Metrics.GREEN_LIGHT_EFFICIENCY.getDescription())) {
double average = crossDirDataHistPOList.stream()
.mapToDouble(CrossDirDataHistPO::getGreenLightEfficiency)
.mapToDouble(CrossDirDataHistPOExt::getGreenLightEfficiency)
.average()
.orElse(0.0);
dirValue = (int) Math.round(average * 100);
} else if (Objects.equals(metricName, StrategyAndMetricsEnum.Metrics.STOP_TIMES.getDescription())) {
double average = crossDirDataHistPOList.stream()
.mapToDouble(CrossDirDataHistPO::getStopTimes)
.mapToDouble(CrossDirDataHistPOExt::getStopTimes)
.average()
.orElse(0.0);
dirValue = (int) Math.round(average);
} else if (Objects.equals(metricName, StrategyAndMetricsEnum.Metrics.AVERAGE_DELAY.getDescription())) {
double average = crossDirDataHistPOList.stream()
.mapToDouble(CrossDirDataHistPO::getDelayTime)
.mapToDouble(CrossDirDataHistPOExt::getDelayTime)
.average()
.orElse(0.0);
dirValue = (int) Math.round(average);
} else if (Objects.equals(metricName, StrategyAndMetricsEnum.Metrics.AVERAGE_SPEED.getDescription())) {
double average = crossDirDataHistPOList.stream()
.mapToDouble(CrossDirDataHistPO::getSpeed)
.mapToDouble(CrossDirDataHistPOExt::getSpeed)
.average()
.orElse(0.0);
dirValue = (int) Math.round(average);
} else if (Objects.equals(metricName, StrategyAndMetricsEnum.Metrics.MAX_QUEUE_LENGTH.getDescription())) {
double max = crossDirDataHistPOList.stream()
.mapToDouble(CrossDirDataHistPO::getQueueLength)
.mapToDouble(CrossDirDataHistPOExt::getQueueLength)
.max()
.orElse(0.0);
dirValue = (int) Math.round(max);
} else if (Objects.equals(metricName, StrategyAndMetricsEnum.Metrics.EFFUSION_RATE.getDescription())) {
double average = crossDirDataHistPOList.stream()
.mapToDouble(CrossDirDataHistPO::getEffusionRate)
.mapToDouble(CrossDirDataHistPOExt::getEffusionRate)
.average()
.orElse(0.0);
dirValue = (int) Math.round(average * 100);
} else if (Objects.equals(metricName, StrategyAndMetricsEnum.Metrics.EMPTY_PHASE.getDescription())) {
for (CrossDirDataHistPO po : crossDirDataHistPOList) {
for (CrossDirDataHistPOExt po : crossDirDataHistPOList) {
// 计算结束时间
Date endTime = new Date(po.getStartTime().getTime() + 5 * 60 * 1000); // 增加5分钟
......@@ -1091,7 +1129,7 @@ public class MainlineEvaluateServiceImpl implements MainlineEvaluateService {
}
}
double sum = crossDirDataHistPOList.stream()
.mapToDouble(CrossDirDataHistPO::getEmptyPhase)
.mapToDouble(CrossDirDataHistPOExt::getEmptyPhase)
.sum();
dirValue = (int) Math.round(sum);
}
......@@ -1099,7 +1137,7 @@ public class MainlineEvaluateServiceImpl implements MainlineEvaluateService {
}
private Integer calcNonCoordValue(
List<Integer> coordDirCodeList, String crossId, List<CrossDirDataHistPO> crossDirDataHistPOList,
List<Integer> coordDirCodeList, String crossId, List<CrossDirDataHistPOExt> crossDirDataHistPOList,
List<BaseCrossDirInfoPO> baseCrossDirInfoPOList) {
// 筛选非协调方向
......@@ -1112,7 +1150,7 @@ public class MainlineEvaluateServiceImpl implements MainlineEvaluateService {
nonCoordDirCodeList.removeAll(coordDirCodeList);
// 查询时段内路口非协调方向数据
List<CrossDirDataHistPO> filteredList = crossDirDataHistPOList.stream()
List<CrossDirDataHistPOExt> filteredList = crossDirDataHistPOList.stream()
.filter(item -> crossId.equals(item.getCrossId()))
.filter(item -> 1 == item.getInOutType())
.filter(item -> nonCoordDirCodeList.contains(item.getDirType()))
......@@ -1120,7 +1158,7 @@ public class MainlineEvaluateServiceImpl implements MainlineEvaluateService {
// 计算非协调方向指标(排队长度)
double nonCoordValueDouble = (filteredList.stream()
.mapToDouble(CrossDirDataHistPO::getQueueLength)
.mapToDouble(CrossDirDataHistPOExt::getQueueLength)
.max()
.orElse(0.0));
int nonCoordValue = (int) Math.round(nonCoordValueDouble);
......@@ -1129,10 +1167,10 @@ public class MainlineEvaluateServiceImpl implements MainlineEvaluateService {
}
private Integer calcCoordValue(
List<Integer> coordDirCodeList, String crossId, List<CrossDirDataHistPO> crossDirDataHistPOList) {
List<Integer> coordDirCodeList, String crossId, List<CrossDirDataHistPOExt> crossDirDataHistPOList) {
// 查询时段内路口协调方向数据
List<CrossDirDataHistPO> filteredList = crossDirDataHistPOList.stream()
List<CrossDirDataHistPOExt> filteredList = crossDirDataHistPOList.stream()
.filter(item -> crossId.equals(item.getCrossId()))
.filter(item -> 1 == item.getInOutType())
.filter(item -> coordDirCodeList.contains(item.getDirType()))
......@@ -1140,7 +1178,7 @@ public class MainlineEvaluateServiceImpl implements MainlineEvaluateService {
// 计算协调方向指标(不停车通过率)
double coordValueDouble = (filteredList.stream()
.mapToDouble(CrossDirDataHistPO::getNoStopRate)
.mapToDouble(CrossDirDataHistPOExt::getNoStopRate)
.average()
.orElse(0.0) * 100);
int coordValue = (int) Math.round(coordValueDouble);
......
......@@ -4,6 +4,7 @@ package net.wanji.databus.dao.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import net.wanji.databus.dto.MetricHistDTO;
import net.wanji.databus.po.CrossDataHistPO;
import net.wanji.databus.po.CrossDataHistPOExt;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
......@@ -31,4 +32,5 @@ public interface CrossDataHistMapper extends BaseMapper<CrossDataHistPO> {
List<CrossDataHistPO> selectByStartEnd(int startStamp, int endStamp);
List<CrossDataHistPOExt> selectExtByCrossIdAndStartEnd(String crossId, int startStamp, int endStamp);
}
......@@ -73,4 +73,6 @@ public interface CrossDirDataHistMapper extends BaseMapper<CrossDirDataHistPO> {
);
List<CrossDirDataHistPO> selectByTimeSection(String boStartDayStr, String boEndDayStr, String startHourMinuteStr, String endHourMinuteStr);
List<CrossDirDataHistPOExt> selectExtByTimeSection(String boStartDayStr, String boEndDayStr, String startHourMinuteStr, String endHourMinuteStr);
}
......@@ -2,13 +2,17 @@ package net.wanji.databus.po;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* @author duanruiming
* @date 2023/03/12 20:49
*/
@EqualsAndHashCode(callSuper = true)
@Data
public class CrossDataHistPOExt extends CrossDataRealtimePO {
@ApiModelProperty(value = "三急一速数量", notes = "")
private Integer emergencyCount;
@ApiModelProperty(value = "绿灯空放时长", notes = "")
private Integer emptyPhase = 0;
}
......@@ -11,5 +11,8 @@ import lombok.Data;
public class CrossDirDataHistPOExt extends CrossDirDataRealtimePO {
@ApiModelProperty(value = "三急一速数量", notes = "")
public Integer emergencyCount;
@ApiModelProperty(value = "绿灯空放时长")
private Integer emptyPhase = 0;
}
......@@ -65,6 +65,4 @@ public class CrossDirDataRealtimePO {
public Double effusionRate;
@ApiModelProperty(value = "绿灯有效利用率", notes = "")
public Double greenLightEfficiency;
@ApiModelProperty(value = "绿灯空放时长")
private Integer emptyPhase = 0;
}
......@@ -123,4 +123,13 @@
order by batch_time
</select>
<select id="selectExtByCrossIdAndStartEnd" resultType="net.wanji.databus.po.CrossDataHistPOExt">
select <include refid="Base_Column_List"></include>
from t_cross_data_hist
where cross_id = #{crossId}
and batch_time <![CDATA[ >= ]]> #{startStamp}
and batch_time <![CDATA[ <= ]]> #{endStamp}
order by batch_time
</select>
</mapper>
\ No newline at end of file
......@@ -240,4 +240,12 @@
AND in_out_type = 1
</select>
<select id="selectExtByTimeSection" resultType="net.wanji.databus.po.CrossDirDataHistPOExt">
SELECT <include refid="Base_Column_List"></include>
FROM t_cross_dir_data_hist
WHERE batch_time BETWEEN UNIX_TIMESTAMP(STR_TO_DATE(concat(#{boStartDayStr}, #{startHourMinuteStr}), '%Y-%m-%d%H:%i'))
AND UNIX_TIMESTAMP(STR_TO_DATE(concat(#{boEndDayStr}, #{endHourMinuteStr}), '%Y-%m-%d%H:%i'))
AND in_out_type = 1
</select>
</mapper>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment