Commit b94fb4dc authored by hanbing's avatar hanbing

[add] 新信号评价-运行评价-详细指标查询-指标信息

parent b0526758
......@@ -39,7 +39,7 @@ public class SignalEvaluateServiceImpl implements SignalEvaluateService {
}
private FlowQueueOutVO getDayQueue(String adCode, String crossId, Date currentTime) {
List<String> time = TimeArrayUtil.getTimeArray();
List<String> time = TimeArrayUtil.getHourArray();
double[] toDay = new double[24];
double[] yesterday = new double[24];
double[] lastWeekDay = new double[24];
......@@ -63,7 +63,7 @@ public class SignalEvaluateServiceImpl implements SignalEvaluateService {
}
private FlowQueueOutVO getDayFlow(String adCode, String crossId, Date currentTime) {
List<String> time = TimeArrayUtil.getTimeArray();
List<String> time = TimeArrayUtil.getHourArray();
double[] toDay = new double[24];
double[] yesterday = new double[24];
double[] lastWeekDay = new double[24];
......
......@@ -175,7 +175,7 @@ public class RunningEvaluateServiceImpl implements RunningEvaluateService {
public List<RunningEvaluateSchemeProblemsVO> schemeProblems(CrossIdAndStartEndDateBO bo) {
String crossId = bo.getCrossId();
List<RunningEvaluateSchemeProblemsVO> res = new ArrayList<>();
List<String> timeArray = TimeArrayUtil.getTimeArray();
List<String> timeArray = TimeArrayUtil.getHourArray();
for (String time : timeArray) {
RunningEvaluateSchemeProblemsVO vo = new RunningEvaluateSchemeProblemsVO();
......@@ -253,9 +253,78 @@ public class RunningEvaluateServiceImpl implements RunningEvaluateService {
if (CollectionUtil.isEmpty(metricHistDTOList)) {
return res;
}
res.setProblemStatusList(buildProblemStatusList(metricHistDTOList));
res.setSchemeList(buildSchemeList(metricHistDTOList, crossId));
// res.setMetricsList(buildMetricsList(metricHistDTOList, minutes));
// 路口级别全量数据
List<MetricHistDTO> crossDTOList = crossDataHistMapper.selectMetricHistDTO(
crossId, startStamp, endStamp);
// 过滤有问题的记录
List<MetricHistDTO> filteredList = crossDTOList.stream()
.filter(metricHistDTO -> metricHistDTO.getStatus() != null && metricHistDTO.getStatus() != 0)
.collect(Collectors.toList());
if (CollectionUtil.isEmpty(filteredList)) {
return res;
}
res.setProblemStatusList(buildProblemStatusList(filteredList));
res.setSchemeList(buildSchemeList(filteredList, crossId));
// 使用全量数据按时间粒度聚合指标
res.setMetricsList(buildMetricsList(metricHistDTOList, minutes));
return res;
}
private List<RunningEvaluateMetricsDetailVO.CrossMetrics> buildMetricsList(
List<MetricHistDTO> metricHistDTOList, Integer minutes) {
List<RunningEvaluateMetricsDetailVO.CrossMetrics> res = new ArrayList<>();
// 按时间段分组
Map<String, List<MetricHistDTO>> groupedByTime = metricHistDTOList.stream()
.collect(Collectors.groupingBy(metricHistDTO -> {
long timestampInSeconds = metricHistDTO.getBatchTime() * 1000L;
Date date = new Date(timestampInSeconds);
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
int minuteOfDay = date.getMinutes() + date.getHours() * 60;
int roundedMinute = (minuteOfDay / minutes) * minutes;
date.setHours(roundedMinute / 60);
date.setMinutes(roundedMinute % 60);
return sdf.format(date);
}));
// 获取时间段数组
List<String> minuteSectionArray = TimeArrayUtil.getMinuteSectionArray(minutes);
// 计算指标
for (String section : minuteSectionArray) {
RunningEvaluateMetricsDetailVO.CrossMetrics crossMetrics = new RunningEvaluateMetricsDetailVO.CrossMetrics();
crossMetrics.setMetricTime(section);
List<MetricHistDTO> dtoList = groupedByTime.get(section);
if (CollectionUtil.isNotEmpty(dtoList)) {
int flowSum = 0;
double speedSum = 0.0;
int capacitySum = 0;
double sturationSum = 0.0;
double stopTimesSum = 0.0;
int delayTimeSum = 0;
for (MetricHistDTO metricHistDTO : dtoList) {
Integer flow = metricHistDTO.getFlow();
Double speed = metricHistDTO.getSpeed();
Integer capacity = metricHistDTO.getCapacity();
Double sturation = metricHistDTO.getSturation();
Double stopTimes = metricHistDTO.getStopTimes();
Integer delayTime = metricHistDTO.getDelayTime();
if (flow != null) flowSum += flow;
if (speed != null) speedSum += speed;
if (capacity != null) capacitySum += capacity;
if (sturation != null) sturationSum += sturationSum;
if (stopTimes != null) stopTimesSum += stopTimes;
if (delayTime != null) delayTimeSum += delayTime;
}
int size = dtoList.size();
crossMetrics.setFlow(flowSum / size);
crossMetrics.setSpeed(speedSum / size);
crossMetrics.setCapacity(capacitySum / size);
crossMetrics.setSturation(sturationSum / size);
crossMetrics.setStopTimes(stopTimesSum / size);
crossMetrics.setDelayTime(delayTimeSum / size);
}
res.add(crossMetrics);
}
return res;
}
......@@ -506,7 +575,7 @@ public class RunningEvaluateServiceImpl implements RunningEvaluateService {
// 构造结果集
List<RunningEvaluateIndexStatusVO> res = new ArrayList<>();
List<String> timeArray = TimeArrayUtil.getTimeArray();
List<String> timeArray = TimeArrayUtil.getHourArray();
for (String time : timeArray) {
RunningEvaluateIndexStatusVO vo = new RunningEvaluateIndexStatusVO();
vo.setTime(time);
......
......@@ -75,8 +75,7 @@ public class RunningEvaluateMetricsDetailVO {
@Data
public static class CrossMetrics {
@ApiModelProperty(value = "时间")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "HH:mm", timezone = "GMT+8")
private Date metricTime;
private String metricTime;
@ApiModelProperty(value = "流量")
private Integer flow;
......@@ -91,7 +90,7 @@ public class RunningEvaluateMetricsDetailVO {
private Double sturation;
@ApiModelProperty(value = "平均停车次数")
private Double stopNumber;
private Double stopTimes;
@ApiModelProperty(value = "平均延误(秒)")
private Integer delayTime ;
......
package net.wanji.common.utils.tool;
import java.text.MessageFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Date;
/**
* @author Kent HAN
......@@ -11,12 +13,12 @@ import java.util.List;
public class TimeArrayUtil {
/**
* 返回一天的时间数组,按小时。如 ["00:00", "01:00" ... "23:00"]
* 返回一天的小时数组,按小时。如 ["00:00", "01:00" ... "23:00"]
*
* @author Kent HAN
* @date 2022/11/3 16:30
*/
public static List<String> getTimeArray() {
public static List<String> getHourArray() {
List<String> res = new ArrayList<>();
for (int i = 0; i < 24; i++) {
if (i < 10) {
......@@ -27,4 +29,22 @@ public class TimeArrayUtil {
}
return res;
}
/**
* 按分钟段返回一天的时间数组。如 ["00:15", "00:30" ... ]
* minutes,分钟段。如按每15分钟生成,则 minute 传15。
* @author Kent HAN
* @date 2022/11/3 16:30
*/
public static List<String> getMinuteSectionArray(Integer minutes) {
List<String> timeSegments = new ArrayList<>();
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
for (int i = 0; i < 24 * 60; i += minutes) {
Date date = new Date();
date.setHours(i / 60);
date.setMinutes(i % 60);
timeSegments.add(sdf.format(date));
}
return timeSegments;
}
}
......@@ -78,7 +78,7 @@
<select id="selectMetricHistDTO" resultType="net.wanji.databus.dto.MetricHistDTO">
select status, start_time, duration, flow, speed, sturation, stop_times, delay_time, batch_time
from t_cross_data_hist
where cross_id = #{crossId} and status != 0
where cross_id = #{crossId}
and batch_time <![CDATA[ >= ]]> #{startStamp}
and batch_time <![CDATA[ <= ]]> #{endStamp}
order by batch_time
......
......@@ -110,7 +110,7 @@
<select id="selectMetricHistDTO" resultType="net.wanji.databus.dto.MetricHistDTO">
select status, start_time, duration, flow, speed, sturation, capacity, stop_times, delay_time, batch_time
from t_cross_dir_data_hist
where cross_id = #{crossId} and status != 0
where cross_id = #{crossId}
and batch_time <![CDATA[ >= ]]> #{startStamp}
and batch_time <![CDATA[ <= ]]> #{endStamp}
order by batch_time
......
......@@ -69,7 +69,7 @@
<select id="selectMetricHistDTO" resultType="net.wanji.databus.dto.MetricHistDTO">
select status, flow, speed, sturation, stop_times, delay_time, batch_time
from t_cross_turn_data_hist
where cross_id = #{crossId} and status != 0
where cross_id = #{crossId}
and batch_time <![CDATA[ >= ]]> #{startStamp}
and batch_time <![CDATA[ <= ]]> #{endStamp}
order by batch_time
......
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