Commit 28a598c5 authored by hanbing's avatar hanbing

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

parent feda485e
...@@ -4,10 +4,12 @@ import lombok.Data; ...@@ -4,10 +4,12 @@ import lombok.Data;
@Data @Data
public class CrossDirDataHistAvgBO { public class CrossDirDataHistAvgBO {
//方向 // 方向
private Integer dirType; private Integer dirType;
//平均通行能力 // 平均通行能力
private Integer avgCapacity; private Integer avgCapacity;
//平均流量 // 平均流量
private Integer avgFlow; private Integer avgFlow;
// 平均排队长度
private Double avgQueueLength;
} }
...@@ -24,6 +24,7 @@ import net.wanji.opt.po.trend.CrossDataRealtimePO; ...@@ -24,6 +24,7 @@ import net.wanji.opt.po.trend.CrossDataRealtimePO;
import net.wanji.opt.service.EvaluateService; import net.wanji.opt.service.EvaluateService;
import net.wanji.opt.vo.EvaluateCrossDetailVO; import net.wanji.opt.vo.EvaluateCrossDetailVO;
import net.wanji.opt.vo.EvaluateMetricsVO; import net.wanji.opt.vo.EvaluateMetricsVO;
import org.jetbrains.annotations.NotNull;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -77,9 +78,9 @@ public class EvaluateServiceImpl implements EvaluateService { ...@@ -77,9 +78,9 @@ public class EvaluateServiceImpl implements EvaluateService {
// 路口流量 // 路口流量
List<EvaluateMetricsVO.CrossFlowElement> crossFlow = buildCrossFlow(crossId, minutes); List<EvaluateMetricsVO.CrossFlowElement> crossFlow = buildCrossFlow(crossId, minutes);
evaluateMetricsVO.setCrossFlow(crossFlow); evaluateMetricsVO.setCrossFlow(crossFlow);
// // 路口排队长度 // 路口排队长度
// List<EvaluateMetricsVO.QueueLengthElement> queueLength = buildQueueLength(); List<EvaluateMetricsVO.QueueLengthElement> queueLength = buildQueueLength(crossId, minutes);
// evaluateMetricsVO.setQueueLength(queueLength); evaluateMetricsVO.setQueueLength(queueLength);
// // 拥堵指数 // // 拥堵指数
// List<EvaluateMetricsVO.TrafficIndexElement> trafficIndex = buildTrafficIndex(); // List<EvaluateMetricsVO.TrafficIndexElement> trafficIndex = buildTrafficIndex();
// evaluateMetricsVO.setTrafficIndex(trafficIndex); // evaluateMetricsVO.setTrafficIndex(trafficIndex);
...@@ -88,23 +89,38 @@ public class EvaluateServiceImpl implements EvaluateService { ...@@ -88,23 +89,38 @@ public class EvaluateServiceImpl implements EvaluateService {
return evaluateMetricsVO; 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) { private List<EvaluateMetricsVO.CrossFlowElement> buildCrossFlow(String crossId, Integer minutes) {
List<EvaluateMetricsVO.CrossFlowElement> res = new ArrayList<>(); List<EvaluateMetricsVO.CrossFlowElement> res = new ArrayList<>();
// 实时数据 // 实时数据
List<CrossDirDataRealtimePO> crossDirDataRealtimePOList = Map<Integer, List<CrossDirDataRealtimePO>> dirObjMapRealtime = getRealTimeData(crossId);
crossDirDataRealtimeMapper.selectByCrossIdAndInOutType(crossId, CrossInOutEnum.IN.getCode());
Map<Integer, List<CrossDirDataRealtimePO>> dirObjMapRealtime = crossDirDataRealtimePOList.stream()
.collect(Collectors.groupingBy(CrossDirDataRealtimePO::getDirType));
// 历史数据 // 历史数据
// 获取当前时间之前某分钟的10位时间戳 Map<Integer, List<CrossDirDataHistAvgBO>> dirObjMapHist = getHistData(crossId, minutes);
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));
for (Integer dir : dirObjMapRealtime.keySet()) { for (Integer dir : dirObjMapRealtime.keySet()) {
EvaluateMetricsVO.CrossFlowElement crossFlowElement = new EvaluateMetricsVO.CrossFlowElement(); EvaluateMetricsVO.CrossFlowElement crossFlowElement = new EvaluateMetricsVO.CrossFlowElement();
...@@ -127,6 +143,29 @@ public class EvaluateServiceImpl implements EvaluateService { ...@@ -127,6 +143,29 @@ public class EvaluateServiceImpl implements EvaluateService {
return res; 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) { private void fillRealtimeData(EvaluateCrossDetailVO evaluateCrossDetailVO, String crossId) {
CrossDataRealtimePO crossDataRealtimePO = crossDataRealtimeMapper.selectByCrossId(crossId); CrossDataRealtimePO crossDataRealtimePO = crossDataRealtimeMapper.selectByCrossId(crossId);
evaluateCrossDetailVO.setSceneStartTime(crossDataRealtimePO.getStartTime()); evaluateCrossDetailVO.setSceneStartTime(crossDataRealtimePO.getStartTime());
......
package net.wanji.opt.vo; package net.wanji.opt.vo;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
...@@ -45,8 +46,10 @@ public class EvaluateMetricsVO { ...@@ -45,8 +46,10 @@ public class EvaluateMetricsVO {
@ApiModelProperty(value = "方向:1北;2东北;3东;4东南;5南;6西南;7西;8西北") @ApiModelProperty(value = "方向:1北;2东北;3东;4东南;5南;6西南;7西;8西北")
private Integer dir; private Integer dir;
@ApiModelProperty(value = "当前时段排队长度") @ApiModelProperty(value = "当前时段排队长度")
@JsonSerialize(using = net.wanji.common.framework.DoubleSerialize.class)
private Double currentLength; private Double currentLength;
@ApiModelProperty(value = "对比时段排队长度") @ApiModelProperty(value = "对比时段排队长度")
@JsonSerialize(using = net.wanji.common.framework.DoubleSerialize.class)
private Double compareLength; private Double compareLength;
} }
...@@ -56,8 +59,10 @@ public class EvaluateMetricsVO { ...@@ -56,8 +59,10 @@ public class EvaluateMetricsVO {
@ApiModelProperty(value = "方向:1北;2东北;3东;4东南;5南;6西南;7西;8西北") @ApiModelProperty(value = "方向:1北;2东北;3东;4东南;5南;6西南;7西;8西北")
private Integer dir; private Integer dir;
@ApiModelProperty(value = "当前时段拥堵指数") @ApiModelProperty(value = "当前时段拥堵指数")
@JsonSerialize(using = net.wanji.common.framework.DoubleSerialize.class)
private Double currentIndex; private Double currentIndex;
@ApiModelProperty(value = "对比时段拥堵指数") @ApiModelProperty(value = "对比时段拥堵指数")
@JsonSerialize(using = net.wanji.common.framework.DoubleSerialize.class)
private Double compareIndex; private Double compareIndex;
} }
...@@ -67,8 +72,10 @@ public class EvaluateMetricsVO { ...@@ -67,8 +72,10 @@ public class EvaluateMetricsVO {
@ApiModelProperty(value = "方向:1北;2东北;3东;4东南;5南;6西南;7西;8西北") @ApiModelProperty(value = "方向:1北;2东北;3东;4东南;5南;6西南;7西;8西北")
private Integer dir; private Integer dir;
@ApiModelProperty(value = "当前时段溢流率") @ApiModelProperty(value = "当前时段溢流率")
@JsonSerialize(using = net.wanji.common.framework.DoubleSerialize.class)
private Double currentRate; private Double currentRate;
@ApiModelProperty(value = "对比时段溢流率") @ApiModelProperty(value = "对比时段溢流率")
@JsonSerialize(using = net.wanji.common.framework.DoubleSerialize.class)
private Double compareRate; private Double compareRate;
} }
} }
...@@ -26,7 +26,8 @@ ...@@ -26,7 +26,8 @@
</select> </select>
<select id="selectByCrossIdInOutTimestamp" resultType="net.wanji.opt.bo.CrossDirDataHistAvgBO"> <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 FROM t_cross_dir_data_hist
WHERE cross_id = #{crossId} WHERE cross_id = #{crossId}
AND in_out_type = #{inOutType} 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