package com.ycl.calculate;
|
|
import com.ycl.platform.domain.entity.CheckIndexFace;
|
import com.ycl.platform.domain.result.UY.MonitorQualifyResult;
|
import com.ycl.platform.mapper.CheckIndexFaceMapper;
|
import com.ycl.platform.service.ICheckIndexFaceService;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Component;
|
import utils.DateUtils;
|
|
import java.math.BigDecimal;
|
import java.util.ArrayList;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
/**
|
* 计算人脸目录一致率
|
* 获取分省厅、区域的map<k,v> k为deptId或者Province_deptId
|
* 更新或新增
|
*/
|
@Component
|
@Slf4j
|
public class FaceConsistentCalculation extends IndexCalculationServe<MonitorQualifyResult, FaceConsistentCalculation.AreaStats> implements CalculationStrategy<MonitorQualifyResult> {
|
@Autowired
|
private CheckIndexFaceMapper checkIndexFaceMapper;
|
@Autowired
|
private ICheckIndexFaceService checkIndexFaceService;
|
|
//区域车辆信息采集准确率的内部类
|
protected static class AreaStats {
|
int totalSites = 0;
|
int newSites = 0;
|
}
|
|
@Override
|
public void calculate(List<MonitorQualifyResult> list) {
|
//获取分区域的指标数量
|
Map<String, FaceConsistentCalculation.AreaStats> areaStatsMap = getAreaStatsMap(list);
|
if (areaStatsMap == null) return;
|
|
// 查询是否index表已经存在今日数据
|
List<CheckIndexFace> checkIndexFaceList = checkIndexFaceMapper.selectToday(DateUtils.getDate());
|
List<CheckIndexFace> checkIndexFaces = new ArrayList<>();
|
areaStatsMap.forEach((deptId, stats) -> {
|
if (stats.totalSites > 0) {
|
CheckIndexFace checkIndexFace = createOrUpdateCheckIndexFace(deptId, stats, checkIndexFaceList);
|
if (checkIndexFace != null) {
|
checkIndexFaces.add(checkIndexFace);
|
}
|
}
|
});
|
|
checkIndexFaceService.saveOrUpdateBatch(checkIndexFaces);
|
}
|
|
/**
|
* 累计人脸目录一致率
|
*/
|
@Override
|
public void updateAreaStats(Map<String, AreaStats> areaStatsMap, String key, MonitorQualifyResult result) {
|
//返回对象的引用,如果不存在会放入新的key,value
|
AreaStats stats = areaStatsMap.computeIfAbsent(key, k -> new AreaStats());
|
stats.totalSites++;
|
if(result.getNewDevice()!=null && result.getNewDevice()){
|
stats.newSites++;
|
}
|
}
|
|
/**
|
* 人脸信息采集正确率
|
*/
|
private CheckIndexFace createOrUpdateCheckIndexFace(String key, AreaStats stats, List<CheckIndexFace> checkIndexFaceList) {
|
CheckIndexFace checkIndexFace = getCheckIndex(key, checkIndexFaceList, CheckIndexFace.class);
|
if (checkIndexFace == null) {
|
return null;
|
}
|
//调用目录一致率计算方法
|
Map<String, Object> param = new HashMap<>();
|
param.put("totalSites", stats.totalSites);
|
param.put("newSites", stats.newSites);
|
BigDecimal directoryConstant = directoryConstant(param);
|
checkIndexFace.setDeviceDirectoryConsistent(directoryConstant);
|
return checkIndexFace;
|
}
|
|
|
}
|