| | |
| | | * 车辆抓拍数据准确性 |
| | | */ |
| | | public static final String Car_DataAccuracy = "carDataAccuracy"; |
| | | |
| | | /** |
| | | * 车辆时钟准确性 |
| | | */ |
| | | public static final String Car_ClockAccuracy = "carClockAccuracy"; |
| | | |
| | | /** |
| | | * 人脸数据上传及时性 |
| | |
| | | * 车辆信息采集正确率 |
| | | */ |
| | | private CheckIndexCar createOrUpdateCheckIndexCar(String key, AreaStats stats, List<CheckIndexCar> checkIndexCarList) { |
| | | CheckIndexCar checkIndexCar = getCheckIndex(key, checkIndexCarList); |
| | | CheckIndexCar checkIndexCar = getCheckIndex(key, checkIndexCarList, CheckIndexCar.class); |
| | | //调用计算方法 |
| | | Map<String, Object> param = new HashMap<>(); |
| | | param.put("totalSites", stats.totalSites); |
New file |
| | |
| | | package com.ycl.calculate; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.ycl.platform.domain.entity.CheckIndexCar; |
| | | import com.ycl.platform.domain.entity.TMonitor; |
| | | import com.ycl.platform.domain.result.HK.SnapshotDataMonitorResult; |
| | | import com.ycl.platform.domain.result.HK.VehicleDeviceInspectionResult; |
| | | import com.ycl.platform.mapper.CheckIndexCarMapper; |
| | | import com.ycl.platform.service.ICheckIndexCarService; |
| | | import com.ycl.platform.service.ITMonitorService; |
| | | import com.ycl.system.mapper.SysConfigMapper; |
| | | import constant.ApiConstants; |
| | | import constant.CheckSnapCountConstants; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.util.CollectionUtils; |
| | | import utils.DateUtils; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.time.LocalDate; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.function.Function; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * 计算车辆时钟准确性 |
| | | * 获取分省厅、区域的map<k,v> k为deptId或者Province_deptId |
| | | * 循环map计算时钟准确性 |
| | | * 更新或新增 |
| | | */ |
| | | @Component |
| | | public class CarClockAccuracyCalculation extends IndexCalculationServe implements CalculationStrategy<VehicleDeviceInspectionResult> { |
| | | @Autowired |
| | | private CheckIndexCarMapper checkIndexCarMapper; |
| | | @Autowired |
| | | private ITMonitorService monitorService; |
| | | @Autowired |
| | | private ICheckIndexCarService checkIndexCarService; |
| | | |
| | | //区域车辆时钟准确性的内部类 |
| | | private static class AreaStats { |
| | | int totalSites = 0; |
| | | int accuracySites = 0; |
| | | } |
| | | |
| | | @Override |
| | | public void calculate(List<VehicleDeviceInspectionResult> list) { |
| | | if (CollectionUtils.isEmpty(list)) { |
| | | return; |
| | | } |
| | | |
| | | //获得国标码为key的设备map |
| | | Map<String, TMonitor> monitorMap = monitorService.list(new QueryWrapper<TMonitor>() |
| | | .in("serial_number", list.stream().map(VehicleDeviceInspectionResult::getExternalIndexCode).collect(Collectors.toList()))) |
| | | .stream().collect(Collectors.toMap(TMonitor::getSerialNumber, Function.identity())); |
| | | //获取省厅国标码集合 |
| | | List<String> provinceIds = getProvince(); |
| | | |
| | | Map<String, AreaStats> areaStatsMap = new HashMap<>(); |
| | | for (VehicleDeviceInspectionResult result : list) { |
| | | TMonitor monitor = monitorMap.get(result.getExternalIndexCode()); |
| | | if (monitor == null) continue; |
| | | |
| | | String deptId = monitor.getDeptId().toString(); |
| | | updateAreaStats(areaStatsMap, deptId, result); |
| | | |
| | | // 处理省厅数据 |
| | | if (!CollectionUtils.isEmpty(provinceIds) && provinceIds.contains(monitor.getSerialNumber())) { |
| | | String provinceKey = "Province_" + deptId; |
| | | updateAreaStats(areaStatsMap, provinceKey, result); |
| | | } |
| | | } |
| | | |
| | | // 查询是否index表已经存在今日数据 |
| | | List<CheckIndexCar> checkIndexCarList = checkIndexCarMapper.selectToday(DateUtils.getDate()); |
| | | List<CheckIndexCar> checkIndexCars = new ArrayList<>(); |
| | | areaStatsMap.forEach((deptId, stats) -> { |
| | | if (stats.totalSites > 0) { |
| | | CheckIndexCar checkIndexCar = createOrUpdateCheckIndexCar(deptId, stats, checkIndexCarList); |
| | | checkIndexCars.add(checkIndexCar); |
| | | } |
| | | }); |
| | | |
| | | checkIndexCarService.saveOrUpdateBatch(checkIndexCars); |
| | | } |
| | | |
| | | /** |
| | | * 累计时钟合格设备 |
| | | */ |
| | | private void updateAreaStats(Map<String, AreaStats> areaStatsMap, String key, VehicleDeviceInspectionResult result) { |
| | | //返回对象的引用,如果不存在会放入新的key,value |
| | | AreaStats stats = areaStatsMap.computeIfAbsent(key, k -> new AreaStats()); |
| | | stats.totalSites++; |
| | | //时钟准确率大于90%为合格设备 |
| | | if (result.getSnapClock().getClockPercent() >= 0.9) { |
| | | stats.accuracySites++; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 车辆时钟准确性 |
| | | */ |
| | | private CheckIndexCar createOrUpdateCheckIndexCar(String key, AreaStats stats, List<CheckIndexCar> checkIndexCarList) { |
| | | CheckIndexCar checkIndexCar = getCheckIndex(key, checkIndexCarList, CheckIndexCar.class); |
| | | //调用时钟准确性计算方法 |
| | | Map<String, Object> siteOnlineParam = new HashMap<>(); |
| | | siteOnlineParam.put("totalSites", stats.totalSites); |
| | | siteOnlineParam.put("accuracySites", stats.accuracySites); |
| | | BigDecimal clockAccuracy = clockAccuracy(siteOnlineParam); |
| | | checkIndexCar.setVehicleTimingAccuracy(clockAccuracy); |
| | | return checkIndexCar; |
| | | } |
| | | } |
| | |
| | | AreaStats stats = areaStatsMap.computeIfAbsent(key, k -> new AreaStats()); |
| | | stats.totalSites++; |
| | | //90%及以上数据合格则此车辆卡口设备被视为抓拍数据完整 |
| | | if(result.getMainNoIntegrityPercent() <= 0.1){ |
| | | if (result.getMainNoIntegrityPercent() <= 0.1) { |
| | | stats.integritySites++; |
| | | } |
| | | //重点点位为六项属性 |
| | | if(importantIds.contains(key)){ |
| | | if (importantIds.contains(key)) { |
| | | stats.importantTotalSites++; |
| | | if(result.getNoIntegrityPercent() <= 0.1){ |
| | | if (result.getNoIntegrityPercent() <= 0.1) { |
| | | stats.importantIntegritySites++; |
| | | } |
| | | } |
| | |
| | | * 车辆信息采集正确率 |
| | | */ |
| | | private CheckIndexCar createOrUpdateCheckIndexCar(String key, AreaStats stats, List<CheckIndexCar> checkIndexCarList) { |
| | | CheckIndexCar checkIndexCar = getCheckIndex(key, checkIndexCarList); |
| | | CheckIndexCar checkIndexCar = getCheckIndex(key, checkIndexCarList, CheckIndexCar.class); |
| | | //调用计算方法 |
| | | Map<String, Object> param = new HashMap<>(); |
| | | param.put("totalSites", stats.totalSites); |
| | |
| | | * 车辆信息采集正确率 |
| | | */ |
| | | private CheckIndexCar createOrUpdateCheckIndexCar(String key, AreaStats stats, List<CheckIndexCar> checkIndexCarList) { |
| | | CheckIndexCar checkIndexCar = getCheckIndex(key, checkIndexCarList); |
| | | CheckIndexCar checkIndexCar = getCheckIndex(key, checkIndexCarList, CheckIndexCar.class); |
| | | //调用计算方法 |
| | | Map<String, Object> param = new HashMap<>(); |
| | | param.put("totalSites", stats.totalSites); |
| | |
| | | checkIndexCarService.saveOrUpdateBatch(checkIndexCars); |
| | | } |
| | | |
| | | /** 累计总点位数、离线数、总抓拍量 */ |
| | | /** |
| | | * 累计总点位数、离线数、总抓拍量 |
| | | */ |
| | | private void updateAreaStats(Map<String, AreaStats> areaStatsMap, String key, SnapshotDataMonitorResult result) { |
| | | //返回对象的引用,如果不存在会放入新的key,value |
| | | AreaStats stats = areaStatsMap.computeIfAbsent(key, k -> new AreaStats()); |
| | |
| | | } |
| | | } |
| | | |
| | | /** 获取2022同期抓拍平均值 */ |
| | | /** |
| | | * 获取2022同期抓拍平均值 |
| | | */ |
| | | private BigDecimal getAverageCount(String configKey) { |
| | | String count = sysConfigMapper.checkConfigKeyUnique(configKey).getConfigValue(); |
| | | return new BigDecimal(count) |
| | |
| | | .divide(new BigDecimal(LocalDate.now().getDayOfMonth()), 0, RoundingMode.HALF_UP); |
| | | } |
| | | |
| | | /** 车辆点位在线率和视图库对接稳定性 */ |
| | | /** |
| | | * 车辆点位在线率和视图库对接稳定性 |
| | | */ |
| | | private CheckIndexCar createOrUpdateCheckIndexCar(String key, AreaStats stats, BigDecimal cityCountAvg, BigDecimal countyCountAvg, List<CheckIndexCar> checkIndexCarList) { |
| | | CheckIndexCar checkIndexCar = getCheckIndex(key, checkIndexCarList); |
| | | CheckIndexCar checkIndexCar = getCheckIndex(key, checkIndexCarList, CheckIndexCar.class); |
| | | //调用点位在线计算方法 |
| | | Map<String, Object> siteOnlineParam = new HashMap<>(); |
| | | siteOnlineParam.put("totalSites", stats.totalSites); |
| | |
| | | * 车辆点位在线率和视图库对接稳定性 |
| | | */ |
| | | private CheckIndexCar createOrUpdateCheckIndexCar(String key, AreaStats stats, List<CheckIndexCar> checkIndexCarList) { |
| | | CheckIndexCar checkIndexCar = getCheckIndex(key, checkIndexCarList); |
| | | CheckIndexCar checkIndexCar = getCheckIndex(key, checkIndexCarList, CheckIndexCar.class); |
| | | //调用抓拍上传及时性计算方法 |
| | | Map<String, Object> param = new HashMap<>(); |
| | | param.put("totalCount", stats.totalCount); |
| | |
| | | package com.ycl.calculate; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.ycl.platform.domain.entity.CheckIndexCar; |
| | | import com.ycl.platform.domain.entity.CheckIndexFace; |
| | | import com.ycl.platform.domain.entity.TMonitor; |
| | | import com.ycl.platform.domain.result.HK.MonitoringDetailResult; |
| | |
| | | * 车辆信息采集正确率 |
| | | */ |
| | | private CheckIndexFace createOrUpdateCheckIndexFace(String key, AreaStats stats, List<CheckIndexFace> checkIndexFaceList) { |
| | | CheckIndexFace checkIndexFace = getCheckIndex(key, checkIndexFaceList); |
| | | CheckIndexFace checkIndexFace = getCheckIndex(key, checkIndexFaceList, CheckIndexFace.class); |
| | | //调用计算方法 |
| | | Map<String, Object> param = new HashMap<>(); |
| | | param.put("totalSites", stats.totalSites); |
| | |
| | | |
| | | //车辆点位在线率和视图库对接稳定性 |
| | | private CheckIndexFace createOrUpdateCheckIndexFace(String key, AreaStats stats, BigDecimal cityCountAvg, BigDecimal countyCountAvg, List<CheckIndexFace> checkIndexFaceList) { |
| | | CheckIndexFace checkIndexFace = getCheckIndex(key, checkIndexFaceList); |
| | | CheckIndexFace checkIndexFace = getCheckIndex(key, checkIndexFaceList, CheckIndexFace.class); |
| | | //调用点位在线计算方法 |
| | | Map<String, Object> siteOnlineParam = new HashMap<>(); |
| | | siteOnlineParam.put("totalSites", stats.totalSites); |
| | |
| | | * 车辆点位在线率和视图库对接稳定性 |
| | | */ |
| | | private CheckIndexFace createOrUpdateCheckIndexFace(String key, AreaStats stats, List<CheckIndexFace> checkIndexFaceList) { |
| | | CheckIndexFace checkIndexFace = getCheckIndex(key, checkIndexFaceList); |
| | | CheckIndexFace checkIndexFace = getCheckIndex(key, checkIndexFaceList, CheckIndexFace.class); |
| | | //调用抓拍上传及时性计算方法 |
| | | Map<String, Object> param = new HashMap<>(); |
| | | param.put("totalCount", stats.totalCount); |
| | |
| | | } |
| | | |
| | | //车辆数据完整性 |
| | | public BigDecimal dataIntegrity(Map<String, Object> param){ |
| | | public BigDecimal dataIntegrity(Map<String, Object> param) { |
| | | BigDecimal totalSites = new BigDecimal((Integer) param.get("totalSites")); |
| | | BigDecimal importantTotalSites = new BigDecimal((Integer) param.get("importantTotalSites")); |
| | | BigDecimal integritySites = new BigDecimal((Integer) param.get("integritySites")); |
| | |
| | | } |
| | | |
| | | //车辆数据完整性 |
| | | public BigDecimal dataAccuracy(Map<String, Object> param){ |
| | | public BigDecimal dataAccuracy(Map<String, Object> param) { |
| | | BigDecimal totalSites = new BigDecimal((Integer) param.get("totalSites")); |
| | | BigDecimal importantTotalSites = new BigDecimal((Integer) param.get("importantTotalSites")); |
| | | BigDecimal accuracySites = new BigDecimal((Integer) param.get("accuracySites")); |
| | |
| | | .add(importantAccuracySites.divide(importantTotalSites, 10, RoundingMode.HALF_UP)); |
| | | return result.setScale(4, RoundingMode.HALF_UP); |
| | | } |
| | | |
| | | //时钟准确性 |
| | | public BigDecimal clockAccuracy(Map<String, Object> param) { |
| | | BigDecimal totalSitesCount = new BigDecimal((Integer) param.get("totalSites")); |
| | | BigDecimal accuracySites = new BigDecimal((Integer) param.get("accuracySites")); |
| | | return accuracySites.divide(totalSitesCount, 4, RoundingMode.HALF_UP); |
| | | } |
| | | |
| | | //返回省厅国标码集合 |
| | | public List<String> getProvince() { |
| | | // TODO: 分省厅市局 需要补充集合数据 |
| | |
| | | } |
| | | |
| | | //检查是否存在当日数据 |
| | | public <T extends CheckIndex> T getCheckIndex(String key, List<T> checkIndexList) { |
| | | public <T extends CheckIndex> T getCheckIndex(String key, List<T> checkIndexList, Class<T> clazz) { |
| | | T checkIndex; |
| | | |
| | | // 检查是否已存在今日数据 |
| | |
| | | checkIndex = existingIndex.get(); |
| | | } else { |
| | | try { |
| | | checkIndex = (T) CheckIndexCar.class.getDeclaredConstructor().newInstance(); |
| | | checkIndex = clazz.getDeclaredConstructor().newInstance(); |
| | | checkIndex.setDeptId(key.startsWith("Province_") ? Long.parseLong(key.split("_")[1]) : Long.parseLong(key)); |
| | | checkIndex.setExamineTag(key.startsWith("Province_") ? CheckConstants.Examine_Tag_City : CheckConstants.Examine_Tag_County); |
| | | checkIndex.setCreateTime(new Date()); |
| | |
| | | calculators.put(CalculationStrategyConstants.Car_DataIntegrity,new CarDataIntegrityCalculation()); |
| | | //车辆数据抓拍准确性 |
| | | calculators.put(CalculationStrategyConstants.Car_DataAccuracy,new CarAttrRecognitionCalculation()); |
| | | //车辆时钟准确性 |
| | | calculators.put(CalculationStrategyConstants.Car_ClockAccuracy,new CarClockAccuracyCalculation()); |
| | | } |
| | | |
| | | public static CalculationStrategy getCalculator(String indexName) { |
| | |
| | | CalculationStrategy calculator = IndexCalculationFactory.getCalculator(CalculationStrategyConstants.Car_DataIntegrity); |
| | | calculator.calculate(results); |
| | | } |
| | | |
| | | public void CarClockAccuracyTask(){ |
| | | Date yesterday = DateUtils.addDays(new Date(), -1); |
| | | //计算车辆卡口设备时钟准确性 |
| | | Query query = new Query(); |
| | | query.addCriteria(Criteria |
| | | .where("mongoCreateTime").gte(DateUtils.getDayStart(yesterday)).lt(DateUtils.getDayEnd(yesterday))); |
| | | List<VehicleDeviceInspectionResult> results = mongoTemplate.find(query, VehicleDeviceInspectionResult.class); |
| | | CalculationStrategy calculator = IndexCalculationFactory.getCalculator(CalculationStrategyConstants.Car_ClockAccuracy); |
| | | calculator.calculate(results); |
| | | } |
| | | } |