Commit ca0a46e3 authored by zhoushiguang's avatar zhoushiguang

场景详细评价平均指标

parent b141f49a
......@@ -18,8 +18,8 @@ public class CrossLaneDataHistPoExtend {
@ApiModelProperty(name = "路口编号",notes = "")
private String crossId;
//车道ID
@ApiModelProperty(value = "车道ID", notes = "")
private String laneId;
@ApiModelProperty(value = "车道", notes = "")
private Integer laneNo;
//方向
@ApiModelProperty(value = "方向", notes = "")
private Integer dirType;
......
......@@ -53,6 +53,8 @@ import java.util.Random;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
......@@ -75,8 +77,7 @@ public class GreenwaveHistProviderImpl extends BaseDubboInterfaceImpl<GreenwaveH
private MainlineEvaluateService mainlineEvaluateService;
@Resource
BaseCrossInfoMapper baseCrossInfoMapper
;
BaseCrossInfoMapper baseCrossInfoMapper;
@Override
public BaseInterfaceMapper<GreenwaveHist> getBaseInterfaceMapper() {
......@@ -156,36 +157,36 @@ public class GreenwaveHistProviderImpl extends BaseDubboInterfaceImpl<GreenwaveH
params.put("endDate", endTime);
params.put("greenDir", greenDir);
List<Map<String,Object>> getList = greenwaveHistoryMapper.findUnCoordinateCrossIndex(params);
List<Map<String, Object>> getList = greenwaveHistoryMapper.findUnCoordinateCrossIndex(params);
List<GreenwaveCrossTrendPo> list = new ArrayList<>();
//存放时段
Set<String> sortedSet = new TreeSet<>();
for (Map<String,Object> map : getList) {
for (Map<String, Object> map : getList) {
GreenwaveCrossTrendPo po = new GreenwaveCrossTrendPo();
String crossNo = map.get("cross_id").toString();
String st = map.get("start_time").toString();
po.setCrossId(crossNo);
po.setStartTime(DateTime.parse(st,DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss")).toDate());
po.setStartTime(DateTime.parse(st, DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss")).toDate());
//提取时间
sortedSet.add(DateUtil.formatDate(po.getStartTime(), "HH:mm"));
String indexList = map.get("index_list").toString();
List<GreenwaveCrossTrendPo> finalList = new ArrayList<>();
Arrays.stream(indexList.split("@")).forEach(o->{
Arrays.stream(indexList.split("@")).forEach(o -> {
String[] sps = o.split(",");
String type = sps[0];
String queueLength = sps[1];
String stopTimes = sps[2];
String flow = sps[3];
if (Objects.equals("1",type)) {
if (Objects.equals("1", type)) {
//非协调方向
po.setFlow(new BigDecimal(flow));
po.setQueueLength(new BigDecimal(queueLength));
po.setStopTimes(new BigDecimal(stopTimes));
} else if (Objects.equals("2",type)){
} else if (Objects.equals("2", type)) {
//协调方向
po.setCordFlow(new BigDecimal(flow));
po.setCordQueueLength(new BigDecimal(queueLength));
......@@ -417,29 +418,26 @@ public class GreenwaveHistProviderImpl extends BaseDubboInterfaceImpl<GreenwaveH
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()));
Map<String, List<CrossLaneDataHistPoExtend>> groupByDir = list.stream().collect(Collectors.groupingBy(o -> o.getCrossId() + "_" + o.getLaneNo() + "_" + o.getDirType() + "_" + o.getTurnType(), TreeMap::new, Collectors.toList()));
Set<String> hasDataScopeList = new HashSet<>();
for (Map.Entry<String, List<CrossLaneDataHistPoExtend>> entry : groupByDir.entrySet()) {
String key = entry.getKey();
String[] sps = key.split("_");
String laneId = sps[1];
String laneNo = laneId.substring(laneId.length() - 2);
String laneNo = sps[1];
Integer dirType = null;
String dirName = null;
String turnDesc = null;
String dirTurnDesc = null;
Map<String, Object> mapList = new HashMap<>();
if (Objects.equals(4,objectType)){
if (Objects.equals(4, objectType)) {
TBaseCrossInfo tBaseCrossInfo = baseCrossInfoMapper.selectByPrimaryKey(sps[0]);
dirTurnDesc = tBaseCrossInfo.getName();
}else if (Objects.equals(3, objectType)) {
mapList.put("laneId", laneId);
} else if (Objects.equals(3, objectType)) {
mapList.put("laneNo", laneNo);
dirType = Integer.parseInt(sps[2]);
dirName = BaseEnum.SignalDirectionEnum.getNameByCode(dirType);
......@@ -462,7 +460,6 @@ 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);
......@@ -539,6 +536,7 @@ public class GreenwaveHistProviderImpl extends BaseDubboInterfaceImpl<GreenwaveH
Set<String> hasDataScopeList = new HashSet<>();
BottomMenuBO bo = new BottomMenuBO();
bo.setCrossId(crossId);
bo.setScope(objectType);
......@@ -551,40 +549,130 @@ public class GreenwaveHistProviderImpl extends BaseDubboInterfaceImpl<GreenwaveH
String cid = sps[0];
String dirType = sps[1];
String dirName = BaseEnum.SignalDirectionEnum.getNameByCode(Integer.valueOf(dirType));
String dirName = null;
if (!Objects.equals("null",dirType)) {
dirName = BaseEnum.SignalDirectionEnum.getNameByCode(Integer.valueOf(dirType));
}
String dirTurnDesc = dirName + "进口";
Map<String, Object> mapList = new HashMap<>();
List<CrossLaneDataHistPoExtend> value = entry.getValue().stream().sorted(Comparator.comparing(o->o.getTurnType())).collect(Collectors.toList());
value.forEach(o->{
if (Objects.equals(2,objectType) || Objects.equals(3,objectType)) {
List<CrossLaneDataHistPoExtend> value = entry.getValue().stream().sorted(Comparator.comparing(o -> o.getTurnType())).collect(Collectors.toList());
//========================路口级服务水平加权平均 start=================================================================//
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 key1 = entry1.getKey();
total += ServiceLevelEnum.getByType(key1).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);
}
//========================路口级服务水平加权平均 end=================================================================//
value.forEach(o -> {
o.setServiceLevel(serviceLevelBuf.toString());
o.setDirTypeName(dirTurnDesc);
if (Objects.equals(2, objectType)) {
o.setTurnTypeName(TurnConvertEnum.getDescByKey(o.getTurnType()));
hasDataScopeList.add(dirTurnDesc+o.getTurnTypeName());
hasDataScopeList.add(dirTurnDesc + o.getTurnTypeName());
} else if (Objects.equals(3, objectType)) {
o.setTurnTypeName(TurnConvertEnum.getDescByKey(o.getTurnType())+ o.getLaneNo() + "车道");
hasDataScopeList.add(dirTurnDesc + o.getTurnTypeName() + o.getLaneNo() + "车道");
} else {
hasDataScopeList.add(dirTurnDesc);
}
});
//===============补充某个方向有数据但是不完整的================================================================================//
if (Objects.nonNull(scopeList)) {
//补充
for (String scopeName1 : scopeList) {
if (!hasDataScopeList.contains(scopeName1) && scopeName1.contains(dirTurnDesc)) {
CrossLaneDataHistPoExtend tmp = new CrossLaneDataHistPoExtend();
tmp.setCrossId(cid);
tmp.setDirType(BaseEnum.SignalDirectionEnum.getCodeByName(scopeName1.substring(0,scopeName1.indexOf("进口"))));
tmp.setDirTypeName(dirTurnDesc);
tmp.setTurnTypeName(scopeName1.substring(dirTurnDesc.length()));
tmp.setTurnType(TurnConvertEnum.getKeyByDesc(tmp.getTurnTypeName()));
//利用正则表达式取车道号
if (Objects.equals(3, objectType)) {
Pattern pattern = Pattern.compile("\\d+");
Matcher matcher = pattern.matcher(scopeName1);
if (matcher.find()) {
Integer laneNo = Integer.valueOf(matcher.group());
tmp.setLaneNo(laneNo);
tmp.setTurnType(TurnConvertEnum.getKeyByDesc(tmp.getTurnTypeName().substring(0,tmp.getTurnTypeName().indexOf(laneNo.toString()))));
hasDataScopeList.add(tmp.getDirTypeName()+tmp.getTurnTypeName());
}
}
value.add(tmp);
}
}
}
value = value.stream().sorted(Comparator.comparing(o->o.getLaneId()+"_"+o.getTurnType())).collect(Collectors.toList());
//===============补充某个方向有数据但是不完整的================================================================================//
if (Objects.equals(2, objectType)) {
value = value.stream().sorted(Comparator.comparing(o -> o.getTurnType())).collect(Collectors.toList());
} else if (Objects.equals(3, objectType)) {
value = value.stream().sorted(Comparator.comparing(o -> o.getLaneNo())).collect(Collectors.toList());
}
mapList.put("scopeCode", key);
mapList.put("dirName", dirTurnDesc);
mapList.put("dirType", BaseEnum.SignalDirectionEnum.getCodeByName(dirTurnDesc.substring(0,dirTurnDesc.indexOf("进口"))));
mapList.put("list", value);
allList.add(mapList);
}
//====================补充方向上无任何车道数据====================================================================================//
if (Objects.nonNull(scopeList)) {
Map<Integer,List<CrossLaneDataHistPoExtend>> tmpListMap = new TreeMap<>();
for (String scopeName1 : scopeList) {
if (!hasDataScopeList.contains(scopeName1)) {
Pattern pattern = Pattern.compile("\\d+");
Matcher matcher = pattern.matcher(scopeName1);
String dirName = scopeName1.substring(0,scopeName1.indexOf("进口")+2);
String turnDesc = scopeName1.substring(dirName.length());
CrossLaneDataHistPoExtend tmp = new CrossLaneDataHistPoExtend();
tmp.setCrossId(crossId);
tmp.setDirType(BaseEnum.SignalDirectionEnum.getCodeByName(scopeName1.substring(0,scopeName1.indexOf("进口"))));
tmp.setDirTypeName(dirName);
tmp.setTurnTypeName(turnDesc);
if (matcher.find()) {
Integer laneNo = Integer.valueOf(matcher.group());
tmp.setTurnType(TurnConvertEnum.getKeyByDesc(tmp.getTurnTypeName().substring(0,tmp.getTurnTypeName().indexOf(laneNo.toString()))));
} else {
tmp.setTurnType(TurnConvertEnum.getKeyByDesc(tmp.getTurnTypeName()));
}
List<CrossLaneDataHistPoExtend> tmpList = tmpListMap.get(tmp.getDirType());
if (tmpList==null){
tmpList = new ArrayList<>();
}
tmpList.add(tmp);
tmpListMap.put(tmp.getDirType(),tmpList);
}
}
for (Map.Entry<Integer,List<CrossLaneDataHistPoExtend>> tmpEntry : tmpListMap.entrySet()) {
Map<String, Object> mapList = new HashMap<>();
String dirDesc = BaseEnum.SignalDirectionEnum.getNameByCode(tmpEntry.getKey());
mapList.put("scopeCode", null);
mapList.put("isLost", true);
mapList.put("dirName", dirDesc+"进口");
mapList.put("dirType", tmpEntry.getKey());
mapList.put("list", tmpEntry.getValue());
allList.add(mapList);
}
}
//=========================================================================================================================================================//
allList = allList.stream().sorted(Comparator.comparing(o->Integer.valueOf(o.get("dirType").toString()))).collect(Collectors.toList());
JSONObject jsonObject = new JSONObject();
jsonObject.put("timeList", sortedSet);
......@@ -612,16 +700,14 @@ public class GreenwaveHistProviderImpl extends BaseDubboInterfaceImpl<GreenwaveH
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()));
Map<String, List<CrossLaneDataHistPoExtend>> groupByDir = list.stream().collect(Collectors.groupingBy(o -> o.getCrossId() + "_" + o.getLaneNo() + "_" + o.getDirType() + "_" + o.getTurnType(), TreeMap::new, Collectors.toList()));
Set<String> scopeList = new TreeSet<>();
for (Map.Entry<String, List<CrossLaneDataHistPoExtend>> entry : groupByDir.entrySet()) {
String key = entry.getKey();
String[] sps = key.split("_");
String laneId = sps[1];
String laneNo = laneId.substring(laneId.length() - 2);
String laneNo = sps[1];
Integer dirType = Integer.parseInt(sps[2]);
String dirName = null;
String turnDesc = null;
......@@ -629,7 +715,6 @@ public class GreenwaveHistProviderImpl extends BaseDubboInterfaceImpl<GreenwaveH
Map<String, Object> mapList = new HashMap<>();
mapList.put("laneId", laneId);
mapList.put("laneNo", laneNo);
dirName = BaseEnum.SignalDirectionEnum.getNameByCode(dirType);
turnDesc = TurnConvertEnum.getDescByKey(Integer.valueOf(sps[3]));
......@@ -679,16 +764,14 @@ public class GreenwaveHistProviderImpl extends BaseDubboInterfaceImpl<GreenwaveH
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()));
Map<String, List<CrossLaneDataHistPoExtend>> groupByDir = list.stream().collect(Collectors.groupingBy(o -> o.getCrossId() + "_" + o.getLaneNo() + "_" + o.getDirType() + "_" + o.getTurnType(), TreeMap::new, Collectors.toList()));
Set<String> scopeList = new TreeSet<>();
for (Map.Entry<String, List<CrossLaneDataHistPoExtend>> entry : groupByDir.entrySet()) {
String key = entry.getKey();
String[] sps = key.split("_");
String laneId = sps[1];
String laneNo = laneId.substring(laneId.length() - 2);
String laneNo = sps[1];
Integer dirType = Integer.parseInt(sps[2]);
String dirName = null;
String turnDesc = null;
......@@ -696,7 +779,6 @@ public class GreenwaveHistProviderImpl extends BaseDubboInterfaceImpl<GreenwaveH
Map<String, Object> mapList = new HashMap<>();
mapList.put("laneId", laneId);
mapList.put("laneNo", laneNo);
if (objectType == 1) {
dirName = BaseEnum.SignalDirectionEnum.getNameByCode(dirType);
......@@ -711,6 +793,7 @@ 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);
......@@ -740,15 +823,15 @@ public class GreenwaveHistProviderImpl extends BaseDubboInterfaceImpl<GreenwaveH
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()));
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();
int avgService = (int) Math.round(total / value.size());
String avgServiceLevel = ServiceLevelEnum.getByVal(avgService) == null ? "A" : ServiceLevelEnum.getByVal(avgService).getType();
serviceLevelBuf.append(avgServiceLevel);
}
......@@ -782,7 +865,6 @@ public class GreenwaveHistProviderImpl extends BaseDubboInterfaceImpl<GreenwaveH
value = value.stream().sorted(Comparator.comparing(CrossLaneDataHistPoExtend::getStartTime)).collect(Collectors.toList());
//==========================================================================================================//
//时间轴
value.forEach(o -> {
......
......@@ -249,7 +249,7 @@
resultType="net.wanji.opt.po.base.CrossLaneDataHistPoExtend">
SELECT MIN(ifnull(t.unit_time,#{startDate})) start_time,
cross_id ,
lane_id ,
lane_no ,
dir_type ,
turn_type ,
SUM(flow) flow,
......@@ -278,7 +278,7 @@
<!-- 方向级 -->
<when test="objectType==1">
dir_type,
null as lane_id,
null as lane_no,
null as turn_type,
null as service_level,
</when>
......@@ -286,19 +286,19 @@
<when test="objectType==2">
t.in_dir+1 as dir_type,
t.turn_type,
null as lane_id,
null as lane_no,
null as service_level,
</when>
<!-- 车道级 -->
<when test="objectType==3">
t.id as lane_id,
t2.sort as lane_no,
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 lane_no,
null as dir_type,
null as turn_type,
ifnull(service_level,'A') service_level,
......@@ -352,7 +352,7 @@
</when>
<!-- 车道级 -->
<when test="objectType==3">
GROUP BY t.cross_id,t.lane_id,t.dir_type,t.turn_type,unit_time
GROUP BY t.cross_id,t.lane_no,t.dir_type,t.turn_type,unit_time
</when>
<!-- 路口级 -->
<when test="objectType==4">
......
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