Commit 7b89ffc9 authored by zhoushiguang's avatar zhoushiguang

场景事件路口级指标

parent 86d4190e
......@@ -239,10 +239,10 @@ public class GreenwaveHistRestServer {
@ApiOperation(httpMethod="GET",value="路口进口【方向级、转向级、车道级】->分粒度指标趋势", notes="")
@ApiImplicitParams({
@ApiImplicitParam(name = "crossId", value = "路口ID", required = true, dataType = "String",defaultValue = "13MOD0B5SI0"),
@ApiImplicitParam(name = "groupType", value = "时间粒度类型 0:5分钟粒度 1:15分钟粒度 2:30分钟粒度 3:小时粒度 4:天粒度", required = true, dataType = "Integer",defaultValue = "1"),
@ApiImplicitParam(name = "groupType", value = "时间粒度类型 0:5分钟粒度 1:15分钟粒度 2:30分钟粒度 3:小时粒度 4:天粒度 5:按时间范围直接做平均【不分粒度】", required = true, dataType = "Integer",defaultValue = "1"),
@ApiImplicitParam(name = "startTime", value = "截止时间,格式:yyyy-MM-dd HH:mm:ss", required = true, dataType = "String",defaultValue = "2024-12-04 00:00:00"),
@ApiImplicitParam(name = "endTime", value = "截止时间,格式:yyyy-MM-dd HH:mm:ss", required = true, dataType = "String",defaultValue = "2024-12-04 23:59:59"),
@ApiImplicitParam(name = "objectType", value = "统计对象类型 1:方向级指标 2:转向级指标 3:车道级指标", required = true, dataType = "Integer",defaultValue = "1"),
@ApiImplicitParam(name = "objectType", value = "统计对象类型 1:方向级指标 2:转向级指标 3:车道级指标 4:路口级指标", required = true, dataType = "Integer",defaultValue = "1"),
})
@ApiResponses({
@ApiResponse(code = 200, message = "成功", response = CrossLaneDataHistPoExtend.class,
......
......@@ -50,6 +50,9 @@ public class CrossLaneDataHistPoExtend {
@ApiModelProperty(value = "饱和度",notes = "")
private Double sturation;
@ApiModelProperty(value = "服务水平",notes = "")
private String serviceLevel;
@ApiModelProperty(value = "开始时间:yyyy-MM-dd HH:mm:ss", notes = "")
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
......
......@@ -49,6 +49,9 @@ public class EventInfoSimplePo implements Serializable {
@ApiModelProperty(value = "事件持续时长,单位秒")
private Integer duration;
@ApiModelProperty(value = "事件发生次数")
private Integer count=1;
@ApiModelProperty(value = "横轴时间轴start", notes = "")
private String timeAxisStart;
......
......@@ -190,6 +190,7 @@ public class EventServiceImpl implements EventService {
po.setStartTime(agoStartTime);
po.setEndTime(currentEndTime);
po.setTimeAxisStart(tmp.getTimeAxisStart());
po.setCount(po.getCount()+1);
//清理合并前的记录
tmpList.remove(tmp);
}
......
......@@ -17,6 +17,7 @@ import net.wanji.databus.po.CrossTurnInfoPO;
import net.wanji.opt.bo.BottomMenuBO;
import net.wanji.opt.common.EsDateIndexUtil;
import net.wanji.opt.common.enums.TimeGranularityEnum;
import net.wanji.opt.constant.ServiceLevelEnum;
import net.wanji.opt.dao.mapper.GreenwaveHistoryMapper;
import net.wanji.opt.entity.GreenwaveHist;
import net.wanji.opt.po.base.CrossLaneDataHistPoExtend;
......@@ -389,6 +390,9 @@ public class GreenwaveHistProviderImpl extends BaseDubboInterfaceImpl<GreenwaveH
List<Map<String, Object>> allList = new ArrayList<>();
List<CrossLaneDataHistPoExtend> list = greenwaveHistoryMapper.findGreenWaveCrossLaneIndex(params);
list = list.stream().sorted(Comparator.comparing(o -> o.getStartTime())).collect(Collectors.toList());
//按时间分组分组
Map<String, List<CrossLaneDataHistPoExtend>> groupByDir = list.stream().collect(Collectors.groupingBy(o -> o.getCrossId() + "_" + o.getLaneId() + "_" + o.getDirType() + "_" + o.getTurnType(), TreeMap::new, Collectors.toList()));
......@@ -400,7 +404,7 @@ public class GreenwaveHistProviderImpl extends BaseDubboInterfaceImpl<GreenwaveH
String[] sps = key.split("_");
String laneId = sps[1];
String laneNo = laneId.substring(laneId.length() - 2);
Integer dirType = Integer.parseInt(sps[2]);
Integer dirType = null;
String dirName = null;
String turnDesc = null;
String dirTurnDesc = null;
......@@ -410,15 +414,17 @@ public class GreenwaveHistProviderImpl extends BaseDubboInterfaceImpl<GreenwaveH
if (Objects.equals(3, objectType)) {
mapList.put("laneId", laneId);
mapList.put("laneNo", laneNo);
dirType = Integer.parseInt(sps[2]);
dirName = BaseEnum.SignalDirectionEnum.getNameByCode(dirType);
turnDesc = TurnConvertEnum.getDescByKey(Integer.valueOf(sps[3]));
dirTurnDesc = dirName + "进口" + turnDesc + laneNo + "车道";
} else if (Objects.equals(2, objectType)) {
dirType = Integer.parseInt(sps[2]);
dirName = BaseEnum.SignalDirectionEnum.getNameByCode(dirType);
turnDesc = TurnConvertEnum.getDescByKey(Integer.valueOf(sps[3]));
dirTurnDesc = dirName + "进口" + turnDesc;
} else if (Objects.equals(1, objectType)) {
dirType = Integer.parseInt(sps[2]);
dirName = BaseEnum.SignalDirectionEnum.getNameByCode(dirType);
dirTurnDesc = dirName + "进口";
}
......@@ -428,6 +434,8 @@ public class GreenwaveHistProviderImpl extends BaseDubboInterfaceImpl<GreenwaveH
//补充缺少时段数据,保留时段字段默认值
List<CrossLaneDataHistPoExtend> value = this.processData(entry, groupType, sortedSet, startTime);
mapList.put("scopeCode", key);
mapList.put("scopeName", dirTurnDesc);
mapList.put("list", value);
......@@ -439,34 +447,36 @@ public class GreenwaveHistProviderImpl extends BaseDubboInterfaceImpl<GreenwaveH
bo.setScope(objectType);
List<String> scopeList = mainlineEvaluateService.bottomMenu(bo);
//补充一条时段都没有的
for (String scopeName1 : scopeList) {
if (!hasDataScopeList.contains(scopeName1)) {
Map<String, Object> mapList = new HashMap<>();
mapList.put("scopeCode", "");
mapList.put("scopeName", scopeName1);
List<CrossLaneDataHistPoExtend> tmpList = new ArrayList<>();
//补充所有时段字段对象
for (String time : sortedSet) {
CrossLaneDataHistPoExtend po = new CrossLaneDataHistPoExtend();
try {
if (Objects.equals("4", groupType)) {
//天粒度
String st = time + "000000";
po.setStartTime(DateUtil.parse(st, "yyyyMMddHHmmss"));
} else {
String st = startTime.substring(0, startTime.lastIndexOf(" ") + 1) + time + ":00";
po.setStartTime(DateUtil.parse(st, "yyyy-MM-dd HH:mm:ss"));
if (Objects.nonNull(scopeList)) {
//补充一条时段都没有的
for (String scopeName1 : scopeList) {
if (!hasDataScopeList.contains(scopeName1)) {
Map<String, Object> mapList = new HashMap<>();
mapList.put("scopeCode", "");
mapList.put("scopeName", scopeName1);
List<CrossLaneDataHistPoExtend> tmpList = new ArrayList<>();
//补充所有时段字段对象
for (String time : sortedSet) {
CrossLaneDataHistPoExtend po = new CrossLaneDataHistPoExtend();
try {
if (Objects.equals("4", groupType)) {
//天粒度
String st = time + "000000";
po.setStartTime(DateUtil.parse(st, "yyyyMMddHHmmss"));
} else {
String st = startTime.substring(0, startTime.lastIndexOf(" ") + 1) + time + ":00";
po.setStartTime(DateUtil.parse(st, "yyyy-MM-dd HH:mm:ss"));
}
} catch (ParseException e) {
e.printStackTrace();
}
} catch (ParseException e) {
e.printStackTrace();
tmpList.add(po);
po.setTimeAxis(time);
}
tmpList.add(po);
po.setTimeAxis(time);
mapList.put("list", tmpList);
allList.add(mapList);
}
mapList.put("list", tmpList);
allList.add(mapList);
}
}
......@@ -620,6 +630,23 @@ public class GreenwaveHistProviderImpl extends BaseDubboInterfaceImpl<GreenwaveH
private List<CrossLaneDataHistPoExtend> processData(Map.Entry<String, List<CrossLaneDataHistPoExtend>> entry, String groupType, Set<String> sortedSet, String startTime) {
//按方向排序
List<CrossLaneDataHistPoExtend> value = entry.getValue().stream().sorted(Comparator.comparing(o -> o.getStartTime())).collect(Collectors.toList());
//========================路口级服务水平加权平均=================================================================//
String serviceLevelList = value.get(0).getServiceLevel();
StringBuilder serviceLevelBuf = new StringBuilder();
if (serviceLevelList != null) {
Map<String,Long> serviceGroup = Arrays.stream(serviceLevelList.split(",")).collect(Collectors.groupingBy(String::valueOf,Collectors.counting()));
double total = 0;
for (Map.Entry<String, Long> entry1 : serviceGroup.entrySet()) {
String key = entry1.getKey();
total += ServiceLevelEnum.getByType(key).getVal() * entry1.getValue();
}
//服务水平加权平均计算:给服务水平(等级得分*该等级的数量)累加/总数量
int avgService = (int) Math.round(total/value.size());
String avgServiceLevel = ServiceLevelEnum.getByVal(avgService)==null?"A":ServiceLevelEnum.getByVal(avgService).getType();
serviceLevelBuf.append(avgServiceLevel);
}
//有实际数据的时刻点
Set<String> timeList = new HashSet<>();
if (Objects.equals("4", groupType)) {
......@@ -647,6 +674,10 @@ public class GreenwaveHistProviderImpl extends BaseDubboInterfaceImpl<GreenwaveH
}
}
value = value.stream().sorted(Comparator.comparing(CrossLaneDataHistPoExtend::getStartTime)).collect(Collectors.toList());
//==========================================================================================================//
//时间轴
value.forEach(o -> {
if (Objects.equals("4", groupType)) {
......@@ -656,6 +687,7 @@ public class GreenwaveHistProviderImpl extends BaseDubboInterfaceImpl<GreenwaveH
} else {
o.setTimeAxis(DateUtil.formatDate(o.getStartTime(), EsDateIndexUtil.HM_FORMATTER));
}
o.setServiceLevel(serviceLevelBuf.toString());
});
return value;
......
......@@ -168,6 +168,7 @@ public class RunningEvaluateServiceImpl implements RunningEvaluateService {
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)==null?"A":ServiceLevelEnum.getByVal(avgService).getType();
......
......@@ -244,7 +244,8 @@
round(AVG(queue_length)) avg_queue_length,
round(AVG(stop_times),2) stop_times,
round(AVG(delay_time),2) delay_time,
round(AVG(sturation),4) sturation
round(AVG(sturation),4) sturation,
group_concat(service_level) service_level
FROM
(
SELECT start_time,
......@@ -264,18 +265,28 @@
dir_type,
null as lane_id,
null as turn_type,
null as service_level,
</when>
<!-- 转向级 -->
<when test="objectType==2">
t.in_dir as dir_type,
t.turn_type,
null as lane_id,
null as service_level,
</when>
<!-- 车道级 -->
<when test="objectType==3">
t.id as lane_id,
t2.dir as dir_type,
t2.turn as turn_type,
null as service_level,
</when>
<!-- 路口级 -->
<when test="objectType==4">
null as lane_id,
null as dir_type,
null as turn_type,
ifnull(service_level,'A') service_level,
</when>
<otherwise>
</otherwise>
......@@ -300,6 +311,10 @@
FROM t_lane_data_hist t join t_base_lane_info t2 on t.id=t2.id
</when>
<!-- 路口级 -->
<when test="objectType==4">
FROM t_cross_data_hist t
</when>
<otherwise>
</otherwise>
</choose>
......@@ -324,6 +339,10 @@
<when test="objectType==3">
GROUP BY t.cross_id,t.lane_id,t.dir_type,t.turn_type,unit_time
</when>
<!-- 路口级 -->
<when test="objectType==4">
GROUP BY t.cross_id,unit_time
</when>
<otherwise>
</otherwise>
</choose>
......
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