Commit af51fec2 authored by duanruiming's avatar duanruiming

[add] 调优平台v2-雷达图;路口列表查询优化;

parent 016742f7
......@@ -16,7 +16,8 @@ public enum EventInfoTypeEnum {
PHASE_EMPTY(5, "701","相位空放"),
CROSS_UNBALANCE(1, "702","路口失衡"),
CROSS_OVERFLOW(3, "703","路口溢出"),
CROSS_DEADLOCK(4, "704","路口死锁"),
// 当前没有
//CROSS_DEADLOCK(4, "704","路口死锁"),
GREEN_SLOW(6, "705","干线-缓行"),
GREEN_CONGEST(7, "706","干线-拥堵"),
CROSS_CONGEST(2, "707","路口拥堵");
......
package net.wanji.opt.servicev2.implv2;
import com.alibaba.nacos.api.utils.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.extern.slf4j.Slf4j;
import net.wanji.databus.dao.mapper.CrossDataHistMapper;
import net.wanji.databus.po.CrossDataHistPO;
import net.wanji.opt.common.enums.EventInfoTypeEnum;
import net.wanji.opt.dao.mapper.HoloEventMapper;
import net.wanji.opt.dao.mapper.StrategyCrossResultMapper;
import net.wanji.opt.servicev2.TrendServiceV2;
......@@ -11,7 +16,12 @@ import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* @author duanruiming
......@@ -25,10 +35,26 @@ public class TrendServiceV2Impl implements TrendServiceV2 {
private HoloEventMapper holoEventMapper;
@Resource
private StrategyCrossResultMapper strategyCrossResultMapper;
@Resource
private CrossDataHistMapper crossDataHistMapper;
@Override
public List<CrossGreenStatusTimeRateVO> crossGreenStatusTimeRate() {
return holoEventMapper.selectCrossGreenStatusTimeRate();
List<CrossGreenStatusTimeRateVO> crossGreenStatusTimeRateVOS = holoEventMapper.selectCrossGreenStatusTimeRate();
if (!CollectionUtils.isEmpty(crossGreenStatusTimeRateVOS)) {
Map<String, CrossGreenStatusTimeRateVO> map = crossGreenStatusTimeRateVOS.stream().collect(Collectors.toMap(CrossGreenStatusTimeRateVO::getType, crossGreenStatusTimeRateVO -> crossGreenStatusTimeRateVO));
for (EventInfoTypeEnum typeEnum : EventInfoTypeEnum.values()) {
String eventType = typeEnum.getEventType();
if (!map.containsKey(eventType)) {
CrossGreenStatusTimeRateVO vo = new CrossGreenStatusTimeRateVO();
vo.setType(eventType);
vo.setCount(0);
crossGreenStatusTimeRateVOS.add(vo);
}
}
}
return crossGreenStatusTimeRateVOS;
}
@Override
......@@ -37,36 +63,42 @@ public class TrendServiceV2Impl implements TrendServiceV2 {
try {
results = new ArrayList<>();
List<CrossOptInfoVO> resultList = strategyCrossResultMapper.selectAICrossListV2();
LocalDateTime now = LocalDateTime.now();
LocalDateTime lastWeekNow = now.minusDays(7);
Instant instant = lastWeekNow.atZone(ZoneId.systemDefault()).toInstant();
long start = instant.getEpochSecond();
long end = start + 5 * 60;
LambdaQueryWrapper<CrossDataHistPO> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.between(CrossDataHistPO::getBatchTime, start, end);
List<CrossDataHistPO> crossDataHistPOS = crossDataHistMapper.selectList(queryWrapper);
if (!CollectionUtils.isEmpty(resultList)) {
for (CrossOptInfoVO entity : resultList) {
CrossOptInfoVO result = new CrossOptInfoVO();
String crossId = entity.getCrossId();
Double trafficIndex = entity.getTrafficIndex();
Integer queueLength = entity.getQueueLength();
String location = entity.getLocation();
location = location.replace("POINT(", "").replace(" ", ",").replace(")", "");
BeanUtils.copyProperties(entity, result);
Integer currentAlgo = entity.getCurrentAlgo();
Date issueTime = entity.getIssueTime();
Date current = new Date();
Integer duration = Objects.nonNull(entity.getDuration()) ? entity.getDuration() : 0;
// 计算结束时间
if (Objects.nonNull(issueTime)) {
if (Objects.equals(2, currentAlgo) && current.getTime() - issueTime.getTime() <= duration * 1000) {
result.setOptStatus("优化中");
result.setOptMethod("均衡调控");
} else if (current.getTime() - issueTime.getTime() > 10 * 1000) {
currentAlgo = null;
result.setLocation(location);
for (CrossDataHistPO crossDataHistPO : crossDataHistPOS) {
String lastWeekCrossId = crossDataHistPO.getCrossId();
Double lastWeekTrafficIndex = crossDataHistPO.getTrafficIndex();
Double lastWeekQueueLength = crossDataHistPO.getQueueLength();
if (StringUtils.equals(crossId, lastWeekCrossId)) {
if (trafficIndex > lastWeekTrafficIndex) {
result.setTrafficIndexUpDown(1);
} else {
result.setTrafficIndexUpDown(0);
}
if (queueLength > lastWeekQueueLength) {
result.setQueueLengthUpDown(1);
} else {
result.setQueueLengthUpDown(0);
}
results.add(result);
}
}
// 0无策略
if (Objects.isNull(currentAlgo) || Objects.equals(0, currentAlgo)) {
result.setOptStatus("正常");
result.setOptMethod("畅通");
} else if (Objects.equals(2, currentAlgo)) {
result.setOptStatus("优化中");
result.setOptMethod("均衡调控");
} else {
result.setOptStatus("优化中");
result.setOptMethod("效率提升");
}
results.add(result);
}
}
} catch (Exception e) {
......
......@@ -25,8 +25,8 @@ public class CrossOptInfoVO {
private Integer currentAlgo;
@ApiModelProperty(value = "响应编码")
private Integer responseCode;
@ApiModelProperty(value = "响应状态")
private String responseContent;
@ApiModelProperty(value = "经纬度")
private String location;
@ApiModelProperty(value = "持续时长")
private Integer duration;
private String strategyName;
......@@ -38,5 +38,9 @@ public class CrossOptInfoVO {
@JsonSerialize(using = Double2TwoDecimalPlacesSerializer.class)
private Double trafficIndex;
@ApiModelProperty(value = "排队长度")
private int queueLength;
private Integer queueLength;
@ApiModelProperty(value = "同比交通指数,0-向下, 1向上")
private Integer trafficIndexUpDown;
@ApiModelProperty(value = "同比排队长度,0-向下, 1向上")
private Integer queueLengthUpDown;
}
\ No newline at end of file
......@@ -249,7 +249,7 @@
TIMESTAMPDIFF(SECOND, start_time, ifnull(end_time,now())) duration,
TIMESTAMPDIFF(SECOND, DATE_FORMAT(start_time, '%Y-%m-%d 00:00:00'), now()) as totalTime
from t_event_info
where type in ('701', '702', '703', '704', '705', '706', '707') and start_time > curdate()
where type in ('701', '702', '703', '705', '706', '707') and start_time > curdate()
) t1 group by t1.type
</select>
......
......@@ -19,9 +19,17 @@
<select id="selectAICrossListV2" resultType="net.wanji.opt.vo2.CrossOptInfoVO">
select t1.id crossId, t1.name crossName, t2.issue_time issueTime, t2.current_algo currentAlgo,
t2.response_code responseCode, t1.location as responseContent, t2.duration,
t3.queue_length queueLength, t3.traffic_index trafficIndex from
select t1.id crossId, t1.name crossName, t2.issue_time issueTime,
case
when t2.current_algo = 2 then '效率提升'
else '均衡调控'
end as strategyName,
t2.response_code responseCode,
t1.location as location,
ifnull(t2.duration, 0) duration,
t3.queue_length queueLength,
t3.traffic_index trafficIndex
from
(select id, name, location from t_base_cross_info where is_signal = 1) t1
left join (select t1.cross_id, t1.issue_time, t1.current_algo, t1.response_code, t1.duration from t_strategy_cross_result t1
inner join (select cross_id, max(issue_time) issue_time from t_strategy_cross_result where issue_time > CURDATE() group by cross_id) t3
......@@ -29,7 +37,7 @@
on t1.id = t2.cross_id
and t2.issue_time > CURDATE()
left join t_cross_data_realtime t3 on t1.id = t3.cross_id
order by t2.issue_time desc
order by t3.traffic_index desc
</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