diff --git a/algorithm/algorithm-boot/src/main/java/com/njcn/algorithm/serviceimpl/line/DayDataServiceImpl.java b/algorithm/algorithm-boot/src/main/java/com/njcn/algorithm/serviceimpl/line/DayDataServiceImpl.java index a017338..65ad1d4 100644 --- a/algorithm/algorithm-boot/src/main/java/com/njcn/algorithm/serviceimpl/line/DayDataServiceImpl.java +++ b/algorithm/algorithm-boot/src/main/java/com/njcn/algorithm/serviceimpl/line/DayDataServiceImpl.java @@ -22,6 +22,7 @@ import org.springframework.stereotype.Component; import javax.annotation.Resource; import java.time.LocalDateTime; import java.util.*; +import java.util.concurrent.atomic.AtomicReference; import java.util.stream.Collectors; /** @@ -64,9 +65,13 @@ public class DayDataServiceImpl implements IDayDataService { private DataInharmVFeignClient dataInharmVFeignClient; @Resource private DataPltFeignClient dataPltFeignClient; - @Resource private PqDataVerifyFeignClient pqDataVerifyFeignClient; + /** + * 查询配置 辽宁版本比较特殊,没有CP95值,采用平均值进行判断 + */ + @Value("${version.used:master}") + private String versionUsed; @Override public void dataVHandler(CalculatedParam calculatedParam) { @@ -102,7 +107,8 @@ public class DayDataServiceImpl implements IDayDataService { dto.setPhasicType(item2.getPhasicType()); dto.setValueType(item3.getValueType().toUpperCase()); dto.setQualityFlag(Objects.equals(item.getQualityFlag(),"null") ? "0" : item.getQualityFlag()); - channelDataVHandler(item3,valueTypes,dto,true); + //默认CP95值取 CP95的最大值;如果有特殊要求,可以根据平均值的数据取CP95 + channelDataVHandler(item3,valueTypes,dto,!Objects.equals(versionUsed, "liaoning")); result.add(dto); }); }); @@ -150,7 +156,7 @@ public class DayDataServiceImpl implements IDayDataService { dto.setPhasicType(item2.getPhasicType()); dto.setValueType(item3.getValueType().toUpperCase()); dto.setQualityFlag(Objects.equals(item.getQualityFlag(),"null") ? "0" : item.getQualityFlag()); - channelDataIHandler(item3,valueTypes,dto,true); + channelDataIHandler(item3,valueTypes,dto,!Objects.equals(versionUsed, "liaoning")); result.add(dto); }); }); @@ -198,7 +204,7 @@ public class DayDataServiceImpl implements IDayDataService { dto.setPhasicType(item2.getPhasicType()); dto.setValueType(item4.toUpperCase()); dto.setQualityFlag(Objects.equals(item.getQualityFlag(),"null") ? "0" : item.getQualityFlag()); - channelDataFlickerHandler(item3,dto,item4,true); + channelDataFlickerHandler(item3,dto,item4,!Objects.equals(versionUsed, "liaoning")); result.add(dto); }); }); @@ -247,7 +253,7 @@ public class DayDataServiceImpl implements IDayDataService { dto.setPhasicType(item2.getPhasicType()); dto.setValueType(item4.toUpperCase()); dto.setQualityFlag(Objects.equals(item.getQualityFlag(),"null") ? "0" : item.getQualityFlag()); - channelDataFlucHandler(item3,dto,item4,true); + channelDataFlucHandler(item3,dto,item4,!Objects.equals(versionUsed, "liaoning")); result.add(dto); }); }); @@ -296,7 +302,7 @@ public class DayDataServiceImpl implements IDayDataService { dto.setPhasicType(item2.getPhasicType()); dto.setValueType(item3.getValueType().toUpperCase()); dto.setQualityFlag(Objects.equals(item.getQualityFlag(),"null") ? "0" : item.getQualityFlag()); - channelDataHarmPhasicIHandler(item3,valueTypes,dto,true); + channelDataHarmPhasicIHandler(item3,valueTypes,dto,!Objects.equals(versionUsed, "liaoning")); result.add(dto); }); }); @@ -344,7 +350,7 @@ public class DayDataServiceImpl implements IDayDataService { dto.setPhasicType(item2.getPhasicType()); dto.setValueType(item3.getValueType().toUpperCase()); dto.setQualityFlag(Objects.equals(item.getQualityFlag(),"null") ? "0" : item.getQualityFlag()); - channelDataHarmPhasicVHandler(item3,valueTypes,dto,true); + channelDataHarmPhasicVHandler(item3,valueTypes,dto,!Objects.equals(versionUsed, "liaoning")); result.add(dto); }); }); @@ -392,7 +398,7 @@ public class DayDataServiceImpl implements IDayDataService { dto.setPhasicType(item2.getPhasicType()); dto.setValueType(item3.getValueType().toUpperCase()); dto.setQualityFlag(Objects.equals(item.getQualityFlag(),"null") ? "0" : item.getQualityFlag()); - channelDataHarmPowerPHandler(item3,valueTypes,dto,true); + channelDataHarmPowerPHandler(item3,valueTypes,dto,!Objects.equals(versionUsed, "liaoning")); result.add(dto); }); }); @@ -440,7 +446,7 @@ public class DayDataServiceImpl implements IDayDataService { dto.setPhasicType(item2.getPhasicType()); dto.setValueType(item3.getValueType().toUpperCase()); dto.setQualityFlag(Objects.equals(item.getQualityFlag(),"null") ? "0" : item.getQualityFlag()); - channelDataHarmPowerQHandler(item3,valueTypes,dto,true); + channelDataHarmPowerQHandler(item3,valueTypes,dto,!Objects.equals(versionUsed, "liaoning")); result.add(dto); }); }); @@ -488,7 +494,7 @@ public class DayDataServiceImpl implements IDayDataService { dto.setPhasicType(item2.getPhasicType()); dto.setValueType(item3.getValueType().toUpperCase()); dto.setQualityFlag(Objects.equals(item.getQualityFlag(),"null") ? "0" : item.getQualityFlag()); - channelDataHarmPowerSHandler(item3,valueTypes,dto,true); + channelDataHarmPowerSHandler(item3,valueTypes,dto,!Objects.equals(versionUsed, "liaoning")); result.add(dto); }); }); @@ -536,7 +542,7 @@ public class DayDataServiceImpl implements IDayDataService { dto.setPhasicType(item2.getPhasicType()); dto.setValueType(item3.getValueType().toUpperCase()); dto.setQualityFlag(Objects.equals(item.getQualityFlag(),"null") ? "0" : item.getQualityFlag()); - channelDataHarmRateIHandler(item3,valueTypes,dto,true); + channelDataHarmRateIHandler(item3,valueTypes,dto,!Objects.equals(versionUsed, "liaoning")); result.add(dto); }); }); @@ -584,7 +590,7 @@ public class DayDataServiceImpl implements IDayDataService { dto.setPhasicType(item2.getPhasicType()); dto.setValueType(item3.getValueType().toUpperCase()); dto.setQualityFlag(Objects.equals(item.getQualityFlag(),"null") ? "0" : item.getQualityFlag()); - channelDataHarmRateVHandler(item3,valueTypes,dto,true); + channelDataHarmRateVHandler(item3,valueTypes,dto,!Objects.equals(versionUsed, "liaoning")); result.add(dto); }); }); @@ -632,7 +638,7 @@ public class DayDataServiceImpl implements IDayDataService { dto.setPhasicType(item2.getPhasicType()); dto.setValueType(item3.getValueType().toUpperCase()); dto.setQualityFlag(Objects.equals(item.getQualityFlag(),"null") ? "0" : item.getQualityFlag()); - channelDataInHarmIHandler(item3,valueTypes,dto,true); + channelDataInHarmIHandler(item3,valueTypes,dto,!Objects.equals(versionUsed, "liaoning")); result.add(dto); }); }); @@ -680,7 +686,7 @@ public class DayDataServiceImpl implements IDayDataService { dto.setPhasicType(item2.getPhasicType()); dto.setValueType(item3.getValueType().toUpperCase()); dto.setQualityFlag(Objects.equals(item.getQualityFlag(),"null") ? "0" : item.getQualityFlag()); - channelDataInHarmVHandler(item3,valueTypes,dto,true); + channelDataInHarmVHandler(item3,valueTypes,dto,!Objects.equals(versionUsed, "liaoning")); result.add(dto); }); }); @@ -728,7 +734,7 @@ public class DayDataServiceImpl implements IDayDataService { dto.setPhasicType(item2.getPhasicType()); dto.setValueType(item4.toUpperCase()); dto.setQualityFlag(Objects.equals(item.getQualityFlag(),"null") ? "0" : item.getQualityFlag()); - channelDataPltHandler(item3,dto,item4,true); + channelDataPltHandler(item3,dto,item4,!Objects.equals(versionUsed, "liaoning")); result.add(dto); }); }); @@ -1549,23 +1555,20 @@ public class DayDataServiceImpl implements IDayDataService { valueType = valueType.toUpperCase(); if (scheme) { switch (valueType) { - case InfluxDbSqlConstant.MAX: - case InfluxDbSqlConstant.CP95: + case "MAX": + case "CP95": Optional max = list.stream().filter(Objects::nonNull).max(Double::compare); -// result = max.orElse(null); result = max.orElse(0.0); break; - case InfluxDbSqlConstant.MIN: + case "MIN": Optional min = list.stream().filter(Objects::nonNull).min(Double::compare); -// result = min.orElse(null); result = min.orElse(0.0); break; - case InfluxDbSqlConstant.AVG_WEB: + case "AVG": OptionalDouble average = list.stream() .filter(Objects::nonNull) .mapToDouble(Double::doubleValue) .average(); -// result = average.isPresent() ? average.getAsDouble() : null; result = average.isPresent() ? average.getAsDouble() : 0.0; break; default: @@ -1573,29 +1576,42 @@ public class DayDataServiceImpl implements IDayDataService { } } else { switch (valueType) { - case InfluxDbSqlConstant.MAX: + case "MAX": Optional max = list.stream().filter(Objects::nonNull).max(Double::compare); -// result = max.orElse(null); result = max.orElse(0.0); break; - case InfluxDbSqlConstant.MIN: + case "MIN": Optional min = list.stream().filter(Objects::nonNull).min(Double::compare); -// result = min.orElse(null); result = min.orElse(0.0); break; - case InfluxDbSqlConstant.AVG_WEB: + case "AVG": OptionalDouble average = list.stream() .filter(Objects::nonNull) .mapToDouble(Double::doubleValue) .average(); -// result = average.isPresent() ? average.getAsDouble() : null; result = average.isPresent() ? average.getAsDouble() : 0.0; break; - case InfluxDbSqlConstant.CP95: - list.sort(Collections.reverseOrder()); - int discardCount = (int) Math.ceil(list.size() * 0.05); - List remainingList = list.subList(discardCount, list.size()); -// result = remainingList.isEmpty() ? null : remainingList.get(0); + case "CP95": + if (list == null || list.isEmpty()) { + result = 0.0; + break; + } + // 过滤掉 null 元素 + List filteredList = list.stream() + .filter(Objects::nonNull) + .collect(Collectors.toList()); + + if (filteredList.isEmpty()) { + result = 0.0; + break; + } + filteredList.sort(Collections.reverseOrder()); + int discardCount = (int) Math.ceil(filteredList.size() * 0.05); + if (discardCount >= filteredList.size()) { + result = 0.0; + break; + } + List remainingList = filteredList.subList(discardCount, filteredList.size()); result = remainingList.isEmpty() ? 0.0 : remainingList.get(0); break; default: @@ -1610,4 +1626,28 @@ public class DayDataServiceImpl implements IDayDataService { return result; } + /** + * 将平均值赋值给 CP95 + */ + public void putCP95ByAvg(List list) { + list.forEach(po1->{ + List phasicTypeList = po1.getPhasicTypeList(); + phasicTypeList.forEach(po2 -> { + List valueTypeList = po2.getValueTypeList(); + AtomicReference>> valueList = new AtomicReference<>(new ArrayList<>()); + valueTypeList.forEach(po3 -> { + if (po3.getValueType().equals(InfluxDbSqlConstant.AVG_WEB)) { + valueList.set(po3.getValueList()); + } + if (po3.getValueType().equals(InfluxDbSqlConstant.CP95)) { + po3.setValueList((List>) valueList); + } + }); + }); + }); + } + + + + } \ No newline at end of file diff --git a/algorithm/algorithm-boot/src/main/java/com/njcn/algorithm/serviceimpl/line/IDataLimitRateAsyncImpl.java b/algorithm/algorithm-boot/src/main/java/com/njcn/algorithm/serviceimpl/line/IDataLimitRateAsyncImpl.java index 437c822..7bf1a81 100644 --- a/algorithm/algorithm-boot/src/main/java/com/njcn/algorithm/serviceimpl/line/IDataLimitRateAsyncImpl.java +++ b/algorithm/algorithm-boot/src/main/java/com/njcn/algorithm/serviceimpl/line/IDataLimitRateAsyncImpl.java @@ -18,6 +18,7 @@ import com.njcn.influx.pojo.constant.InfluxDBTableConstant; import lombok.extern.slf4j.Slf4j; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; @@ -53,6 +54,11 @@ public class IDataLimitRateAsyncImpl implements IDataLimitRateAsync { private DataLimitRateFeignClient dataLimitRateFeignClient; @Resource private DataLimitRateDetailFeignClient dataLimitRateDetailFeignClient; + /** + * 查询配置 辽宁版本比较特殊,没有CP95值,采用平均值进行判断 + */ + @Value("${version.used:master}") + private String versionUsed; @Override @@ -80,6 +86,7 @@ public class IDataLimitRateAsyncImpl implements IDataLimitRateAsync { List dataVInHarmList = dataInharmVFeignClient.getRawData(lineParam).getData(); //电流数据 List dataIList = dataIFeignClient.getRawData(lineParam).getData(); + /** * 功能描述:获取influxDB -> data_v -> * 总计算次数(用data_v中phasic_type=A,value_type=avg,quality_flag=0来参与统计) @@ -122,53 +129,109 @@ public class IDataLimitRateAsyncImpl implements IDataLimitRateAsync { *功能描述:获取influxDB -> data_harmrate_v -> * 2-25次谐波电压含有率 -> A相||B相||C相的日95%概率值 */ - Map> harmRateV = dataVHarmList.stream() - .filter(x -> phase.contains(x.getPhasicType())) - .filter(x -> InfluxDBTableConstant.CP95.equalsIgnoreCase(x.getValueType())) - .collect(Collectors.groupingBy(DataHarmDto::getLineId)); + Map> harmRateV; + if (Objects.equals(versionUsed, "liaoning")) { + harmRateV = dataVHarmList.stream() + .filter(x -> phase.contains(x.getPhasicType())) + .filter(x -> InfluxDBTableConstant.AVG.equalsIgnoreCase(x.getValueType())) + .peek(x -> x.setValueType(InfluxDBTableConstant.CP95)) + .collect(Collectors.groupingBy(DataHarmDto::getLineId)); + } else { + harmRateV = dataVHarmList.stream() + .filter(x -> phase.contains(x.getPhasicType())) + .filter(x -> InfluxDBTableConstant.CP95.equalsIgnoreCase(x.getValueType())) + .collect(Collectors.groupingBy(DataHarmDto::getLineId)); + } /** * 功能描述:获取influxDB -> data_i -> 2-25次谐波电流 -> 日95%概率值 */ - Map> dataI = dataIList.stream() - .filter(x -> phase.contains(x.getPhasicType())) - .filter(x -> InfluxDBTableConstant.CP95.equalsIgnoreCase(x.getValueType())) - .collect(Collectors.groupingBy(DataIDto::getLineId)); - + Map> dataI; + if (Objects.equals(versionUsed, "liaoning")) { + dataI = dataIList.stream() + .filter(x -> phase.contains(x.getPhasicType())) + .filter(x -> InfluxDBTableConstant.AVG.equalsIgnoreCase(x.getValueType())) + .peek(x -> x.setValueType(InfluxDBTableConstant.CP95)) + .collect(Collectors.groupingBy(DataIDto::getLineId)); + } else { + dataI = dataIList.stream() + .filter(x -> phase.contains(x.getPhasicType())) + .filter(x -> InfluxDBTableConstant.CP95.equalsIgnoreCase(x.getValueType())) + .collect(Collectors.groupingBy(DataIDto::getLineId)); + } /** * 功能描述:获取influxDB -> data_inharm_v -> 0.5-15.5次间谐波电压含有率 -> 日95%概率值 */ - Map> inHarmV = dataVInHarmList.stream() - .filter(x -> phase.contains(x.getPhasicType())) - .filter(x -> InfluxDBTableConstant.CP95.equalsIgnoreCase(x.getValueType())) - .collect(Collectors.groupingBy(DataHarmDto::getLineId)); + Map> inHarmV; + if (Objects.equals(versionUsed, "liaoning")) { + inHarmV = dataVInHarmList.stream() + .filter(x -> phase.contains(x.getPhasicType())) + .filter(x -> InfluxDBTableConstant.AVG.equalsIgnoreCase(x.getValueType())) + .peek(x -> x.setValueType(InfluxDBTableConstant.CP95)) + .collect(Collectors.groupingBy(DataHarmDto::getLineId)); + } else { + inHarmV = dataVInHarmList.stream() + .filter(x -> phase.contains(x.getPhasicType())) + .filter(x -> InfluxDBTableConstant.CP95.equalsIgnoreCase(x.getValueType())) + .collect(Collectors.groupingBy(DataHarmDto::getLineId)); + } /** * 功能描述:获取influxDB -> data_v -> 电压总谐波畸变率 -> 日95%概率值 */ - Map> dataVThd = dataVAllTime.stream() - .filter(x -> phase.contains(x.getPhasicType())) - .filter(x -> InfluxDBTableConstant.CP95.equalsIgnoreCase(x.getValueType())) - .collect(Collectors.groupingBy(DataVDto::getLineId)); + Map> dataVThd; + if (Objects.equals(versionUsed, "liaoning")) { + dataVThd = dataVAllTime.stream() + .filter(x -> phase.contains(x.getPhasicType())) + .filter(x -> InfluxDBTableConstant.AVG.equalsIgnoreCase(x.getValueType())) + .peek(x -> x.setValueType(InfluxDBTableConstant.CP95)) + .collect(Collectors.groupingBy(DataVDto::getLineId)); + } else { + dataVThd = dataVAllTime.stream() + .filter(x -> phase.contains(x.getPhasicType())) + .filter(x -> InfluxDBTableConstant.CP95.equalsIgnoreCase(x.getValueType())) + .collect(Collectors.groupingBy(DataVDto::getLineId)); + } /** * 功能描述:获取influxDB -> data_v -> 负序电压不平衡度 -> 最大值 && 日95%概率值 */ - Map> dataVUnbalance = dataVAllTime.stream() - .filter(x -> InfluxDBTableConstant.PHASE_TYPE_T.equalsIgnoreCase(x.getPhasicType())) - .filter(x -> InfluxDBTableConstant.CP95.equalsIgnoreCase(x.getValueType()) || - InfluxDBTableConstant.MAX.equalsIgnoreCase(x.getValueType())) - .collect(Collectors.groupingBy(DataVDto::getLineId)); + Map> dataVUnbalance; + if (Objects.equals(versionUsed, "liaoning")) { + dataVUnbalance = dataVAllTime.stream() + .filter(x -> InfluxDBTableConstant.PHASE_TYPE_T.equalsIgnoreCase(x.getPhasicType())) + .filter(x -> InfluxDBTableConstant.AVG.equalsIgnoreCase(x.getValueType()) || + InfluxDBTableConstant.MAX.equalsIgnoreCase(x.getValueType())) + .peek(x -> x.setValueType(InfluxDBTableConstant.CP95)) + .collect(Collectors.groupingBy(DataVDto::getLineId)); + } else { + dataVUnbalance = dataVAllTime.stream() + .filter(x -> InfluxDBTableConstant.PHASE_TYPE_T.equalsIgnoreCase(x.getPhasicType())) + .filter(x -> InfluxDBTableConstant.CP95.equalsIgnoreCase(x.getValueType()) || + InfluxDBTableConstant.MAX.equalsIgnoreCase(x.getValueType())) + .collect(Collectors.groupingBy(DataVDto::getLineId)); + } /** * 功能描述:获取influxDB -> data_i -> 负序电流 -> 最大值 && 日95%概率值 */ - Map> dataINeg = dataIList.stream() - .filter(x -> InfluxDBTableConstant.PHASE_TYPE_T.equalsIgnoreCase(x.getPhasicType())) - .filter(x -> InfluxDBTableConstant.CP95.equalsIgnoreCase(x.getValueType()) || - InfluxDBTableConstant.MAX.equalsIgnoreCase(x.getValueType())) - .collect(Collectors.groupingBy(DataIDto::getLineId)); + + Map> dataINeg; + if (Objects.equals(versionUsed, "liaoning")) { + dataINeg = dataIList.stream() + .filter(x -> InfluxDBTableConstant.PHASE_TYPE_T.equalsIgnoreCase(x.getPhasicType())) + .filter(x -> InfluxDBTableConstant.AVG.equalsIgnoreCase(x.getValueType()) || + InfluxDBTableConstant.MAX.equalsIgnoreCase(x.getValueType())) + .peek(x -> x.setValueType(InfluxDBTableConstant.CP95)) + .collect(Collectors.groupingBy(DataIDto::getLineId)); + } else { + dataINeg = dataIList.stream() + .filter(x -> InfluxDBTableConstant.PHASE_TYPE_T.equalsIgnoreCase(x.getPhasicType())) + .filter(x -> InfluxDBTableConstant.CP95.equalsIgnoreCase(x.getValueType()) || + InfluxDBTableConstant.MAX.equalsIgnoreCase(x.getValueType())) + .collect(Collectors.groupingBy(DataIDto::getLineId)); + } /** * 功能描述:获取influxDB -> data_v -> 频率偏差 -> 最大值 && 最小值 @@ -307,9 +370,6 @@ public class IDataLimitRateAsyncImpl implements IDataLimitRateAsync { result.add(c); result.add(t); - - - return result; }