Commit 9060a6a9 authored by yangyang's avatar yangyang

智慧分析 - 健康等级

parent 11a40a1d
......@@ -16,6 +16,8 @@ import java.util.List;
*/
public interface IFanHealthIndexService {
List<FanHealthIndex> getInfoListByGroupByCdFan(String startTime, String tableName, String analysisObjectType);
List<FanHealthIndex> getInfoListByGroupByZxtFan(String startTime, String tableName, String analysisObjectType);
/**
......
......@@ -17,6 +17,10 @@ import java.util.List;
*/
public interface IPvHealthIndexService {
List<PvHealthIndex> getInfoListByGroupByCdPv(String startTime,
String tableName,
String analysisObjectType);
/**
* 设备加权平均
......
......@@ -36,6 +36,52 @@ public class FanHealthIndexServiceImpl implements IFanHealthIndexService {
@Autowired
private IdxBizFanWeightMapper idxBizFanWeightMapper;
@Override
public List<FanHealthIndex> getInfoListByGroupByCdFan(String startTime, String tableName, String analysisObjectType) {
List<FanHealthIndex> fanHealthIndicesZxt = fanHealthIndexMapper.getInfoList(startTime, tableName, analysisObjectType);
QueryWrapper<IdxBizFanWeight> idxBizFanWeightQueryWrapper = new QueryWrapper<>();
idxBizFanWeightQueryWrapper.eq("type", "5");
idxBizFanWeightQueryWrapper.isNotNull("value");
List<IdxBizFanWeight> idxBizFanWeights = idxBizFanWeightMapper.selectList(idxBizFanWeightQueryWrapper);
Map<String, Float> weightMap = idxBizFanWeights.stream().collect(Collectors.toMap(o -> o.getArae() + o.getStation() + o.getEquipmentName() + o.getSubarray() + o.getPointName(), IdxBizFanWeight::getValue));
// 开始计算加权平均
Map<String, List<FanHealthIndex>> fanHealthIndicesZxtMap = fanHealthIndicesZxt.stream().collect(Collectors.groupingBy(o -> o.getGatewayId() + o.getStation() + o.getAnalysisObjType() + o.getArea() + o.getSubSystem() + o.getEquipmentName() + o.getNumber() + o.getOrgCode()));
List<FanHealthIndex> fanHealthIndicesZxtNews = new ArrayList<>();
fanHealthIndicesZxtMap.forEach((k, v) -> {
FanHealthIndex fanHealthIndex = new FanHealthIndex();
fanHealthIndex.setIndexAddress(v.get(0).getIndexAddress());
fanHealthIndex.setGatewayId(v.get(0).getGatewayId());
fanHealthIndex.setStation(v.get(0).getStation());
fanHealthIndex.setAnalysisObjType("测点");
fanHealthIndex.setAnalysisObjSeq(v.get(0).getAnalysisObjSeq());
fanHealthIndex.setWeight(v.get(0).getWeight());
fanHealthIndex.setArea(v.get(0).getArea());
fanHealthIndex.setSubSystem(v.get(0).getSubSystem());
fanHealthIndex.setNumber(v.get(0).getNumber());
fanHealthIndex.setEquipmentName(v.get(0).getEquipmentName());
fanHealthIndex.setPointName(v.get(0).getPointName());
fanHealthIndex.setKks(v.get(0).getNumber());
fanHealthIndex.setOrgCode(v.get(0).getOrgCode());
// 例如 子系统 = (测点1 * 测点1权重 + 测点2 * 测点2权重 + .... 测点n权重) / (测点1权重 + 测点2权重 + .... 测点n权重)
// 但是测点是没有权重的,所以子系统无法计算加权平均
// 设备 = (子系统1 * 子系统1权重 + 子系统2 * 子系统2权重 + .... 子系统n权重) / (子系统1权重 + 子系统2权重 + .... 子系统n权重)
// 但如果没有配置子系统的权重,如何计算?
try {
// 加权平均
Double totalHealthIndex = v.stream().mapToDouble(o -> getWeight(() -> o.getArea() + o.getStation() + o.getEquipmentName() + o.getSubSystem() + o.getPointName(), weightMap) * o.getHealthIndex()).sum();
Double totalAnomaly = v.stream().mapToDouble(o -> getWeight(() -> o.getArea() + o.getStation() + o.getEquipmentName() + o.getSubSystem() + o.getPointName(), weightMap) * o.getAnomaly()).sum();
Double totalWeight = v.stream().mapToDouble(o -> getWeight(() -> o.getArea() + o.getStation() + o.getEquipmentName() + o.getSubSystem() + o.getPointName(), weightMap)).sum();
fanHealthIndex.setAnomaly(totalAnomaly / totalWeight);
fanHealthIndex.setHealthIndex(totalHealthIndex / totalWeight);
} catch (Exception e) {
// 普通平均
this.calculateAvg(fanHealthIndex, v);
}
fanHealthIndicesZxtNews.add(fanHealthIndex);
});
return fanHealthIndicesZxtNews;
}
/**
* 子系统加权平均
* 加权平均数 = (w1 * x1 + w2 * x2 + … + wn * xn) / (w1 + w2 + … + wn)
......
......@@ -37,6 +37,53 @@ public class PvHealthIndexServiceImpl implements IPvHealthIndexService {
@Autowired
private IdxBizPvWeightMapper idxBizPvWeightMapper;
@Override
public List<PvHealthIndex> getInfoListByGroupByCdPv(String startTime, String tableName, String analysisObjectType) {
List<PvHealthIndex> pvHealthIndices = pvHealthIndexMapper.getInfoList(startTime, tableName, analysisObjectType);
QueryWrapper<IdxBizPvWeight> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("type", "5");
queryWrapper.isNotNull("value");
List<IdxBizPvWeight> idxBizFanWeights = idxBizPvWeightMapper.selectList(queryWrapper);
Map<String, Float> weightMap = idxBizFanWeights.stream().collect(Collectors.toMap(o -> o.getArae() + o.getStation() + o.getEquipmentName() + o.getSubarray() + o.getPointName(), IdxBizPvWeight::getValue));
// 开始计算加权平均
Map<String, List<PvHealthIndex>> healthIndicesMap = pvHealthIndices.stream().collect(Collectors.groupingBy(o -> o.getGatewayId() + o.getIndexAddress() + o.getStation() + o.getAnalysisObjType() + o.getAnalysisObjSeq() + o.getWeight() + o.getArea() + o.getSubarray() + o.getManufacturer() + o.getEquipmentName() + o.getPointName() + o.getDeviceType() + o.getKks() + o.getOrgCode()));
List<PvHealthIndex> pvHealthIndexList = new ArrayList<>();
healthIndicesMap.forEach((k, v) -> {
PvHealthIndex pvHealthIndex = new PvHealthIndex();
pvHealthIndex.setIndexAddress(v.get(0).getIndexAddress());
pvHealthIndex.setGatewayId(v.get(0).getGatewayId());
pvHealthIndex.setStation(v.get(0).getStation());
pvHealthIndex.setAnalysisObjType("测点");
pvHealthIndex.setAnalysisObjSeq(v.get(0).getAnalysisObjSeq());
pvHealthIndex.setWeight(v.get(0).getWeight());
pvHealthIndex.setArea(v.get(0).getArea());
pvHealthIndex.setSubarray(v.get(0).getSubarray());
pvHealthIndex.setManufacturer(v.get(0).getManufacturer());
pvHealthIndex.setEquipmentName(v.get(0).getEquipmentName());
pvHealthIndex.setPointName(v.get(0).getPointName());
pvHealthIndex.setDeviceType(v.get(0).getDeviceType());
pvHealthIndex.setKks(v.get(0).getKks());
pvHealthIndex.setOrgCode(v.get(0).getOrgCode());
// 例如 子系统 = (测点1 * 测点1权重 + 测点2 * 测点2权重 + .... 测点n权重) / (测点1权重 + 测点2权重 + .... 测点n权重)
// 但是测点是没有权重的,所以子系统无法计算加权平均
// 设备 = (子系统1 * 子系统1权重 + 子系统2 * 子系统2权重 + .... 子系统n权重) / (子系统1权重 + 子系统2权重 + .... 子系统n权重)
// 但如果没有配置子系统的权重,如何计算?
try {
// 加权平均
Double totalHealthIndex = v.stream().mapToDouble(o -> getWeight(() -> o.getArea() + o.getStation() + o.getEquipmentName() + o.getSubarray() + o.getPointName(), weightMap) * o.getHealthIndex()).sum();
Double totalAnomaly = v.stream().mapToDouble(o -> getWeight(() -> o.getArea() + o.getStation() + o.getEquipmentName() + o.getSubarray() + o.getPointName(), weightMap) * o.getAnomaly()).sum();
Double totalWeight = v.stream().mapToDouble(o -> getWeight(() -> o.getArea() + o.getStation() + o.getEquipmentName() + o.getSubarray() + o.getPointName(), weightMap)).sum();
pvHealthIndex.setAnomaly(totalAnomaly / totalWeight);
pvHealthIndex.setHealthIndex(totalHealthIndex / totalWeight);
} catch (Exception e) {
// 普通平均
this.calculateAvg(pvHealthIndex, v);
}
pvHealthIndexList.add(pvHealthIndex);
});
return pvHealthIndexList;
}
/**
* 设备加权平均
* 加权平均数 = (w1 * x1 + w2 * x2 + … + wn * xn) / (w1 + w2 + … + wn)
......@@ -87,7 +134,6 @@ public class PvHealthIndexServiceImpl implements IPvHealthIndexService {
pvHealthIndex.setHealthIndex(totalHealthIndex / totalWeight);
} catch (Exception e) {
// 普通平均
log.error("计算加权平均异常", e.getMessage());
this.calculateAvg(pvHealthIndex, v);
}
pvHealthIndexList.add(pvHealthIndex);
......@@ -144,7 +190,6 @@ public class PvHealthIndexServiceImpl implements IPvHealthIndexService {
pvHealthIndex.setHealthIndex(totalHealthIndex / totalWeight);
} catch (Exception e) {
// 普通平均
log.error("计算加权平均异常", e.getMessage());
this.calculateAvg(pvHealthIndex, v);
}
pvHealthIndexList.add(pvHealthIndex);
......@@ -199,7 +244,6 @@ public class PvHealthIndexServiceImpl implements IPvHealthIndexService {
pvHealthIndex.setAnomaly(totalAnomaly / totalWeight);
pvHealthIndex.setHealthIndex(totalHealthIndex / totalWeight);
} catch (Exception e) {
log.error("计算加权平均异常", e.getMessage());
// 普通平均
this.calculateAvg(pvHealthIndex, v);
}
......@@ -253,7 +297,6 @@ public class PvHealthIndexServiceImpl implements IPvHealthIndexService {
pvHealthIndex.setAnomaly(totalAnomaly / totalWeight);
pvHealthIndex.setHealthIndex(totalHealthIndex / totalWeight);
} catch (Exception e) {
log.error("计算加权平均异常", e.getMessage());
// 普通平均
this.calculateAvg(pvHealthIndex, v);
}
......@@ -307,7 +350,6 @@ public class PvHealthIndexServiceImpl implements IPvHealthIndexService {
pvHealthIndex.setHealthIndex(totalHealthIndex / totalWeight);
} catch (Exception e) {
// 普通平均
log.error("计算加权平均异常", e.getMessage());
this.calculateAvg(pvHealthIndex, v);
}
pvHealthIndexList.add(pvHealthIndex);
......
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