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
}
int totalTime = Seconds.secondsBetween(startDateTime,endDateTime).getSeconds();
for (GreenWaveRunStateVO vo : list ) {
if (vo.getDuration()<=0) {
vo.setDuration(getRandomValue(totalTime / 10, 120));
}
// if (vo.getDuration()<=0) {
// vo.setDuration(getRandomValue(totalTime / 10, 120));
// }
vo.setTotalTime(totalTime);
}
......
......@@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import net.wanji.common.enums.CrossStatusEnum;
......@@ -23,11 +24,13 @@ import net.wanji.databus.po.BaseCrossInfoPO;
import net.wanji.databus.po.CrossDataHistPO;
import net.wanji.databus.po.CrossTurnInfoPO;
import net.wanji.databus.po.LaneInfoPO;
import net.wanji.databus.po.TBaseCrossInfo;
import net.wanji.databus.vo.RunningEvaluateCrossListVO;
import net.wanji.opt.bo.CrossNameBO;
import net.wanji.opt.bo.MetricsDetailBO;
import net.wanji.opt.common.KafkaConsumerUtil;
import net.wanji.opt.constant.EventAbnormalEnum;
import net.wanji.opt.constant.ServiceLevelEnum;
import net.wanji.opt.dto.PhaseEmptyResult;
import net.wanji.opt.service.GreenwaveHistProvider;
import net.wanji.opt.service.RunningEvaluateService;
......@@ -150,54 +153,44 @@ public class RunningEvaluateServiceImpl implements RunningEvaluateService {
String crossId = bo.getCrossId();
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 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();
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");
int sumB = crossDataHistPOList.stream()
.filter(po -> isInTimeRange(po.getBatchTime()))
.mapToInt(CrossDataHistPO::getFlow)
.sum();
//按服务水平分组
Map<String, List<CrossDataHistPO>> groupByServerLevel = crossDataHistPOList.stream().collect(Collectors.groupingBy(o -> o.getServiceLevel()));
double total = 0;
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);
// *******************************************************************************************************//
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.setCongestionTimes(congestionEventList.size());
// int congestionSum = congestionEventList.stream()
// .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());
int unbalanceSum = groupList.get(EventAbnormalEnum.CROSS_UNBALANCE.getType()) == null ? 0 : groupList.get(EventAbnormalEnum.CROSS_UNBALANCE.getType()).getDuration();
vo.setUnbalanceSum(Math.round(unbalanceSum/60));
vo.setUnbalanceTimes(groupList.get(EventAbnormalEnum.CROSS_UNBALANCE.getType())==null?0:groupList.get(EventAbnormalEnum.CROSS_UNBALANCE.getType()).getCount());
int unbalanceSum = groupList.get(EventAbnormalEnum.CROSS_UNBALANCE.getType())==null?0:groupList.get(EventAbnormalEnum.CROSS_UNBALANCE.getType()).getDuration();
vo.setUnbalanceSum(unbalanceSum);
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(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.setEmptyPhaseSum(emptyPhaseSum);
vo.setEmptyPhaseSum(Math.round(emptyPhaseSum/60));
// *******************************************************************************************************//
return vo;
}
......
......@@ -211,4 +211,8 @@ public class CrossDataRealtimePO {
@ApiModelProperty(value = "是否空放 0否 1是", notes = "")
@TableField("empty_pass")
private Integer emptyPass;
@ApiModelProperty(value = "服务水平[A-F]", notes = "")
@TableField("service_level")
private String serviceLevel;
}
......@@ -125,7 +125,7 @@
</select>
<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
<where>
<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