Commit 7d727f4a authored by yangyang's avatar yangyang

智慧分析 - 健康等级计算调整

parent 366a7a6a
...@@ -13,6 +13,7 @@ import org.springframework.stereotype.Component; ...@@ -13,6 +13,7 @@ import org.springframework.stereotype.Component;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.function.Supplier;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
...@@ -54,11 +55,12 @@ public class FanHealthIndexServiceImpl implements IFanHealthIndexService { ...@@ -54,11 +55,12 @@ public class FanHealthIndexServiceImpl implements IFanHealthIndexService {
public List<FanHealthIndex> getInfoListByGroupByZxtFan(String startTime, String tableName, String analysisObjectType) { public List<FanHealthIndex> getInfoListByGroupByZxtFan(String startTime, String tableName, String analysisObjectType) {
List<FanHealthIndex> fanHealthIndicesZxt = fanHealthIndexMapper.getInfoList(startTime, tableName, analysisObjectType); List<FanHealthIndex> fanHealthIndicesZxt = fanHealthIndexMapper.getInfoList(startTime, tableName, analysisObjectType);
QueryWrapper<IdxBizFanWeight> idxBizFanWeightQueryWrapper = new QueryWrapper<>(); QueryWrapper<IdxBizFanWeight> idxBizFanWeightQueryWrapper = new QueryWrapper<>();
idxBizFanWeightQueryWrapper.ne("type", "5"); idxBizFanWeightQueryWrapper.eq("type", "5");
idxBizFanWeightQueryWrapper.isNotNull("value");
List<IdxBizFanWeight> idxBizFanWeights = idxBizFanWeightMapper.selectList(idxBizFanWeightQueryWrapper); 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, 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.getArea() + o.getStation() + o.getEquipmentName() + o.getSubSystem() + o.getOrgCode() + o.getPointName())); 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<>(); List<FanHealthIndex> fanHealthIndicesZxtNews = new ArrayList<>();
fanHealthIndicesZxtMap.forEach((k, v) -> { fanHealthIndicesZxtMap.forEach((k, v) -> {
FanHealthIndex fanHealthIndex = new FanHealthIndex(); FanHealthIndex fanHealthIndex = new FanHealthIndex();
...@@ -74,14 +76,19 @@ public class FanHealthIndexServiceImpl implements IFanHealthIndexService { ...@@ -74,14 +76,19 @@ public class FanHealthIndexServiceImpl implements IFanHealthIndexService {
// 但是测点是没有权重的,所以子系统无法计算加权平均 // 但是测点是没有权重的,所以子系统无法计算加权平均
// 设备 = (子系统1 * 子系统1权重 + 子系统2 * 子系统2权重 + .... 子系统n权重) / (子系统1权重 + 子系统2权重 + .... 子系统n权重) // 设备 = (子系统1 * 子系统1权重 + 子系统2 * 子系统2权重 + .... 子系统n权重) / (子系统1权重 + 子系统2权重 + .... 子系统n权重)
// 但如果没有配置子系统的权重,如何计算? // 但如果没有配置子系统的权重,如何计算?
Double totalHealthIndex = v.stream().mapToDouble(o -> weightMap.get(o.getArea() + o.getStation() + o.getEquipmentName() + o.getSubSystem() + o.getPointName()).doubleValue() * o.getHealthIndex()).sum(); try {
Double totalAnomaly = v.stream().mapToDouble(o -> weightMap.get(o.getArea() + o.getStation() + o.getEquipmentName() + o.getSubSystem() + o.getPointName()).doubleValue() * o.getAnomaly()).sum(); // 加权平均
Double totalWeight = v.stream().mapToDouble(o -> weightMap.get(o.getArea() + o.getStation() + o.getEquipmentName() + o.getSubSystem() + o.getPointName()).doubleValue()).sum(); 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.setAnomaly(totalAnomaly / totalWeight);
fanHealthIndex.setHealthIndex(totalHealthIndex / totalWeight); fanHealthIndex.setHealthIndex(totalHealthIndex / totalWeight);
} catch (Exception e) {
// 普通平均
this.calculateAvg(fanHealthIndex, v);
}
fanHealthIndicesZxtNews.add(fanHealthIndex); fanHealthIndicesZxtNews.add(fanHealthIndex);
}); });
return fanHealthIndicesZxtNews; return fanHealthIndicesZxtNews;
} }
...@@ -104,7 +111,8 @@ public class FanHealthIndexServiceImpl implements IFanHealthIndexService { ...@@ -104,7 +111,8 @@ public class FanHealthIndexServiceImpl implements IFanHealthIndexService {
public List<FanHealthIndex> getInfoListByGroupBySbFan(String startTime, String tableName, String analysisObjectType) { public List<FanHealthIndex> getInfoListByGroupBySbFan(String startTime, String tableName, String analysisObjectType) {
List<FanHealthIndex> fanHealthIndicesZxt = fanHealthIndexMapper.getInfoList(startTime, tableName, analysisObjectType); List<FanHealthIndex> fanHealthIndicesZxt = fanHealthIndexMapper.getInfoList(startTime, tableName, analysisObjectType);
QueryWrapper<IdxBizFanWeight> idxBizFanWeightQueryWrapper = new QueryWrapper<>(); QueryWrapper<IdxBizFanWeight> idxBizFanWeightQueryWrapper = new QueryWrapper<>();
idxBizFanWeightQueryWrapper.ne("type", "5"); idxBizFanWeightQueryWrapper.eq("type", "4");
idxBizFanWeightQueryWrapper.isNotNull("value");
List<IdxBizFanWeight> idxBizFanWeights = idxBizFanWeightMapper.selectList(idxBizFanWeightQueryWrapper); List<IdxBizFanWeight> idxBizFanWeights = idxBizFanWeightMapper.selectList(idxBizFanWeightQueryWrapper);
Map<String, Float> weightMap = idxBizFanWeights.stream().collect(Collectors.toMap(o -> o.getArae() + o.getStation() + o.getEquipmentName() + o.getSubarray(), IdxBizFanWeight::getValue)); Map<String, Float> weightMap = idxBizFanWeights.stream().collect(Collectors.toMap(o -> o.getArae() + o.getStation() + o.getEquipmentName() + o.getSubarray(), IdxBizFanWeight::getValue));
// 开始计算加权平均 // 开始计算加权平均
...@@ -123,11 +131,17 @@ public class FanHealthIndexServiceImpl implements IFanHealthIndexService { ...@@ -123,11 +131,17 @@ public class FanHealthIndexServiceImpl implements IFanHealthIndexService {
// 但是测点是没有权重的,所以子系统无法计算加权平均 // 但是测点是没有权重的,所以子系统无法计算加权平均
// 设备 = (子系统1 * 子系统1权重 + 子系统2 * 子系统2权重 + .... 子系统n权重) / (子系统1权重 + 子系统2权重 + .... 子系统n权重) // 设备 = (子系统1 * 子系统1权重 + 子系统2 * 子系统2权重 + .... 子系统n权重) / (子系统1权重 + 子系统2权重 + .... 子系统n权重)
// 但如果没有配置子系统的权重,如何计算? // 但如果没有配置子系统的权重,如何计算?
Double totalHealthIndex = v.stream().mapToDouble(o -> weightMap.get(o.getArea() + o.getStation() + o.getEquipmentName() + o.getSubSystem()).doubleValue() * o.getHealthIndex()).sum(); try {
Double totalAnomaly = v.stream().mapToDouble(o -> weightMap.get(o.getArea() + o.getStation() + o.getEquipmentName() + o.getSubSystem()).doubleValue() * o.getAnomaly()).sum(); // 加权平均
Double totalWeight = v.stream().mapToDouble(o -> weightMap.get(o.getArea() + o.getStation() + o.getEquipmentName() + o.getSubSystem()).doubleValue()).sum(); Double totalHealthIndex = v.stream().mapToDouble(o -> getWeight(() -> o.getArea() + o.getStation() + o.getEquipmentName() + o.getSubSystem(), weightMap) * o.getHealthIndex()).sum();
Double totalAnomaly = v.stream().mapToDouble(o -> getWeight(() -> o.getArea() + o.getStation() + o.getEquipmentName() + o.getSubSystem(), weightMap) * o.getAnomaly()).sum();
Double totalWeight = v.stream().mapToDouble(o -> getWeight(() -> o.getArea() + o.getStation() + o.getEquipmentName() + o.getSubSystem(), weightMap)).sum();
fanHealthIndex.setAnomaly(totalAnomaly / totalWeight); fanHealthIndex.setAnomaly(totalAnomaly / totalWeight);
fanHealthIndex.setHealthIndex(totalHealthIndex / totalWeight); fanHealthIndex.setHealthIndex(totalHealthIndex / totalWeight);
} catch (Exception e) {
// 普通平均
this.calculateAvg(fanHealthIndex, v);
}
fanHealthIndicesZxtNews.add(fanHealthIndex); fanHealthIndicesZxtNews.add(fanHealthIndex);
}); });
return fanHealthIndicesZxtNews; return fanHealthIndicesZxtNews;
...@@ -152,7 +166,8 @@ public class FanHealthIndexServiceImpl implements IFanHealthIndexService { ...@@ -152,7 +166,8 @@ public class FanHealthIndexServiceImpl implements IFanHealthIndexService {
public List<FanHealthIndex> getInfoListByGroupByCzFan(String startTime, String tableName, String analysisObjectType) { public List<FanHealthIndex> getInfoListByGroupByCzFan(String startTime, String tableName, String analysisObjectType) {
List<FanHealthIndex> fanHealthIndicesZxt = fanHealthIndexMapper.getInfoList(startTime, tableName, analysisObjectType); List<FanHealthIndex> fanHealthIndicesZxt = fanHealthIndexMapper.getInfoList(startTime, tableName, analysisObjectType);
QueryWrapper<IdxBizFanWeight> idxBizFanWeightQueryWrapper = new QueryWrapper<>(); QueryWrapper<IdxBizFanWeight> idxBizFanWeightQueryWrapper = new QueryWrapper<>();
idxBizFanWeightQueryWrapper.ne("type", "5"); idxBizFanWeightQueryWrapper.eq("type", "3");
idxBizFanWeightQueryWrapper.isNotNull("value");
List<IdxBizFanWeight> idxBizFanWeights = idxBizFanWeightMapper.selectList(idxBizFanWeightQueryWrapper); List<IdxBizFanWeight> idxBizFanWeights = idxBizFanWeightMapper.selectList(idxBizFanWeightQueryWrapper);
Map<String, Float> weightMap = idxBizFanWeights.stream().collect(Collectors.toMap(o -> o.getArae() + o.getStation() + o.getEquipmentName(), IdxBizFanWeight::getValue)); Map<String, Float> weightMap = idxBizFanWeights.stream().collect(Collectors.toMap(o -> o.getArae() + o.getStation() + o.getEquipmentName(), IdxBizFanWeight::getValue));
// 开始计算加权平均 // 开始计算加权平均
...@@ -169,11 +184,17 @@ public class FanHealthIndexServiceImpl implements IFanHealthIndexService { ...@@ -169,11 +184,17 @@ public class FanHealthIndexServiceImpl implements IFanHealthIndexService {
// 但是测点是没有权重的,所以子系统无法计算加权平均 // 但是测点是没有权重的,所以子系统无法计算加权平均
// 设备 = (子系统1 * 子系统1权重 + 子系统2 * 子系统2权重 + .... 子系统n权重) / (子系统1权重 + 子系统2权重 + .... 子系统n权重) // 设备 = (子系统1 * 子系统1权重 + 子系统2 * 子系统2权重 + .... 子系统n权重) / (子系统1权重 + 子系统2权重 + .... 子系统n权重)
// 但如果没有配置子系统的权重,如何计算? // 但如果没有配置子系统的权重,如何计算?
Double totalHealthIndex = v.stream().mapToDouble(o -> weightMap.get(o.getArea() + o.getStation() + o.getEquipmentName()).doubleValue() * o.getHealthIndex()).sum(); try {
Double totalAnomaly = v.stream().mapToDouble(o -> weightMap.get(o.getArea() + o.getStation() + o.getEquipmentName()).doubleValue() * o.getAnomaly()).sum(); // 加权平均
Double totalWeight = v.stream().mapToDouble(o -> weightMap.get(o.getArea() + o.getStation() + o.getEquipmentName()).doubleValue()).sum(); Double totalHealthIndex = v.stream().mapToDouble(o -> getWeight(() -> o.getArea() + o.getStation() + o.getEquipmentName(), weightMap) * o.getHealthIndex()).sum();
Double totalAnomaly = v.stream().mapToDouble(o -> getWeight(() -> o.getArea() + o.getStation() + o.getEquipmentName(), weightMap) * o.getAnomaly()).sum();
Double totalWeight = v.stream().mapToDouble(o -> getWeight(() -> o.getArea() + o.getStation() + o.getEquipmentName(), weightMap)).sum();
fanHealthIndex.setAnomaly(totalAnomaly / totalWeight); fanHealthIndex.setAnomaly(totalAnomaly / totalWeight);
fanHealthIndex.setHealthIndex(totalHealthIndex / totalWeight); fanHealthIndex.setHealthIndex(totalHealthIndex / totalWeight);
} catch (Exception e) {
// 普通平均
this.calculateAvg(fanHealthIndex, v);
}
fanHealthIndicesZxtNews.add(fanHealthIndex); fanHealthIndicesZxtNews.add(fanHealthIndex);
}); });
return fanHealthIndicesZxtNews; return fanHealthIndicesZxtNews;
...@@ -198,7 +219,8 @@ public class FanHealthIndexServiceImpl implements IFanHealthIndexService { ...@@ -198,7 +219,8 @@ public class FanHealthIndexServiceImpl implements IFanHealthIndexService {
public List<FanHealthIndex> getInfoListByGroupByQyFan(String startTime, String tableName, String analysisObjectType) { public List<FanHealthIndex> getInfoListByGroupByQyFan(String startTime, String tableName, String analysisObjectType) {
List<FanHealthIndex> fanHealthIndicesZxt = fanHealthIndexMapper.getInfoList(startTime, tableName, analysisObjectType); List<FanHealthIndex> fanHealthIndicesZxt = fanHealthIndexMapper.getInfoList(startTime, tableName, analysisObjectType);
QueryWrapper<IdxBizFanWeight> idxBizFanWeightQueryWrapper = new QueryWrapper<>(); QueryWrapper<IdxBizFanWeight> idxBizFanWeightQueryWrapper = new QueryWrapper<>();
idxBizFanWeightQueryWrapper.ne("type", "5"); idxBizFanWeightQueryWrapper.eq("type", "2");
idxBizFanWeightQueryWrapper.isNotNull("value");
List<IdxBizFanWeight> idxBizFanWeights = idxBizFanWeightMapper.selectList(idxBizFanWeightQueryWrapper); List<IdxBizFanWeight> idxBizFanWeights = idxBizFanWeightMapper.selectList(idxBizFanWeightQueryWrapper);
Map<String, Float> weightMap = idxBizFanWeights.stream().collect(Collectors.toMap(o -> o.getArae() + o.getStation(), IdxBizFanWeight::getValue)); Map<String, Float> weightMap = idxBizFanWeights.stream().collect(Collectors.toMap(o -> o.getArae() + o.getStation(), IdxBizFanWeight::getValue));
// 开始计算加权平均 // 开始计算加权平均
...@@ -213,11 +235,17 @@ public class FanHealthIndexServiceImpl implements IFanHealthIndexService { ...@@ -213,11 +235,17 @@ public class FanHealthIndexServiceImpl implements IFanHealthIndexService {
// 但是测点是没有权重的,所以子系统无法计算加权平均 // 但是测点是没有权重的,所以子系统无法计算加权平均
// 设备 = (子系统1 * 子系统1权重 + 子系统2 * 子系统2权重 + .... 子系统n权重) / (子系统1权重 + 子系统2权重 + .... 子系统n权重) // 设备 = (子系统1 * 子系统1权重 + 子系统2 * 子系统2权重 + .... 子系统n权重) / (子系统1权重 + 子系统2权重 + .... 子系统n权重)
// 但如果没有配置子系统的权重,如何计算? // 但如果没有配置子系统的权重,如何计算?
Double totalHealthIndex = v.stream().mapToDouble(o -> weightMap.get(o.getArea() + o.getStation()).doubleValue() * o.getHealthIndex()).sum(); try {
Double totalAnomaly = v.stream().mapToDouble(o -> weightMap.get(o.getArea() + o.getStation()).doubleValue() * o.getAnomaly()).sum(); // 加权平均
Double totalWeight = v.stream().mapToDouble(o -> weightMap.get(o.getArea() + o.getStation()).doubleValue()).sum(); Double totalHealthIndex = v.stream().mapToDouble(o -> getWeight(() -> o.getArea() + o.getStation(), weightMap) * o.getHealthIndex()).sum();
Double totalAnomaly = v.stream().mapToDouble(o -> getWeight(() -> o.getArea() + o.getStation(), weightMap) * o.getAnomaly()).sum();
Double totalWeight = v.stream().mapToDouble(o -> getWeight(() -> o.getArea() + o.getStation(), weightMap)).sum();
fanHealthIndex.setAnomaly(totalAnomaly / totalWeight); fanHealthIndex.setAnomaly(totalAnomaly / totalWeight);
fanHealthIndex.setHealthIndex(totalHealthIndex / totalWeight); fanHealthIndex.setHealthIndex(totalHealthIndex / totalWeight);
} catch (Exception e) {
// 普通平均
this.calculateAvg(fanHealthIndex, v);
}
fanHealthIndicesZxtNews.add(fanHealthIndex); fanHealthIndicesZxtNews.add(fanHealthIndex);
}); });
return fanHealthIndicesZxtNews; return fanHealthIndicesZxtNews;
...@@ -242,7 +270,8 @@ public class FanHealthIndexServiceImpl implements IFanHealthIndexService { ...@@ -242,7 +270,8 @@ public class FanHealthIndexServiceImpl implements IFanHealthIndexService {
public List<FanHealthIndex> getInfoListByGroupByQgFan(String startTime, String tableName, String analysisObjectType) { public List<FanHealthIndex> getInfoListByGroupByQgFan(String startTime, String tableName, String analysisObjectType) {
List<FanHealthIndex> fanHealthIndicesZxt = fanHealthIndexMapper.getInfoList(startTime, tableName, analysisObjectType); List<FanHealthIndex> fanHealthIndicesZxt = fanHealthIndexMapper.getInfoList(startTime, tableName, analysisObjectType);
QueryWrapper<IdxBizFanWeight> idxBizFanWeightQueryWrapper = new QueryWrapper<>(); QueryWrapper<IdxBizFanWeight> idxBizFanWeightQueryWrapper = new QueryWrapper<>();
idxBizFanWeightQueryWrapper.ne("type", "5"); idxBizFanWeightQueryWrapper.eq("type", "1");
idxBizFanWeightQueryWrapper.isNotNull("value");
List<IdxBizFanWeight> idxBizFanWeights = idxBizFanWeightMapper.selectList(idxBizFanWeightQueryWrapper); List<IdxBizFanWeight> idxBizFanWeights = idxBizFanWeightMapper.selectList(idxBizFanWeightQueryWrapper);
Map<String, Float> weightMap = idxBizFanWeights.stream().collect(Collectors.toMap(o -> o.getArae(), IdxBizFanWeight::getValue)); Map<String, Float> weightMap = idxBizFanWeights.stream().collect(Collectors.toMap(o -> o.getArae(), IdxBizFanWeight::getValue));
// 开始计算加权平均 // 开始计算加权平均
...@@ -256,14 +285,39 @@ public class FanHealthIndexServiceImpl implements IFanHealthIndexService { ...@@ -256,14 +285,39 @@ public class FanHealthIndexServiceImpl implements IFanHealthIndexService {
// 但是测点是没有权重的,所以子系统无法计算加权平均 // 但是测点是没有权重的,所以子系统无法计算加权平均
// 设备 = (子系统1 * 子系统1权重 + 子系统2 * 子系统2权重 + .... 子系统n权重) / (子系统1权重 + 子系统2权重 + .... 子系统n权重) // 设备 = (子系统1 * 子系统1权重 + 子系统2 * 子系统2权重 + .... 子系统n权重) / (子系统1权重 + 子系统2权重 + .... 子系统n权重)
// 但如果没有配置子系统的权重,如何计算? // 但如果没有配置子系统的权重,如何计算?
Double totalHealthIndex = v.stream().mapToDouble(o -> weightMap.get(o.getArea()).doubleValue() * o.getHealthIndex()).sum(); try {
Double totalAnomaly = v.stream().mapToDouble(o -> weightMap.get(o.getArea()).doubleValue() * o.getAnomaly()).sum(); // 加权平均
Double totalWeight = v.stream().mapToDouble(o -> weightMap.get(o.getArea()).doubleValue()).sum(); Double totalHealthIndex = v.stream().mapToDouble(o -> getWeight(() -> o.getArea(), weightMap) * o.getHealthIndex()).sum();
Double totalAnomaly = v.stream().mapToDouble(o -> getWeight(() -> o.getArea(), weightMap) * o.getAnomaly()).sum();
Double totalWeight = v.stream().mapToDouble(o -> getWeight(() -> o.getArea(), weightMap)).sum();
fanHealthIndex.setAnomaly(totalAnomaly / totalWeight); fanHealthIndex.setAnomaly(totalAnomaly / totalWeight);
fanHealthIndex.setHealthIndex(totalHealthIndex / totalWeight); fanHealthIndex.setHealthIndex(totalHealthIndex / totalWeight);
} catch (Exception e) {
// 普通平均
this.calculateAvg(fanHealthIndex, v);
}
fanHealthIndicesZxtNews.add(fanHealthIndex); fanHealthIndicesZxtNews.add(fanHealthIndex);
}); });
return fanHealthIndicesZxtNews; return fanHealthIndicesZxtNews;
} }
public void calculateAvg(FanHealthIndex healthIndex, List<FanHealthIndex> v) {
// 普通平均
Double avgHealthIndex = v.stream().mapToDouble(o -> o.getHealthIndex()).sum();
Double avgAnomaly = v.stream().mapToDouble(o -> o.getAnomaly()).sum();
Long totalHealthIndex = v.stream().filter(o -> o.getHealthIndex() != null).mapToDouble(o -> o.getHealthIndex()).count();
Long totalAnomaly = v.stream().filter(o -> o.getAnomaly() != null).mapToDouble(o -> o.getAnomaly()).count();
healthIndex.setAnomaly(avgAnomaly / totalHealthIndex);
healthIndex.setHealthIndex(avgHealthIndex / totalAnomaly);
}
public Double getWeight(Supplier<String> key, Map<String, Float> weightMap) {
Float weight = weightMap.get(key.get());
if (weight == null) {
log.error("计算加权平均异常【" + key.get() + "】没有配置测点权重");
throw new RuntimeException("【" + key.get() + "】没有配置测点权重");
}
return weight.doubleValue();
}
} }
...@@ -14,6 +14,7 @@ import org.springframework.stereotype.Component; ...@@ -14,6 +14,7 @@ import org.springframework.stereotype.Component;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.function.Supplier;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
...@@ -57,7 +58,8 @@ public class PvHealthIndexServiceImpl implements IPvHealthIndexService { ...@@ -57,7 +58,8 @@ public class PvHealthIndexServiceImpl implements IPvHealthIndexService {
String analysisObjectType) { String analysisObjectType) {
List<PvHealthIndex> pvHealthIndices = pvHealthIndexMapper.getInfoList(startTime, tableName, analysisObjectType); List<PvHealthIndex> pvHealthIndices = pvHealthIndexMapper.getInfoList(startTime, tableName, analysisObjectType);
QueryWrapper<IdxBizPvWeight> queryWrapper = new QueryWrapper<>(); QueryWrapper<IdxBizPvWeight> queryWrapper = new QueryWrapper<>();
queryWrapper.ne("type", "5"); queryWrapper.eq("type", "5");
queryWrapper.isNotNull("value");
List<IdxBizPvWeight> idxBizFanWeights = idxBizPvWeightMapper.selectList(queryWrapper); 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, Float> weightMap = idxBizFanWeights.stream().collect(Collectors.toMap(o -> o.getArae() + o.getStation() + o.getEquipmentName() + o.getSubarray() + o.getPointName(), IdxBizPvWeight::getValue));
// 开始计算加权平均 // 开始计算加权平均
...@@ -76,11 +78,18 @@ public class PvHealthIndexServiceImpl implements IPvHealthIndexService { ...@@ -76,11 +78,18 @@ public class PvHealthIndexServiceImpl implements IPvHealthIndexService {
// 但是测点是没有权重的,所以子系统无法计算加权平均 // 但是测点是没有权重的,所以子系统无法计算加权平均
// 设备 = (子系统1 * 子系统1权重 + 子系统2 * 子系统2权重 + .... 子系统n权重) / (子系统1权重 + 子系统2权重 + .... 子系统n权重) // 设备 = (子系统1 * 子系统1权重 + 子系统2 * 子系统2权重 + .... 子系统n权重) / (子系统1权重 + 子系统2权重 + .... 子系统n权重)
// 但如果没有配置子系统的权重,如何计算? // 但如果没有配置子系统的权重,如何计算?
Double totalHealthIndex = v.stream().mapToDouble(o -> weightMap.get(o.getArea() + o.getStation() + o.getEquipmentName() + o.getSubarray() + o.getPointName()).doubleValue() * o.getHealthIndex()).sum(); try {
Double totalAnomaly = v.stream().mapToDouble(o -> weightMap.get(o.getArea() + o.getStation() + o.getEquipmentName() + o.getSubarray() + o.getPointName()).doubleValue() * o.getAnomaly()).sum(); // 加权平均
Double totalWeight = v.stream().mapToDouble(o -> weightMap.get(o.getArea() + o.getStation() + o.getEquipmentName() + o.getSubarray() + o.getPointName()).doubleValue()).sum(); 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.setAnomaly(totalAnomaly / totalWeight);
pvHealthIndex.setHealthIndex(totalHealthIndex / totalWeight); pvHealthIndex.setHealthIndex(totalHealthIndex / totalWeight);
} catch (Exception e) {
// 普通平均
log.error("计算加权平均异常", e.getMessage());
this.calculateAvg(pvHealthIndex, v);
}
pvHealthIndexList.add(pvHealthIndex); pvHealthIndexList.add(pvHealthIndex);
}); });
return pvHealthIndexList; return pvHealthIndexList;
...@@ -107,7 +116,8 @@ public class PvHealthIndexServiceImpl implements IPvHealthIndexService { ...@@ -107,7 +116,8 @@ public class PvHealthIndexServiceImpl implements IPvHealthIndexService {
String analysisObjectType) { String analysisObjectType) {
List<PvHealthIndex> pvHealthIndices = pvHealthIndexMapper.getInfoList(startTime, tableName, analysisObjectType); List<PvHealthIndex> pvHealthIndices = pvHealthIndexMapper.getInfoList(startTime, tableName, analysisObjectType);
QueryWrapper<IdxBizPvWeight> queryWrapper = new QueryWrapper<>(); QueryWrapper<IdxBizPvWeight> queryWrapper = new QueryWrapper<>();
queryWrapper.ne("type", "5"); queryWrapper.eq("type", "4");
queryWrapper.isNotNull("value");
List<IdxBizPvWeight> idxBizFanWeights = idxBizPvWeightMapper.selectList(queryWrapper); List<IdxBizPvWeight> idxBizFanWeights = idxBizPvWeightMapper.selectList(queryWrapper);
Map<String, Float> weightMap = idxBizFanWeights.stream().collect(Collectors.toMap(o -> o.getArae() + o.getStation() + o.getEquipmentName() + o.getSubarray(), IdxBizPvWeight::getValue)); Map<String, Float> weightMap = idxBizFanWeights.stream().collect(Collectors.toMap(o -> o.getArae() + o.getStation() + o.getEquipmentName() + o.getSubarray(), IdxBizPvWeight::getValue));
// 开始计算加权平均 // 开始计算加权平均
...@@ -125,11 +135,18 @@ public class PvHealthIndexServiceImpl implements IPvHealthIndexService { ...@@ -125,11 +135,18 @@ public class PvHealthIndexServiceImpl implements IPvHealthIndexService {
// 但是测点是没有权重的,所以子系统无法计算加权平均 // 但是测点是没有权重的,所以子系统无法计算加权平均
// 设备 = (子系统1 * 子系统1权重 + 子系统2 * 子系统2权重 + .... 子系统n权重) / (子系统1权重 + 子系统2权重 + .... 子系统n权重) // 设备 = (子系统1 * 子系统1权重 + 子系统2 * 子系统2权重 + .... 子系统n权重) / (子系统1权重 + 子系统2权重 + .... 子系统n权重)
// 但如果没有配置子系统的权重,如何计算? // 但如果没有配置子系统的权重,如何计算?
Double totalHealthIndex = v.stream().mapToDouble(o -> weightMap.get(o.getArea() + o.getStation() + o.getEquipmentName() + o.getSubarray()).doubleValue() * o.getHealthIndex()).sum(); try {
Double totalAnomaly = v.stream().mapToDouble(o -> weightMap.get(o.getArea() + o.getStation() + o.getEquipmentName() + o.getSubarray()).doubleValue() * o.getAnomaly()).sum(); // 加权平均
Double totalWeight = v.stream().mapToDouble(o -> weightMap.get(o.getArea() + o.getStation() + o.getEquipmentName() + o.getSubarray()).doubleValue()).sum(); Double totalHealthIndex = v.stream().mapToDouble(o -> getWeight(() -> o.getArea() + o.getStation() + o.getEquipmentName() + o.getSubarray(), weightMap) * o.getHealthIndex()).sum();
Double totalAnomaly = v.stream().mapToDouble(o -> getWeight(() -> o.getArea() + o.getStation() + o.getEquipmentName() + o.getSubarray(), weightMap) * o.getAnomaly()).sum();
Double totalWeight = v.stream().mapToDouble(o -> getWeight(() -> o.getArea() + o.getStation() + o.getEquipmentName() + o.getSubarray(), weightMap)).sum();
pvHealthIndex.setAnomaly(totalAnomaly / totalWeight); pvHealthIndex.setAnomaly(totalAnomaly / totalWeight);
pvHealthIndex.setHealthIndex(totalHealthIndex / totalWeight); pvHealthIndex.setHealthIndex(totalHealthIndex / totalWeight);
} catch (Exception e) {
// 普通平均
log.error("计算加权平均异常", e.getMessage());
this.calculateAvg(pvHealthIndex, v);
}
pvHealthIndexList.add(pvHealthIndex); pvHealthIndexList.add(pvHealthIndex);
}); });
return pvHealthIndexList; return pvHealthIndexList;
...@@ -156,7 +173,8 @@ public class PvHealthIndexServiceImpl implements IPvHealthIndexService { ...@@ -156,7 +173,8 @@ public class PvHealthIndexServiceImpl implements IPvHealthIndexService {
String analysisObjectType) { String analysisObjectType) {
List<PvHealthIndex> pvHealthIndices = pvHealthIndexMapper.getInfoList(startTime, tableName, analysisObjectType); List<PvHealthIndex> pvHealthIndices = pvHealthIndexMapper.getInfoList(startTime, tableName, analysisObjectType);
QueryWrapper<IdxBizPvWeight> queryWrapper = new QueryWrapper<>(); QueryWrapper<IdxBizPvWeight> queryWrapper = new QueryWrapper<>();
queryWrapper.ne("type", "5"); queryWrapper.eq("type", "3");
queryWrapper.isNotNull("value");
List<IdxBizPvWeight> idxBizFanWeights = idxBizPvWeightMapper.selectList(queryWrapper); List<IdxBizPvWeight> idxBizFanWeights = idxBizPvWeightMapper.selectList(queryWrapper);
Map<String, Float> weightMap = idxBizFanWeights.stream().collect(Collectors.toMap(o -> o.getArae() + o.getStation() + o.getEquipmentName(), IdxBizPvWeight::getValue)); Map<String, Float> weightMap = idxBizFanWeights.stream().collect(Collectors.toMap(o -> o.getArae() + o.getStation() + o.getEquipmentName(), IdxBizPvWeight::getValue));
// 开始计算加权平均 // 开始计算加权平均
...@@ -173,11 +191,18 @@ public class PvHealthIndexServiceImpl implements IPvHealthIndexService { ...@@ -173,11 +191,18 @@ public class PvHealthIndexServiceImpl implements IPvHealthIndexService {
// 但是测点是没有权重的,所以子系统无法计算加权平均 // 但是测点是没有权重的,所以子系统无法计算加权平均
// 设备 = (子系统1 * 子系统1权重 + 子系统2 * 子系统2权重 + .... 子系统n权重) / (子系统1权重 + 子系统2权重 + .... 子系统n权重) // 设备 = (子系统1 * 子系统1权重 + 子系统2 * 子系统2权重 + .... 子系统n权重) / (子系统1权重 + 子系统2权重 + .... 子系统n权重)
// 但如果没有配置子系统的权重,如何计算? // 但如果没有配置子系统的权重,如何计算?
Double totalHealthIndex = v.stream().mapToDouble(o -> weightMap.get(o.getArea() + o.getStation() + o.getEquipmentName()).doubleValue() * o.getHealthIndex()).sum(); try {
Double totalAnomaly = v.stream().mapToDouble(o -> weightMap.get(o.getArea() + o.getStation() + o.getEquipmentName()).doubleValue() * o.getAnomaly()).sum(); // 加权平均
Double totalWeight = v.stream().mapToDouble(o -> weightMap.get(o.getArea() + o.getStation() + o.getEquipmentName()).doubleValue()).sum(); Double totalHealthIndex = v.stream().mapToDouble(o -> getWeight(() -> o.getArea() + o.getStation() + o.getEquipmentName(), weightMap) * o.getHealthIndex()).sum();
Double totalAnomaly = v.stream().mapToDouble(o -> getWeight(() -> o.getArea() + o.getStation() + o.getEquipmentName(), weightMap) * o.getAnomaly()).sum();
Double totalWeight = v.stream().mapToDouble(o -> getWeight(() -> o.getArea() + o.getStation() + o.getEquipmentName(), weightMap)).sum();
pvHealthIndex.setAnomaly(totalAnomaly / totalWeight); pvHealthIndex.setAnomaly(totalAnomaly / totalWeight);
pvHealthIndex.setHealthIndex(totalHealthIndex / totalWeight); pvHealthIndex.setHealthIndex(totalHealthIndex / totalWeight);
} catch (Exception e) {
log.error("计算加权平均异常", e.getMessage());
// 普通平均
this.calculateAvg(pvHealthIndex, v);
}
pvHealthIndexList.add(pvHealthIndex); pvHealthIndexList.add(pvHealthIndex);
}); });
return pvHealthIndexList; return pvHealthIndexList;
...@@ -204,7 +229,8 @@ public class PvHealthIndexServiceImpl implements IPvHealthIndexService { ...@@ -204,7 +229,8 @@ public class PvHealthIndexServiceImpl implements IPvHealthIndexService {
String analysisObjectType) { String analysisObjectType) {
List<PvHealthIndex> pvHealthIndices = pvHealthIndexMapper.getInfoList(startTime, tableName, analysisObjectType); List<PvHealthIndex> pvHealthIndices = pvHealthIndexMapper.getInfoList(startTime, tableName, analysisObjectType);
QueryWrapper<IdxBizPvWeight> queryWrapper = new QueryWrapper<>(); QueryWrapper<IdxBizPvWeight> queryWrapper = new QueryWrapper<>();
queryWrapper.ne("type", "5"); queryWrapper.eq("type", "2");
queryWrapper.isNotNull("value");
List<IdxBizPvWeight> idxBizFanWeights = idxBizPvWeightMapper.selectList(queryWrapper); List<IdxBizPvWeight> idxBizFanWeights = idxBizPvWeightMapper.selectList(queryWrapper);
Map<String, Float> weightMap = idxBizFanWeights.stream().collect(Collectors.toMap(o -> o.getArae() + o.getStation(), IdxBizPvWeight::getValue)); Map<String, Float> weightMap = idxBizFanWeights.stream().collect(Collectors.toMap(o -> o.getArae() + o.getStation(), IdxBizPvWeight::getValue));
// 开始计算加权平均 // 开始计算加权平均
...@@ -219,11 +245,18 @@ public class PvHealthIndexServiceImpl implements IPvHealthIndexService { ...@@ -219,11 +245,18 @@ public class PvHealthIndexServiceImpl implements IPvHealthIndexService {
// 但是测点是没有权重的,所以子系统无法计算加权平均 // 但是测点是没有权重的,所以子系统无法计算加权平均
// 设备 = (子系统1 * 子系统1权重 + 子系统2 * 子系统2权重 + .... 子系统n权重) / (子系统1权重 + 子系统2权重 + .... 子系统n权重) // 设备 = (子系统1 * 子系统1权重 + 子系统2 * 子系统2权重 + .... 子系统n权重) / (子系统1权重 + 子系统2权重 + .... 子系统n权重)
// 但如果没有配置子系统的权重,如何计算? // 但如果没有配置子系统的权重,如何计算?
Double totalHealthIndex = v.stream().mapToDouble(o -> weightMap.get(o.getArea() + o.getStation()).doubleValue() * o.getHealthIndex()).sum(); try {
Double totalAnomaly = v.stream().mapToDouble(o -> weightMap.get(o.getArea() + o.getStation()).doubleValue() * o.getAnomaly()).sum(); // 加权平均
Double totalWeight = v.stream().mapToDouble(o -> weightMap.get(o.getArea() + o.getStation()).doubleValue()).sum(); Double totalHealthIndex = v.stream().mapToDouble(o -> getWeight(() -> o.getArea() + o.getStation(), weightMap) * o.getHealthIndex()).sum();
Double totalAnomaly = v.stream().mapToDouble(o -> getWeight(() -> o.getArea() + o.getStation(), weightMap) * o.getAnomaly()).sum();
Double totalWeight = v.stream().mapToDouble(o -> getWeight(() -> o.getArea() + o.getStation(), weightMap)).sum();
pvHealthIndex.setAnomaly(totalAnomaly / totalWeight); pvHealthIndex.setAnomaly(totalAnomaly / totalWeight);
pvHealthIndex.setHealthIndex(totalHealthIndex / totalWeight); pvHealthIndex.setHealthIndex(totalHealthIndex / totalWeight);
} catch (Exception e) {
log.error("计算加权平均异常", e.getMessage());
// 普通平均
this.calculateAvg(pvHealthIndex, v);
}
pvHealthIndexList.add(pvHealthIndex); pvHealthIndexList.add(pvHealthIndex);
}); });
return pvHealthIndexList; return pvHealthIndexList;
...@@ -250,7 +283,8 @@ public class PvHealthIndexServiceImpl implements IPvHealthIndexService { ...@@ -250,7 +283,8 @@ public class PvHealthIndexServiceImpl implements IPvHealthIndexService {
String analysisObjectType) { String analysisObjectType) {
List<PvHealthIndex> pvHealthIndices = pvHealthIndexMapper.getInfoList(startTime, tableName, analysisObjectType); List<PvHealthIndex> pvHealthIndices = pvHealthIndexMapper.getInfoList(startTime, tableName, analysisObjectType);
QueryWrapper<IdxBizPvWeight> queryWrapper = new QueryWrapper<>(); QueryWrapper<IdxBizPvWeight> queryWrapper = new QueryWrapper<>();
queryWrapper.ne("type", "5"); queryWrapper.eq("type", "1");
queryWrapper.isNotNull("value");
List<IdxBizPvWeight> idxBizFanWeights = idxBizPvWeightMapper.selectList(queryWrapper); List<IdxBizPvWeight> idxBizFanWeights = idxBizPvWeightMapper.selectList(queryWrapper);
Map<String, Float> weightMap = idxBizFanWeights.stream().collect(Collectors.toMap(o -> o.getArae(), IdxBizPvWeight::getValue)); Map<String, Float> weightMap = idxBizFanWeights.stream().collect(Collectors.toMap(o -> o.getArae(), IdxBizPvWeight::getValue));
// 开始计算加权平均 // 开始计算加权平均
...@@ -264,14 +298,41 @@ public class PvHealthIndexServiceImpl implements IPvHealthIndexService { ...@@ -264,14 +298,41 @@ public class PvHealthIndexServiceImpl implements IPvHealthIndexService {
// 但是测点是没有权重的,所以子系统无法计算加权平均 // 但是测点是没有权重的,所以子系统无法计算加权平均
// 设备 = (子系统1 * 子系统1权重 + 子系统2 * 子系统2权重 + .... 子系统n权重) / (子系统1权重 + 子系统2权重 + .... 子系统n权重) // 设备 = (子系统1 * 子系统1权重 + 子系统2 * 子系统2权重 + .... 子系统n权重) / (子系统1权重 + 子系统2权重 + .... 子系统n权重)
// 但如果没有配置子系统的权重,如何计算? // 但如果没有配置子系统的权重,如何计算?
Double totalHealthIndex = v.stream().mapToDouble(o -> weightMap.get(o.getArea()).doubleValue() * o.getHealthIndex()).sum(); try {
Double totalAnomaly = v.stream().mapToDouble(o -> weightMap.get(o.getArea()).doubleValue() * o.getAnomaly()).sum(); // 加权平均
Double totalWeight = v.stream().mapToDouble(o -> weightMap.get(o.getArea()).doubleValue()).sum(); Double totalHealthIndex = v.stream().mapToDouble(o -> getWeight(() -> o.getArea(), weightMap) * o.getHealthIndex()).sum();
Double totalAnomaly = v.stream().mapToDouble(o -> getWeight(() -> o.getArea(), weightMap) * o.getAnomaly()).sum();
Double totalWeight = v.stream().mapToDouble(o -> getWeight(() -> o.getArea(), weightMap)).sum();
pvHealthIndex.setAnomaly(totalAnomaly / totalWeight); pvHealthIndex.setAnomaly(totalAnomaly / totalWeight);
pvHealthIndex.setHealthIndex(totalHealthIndex / totalWeight); pvHealthIndex.setHealthIndex(totalHealthIndex / totalWeight);
} catch (Exception e) {
// 普通平均
log.error("计算加权平均异常", e.getMessage());
this.calculateAvg(pvHealthIndex, v);
}
pvHealthIndexList.add(pvHealthIndex); pvHealthIndexList.add(pvHealthIndex);
}); });
return pvHealthIndexList; return pvHealthIndexList;
} }
public void calculateAvg(PvHealthIndex healthIndex, List<PvHealthIndex> v) {
// 普通平均
Double avgHealthIndex = v.stream().mapToDouble(o -> o.getHealthIndex()).sum();
Double avgAnomaly = v.stream().mapToDouble(o -> o.getAnomaly()).sum();
Long totalHealthIndex = v.stream().filter(o -> o.getHealthIndex() != null).mapToDouble(o -> o.getHealthIndex()).count();
Long totalAnomaly = v.stream().filter(o -> o.getAnomaly() != null).mapToDouble(o -> o.getAnomaly()).count();
healthIndex.setAnomaly(avgAnomaly / totalHealthIndex);
healthIndex.setHealthIndex(avgHealthIndex / totalAnomaly);
}
public Double getWeight(Supplier<String> key, Map<String, Float> weightMap) {
Float weight = weightMap.get(key.get());
if (weight == null) {
log.error("计算加权平均异常【" + key.get() + "】没有配置测点权重");
throw new RuntimeException("没有配置测点权重");
}
return weight.doubleValue();
}
} }
...@@ -542,7 +542,8 @@ ...@@ -542,7 +542,8 @@
number, number,
anomaly, anomaly,
org_code, org_code,
health_index health_index,
point_name
from from
#{tableName} #{tableName}
where where
......
...@@ -304,7 +304,8 @@ ...@@ -304,7 +304,8 @@
equipment_name, equipment_name,
anomaly, anomaly,
org_code, org_code,
health_index health_index,
point_name
from from
#{tableName} #{tableName}
where where
......
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