Commit be974d51 authored by yangyang's avatar yangyang

智慧分析 - 健康等级 片区/全国计算调整

parent 65b8929a
......@@ -14,12 +14,15 @@ import com.yeejoin.amos.boot.module.jxiop.biz.tdengine.PvHealthIndex;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collectors;
......@@ -49,6 +52,9 @@ public class FanHealthIndexServiceImpl implements IFanHealthIndexService {
@Autowired
private IdxBizPvWeightMapper idxBizPvWeightMapper;
@Value("${analysis.weightRounding:false}")
private Boolean weightRounding;
@Override
public List<FanHealthIndex> getInfoListByGroupByCdFan(String startTime, String tableName, String analysisObjectType) {
List<FanHealthIndex> fanHealthIndicesZxt = fanHealthIndexMapper.getInfoList(startTime, tableName, analysisObjectType);
......@@ -81,11 +87,8 @@ public class FanHealthIndexServiceImpl implements IFanHealthIndexService {
// 但如果没有配置子系统的权重,如何计算?
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);
Function<FanHealthIndex, String> assembleKey = o -> o.getArea() + o.getStation() + o.getEquipmentName() + o.getSubSystem() + o.getPointName();
this.weightedMean(assembleKey, fanHealthIndex, v, weightMap);
} catch (Exception e) {
// 普通平均
this.calculateAvg(fanHealthIndex, v);
......@@ -137,11 +140,8 @@ public class FanHealthIndexServiceImpl implements IFanHealthIndexService {
// 但如果没有配置子系统的权重,如何计算?
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);
Function<FanHealthIndex, String> assembleKey = o -> o.getArea() + o.getStation() + o.getEquipmentName() + o.getSubSystem() + o.getPointName();
this.weightedMean(assembleKey, fanHealthIndex, v, weightMap);
} catch (Exception e) {
// 普通平均
this.calculateAvg(fanHealthIndex, v);
......@@ -192,11 +192,8 @@ public class FanHealthIndexServiceImpl implements IFanHealthIndexService {
// 但如果没有配置子系统的权重,如何计算?
try {
// 加权平均
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.setHealthIndex(totalHealthIndex / totalWeight);
Function<FanHealthIndex, String> assembleKey = o -> o.getArea() + o.getStation() + o.getEquipmentName() + o.getSubSystem();
this.weightedMean(assembleKey, fanHealthIndex, v, weightMap);
} catch (Exception e) {
// 普通平均
this.calculateAvg(fanHealthIndex, v);
......@@ -245,11 +242,8 @@ public class FanHealthIndexServiceImpl implements IFanHealthIndexService {
// 但如果没有配置子系统的权重,如何计算?
try {
// 加权平均
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.setHealthIndex(totalHealthIndex / totalWeight);
Function<FanHealthIndex, String> assembleKey = o -> o.getArea() + o.getStation() + o.getEquipmentName();
this.weightedMean(assembleKey, fanHealthIndex, v, weightMap);
} catch (Exception e) {
// 普通平均
this.calculateAvg(fanHealthIndex, v);
......@@ -297,11 +291,8 @@ public class FanHealthIndexServiceImpl implements IFanHealthIndexService {
// 但如果没有配置子系统的权重,如何计算?
try {
// 加权平均
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.setHealthIndex(totalHealthIndex / totalWeight);
Function<FanHealthIndex, String> assembleKey = o -> o.getArea() + o.getStation();
this.weightedMean(assembleKey, fanHealthIndex, v, weightMap);
} catch (Exception e) {
// 普通平均
this.calculateAvg(fanHealthIndex, v);
......@@ -348,11 +339,8 @@ public class FanHealthIndexServiceImpl implements IFanHealthIndexService {
// 但如果没有配置子系统的权重,如何计算?
try {
// 加权平均
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.setHealthIndex(totalHealthIndex / totalWeight);
Function<FanHealthIndex, String> assembleKey = o -> o.getArea();
this.weightedMean(assembleKey, fanHealthIndex, v, weightMap);
} catch (Exception e) {
// 普通平均
this.calculateAvg(fanHealthIndex, v);
......@@ -393,11 +381,8 @@ public class FanHealthIndexServiceImpl implements IFanHealthIndexService {
// 但如果没有配置子系统的权重,如何计算?
try {
// 加权平均
Double totalHealthIndex = v.stream().mapToDouble(o -> getWeight(() -> o.getType() + o.getArea() + o.getStation(), weightMap) * o.getHealthIndex()).sum();
Double totalAnomaly = v.stream().mapToDouble(o -> getWeight(() -> o.getType() + o.getArea() + o.getStation(), weightMap) * o.getAnomaly()).sum();
Double totalWeight = v.stream().mapToDouble(o -> getWeight(() -> o.getType() + o.getArea() + o.getStation(), weightMap)).sum();
healthIndex.setAnomaly(totalAnomaly / totalWeight);
healthIndex.setHealthIndex(totalHealthIndex / totalWeight);
Function<HealthIndexDTO, String> assembleKey = o -> o.getType() + o.getArea() + o.getStation();
this.weightedMean(assembleKey, healthIndex, v, weightMap);
} catch (Exception e) {
// 普通平均
this.calculateAvg(healthIndex, v);
......@@ -438,11 +423,8 @@ public class FanHealthIndexServiceImpl implements IFanHealthIndexService {
// 但如果没有配置子系统的权重,如何计算?
try {
// 加权平均
Double totalHealthIndex = v.stream().mapToDouble(o -> getWeight(() -> o.getType() + o.getArea(), weightMap) * o.getHealthIndex()).sum();
Double totalAnomaly = v.stream().mapToDouble(o -> getWeight(() -> o.getType() + o.getArea(), weightMap) * o.getAnomaly()).sum();
Double totalWeight = v.stream().mapToDouble(o -> getWeight(() -> o.getType() + o.getArea(), weightMap)).sum();
healthIndex.setAnomaly(totalAnomaly / totalWeight);
healthIndex.setHealthIndex(totalHealthIndex / totalWeight);
Function<HealthIndexDTO, String> assembleKey = o -> o.getType() + o.getArea();
this.weightedMean(assembleKey, healthIndex, v, weightMap);
} catch (Exception e) {
// 普通平均
this.calculateAvg(healthIndex, v);
......@@ -452,14 +434,30 @@ public class FanHealthIndexServiceImpl implements IFanHealthIndexService {
return fanHealthIndicesZxtNews;
}
public void weightedMean(Function<HealthIndexDTO, String> assembleKey, HealthIndexDTO healthIndex, List<HealthIndexDTO> v, Map<String, Float> weightMap) {
Double totalHealthIndex = v.stream().mapToDouble(o -> getWeight(() -> assembleKey.apply(o), weightMap) * o.getHealthIndex()).sum();
Double totalAnomaly = v.stream().mapToDouble(o -> getWeight(() -> assembleKey.apply(o), weightMap) * o.getAnomaly()).sum();
Double totalWeight = v.stream().mapToDouble(o -> getWeight(() -> assembleKey.apply(o), weightMap)).sum();
healthIndex.setAnomaly(division(totalAnomaly, totalWeight));
healthIndex.setHealthIndex(division(totalHealthIndex, totalWeight));
}
public void weightedMean(Function<FanHealthIndex, String> assembleKey, FanHealthIndex healthIndex, List<FanHealthIndex> v, Map<String, Float> weightMap) {
Double totalHealthIndex = v.stream().mapToDouble(o -> getWeight(() -> assembleKey.apply(o), weightMap) * o.getHealthIndex()).sum();
Double totalAnomaly = v.stream().mapToDouble(o -> getWeight(() -> assembleKey.apply(o), weightMap) * o.getAnomaly()).sum();
Double totalWeight = v.stream().mapToDouble(o -> getWeight(() -> assembleKey.apply(o), weightMap)).sum();
healthIndex.setAnomaly(division(totalAnomaly, totalWeight));
healthIndex.setHealthIndex(division(totalHealthIndex, totalWeight));
}
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);
healthIndex.setAnomaly(division(avgAnomaly, totalAnomaly.doubleValue()));
healthIndex.setHealthIndex(division(avgHealthIndex, totalHealthIndex.doubleValue()));
}
public void calculateAvg(HealthIndexDTO healthIndex, List<HealthIndexDTO> v) {
......@@ -468,8 +466,8 @@ public class FanHealthIndexServiceImpl implements IFanHealthIndexService {
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);
healthIndex.setAnomaly(division(avgAnomaly, totalAnomaly.doubleValue()));
healthIndex.setHealthIndex(division(avgHealthIndex, totalHealthIndex.doubleValue()));
}
public Double getWeight(Supplier<String> key, Map<String, Float> weightMap) {
......@@ -513,4 +511,24 @@ public class FanHealthIndexServiceImpl implements IFanHealthIndexService {
return pvHealthIndex;
}
/**
* 计算的时候,会使用原始数据计算,页面显示数据会四舍五入到1位小数
*
* 启用weightRounding 配置则会四舍五入到小数点后1位
*
* @param a a
* @param b b
* @return {@link Double}
* @throws
* @author yangyang
* @date 2024/7/25 17:28
*/
private Double division(Double a, Double b) {
if (weightRounding) {
BigDecimal c = new BigDecimal(a).divide(new BigDecimal(b), 1, BigDecimal.ROUND_HALF_UP);
return c.doubleValue();
}
return a / b;
}
}
......@@ -9,11 +9,14 @@ import com.yeejoin.amos.boot.module.jxiop.biz.tdengine.FanHealthIndex;
import com.yeejoin.amos.boot.module.jxiop.biz.tdengine.PvHealthIndex;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collectors;
......@@ -37,6 +40,9 @@ public class PvHealthIndexServiceImpl implements IPvHealthIndexService {
@Autowired
private IdxBizPvWeightMapper idxBizPvWeightMapper;
@Value ("${analysis.weightRounding:false}")
private Boolean weightRounding;
@Override
public List<PvHealthIndex> getInfoListByGroupByCdPv(String startTime, String tableName, String analysisObjectType) {
List<PvHealthIndex> pvHealthIndices = pvHealthIndexMapper.getInfoList(startTime, tableName, analysisObjectType);
......@@ -70,11 +76,8 @@ public class PvHealthIndexServiceImpl implements IPvHealthIndexService {
// 但如果没有配置子系统的权重,如何计算?
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);
Function<PvHealthIndex, String> assembleKey = o -> o.getArea() + o.getStation() + o.getEquipmentName() + o.getSubarray() + o.getPointName();
this.weightedMean(assembleKey, pvHealthIndex, v, weightMap);
} catch (Exception e) {
// 普通平均
this.calculateAvg(pvHealthIndex, v);
......@@ -127,11 +130,8 @@ public class PvHealthIndexServiceImpl implements IPvHealthIndexService {
// 但如果没有配置子系统的权重,如何计算?
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);
Function<PvHealthIndex, String> assembleKey = o -> o.getArea() + o.getStation() + o.getEquipmentName() + o.getSubarray() + o.getPointName();
this.weightedMean(assembleKey, pvHealthIndex, v, weightMap);
} catch (Exception e) {
// 普通平均
this.calculateAvg(pvHealthIndex, v);
......@@ -183,11 +183,8 @@ public class PvHealthIndexServiceImpl implements IPvHealthIndexService {
// 但如果没有配置子系统的权重,如何计算?
try {
// 加权平均
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.setHealthIndex(totalHealthIndex / totalWeight);
Function<PvHealthIndex, String> assembleKey = o -> o.getArea() + o.getStation() + o.getEquipmentName() + o.getSubarray();
this.weightedMean(assembleKey, pvHealthIndex, v, weightMap);
} catch (Exception e) {
// 普通平均
this.calculateAvg(pvHealthIndex, v);
......@@ -238,11 +235,8 @@ public class PvHealthIndexServiceImpl implements IPvHealthIndexService {
// 但如果没有配置子系统的权重,如何计算?
try {
// 加权平均
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.setHealthIndex(totalHealthIndex / totalWeight);
Function<PvHealthIndex, String> assembleKey = o -> o.getArea() + o.getStation() + o.getEquipmentName();
this.weightedMean(assembleKey, pvHealthIndex, v, weightMap);
} catch (Exception e) {
// 普通平均
this.calculateAvg(pvHealthIndex, v);
......@@ -291,11 +285,8 @@ public class PvHealthIndexServiceImpl implements IPvHealthIndexService {
// 但如果没有配置子系统的权重,如何计算?
try {
// 加权平均
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.setHealthIndex(totalHealthIndex / totalWeight);
Function<PvHealthIndex, String> assembleKey = o -> o.getArea() + o.getStation();
this.weightedMean(assembleKey, pvHealthIndex, v, weightMap);
} catch (Exception e) {
// 普通平均
this.calculateAvg(pvHealthIndex, v);
......@@ -343,11 +334,8 @@ public class PvHealthIndexServiceImpl implements IPvHealthIndexService {
// 但如果没有配置子系统的权重,如何计算?
try {
// 加权平均
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.setHealthIndex(totalHealthIndex / totalWeight);
Function<PvHealthIndex, String> assembleKey = o -> o.getArea();
this.weightedMean(assembleKey, pvHealthIndex, v, weightMap);
} catch (Exception e) {
// 普通平均
this.calculateAvg(pvHealthIndex, v);
......@@ -357,15 +345,44 @@ public class PvHealthIndexServiceImpl implements IPvHealthIndexService {
return pvHealthIndexList;
}
/**
* 加权平均
*
* @param assembleKey assembleKey
* @param healthIndex healthIndex
* @param v v
* @param weightMap weightMap
* @return {@link }
* @throws
* @author yangyang
* @date 2024/7/25 17:36
*/
public void weightedMean(Function<PvHealthIndex, String> assembleKey, PvHealthIndex healthIndex, List<PvHealthIndex> v, Map<String, Float> weightMap) {
Double totalHealthIndex = v.stream().mapToDouble(o -> getWeight(() -> assembleKey.apply(o), weightMap) * o.getHealthIndex()).sum();
Double totalAnomaly = v.stream().mapToDouble(o -> getWeight(() -> assembleKey.apply(o), weightMap) * o.getAnomaly()).sum();
Double totalWeight = v.stream().mapToDouble(o -> getWeight(() -> assembleKey.apply(o), weightMap)).sum();
healthIndex.setAnomaly(division(totalAnomaly, totalWeight));
healthIndex.setHealthIndex(division(totalHealthIndex, totalWeight));
}
/**
* 普通平均
*
* @param healthIndex healthIndex
* @param v v
* @return {@link }
* @throws
* @author yangyang
* @date 2024/7/25 17:37
*/
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);
healthIndex.setAnomaly(division(avgAnomaly, totalAnomaly.doubleValue()));
healthIndex.setHealthIndex(division(avgHealthIndex, totalHealthIndex.doubleValue()));
}
public Double getWeight(Supplier<String> key, Map<String, Float> weightMap) {
......@@ -377,4 +394,24 @@ public class PvHealthIndexServiceImpl implements IPvHealthIndexService {
return weight.doubleValue();
}
/**
* 计算的时候,会使用原始数据计算,页面显示数据会四舍五入到1位小数
*
* 启用weightRounding 配置则会四舍五入到小数点后1位
*
* @param a a
* @param b b
* @return {@link Double}
* @throws
* @author yangyang
* @date 2024/7/25 17:28
*/
private Double division(Double a, Double b) {
if (weightRounding) {
BigDecimal c = new BigDecimal(a).divide(new BigDecimal(b), 1, BigDecimal.ROUND_HALF_UP);
return c.doubleValue();
}
return a / b;
}
}
......@@ -474,14 +474,10 @@ public class TdengineTimeServiceImpl {
}
public void printPv(String desc, List<PvHealthIndex> olds, List<PvHealthIndex> news) {
try {
olds.sort(Comparator.comparing(PvHealthIndex::getArea).thenComparing(PvHealthIndex::getStation).thenComparing(PvHealthIndex::getEquipmentName).thenComparing(PvHealthIndex::getSubarray).thenComparing(PvHealthIndex::getPointName));
news.sort(Comparator.comparing(PvHealthIndex::getArea).thenComparing(PvHealthIndex::getStation).thenComparing(PvHealthIndex::getEquipmentName).thenComparing(PvHealthIndex::getSubarray).thenComparing(PvHealthIndex::getPointName));
log.info("对比{} old => {}", desc, olds);
log.info("对比{} news => {}", desc, news);
} catch (Exception e) {
e.printStackTrace();
}
olds.sort(Comparator.comparing(PvHealthIndex::getArea).thenComparing(PvHealthIndex::getStation).thenComparing(PvHealthIndex::getSubarray).thenComparing(PvHealthIndex::getEquipmentName).thenComparing(PvHealthIndex::getPointName));
news.sort(Comparator.comparing(PvHealthIndex::getArea).thenComparing(PvHealthIndex::getStation).thenComparing(PvHealthIndex::getSubarray).thenComparing(PvHealthIndex::getEquipmentName).thenComparing(PvHealthIndex::getPointName));
log.info("对比{} old => {}", desc, olds);
log.info("对比{} news => {}", desc, news);
}
public void insertMomentDataAll(String recDate) throws ParseException {
......
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