Commit 28a598c5 authored by hanbing's avatar hanbing

[add] 信号评价,评价指标-路口排队长度

parent feda485e
......@@ -4,10 +4,12 @@ import lombok.Data;
@Data
public class CrossDirDataHistAvgBO {
//方向
// 方向
private Integer dirType;
//平均通行能力
// 平均通行能力
private Integer avgCapacity;
//平均流量
// 平均流量
private Integer avgFlow;
// 平均排队长度
private Double avgQueueLength;
}
......@@ -24,6 +24,7 @@ import net.wanji.opt.po.trend.CrossDataRealtimePO;
import net.wanji.opt.service.EvaluateService;
import net.wanji.opt.vo.EvaluateCrossDetailVO;
import net.wanji.opt.vo.EvaluateMetricsVO;
import org.jetbrains.annotations.NotNull;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
......@@ -77,9 +78,9 @@ public class EvaluateServiceImpl implements EvaluateService {
// 路口流量
List<EvaluateMetricsVO.CrossFlowElement> crossFlow = buildCrossFlow(crossId, minutes);
evaluateMetricsVO.setCrossFlow(crossFlow);
// // 路口排队长度
// List<EvaluateMetricsVO.QueueLengthElement> queueLength = buildQueueLength();
// evaluateMetricsVO.setQueueLength(queueLength);
// 路口排队长度
List<EvaluateMetricsVO.QueueLengthElement> queueLength = buildQueueLength(crossId, minutes);
evaluateMetricsVO.setQueueLength(queueLength);
// // 拥堵指数
// List<EvaluateMetricsVO.TrafficIndexElement> trafficIndex = buildTrafficIndex();
// evaluateMetricsVO.setTrafficIndex(trafficIndex);
......@@ -88,23 +89,38 @@ public class EvaluateServiceImpl implements EvaluateService {
return evaluateMetricsVO;
}
private List<EvaluateMetricsVO.QueueLengthElement> buildQueueLength(String crossId, Integer minutes) {
List<EvaluateMetricsVO.QueueLengthElement> res = new ArrayList<>();
// 实时数据
Map<Integer, List<CrossDirDataRealtimePO>> dirObjMapRealtime = getRealTimeData(crossId);
// 历史数据
Map<Integer, List<CrossDirDataHistAvgBO>> dirObjMapHist = getHistData(crossId, minutes);
for (Integer dir : dirObjMapRealtime.keySet()) {
EvaluateMetricsVO.QueueLengthElement queueLengthElement = new EvaluateMetricsVO.QueueLengthElement();
queueLengthElement.setDir(dir);
List<CrossDirDataRealtimePO> realtimeObj = dirObjMapRealtime.get(dir);
if (CollectionUtil.isNotEmpty(realtimeObj)) {
CrossDirDataRealtimePO crossDirDataRealtimePO = realtimeObj.get(0);
queueLengthElement.setCurrentLength(crossDirDataRealtimePO.getLength());
}
List<CrossDirDataHistAvgBO> histObj = dirObjMapHist.get(dir);
if (CollectionUtil.isNotEmpty(histObj)) {
CrossDirDataHistAvgBO crossDirDataHistAvgBO = histObj.get(0);
queueLengthElement.setCompareLength(crossDirDataHistAvgBO.getAvgQueueLength());
}
res.add(queueLengthElement);
}
return res;
}
private List<EvaluateMetricsVO.CrossFlowElement> buildCrossFlow(String crossId, Integer minutes) {
List<EvaluateMetricsVO.CrossFlowElement> res = new ArrayList<>();
// 实时数据
List<CrossDirDataRealtimePO> crossDirDataRealtimePOList =
crossDirDataRealtimeMapper.selectByCrossIdAndInOutType(crossId, CrossInOutEnum.IN.getCode());
Map<Integer, List<CrossDirDataRealtimePO>> dirObjMapRealtime = crossDirDataRealtimePOList.stream()
.collect(Collectors.groupingBy(CrossDirDataRealtimePO::getDirType));
Map<Integer, List<CrossDirDataRealtimePO>> dirObjMapRealtime = getRealTimeData(crossId);
// 历史数据
// 获取当前时间之前某分钟的10位时间戳
long currentSeconds = DateUtil.currentSeconds();
// todo 测试用 固定当前时间为1676085300
currentSeconds = 1676085300;
long preSeconds = currentSeconds - minutes * 60;
List<CrossDirDataHistAvgBO> crossDirDataHistAvgBOList = crossDirDataHistMapper.selectByCrossIdInOutTimestamp(
crossId, CrossInOutEnum.IN.getCode(), preSeconds);
Map<Integer, List<CrossDirDataHistAvgBO>> dirObjMapHist = crossDirDataHistAvgBOList.stream()
.collect(Collectors.groupingBy(CrossDirDataHistAvgBO::getDirType));
Map<Integer, List<CrossDirDataHistAvgBO>> dirObjMapHist = getHistData(crossId, minutes);
for (Integer dir : dirObjMapRealtime.keySet()) {
EvaluateMetricsVO.CrossFlowElement crossFlowElement = new EvaluateMetricsVO.CrossFlowElement();
......@@ -127,6 +143,29 @@ public class EvaluateServiceImpl implements EvaluateService {
return res;
}
@NotNull
private Map<Integer, List<CrossDirDataHistAvgBO>> getHistData(String crossId, Integer minutes) {
// 获取当前时间之前某分钟的10位时间戳
long currentSeconds = DateUtil.currentSeconds();
// todo 测试用 固定当前时间为1676085300
currentSeconds = 1676085300;
long preSeconds = currentSeconds - minutes * 60;
List<CrossDirDataHistAvgBO> crossDirDataHistAvgBOList = crossDirDataHistMapper.selectByCrossIdInOutTimestamp(
crossId, CrossInOutEnum.IN.getCode(), preSeconds);
Map<Integer, List<CrossDirDataHistAvgBO>> dirObjMapHist = crossDirDataHistAvgBOList.stream()
.collect(Collectors.groupingBy(CrossDirDataHistAvgBO::getDirType));
return dirObjMapHist;
}
@NotNull
private Map<Integer, List<CrossDirDataRealtimePO>> getRealTimeData(String crossId) {
List<CrossDirDataRealtimePO> crossDirDataRealtimePOList =
crossDirDataRealtimeMapper.selectByCrossIdAndInOutType(crossId, CrossInOutEnum.IN.getCode());
Map<Integer, List<CrossDirDataRealtimePO>> dirObjMapRealtime = crossDirDataRealtimePOList.stream()
.collect(Collectors.groupingBy(CrossDirDataRealtimePO::getDirType));
return dirObjMapRealtime;
}
private void fillRealtimeData(EvaluateCrossDetailVO evaluateCrossDetailVO, String crossId) {
CrossDataRealtimePO crossDataRealtimePO = crossDataRealtimeMapper.selectByCrossId(crossId);
evaluateCrossDetailVO.setSceneStartTime(crossDataRealtimePO.getStartTime());
......
package net.wanji.opt.vo;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
......@@ -45,8 +46,10 @@ public class EvaluateMetricsVO {
@ApiModelProperty(value = "方向:1北;2东北;3东;4东南;5南;6西南;7西;8西北")
private Integer dir;
@ApiModelProperty(value = "当前时段排队长度")
@JsonSerialize(using = net.wanji.common.framework.DoubleSerialize.class)
private Double currentLength;
@ApiModelProperty(value = "对比时段排队长度")
@JsonSerialize(using = net.wanji.common.framework.DoubleSerialize.class)
private Double compareLength;
}
......@@ -56,8 +59,10 @@ public class EvaluateMetricsVO {
@ApiModelProperty(value = "方向:1北;2东北;3东;4东南;5南;6西南;7西;8西北")
private Integer dir;
@ApiModelProperty(value = "当前时段拥堵指数")
@JsonSerialize(using = net.wanji.common.framework.DoubleSerialize.class)
private Double currentIndex;
@ApiModelProperty(value = "对比时段拥堵指数")
@JsonSerialize(using = net.wanji.common.framework.DoubleSerialize.class)
private Double compareIndex;
}
......@@ -67,8 +72,10 @@ public class EvaluateMetricsVO {
@ApiModelProperty(value = "方向:1北;2东北;3东;4东南;5南;6西南;7西;8西北")
private Integer dir;
@ApiModelProperty(value = "当前时段溢流率")
@JsonSerialize(using = net.wanji.common.framework.DoubleSerialize.class)
private Double currentRate;
@ApiModelProperty(value = "对比时段溢流率")
@JsonSerialize(using = net.wanji.common.framework.DoubleSerialize.class)
private Double compareRate;
}
}
......@@ -26,7 +26,8 @@
</select>
<select id="selectByCrossIdInOutTimestamp" resultType="net.wanji.opt.bo.CrossDirDataHistAvgBO">
SELECT dir_type as dirType, avg(capacity) as avgCapacity, avg(flow) as avgFlow
SELECT dir_type as dirType, avg(capacity) as avgCapacity, avg(flow) as avgFlow,
avg(queue_length) as avgQueueLength
FROM t_cross_dir_data_hist
WHERE cross_id = #{crossId}
AND in_out_type = #{inOutType}
......
package net.wanji.common.framework;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import java.io.IOException;
import java.text.DecimalFormat;
/**
* Double序列化保留两位小鼠
*
* @author Kent HAN
* @date 2023/3/12 14:03
*/
public class DoubleSerialize extends JsonSerializer<Double> {
private DecimalFormat df = new DecimalFormat("##.00");
@Override
public void serialize(Double value, JsonGenerator gen, SerializerProvider serializers)
throws IOException, JsonProcessingException {
if (value != null) {
gen.writeString(df.format(value));
}
}
}
\ 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