Commit c71feebc authored by zhoushiguang's avatar zhoushiguang

干线交通状态分析

parent c21f74ae
package net.wanji.opt.constant;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
/**
* @ClassName EventAbnormalEnum
* @Description
* @Date 2021/4/15 11:13
* @Version 1.0
*/
public enum EventAbnormalEnum {
CROSS_PHASE_EMPTY(701,"相位空放" ),
CROSS_UNBALANCE(702,"路口失衡" ),
CROSS_OVERFLOW(703,"路口溢出" ),
CROSS_DEADLOCK(704,"路口死锁" ),
GREEN_WAVE_SLOW_RUN(705,"干线-缓行" ),
GREEN_WAVE_CONGEST(706,"干线-拥堵" ),
;
public final static double step_default = 1;
Integer type;
String desc;
EventAbnormalEnum(Integer type, String desc ) {
this.type = type;
this.desc = desc;
}
public Integer getType(){
return type;
}
public String getDesc() {
return desc;
}
public static EventAbnormalEnum getByType(String type){
for (EventAbnormalEnum abnormalEnum : EventAbnormalEnum.values()) {
if(abnormalEnum.getType().equals(type)){
return abnormalEnum;
}
}
return null;
}
}
...@@ -62,11 +62,12 @@ public class GreenwaveHistRestServer { ...@@ -62,11 +62,12 @@ public class GreenwaveHistRestServer {
responseHeaders = {@ResponseHeader(name = "Content-Type", description = "application/json")}) responseHeaders = {@ResponseHeader(name = "Content-Type", description = "application/json")})
}) })
public JsonViewObject findGreenWaveRunState(Integer greenId,@RequestParam(defaultValue ="2024-12-04 00:00:00") String startTime, public JsonViewObject findGreenWaveRunState(Integer greenId,@RequestParam(defaultValue ="2024-12-04 00:00:00") String startTime,
@RequestParam(defaultValue ="2024-12-05 00:00:00") String endTime) { @RequestParam(defaultValue ="2024-12-05 00:00:00") String endTime,
@RequestParam(defaultValue ="705,706") String eventType) {
JsonViewObject jsonView = JsonViewObject.newInstance(); JsonViewObject jsonView = JsonViewObject.newInstance();
long start=System.currentTimeMillis(); long start=System.currentTimeMillis();
try { try {
List<GreenWaveRunStateVO> list = greenwaveHistProvider.findGreenWaveRunState(greenId,startTime,endTime); List<GreenWaveRunStateVO> list = greenwaveHistProvider.findGreenWaveRunState(greenId,null,startTime,endTime,eventType);
jsonView.success(list); jsonView.success(list);
} catch (DubboProviderException e) { } catch (DubboProviderException e) {
jsonView.fail(I18nResourceBundle.getConstants("GET_FAILED_MSG")); jsonView.fail(I18nResourceBundle.getConstants("GET_FAILED_MSG"));
......
...@@ -4,6 +4,7 @@ import io.swagger.annotations.Api; ...@@ -4,6 +4,7 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse; import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses; import io.swagger.annotations.ApiResponses;
import net.wanji.common.framework.exception.DubboProviderException;
import net.wanji.common.framework.rest.JsonViewObject; import net.wanji.common.framework.rest.JsonViewObject;
import net.wanji.databus.bo.CrossIdAndStartEndDateBO; import net.wanji.databus.bo.CrossIdAndStartEndDateBO;
import net.wanji.databus.bo.CrossIdBO; import net.wanji.databus.bo.CrossIdBO;
...@@ -57,7 +58,12 @@ public class RunningEvaluateController { ...@@ -57,7 +58,12 @@ public class RunningEvaluateController {
@ApiResponse(code = 200, message = "OK", response = RunningEvaluateCrossEvaluateVO.class), @ApiResponse(code = 200, message = "OK", response = RunningEvaluateCrossEvaluateVO.class),
}) })
public JsonViewObject crossEvaluate(@RequestBody CrossIdAndStartEndDateBO bo) { public JsonViewObject crossEvaluate(@RequestBody CrossIdAndStartEndDateBO bo) {
RunningEvaluateCrossEvaluateVO res = runningEvaluateService.crossEvaluate(bo); RunningEvaluateCrossEvaluateVO res = null;
try {
res = runningEvaluateService.crossEvaluate(bo);
} catch (DubboProviderException e) {
e.printStackTrace();
}
return JsonViewObject.newInstance().success(res); return JsonViewObject.newInstance().success(res);
} }
......
...@@ -78,5 +78,5 @@ public interface GreenwaveHistProvider extends BaseDubboInterface<GreenwaveHist> ...@@ -78,5 +78,5 @@ public interface GreenwaveHistProvider extends BaseDubboInterface<GreenwaveHist>
* @param endTime * @param endTime
* @return * @return
*/ */
List<GreenWaveRunStateVO> findGreenWaveRunState(Integer greenId, String startTime, String endTime) throws DubboProviderException; List<GreenWaveRunStateVO> findGreenWaveRunState(Integer greenId,String crossId, String startTime, String endTime,String eventType) throws DubboProviderException;
} }
package net.wanji.opt.service; package net.wanji.opt.service;
import net.wanji.common.framework.exception.DubboProviderException;
import net.wanji.databus.bo.CrossIdAndStartEndDateBO; import net.wanji.databus.bo.CrossIdAndStartEndDateBO;
import net.wanji.databus.bo.CrossIdBO; import net.wanji.databus.bo.CrossIdBO;
import net.wanji.databus.bo.HeatMapBO; import net.wanji.databus.bo.HeatMapBO;
...@@ -13,7 +14,7 @@ import java.util.List; ...@@ -13,7 +14,7 @@ import java.util.List;
public interface RunningEvaluateService { public interface RunningEvaluateService {
List<RunningEvaluateCrossListVO> crossList(CrossNameBO crossNameBO); List<RunningEvaluateCrossListVO> crossList(CrossNameBO crossNameBO);
RunningEvaluateCrossEvaluateVO crossEvaluate(CrossIdAndStartEndDateBO bo); RunningEvaluateCrossEvaluateVO crossEvaluate(CrossIdAndStartEndDateBO bo) throws DubboProviderException;
RunningEvaluateStatusVO congestionStatus(CrossIdAndStartEndDateBO bo); RunningEvaluateStatusVO congestionStatus(CrossIdAndStartEndDateBO bo);
......
...@@ -13,15 +13,18 @@ import net.wanji.opt.dao.mapper.GreenwaveHistoryMapper; ...@@ -13,15 +13,18 @@ import net.wanji.opt.dao.mapper.GreenwaveHistoryMapper;
import net.wanji.opt.entity.GreenwaveHist; import net.wanji.opt.entity.GreenwaveHist;
import net.wanji.opt.service.GreenwaveHistProvider; import net.wanji.opt.service.GreenwaveHistProvider;
import net.wanji.opt.vo.GreenWaveRunStateVO; import net.wanji.opt.vo.GreenWaveRunStateVO;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboService; import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator; import java.util.Comparator;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import java.util.Set; import java.util.Set;
import java.util.TreeMap; import java.util.TreeMap;
import java.util.TreeSet; import java.util.TreeSet;
...@@ -247,13 +250,19 @@ public class GreenwaveHistProviderImpl extends BaseDubboInterfaceImpl<GreenwaveH ...@@ -247,13 +250,19 @@ public class GreenwaveHistProviderImpl extends BaseDubboInterfaceImpl<GreenwaveH
} }
@Override @Override
public List<GreenWaveRunStateVO> findGreenWaveRunState(Integer greenId, String startTime, String endTime) { public List<GreenWaveRunStateVO> findGreenWaveRunState(Integer greenId,String crossId, String startTime, String endTime,String eventType) {
Map<String, Object> params = new HashMap<>(); Map<String, Object> params = new HashMap<>();
params.put("greenId", greenId); params.put("greenId", greenId);
params.put("startDate", startTime); params.put("startDate", startTime);
params.put("endDate", endTime); params.put("endDate", endTime);
params.put("crossId", crossId);
if (Objects.nonNull(eventType)) {
String[] arr = StringUtils.split(eventType, ",");
params.put("eventTypeList", Arrays.asList(arr));
}
int[] stateList = new int[]{1, 2, 3}; int[] stateList = new int[]{704,705};
List<GreenWaveRunStateVO> list = greenwaveHistoryMapper.findGreenWaveRunState(params); List<GreenWaveRunStateVO> list = greenwaveHistoryMapper.findGreenWaveRunState(params);
Map<Integer,GreenWaveRunStateVO> groupList = list.stream().collect(Collectors.toMap(o -> o.getState(), o -> o)); Map<Integer,GreenWaveRunStateVO> groupList = list.stream().collect(Collectors.toMap(o -> o.getState(), o -> o));
......
...@@ -8,6 +8,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; ...@@ -8,6 +8,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import net.wanji.common.enums.CrossStatusEnum; import net.wanji.common.enums.CrossStatusEnum;
import net.wanji.common.enums.TurnConvertEnum; import net.wanji.common.enums.TurnConvertEnum;
import net.wanji.common.framework.exception.DubboProviderException;
import net.wanji.common.utils.tool.CrossUtil; import net.wanji.common.utils.tool.CrossUtil;
import net.wanji.common.utils.tool.StringUtils; import net.wanji.common.utils.tool.StringUtils;
import net.wanji.common.utils.tool.TimeArrayUtil; import net.wanji.common.utils.tool.TimeArrayUtil;
...@@ -26,7 +27,9 @@ import net.wanji.databus.vo.RunningEvaluateCrossListVO; ...@@ -26,7 +27,9 @@ import net.wanji.databus.vo.RunningEvaluateCrossListVO;
import net.wanji.opt.bo.CrossNameBO; import net.wanji.opt.bo.CrossNameBO;
import net.wanji.opt.bo.MetricsDetailBO; import net.wanji.opt.bo.MetricsDetailBO;
import net.wanji.opt.common.KafkaConsumerUtil; import net.wanji.opt.common.KafkaConsumerUtil;
import net.wanji.opt.constant.EventAbnormalEnum;
import net.wanji.opt.dto.PhaseEmptyResult; import net.wanji.opt.dto.PhaseEmptyResult;
import net.wanji.opt.service.GreenwaveHistProvider;
import net.wanji.opt.service.RunningEvaluateService; import net.wanji.opt.service.RunningEvaluateService;
import net.wanji.opt.vo.*; import net.wanji.opt.vo.*;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
...@@ -34,6 +37,7 @@ import org.springframework.beans.factory.annotation.Qualifier; ...@@ -34,6 +37,7 @@ import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode; import java.math.RoundingMode;
import java.text.DecimalFormat; import java.text.DecimalFormat;
...@@ -75,6 +79,9 @@ public class RunningEvaluateServiceImpl implements RunningEvaluateService { ...@@ -75,6 +79,9 @@ public class RunningEvaluateServiceImpl implements RunningEvaluateService {
private final CrossTurnDataHistMapper crossTurnDataHistMapper; private final CrossTurnDataHistMapper crossTurnDataHistMapper;
private final CrossLaneDataHistMapper crossLaneDataHistMapper; private final CrossLaneDataHistMapper crossLaneDataHistMapper;
@Resource
private GreenwaveHistProvider greenwaveHistProvider;
SimpleDateFormat HOUR_SDF = new SimpleDateFormat("HH:mm"); SimpleDateFormat HOUR_SDF = new SimpleDateFormat("HH:mm");
SimpleDateFormat DAY_SDF = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat DAY_SDF = new SimpleDateFormat("yyyy-MM-dd");
...@@ -138,12 +145,18 @@ public class RunningEvaluateServiceImpl implements RunningEvaluateService { ...@@ -138,12 +145,18 @@ public class RunningEvaluateServiceImpl implements RunningEvaluateService {
} }
@Override @Override
public RunningEvaluateCrossEvaluateVO crossEvaluate(CrossIdAndStartEndDateBO bo) { public RunningEvaluateCrossEvaluateVO crossEvaluate(CrossIdAndStartEndDateBO bo) throws DubboProviderException {
RunningEvaluateCrossEvaluateVO vo = new RunningEvaluateCrossEvaluateVO(); RunningEvaluateCrossEvaluateVO vo = new RunningEvaluateCrossEvaluateVO();
String crossId = bo.getCrossId(); String crossId = bo.getCrossId();
List<CrossDataHistPO> crossDataHistPOList = buildCrossDataHistPOList(bo, crossId); List<CrossDataHistPO> crossDataHistPOList = buildCrossDataHistPOList(bo, crossId);
String startTime = net.wanji.common.utils.tool.DateUtil.formatDate(bo.getStartDate(),"yyyy-MM-dd HH:mm:ss");
String endTime = net.wanji.common.utils.tool.DateUtil.formatDate(bo.getEndDate(),"yyyy-MM-dd HH:mm:ss");
List<GreenWaveRunStateVO> runStateList = greenwaveHistProvider.findGreenWaveRunState(null,bo.getCrossId(), startTime,endTime ,"701,702,703");
Map<Integer,GreenWaveRunStateVO> groupList = runStateList.stream().collect(Collectors.toMap(o -> o.getState(), o -> o));
// 服务水平 // 服务水平
double sumA = crossDataHistPOList.stream() double sumA = crossDataHistPOList.stream()
.filter(po -> isInTimeRange(po.getBatchTime())) .filter(po -> isInTimeRange(po.getBatchTime()))
...@@ -160,63 +173,31 @@ public class RunningEvaluateServiceImpl implements RunningEvaluateService { ...@@ -160,63 +173,31 @@ public class RunningEvaluateServiceImpl implements RunningEvaluateService {
vo.setServiceLevel(serviceLevel); vo.setServiceLevel(serviceLevel);
List<CrossDataHistPO> congestionEventList = buildCongestionEvents(crossDataHistPOList); // 获取拥堵事件集合 // List<CrossDataHistPO> congestionEventList = buildCongestionEvents(crossDataHistPOList); // 获取拥堵事件集合
vo.setCongestionTimes(congestionEventList.size()); // vo.setCongestionTimes(congestionEventList.size());
int congestionSum = congestionEventList.stream() // int congestionSum = congestionEventList.stream()
.filter(Objects::nonNull) // .filter(Objects::nonNull)
.map(CrossDataHistPO::getDuration) // .map(CrossDataHistPO::getDuration)
.filter(Objects::nonNull) // .filter(Objects::nonNull)
.mapToInt(Integer::intValue) // .mapToInt(Integer::intValue)
.sum(); // .sum();
vo.setCongestionSum(congestionSum); // vo.setCongestionSum(congestionSum);
List<CrossDataHistPO> unbalanceEventList = buildUnbalanceEvents(crossDataHistPOList); // 获取失衡事件集合 vo.setUnbalanceTimes(groupList.get(EventAbnormalEnum.CROSS_UNBALANCE.getType()).getCount());
vo.setUnbalanceTimes(unbalanceEventList.size()); int unbalanceSum = groupList.get(EventAbnormalEnum.CROSS_UNBALANCE.getType()).getDuration();
int unbalanceSum = unbalanceEventList.stream()
.filter(Objects::nonNull)
.map(CrossDataHistPO::getDuration)
.filter(Objects::nonNull)
.mapToInt(Integer::intValue)
.sum();
vo.setUnbalanceSum(unbalanceSum); vo.setUnbalanceSum(unbalanceSum);
List<CrossDataHistPO> spilloverEventList = buildSpilloverEvents(crossDataHistPOList); // 获取溢出事件集合 vo.setSpilloverTimes(groupList.get(EventAbnormalEnum.CROSS_OVERFLOW.getType()).getCount());
vo.setSpilloverTimes(spilloverEventList.size()); int spilloverSum =groupList.get(EventAbnormalEnum.CROSS_OVERFLOW.getType()).getDuration();
int spilloverSum = spilloverEventList.stream()
.filter(Objects::nonNull)
.map(CrossDataHistPO::getDuration)
.filter(Objects::nonNull)
.mapToInt(Integer::intValue)
.sum();
vo.setSpilloverSum(spilloverSum); vo.setSpilloverSum(spilloverSum);
// 相位空放指标
Date startDate = bo.getStartDate();
Date endDate = bo.getEndDate(); int emptyPhaseCount = groupList.get(EventAbnormalEnum.CROSS_PHASE_EMPTY.getType()).getCount();
if (isZeros(endDate)) { int emptyPhaseSum = groupList.get(EventAbnormalEnum.CROSS_PHASE_EMPTY.getType()).getDuration();
endDate = DateUtil.offsetDay(endDate, 1); // 包含最后一天
}
long startTime = startDate.getTime();
long endTime = endDate.getTime();
KafkaConsumerUtil kafkaConsumerUtil = new KafkaConsumerUtil(bootstrapServers, "empty-phase-evaluate");
List<PhaseEmptyResult> phaseEmptyResults =
kafkaConsumerUtil.consumeEmptyPhaseForTimeRange(emptyPhaseTopic, 0, startTime, endTime);
int emptyPhaseCount = (int) phaseEmptyResults.stream()
.filter(result -> result != null && crossId.equals(result.getCrossId()))
.count();
int emptyPhaseSum = phaseEmptyResults.stream()
.filter(result -> result != null && crossId.equals(result.getCrossId()))
.map(PhaseEmptyResult::getDuration)
.filter(Objects::nonNull)
.mapToInt(Integer::intValue)
.sum();
vo.setEmptyPhaseTimes(emptyPhaseCount); vo.setEmptyPhaseTimes(emptyPhaseCount);
vo.setEmptyPhaseSum(emptyPhaseSum); vo.setEmptyPhaseSum(emptyPhaseSum);
Integer schemeProblems = calcSchemeProblems(
congestionEventList, unbalanceEventList, spilloverEventList, crossId); // 计算方案问题
vo.setSchemeProblems(schemeProblems);
return vo; return vo;
} }
......
...@@ -17,12 +17,15 @@ public class GreenWaveRunStateVO { ...@@ -17,12 +17,15 @@ public class GreenWaveRunStateVO {
@ApiModelProperty(value = "干线ID") @ApiModelProperty(value = "干线ID")
private Integer greenId; private Integer greenId;
@ApiModelProperty(value = "干线运行状态 1:畅通 2:缓行 3:拥堵") @ApiModelProperty(value = "干线运行状态 701相位空放 702路口失衡 703路口溢出 704路口死锁 705干线-缓行 706干线-拥堵")
private int state; private int state;
@ApiModelProperty(value = "状态持续时长,单位秒") @ApiModelProperty(value = "状态持续时长,单位秒")
private int duration; private int duration;
@ApiModelProperty(value = "状态发送次数")
private int count;
@ApiModelProperty(value = "分析时段总时长,单位秒") @ApiModelProperty(value = "分析时段总时长,单位秒")
private int totalTime; private int totalTime;
......
...@@ -173,12 +173,17 @@ ...@@ -173,12 +173,17 @@
</select> </select>
<!-- 查看干线拥堵运行状态 --> <!-- 查看干线拥堵运行状态 -->
<select id="findGreenWaveRunState" resultType="net.wanji.opt.vo.GreenWaveRunStateVO"> <select id="findGreenWaveRunState" resultType="net.wanji.opt.vo.GreenWaveRunStateVO">
select type as state, select type as state,count(*) count,
SUM(TIMESTAMPDIFF(SECOND,start_time, end_time)) duration, SUM(TIMESTAMPDIFF(SECOND,start_time, end_time)) duration,
TIMESTAMPDIFF(SECOND,#{startDate}, #{endDate}) total_time TIMESTAMPDIFF(SECOND,#{startDate}, #{endDate}) total_time
from t_event_info t from t_event_info t
where <!-- type in (705,706) and --> start_time > #{startDate} where start_time > #{startDate} and start_time &lt; #{endDate}
and start_time &lt; #{endDate} <if test="eventTypeList!=null and eventTypeList.size>0">
and t.type in
<foreach collection="eventTypeList" item="item" index="index" open="(" close=")" separator=",">
#{item}
</foreach>
</if>
GROUP BY type GROUP BY type
</select> </select>
......
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