Java 代码实现车辆伴随关系分析
/**
- 根据统计条件中的开始结束日期查出过车记录集合
*/
List
vehicleList = getVehicleList(startDate, endDate);
/**
- 按照gcsj升序排序 */ Collections.sort(vehicleList, Comparator.comparing(AnalysisJudgmentVehiceFollowVO::getGcsj));
/**
- 新集合,用于保存伴随车辆信息
*/
List
followCarList = new ArrayList<>();
/**
-
遍历过车记录集合,查询每一辆车的可能伴随车辆 */ for(int i=0; i<vehicleList.size(); i++) { AnalysisJudgmentVehiceFollowVO vehicleA = vehicleList.get(i); for(int j=i+1; j<vehicleList.size(); j++) { AnalysisJudgmentVehiceFollowVO vehicleB = vehicleList.get(j);
/** * Rule 1: A车与B车号牌号码号牌种类相同则不计算。 */ if(vehicleA.getHpzl().equals(vehicleB.getHpzl()) && vehicleA.getHphm().equals(vehicleB.getHphm())) { continue; } /** * Rule 2: A车与B车的过车记录都经过了卡口1,卡口2,卡口3,卡口4。且A车与B车经过每个相同卡口的gcsj间隔<=X。 */ int bscs = 0; // 经过相同卡口次数 int bscTime = 0; // 伴随时间,单位为分钟 List<String> sbidList = new ArrayList<>(); // 经过相同卡口的设备集合 for(String sbid : sbidArray) { // sbidArray为卡口集合 /** * 查询A车在当前卡口的过车记录 */ AnalysisJudgmentVehiceFollowVO vehicleARecord = getVehicleRecordBySbid(vehicleA, sbid); if(vehicleARecord == null) { break; // A车未经过当前卡口,跳出循环 } /** * 查询B车在当前卡口的过车记录 */ AnalysisJudgmentVehiceFollowVO vehicleBRecord = getVehicleRecordBySbid(vehicleB, sbid); if(vehicleBRecord == null) { break; // B车未经过当前卡口,跳出循环 } /** * 计算A车与B车经过当前卡口的gcsj间隔 */ int gcsjInterval = getGcsjInterval(vehicleARecord.getGcsj(), vehicleBRecord.getGcsj()); if(gcsjInterval > X) { // gcsj间隔超过X,跳出循环 break; } /** * 经过相同卡口次数+1 */ bscs++; /** * 更新伴随时间和设备集合 */ if(bscs == 1) { bscTime = getBscTime(vehicleARecord.getGcsj(), vehicleBRecord.getGcsj()); sbidList.add(sbid); } else { bscTime += getBscTime(vehicleARecord.getGcsj(), vehicleBRecord.getGcsj()); sbidList.add(sbid); } } /** * 判断是否为伴随车辆 */ if(bscs >= Y) { /** * 将A车与B车保存到新对象中 */ AnalysisJudgmentFollowCarVO followCar = new AnalysisJudgmentFollowCarVO(); followCar.setHpzl(vehicleA.getHpzl()); followCar.setHphm(vehicleA.getHphm()); followCar.setBscHpzl(vehicleB.getHpzl()); followCar.setBscHphm(vehicleB.getHphm()); followCar.setBssj(String.valueOf(bscTime)); followCar.setSbidList(sbidList); /** * 添加到新集合中 */ followCarList.add(followCar); }} }
/**
- 返回新集合 */ return followCarList;
原文地址: https://www.cveoy.top/t/topic/n1qe 著作权归作者所有。请勿转载和采集!