Commit eee551f9 authored by zhoushiguang's avatar zhoushiguang

路口服务水平加权计算

parent 2dbbce32
package net.wanji.opt.constant;
/**
* @ClassName ServiceLevelEnum
* @Description
* @Date 2021/4/15 11:13
* @Version 1.0
*/
public enum ServiceLevelEnum {
CROSS_PHASE_EMPTY("A",1 ),
CROSS_UNBALANCE("B",2 ),
CROSS_OVERFLOW("C",3 ),
CROSS_DEADLOCK("D",4 ),
GREEN_WAVE_SLOW_RUN("E",5 ),
GREEN_WAVE_CONGEST("F",6 ),
;
String type;
Integer val;
ServiceLevelEnum(String type, Integer val ) {
this.type = type;
this.val = val;
}
public String getType(){
return type;
}
public Integer getVal() {
return val;
}
public static ServiceLevelEnum getByType(String type){
for (ServiceLevelEnum abnormalEnum : ServiceLevelEnum.values()) {
if(abnormalEnum.getType().equals(type)){
return abnormalEnum;
}
}
return null;
}
public static ServiceLevelEnum getByVal(Integer type){
for (ServiceLevelEnum abnormalEnum : ServiceLevelEnum.values()) {
if(abnormalEnum.getVal().equals(type)){
return abnormalEnum;
}
}
return null;
}
}
...@@ -288,9 +288,9 @@ public class GreenwaveHistProviderImpl extends BaseDubboInterfaceImpl<GreenwaveH ...@@ -288,9 +288,9 @@ public class GreenwaveHistProviderImpl extends BaseDubboInterfaceImpl<GreenwaveH
} }
int totalTime = Seconds.secondsBetween(startDateTime,endDateTime).getSeconds(); int totalTime = Seconds.secondsBetween(startDateTime,endDateTime).getSeconds();
for (GreenWaveRunStateVO vo : list ) { for (GreenWaveRunStateVO vo : list ) {
if (vo.getDuration()<=0) { // if (vo.getDuration()<=0) {
vo.setDuration(getRandomValue(totalTime / 10, 120)); // vo.setDuration(getRandomValue(totalTime / 10, 120));
} // }
vo.setTotalTime(totalTime); vo.setTotalTime(totalTime);
} }
......
...@@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollectionUtil; ...@@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateTime; import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fasterxml.jackson.databind.ObjectMapper; 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;
...@@ -23,11 +24,13 @@ import net.wanji.databus.po.BaseCrossInfoPO; ...@@ -23,11 +24,13 @@ import net.wanji.databus.po.BaseCrossInfoPO;
import net.wanji.databus.po.CrossDataHistPO; import net.wanji.databus.po.CrossDataHistPO;
import net.wanji.databus.po.CrossTurnInfoPO; import net.wanji.databus.po.CrossTurnInfoPO;
import net.wanji.databus.po.LaneInfoPO; import net.wanji.databus.po.LaneInfoPO;
import net.wanji.databus.po.TBaseCrossInfo;
import net.wanji.databus.vo.RunningEvaluateCrossListVO; 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.constant.EventAbnormalEnum;
import net.wanji.opt.constant.ServiceLevelEnum;
import net.wanji.opt.dto.PhaseEmptyResult; import net.wanji.opt.dto.PhaseEmptyResult;
import net.wanji.opt.service.GreenwaveHistProvider; import net.wanji.opt.service.GreenwaveHistProvider;
import net.wanji.opt.service.RunningEvaluateService; import net.wanji.opt.service.RunningEvaluateService;
...@@ -150,54 +153,44 @@ public class RunningEvaluateServiceImpl implements RunningEvaluateService { ...@@ -150,54 +153,44 @@ public class RunningEvaluateServiceImpl implements RunningEvaluateService {
String crossId = bo.getCrossId(); String crossId = bo.getCrossId();
List<CrossDataHistPO> crossDataHistPOList = buildCrossDataHistPOList(bo, crossId); List<CrossDataHistPO> crossDataHistPOList = buildCrossDataHistPOList(bo, crossId);
for (CrossDataHistPO po : crossDataHistPOList) {
//历史未存服务水平字段数据置为A,否则分组报异常
po.setServiceLevel(po.getServiceLevel()==null?"A":po.getServiceLevel());
}
String startTime = net.wanji.common.utils.tool.DateUtil.formatDate(bo.getStartDate(),"yyyy-MM-dd HH:mm:ss"); 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"); 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()
.filter(po -> isInTimeRange(po.getBatchTime()))
.mapToDouble(po -> po.getFlow() * po.getSturation())
.sum();
int sumB = crossDataHistPOList.stream() //按服务水平分组
.filter(po -> isInTimeRange(po.getBatchTime())) Map<String, List<CrossDataHistPO>> groupByServerLevel = crossDataHistPOList.stream().collect(Collectors.groupingBy(o -> o.getServiceLevel()));
.mapToInt(CrossDataHistPO::getFlow) double total = 0;
.sum(); for (Map.Entry<String, List<CrossDataHistPO>> entry1 : groupByServerLevel.entrySet()) {
String key = entry1.getKey();
total += ServiceLevelEnum.getByType(key).getVal() * entry1.getValue().size();
}
int avgService = (int) Math.round(total/crossDataHistPOList.size());
String serviceLevel = ServiceLevelEnum.getByVal(avgService).getType();
double saturation = sumA / sumB;
String serviceLevel = CrossUtil.getServiceLevel(saturation);
vo.setServiceLevel(serviceLevel); vo.setServiceLevel(serviceLevel);
// *******************************************************************************************************//
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));
// List<CrossDataHistPO> congestionEventList = buildCongestionEvents(crossDataHistPOList); // 获取拥堵事件集合 vo.setUnbalanceTimes(groupList.get(EventAbnormalEnum.CROSS_UNBALANCE.getType()) == null ? 0 : groupList.get(EventAbnormalEnum.CROSS_UNBALANCE.getType()).getCount());
// vo.setCongestionTimes(congestionEventList.size()); int unbalanceSum = groupList.get(EventAbnormalEnum.CROSS_UNBALANCE.getType()) == null ? 0 : groupList.get(EventAbnormalEnum.CROSS_UNBALANCE.getType()).getDuration();
// int congestionSum = congestionEventList.stream() vo.setUnbalanceSum(Math.round(unbalanceSum/60));
// .filter(Objects::nonNull)
// .map(CrossDataHistPO::getDuration)
// .filter(Objects::nonNull)
// .mapToInt(Integer::intValue)
// .sum();
// vo.setCongestionSum(congestionSum);
vo.setUnbalanceTimes(groupList.get(EventAbnormalEnum.CROSS_UNBALANCE.getType())==null?0:groupList.get(EventAbnormalEnum.CROSS_UNBALANCE.getType()).getCount()); vo.setSpilloverTimes(groupList.get(EventAbnormalEnum.CROSS_OVERFLOW.getType()) == null ? 0 : groupList.get(EventAbnormalEnum.CROSS_OVERFLOW.getType()).getCount());
int unbalanceSum = groupList.get(EventAbnormalEnum.CROSS_UNBALANCE.getType())==null?0:groupList.get(EventAbnormalEnum.CROSS_UNBALANCE.getType()).getDuration(); int spilloverSum = groupList.get(EventAbnormalEnum.CROSS_OVERFLOW.getType()) == null ? 0 : groupList.get(EventAbnormalEnum.CROSS_OVERFLOW.getType()).getDuration();
vo.setUnbalanceSum(unbalanceSum); vo.setSpilloverSum(Math.round(spilloverSum/60));
vo.setSpilloverTimes(groupList.get(EventAbnormalEnum.CROSS_OVERFLOW.getType())==null?0:groupList.get(EventAbnormalEnum.CROSS_OVERFLOW.getType()).getCount());
int spilloverSum =groupList.get(EventAbnormalEnum.CROSS_OVERFLOW.getType())==null?0:groupList.get(EventAbnormalEnum.CROSS_OVERFLOW.getType()).getDuration();
vo.setSpilloverSum(spilloverSum);
int emptyPhaseCount = groupList.get(EventAbnormalEnum.CROSS_PHASE_EMPTY.getType()) == null ? 0 : groupList.get(EventAbnormalEnum.CROSS_PHASE_EMPTY.getType()).getCount();
int emptyPhaseSum = groupList.get(EventAbnormalEnum.CROSS_PHASE_EMPTY.getType()) == null ? 0 : groupList.get(EventAbnormalEnum.CROSS_PHASE_EMPTY.getType()).getDuration();
int emptyPhaseCount = groupList.get(EventAbnormalEnum.CROSS_PHASE_EMPTY.getType())==null?0:groupList.get(EventAbnormalEnum.CROSS_PHASE_EMPTY.getType()).getCount();
int emptyPhaseSum = groupList.get(EventAbnormalEnum.CROSS_PHASE_EMPTY.getType())==null?0:groupList.get(EventAbnormalEnum.CROSS_PHASE_EMPTY.getType()).getDuration();
vo.setEmptyPhaseTimes(emptyPhaseCount); vo.setEmptyPhaseTimes(emptyPhaseCount);
vo.setEmptyPhaseSum(emptyPhaseSum); vo.setEmptyPhaseSum(Math.round(emptyPhaseSum/60));
// *******************************************************************************************************//
return vo; return vo;
} }
......
...@@ -211,4 +211,8 @@ public class CrossDataRealtimePO { ...@@ -211,4 +211,8 @@ public class CrossDataRealtimePO {
@ApiModelProperty(value = "是否空放 0否 1是", notes = "") @ApiModelProperty(value = "是否空放 0否 1是", notes = "")
@TableField("empty_pass") @TableField("empty_pass")
private Integer emptyPass; private Integer emptyPass;
@ApiModelProperty(value = "服务水平[A-F]", notes = "")
@TableField("service_level")
private String serviceLevel;
} }
...@@ -125,7 +125,7 @@ ...@@ -125,7 +125,7 @@
</select> </select>
<select id="selectByCrossName" resultType="net.wanji.databus.vo.RunningEvaluateCrossListVO"> <select id="selectByCrossName" resultType="net.wanji.databus.vo.RunningEvaluateCrossListVO">
select t1.cross_id as crossId, t1.sturation as sturation, t2.name as crossName, t1.congestion_index select t1.cross_id as crossId, t1.sturation as sturation, t2.name as crossName, t1.traffic_index congestionIndex, t1.service_level serviceLevel
from t_cross_data_realtime t1 join t_base_cross_info t2 on t1.cross_id = t2.id and t2.is_signal = 1 from t_cross_data_realtime t1 join t_base_cross_info t2 on t1.cross_id = t2.id and t2.is_signal = 1
<where> <where>
<if test="crossName != null and crossName != ''"> <if test="crossName != null and crossName != ''">
......
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