Commit 9b89cea1 authored by xululu@wanji.net.cn's avatar xululu@wanji.net.cn

程序优化

parent a1375a7f
......@@ -73,6 +73,11 @@ public class Constant {
*/
public static int CROSSING = 1;
/**
* 行人灯转向
*/
public static final String PEDESTRAIN_LIGHT_CODE = "20";
/**
* 入侵结果
*/
......
......@@ -468,13 +468,14 @@ public class CarTrajectoryIndexMain {
//计算溢出
SingleOutputStreamOperator<CarTrackModel> carTrackStreamInCrossRoad = frameModelStream.flatMap(new CarTrackInCrossRoadFlatMap())
SingleOutputStreamOperator<CarTrackModel> carTrackStreamInCrossRoad = frameModelStream
.flatMap(new CarTrackInCrossRoadFlatMap())
.setParallelism(1)
.name("过滤出位于路口和指定路段区域带有车牌的车辆轨迹数据");
//计算1分钟内的路口溢出指数和是否死锁
double avgSpeedEvaluationIndex = Double.parseDouble(properties.getProperty("road.overflow.avg.speed"));
String durationEvaluationIndex = properties.getProperty("road.overflow.duration");
int durationEvaluationIndex = Integer.parseInt(properties.getProperty("road.overflow.duration"));
int carNumber = Integer.parseInt(properties.getProperty("cross.road.deadlock.car.number"));
double crossAvgSpeedIndex = Double.parseDouble(properties.getProperty("cross.road.deadlock.avg.speed"));
......@@ -492,7 +493,7 @@ public class CarTrajectoryIndexMain {
//过滤出位于指定区域内的数据
List<CarTrackModel> carTracesInSpecificArea = carInCrossRoadList.stream().filter(car -> car.getIsInSpecificArea() == 1).collect(Collectors.toList());
List<CarTrackModel> carTracesInCrossRoad = carInCrossRoadList.stream().filter(car -> car.getRoadnet().getInCrossFlag() == 1).collect(Collectors.toList());
//根据路口进行预取划分
//根据路口进行区域划分
Map<String, List<CarTrackModel>> groupMapInExitArea = carTracesInSpecificArea.stream().collect(Collectors.groupingBy(car -> car.getRoadnet().getRid()));
//对每个路口区域进行统计
......@@ -513,6 +514,7 @@ public class CarTrajectoryIndexMain {
map.put(timestamp, avgSpeed);
});
//出口车道的平均速度
double ridAvgSpeed = map.values().stream().mapToDouble(number -> number).summaryStatistics().getAverage();
List<Map.Entry<Long, Double>> entryList = map.entrySet().stream().sorted(Map.Entry.comparingByKey()).collect(Collectors.toList());
......@@ -528,7 +530,7 @@ public class CarTrajectoryIndexMain {
consecutiveSeconds = 0;
}
}
if(consecutiveSeconds > Integer.parseInt(durationEvaluationIndex)){
if(consecutiveSeconds > durationEvaluationIndex){
//计算路口的溢出指数
double index = 30 / ridAvgSpeed;
if(index > 5){
......@@ -537,7 +539,7 @@ public class CarTrajectoryIndexMain {
detail.setRid(rid);
detail.setTimestamp(overflowTimestamp);
detail.setDatetime(DateUtil.toDateTime(overflowTimestamp, DateUtil.YYYY_MM_DD_HH_MM_SS));
detail.setIndex(index);
detail.setIndex(Double.parseDouble(String.format("%.2f", index)));
details.add(detail);
}
......@@ -550,6 +552,7 @@ public class CarTrajectoryIndexMain {
OverFlowIndexResult result = new OverFlowIndexResult();
result.setCrossId(crossId);
result.setDetails(details);
//溢出上报时间戳
result.setGlobalTimeStamp(context.window().getEnd());
result.setDateTime(DateUtil.toDateTime(result.getGlobalTimeStamp(), DateUtil.YYYY_MM_DD_HH_MM_SS));
result.setStartTime(context.window().getStart());
......@@ -559,13 +562,7 @@ public class CarTrajectoryIndexMain {
if(details.size() >= 2){
Map<String, List<CarTrackModel>> groupMapByPlate = carTracesInCrossRoad.stream().collect(Collectors.groupingBy(CarTrackModel::getPicLicense));
if(groupMapByPlate.size() > carNumber){
AtomicReference<Double> totalCarSpeed = new AtomicReference<>((double) 0);
groupMapByPlate.forEach((carPlate, traces) -> {
double carAvgSpeed = traces.stream().mapToDouble(CarTrackModel::getSpeed).summaryStatistics().getAverage();
totalCarSpeed.updateAndGet(v -> (v + carAvgSpeed));
});
double crossAvgSpeed = totalCarSpeed.get() / groupMapByPlate.size();
double crossAvgSpeed = carTracesInCrossRoad.stream().mapToDouble(CarTrackModel::getSpeed).summaryStatistics().getAverage();
if(crossAvgSpeed < crossAvgSpeedIndex){
result.setDeadLock(true);
}
......
package com.wanji.indicators.task.trajectory;
import java.util.UUID;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/**
* @author : jenny
......@@ -10,7 +12,11 @@ import java.util.UUID;
*/
public class Test2 {
public static void main(String[] args) {
String eventSerialNumber = UUID.randomUUID().toString().replace("-","");
System.out.println(eventSerialNumber);
List<String> list = new ArrayList<>();
List<String> filteredList = list.stream()
.filter(element -> element.length() > 4)
.collect(Collectors.toList());
System.out.println(filteredList.size());
}
}
......@@ -55,6 +55,7 @@ public class VehicleGapTimeProcessFunction extends KeyedProcessFunction<String,
ridLightStatusList.stream()
.filter(o -> Objects.nonNull(o) && !StringUtils.isEmpty(o.getLampState()) && o.getLampState().trim().equals(LightStatusEnum.GREEN.getType()))
.filter(o -> o.getDir() == 1 || o.getDir() == 4 || o.getDir() == 5)//南北方向
.filter(o -> !o.getTurn().equals(Constant.PEDESTRAIN_LIGHT_CODE))//非行人灯
.collect(Collectors.groupingBy(CrossRidTurnLampStatusModel::getDir));
//存储当前南北方向绿灯结束的路口和绿灯时长
......@@ -64,7 +65,7 @@ public class VehicleGapTimeProcessFunction extends KeyedProcessFunction<String,
for(String key: keys){
String[] split = key.trim().split("-");
int dir = Integer.parseInt(split[1]);
if(groupLightStatus.containsKey(dir)){
if(!groupLightStatus.containsKey(dir)){
expiredGreenLightMap.put(dir, greenTotalTimeState.get(key));
}
}
......@@ -140,7 +141,7 @@ public class VehicleGapTimeProcessFunction extends KeyedProcessFunction<String,
VehicleHeadTimeModel timeModel = new VehicleHeadTimeModel();
timeModel.setLaneId(laneId);
timeModel.setCrossId(lastCar.getRoadnet().getCrossId());
timeModel.setCrossId(crossId);
timeModel.setRid(lastCar.getRoadnet().getRid());
timeModel.setDir(dir);
timeModel.setHeadTime(time);
......
......@@ -56,7 +56,7 @@ north.south.rid.direction.list=13NG40B5SK013NI00B5RM00:1,13NEH0B5RJ013NGH0B5RC00
#路口溢出评价指标
road.overflow.avg.speed=5.0
road.overflow.duration=3
road.overflow.duration=3000
road.overflow.deadlock.index.analysis.topic=crossroad.overflow.deadlock.index.analysis
#路口失衡topic
......
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