指标越限概率分布功能优化

This commit is contained in:
xy
2026-02-09 11:25:52 +08:00
parent bd1fb82532
commit 6e0a36fd80
3 changed files with 196 additions and 38 deletions

View File

@@ -98,6 +98,7 @@ class IcdServiceImpl implements IcdService {
detail.setDevType(Objects.isNull(finalSysDicTreeMap.get(dev.getDevModel())) ? "/":finalSysDicTreeMap.get(dev.getDevModel()).getCode());
detail.setNode(dev.getNodeProcess());
detail.setMaxProcessNum(node.getMaxProcessNum());
detail.setDevLogLevel(dev.getDevLogLevel());
// 只获取当前设备的监测点数据
List<CsLinePO> lines = lineMap.get(dev.getId());
@@ -116,6 +117,7 @@ class IcdServiceImpl implements IcdService {
monitorInfo.setPt2(line.getPt2Ratio());
monitorInfo.setCt1(line.getCtRatio());
monitorInfo.setCt2(line.getCt2Ratio());
monitorInfo.setLineLogLevel(line.getLineLogLevel());
monitorInfos.add(monitorInfo);
});
detail.setMonitorData(monitorInfos);

View File

@@ -1,6 +1,7 @@
package com.njcn.csharmonic.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.lang.Pair;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
@@ -34,6 +35,7 @@ import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.time.LocalDate;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
@DS("sjzx")
@@ -278,10 +280,69 @@ public class RStatLimitRateDetailDServiceImpl extends ServiceImpl<RStatLimitRate
);
CsLinePO linePO = csLineFeignClient.getById(param.getLineId()).getData();
List<Overlimit> overlimitList = overLimitClient.getOverLimitByLineIds(Collections.singletonList(linePO.getLineId())).getData();
JSONObject overlimitJSON = null;
JSONObject overlimitJSON;
if (CollUtil.isNotEmpty(overlimitList)) {
overlimitJSON = JSONUtil.parseObj(overlimitList.get(0));
} else {
overlimitJSON = null;
}
//按日期获取各个指标最大值
Map<LocalDate, List<RStatLimitRateDetailDPO>> detailMap = detailList.stream().sorted(Comparator.comparing(RStatLimitRateDetailDPO::getTime)).collect(Collectors.groupingBy(RStatLimitRateDetailDPO::getTime));
Map<LocalDate, Map<String,Float>> maxValueMapByDay = new HashMap<>();
detailMap.forEach((k,v)->{
Map<String, Pair<Float, RStatLimitRateDetailDPO>> maxValueMap = findMaxValueHandle(v);
Map<String,Float> m1 = new HashMap<>();
maxValueMap.forEach((k1,v1)->{
m1.put(k1,v1.getKey());
});
Map<String,Float> m2 = new HashMap<>();
m1.forEach((k1,v1)->{
double extentValue = 0;
if (k1.startsWith("uharm") && k1.endsWith("Overtime")) {
String d1 = k1.replaceAll("([a-zA-Z]+)(\\d+)(.*)", "$1$2");
String d2 = k1.replaceAll("([a-zA-Z]+)(\\d+)(.*)", "$1");
assert overlimitJSON != null;
double limitValue = overlimitJSON.getDouble(d1);
extentValue = calculatePercentage(v1.doubleValue() - limitValue, limitValue);
m2.put(d2,(float) extentValue);
} else if (k1.startsWith("iharm") && k1.endsWith("Overtime")) {
String d1 = k1.replaceAll("([a-zA-Z]+)(\\d+)(.*)", "$1$2");
String d2 = k1.replaceAll("([a-zA-Z]+)(\\d+)(.*)", "$1");
assert overlimitJSON != null;
double limitValue = overlimitJSON.getDouble(d1);
extentValue = calculatePercentage(v1.doubleValue() - limitValue, limitValue);
m2.put(d2,(float) extentValue);
} else {
if (v1.doubleValue() != 0.0) {
assert overlimitJSON != null;
double limitValue = overlimitJSON.getDouble(k1);
extentValue = calculatePercentage(v1.doubleValue() - limitValue, limitValue);
}
m2.put(k1,(float) extentValue);
}
});
Float f1 = m2.get("uharm");
Float f2 = m2.get("uaberrance");
m2.remove("uharm");
m2.remove("uaberrance");
m2.put("uharm",Math.max(f1,f2));
maxValueMapByDay.put(k,m2);
});
// 确保 extentMap 初始化为线程安全的 ConcurrentHashMap
Map<String, List<Float>> extentMap = new ConcurrentHashMap<>();
maxValueMapByDay.forEach((dayKey, dayValues) -> {
dayValues.forEach((key, value) -> {
// 获取当前 key 对应的列表,若不存在则初始化为空列表
List<Float> list = extentMap.computeIfAbsent(key, k -> new ArrayList<>());
// 直接添加值到列表中
if (value > 0.0) {
list.add(value);
}
});
});
LimitProbabilityVO probabilityVO;
for (Map.Entry<String, String> indexEntry : indexMap.entrySet()) {
String indexCode = indexEntry.getKey();
@@ -290,33 +351,21 @@ public class RStatLimitRateDetailDServiceImpl extends ServiceImpl<RStatLimitRate
probabilityVO.setIndexCode(indexCode);
probabilityVO.setLineId(linePO.getLineId());
probabilityVO.setLineName(linePO.getName());
// 计算越限程度
List<Double> extentValuesList = new ArrayList<>();
for (RStatLimitRateDetailDPO detail : detailList) {
JSONObject entries = JSONUtil.parseObj(detail);
for (Map.Entry<String, Object> dayEntry : entries.entrySet()) {
String key = dayEntry.getKey();
if (shouldProcess(key, indexCode)) {
double extentValue = 0;
Object data = dayEntry.getValue();
if (ObjectUtil.isNotEmpty(data) && overlimitJSON != null) {
float maxValue = parseMaxValueFromJsonArray(data);
String itemKey = StrUtil.sub(key, 0, key.length() - 8);
double limitValue = overlimitJSON.getDouble(itemKey);
if (limitValue != 0) {
extentValue = calculatePercentage(maxValue - limitValue, limitValue);
}
}
extentValuesList.add(extentValue);
}
}
}
List<Map<Integer, Integer>> extentGrades = new ArrayList<>();
for (int i = 0; i < extentPeriodList.size(); i++) {
Map<Integer, Integer> grade = new HashMap<>();
int times = 0;
for (Double extentValue : extentValuesList) {
List<Map<Integer, Integer>> extentGrades = getFenBu(extentMap.get(indexCode));
probabilityVO.setExtentGrades(extentGrades);
result.add(probabilityVO);
}
return result;
}
public List<Map<Integer, Integer>> getFenBu(List<Float> data) {
List<Map<Integer, Integer>> result = new ArrayList<>();
for (int i = 0; i < extentPeriodList.size(); i++) {
Map<Integer, Integer> grade = new HashMap<>();
int times = 0;
if (CollectionUtil.isNotEmpty(data)) {
for (Float extentValue : data) {
List<Integer> period = extentPeriodList.get(i);
Integer start = period.get(0);
Integer end = period.get(1);
@@ -327,15 +376,84 @@ public class RStatLimitRateDetailDServiceImpl extends ServiceImpl<RStatLimitRate
times++;
}
}
grade.put(i, times);
extentGrades.add(grade);
}
probabilityVO.setExtentGrades(extentGrades);
result.add(probabilityVO);
grade.put(i, times);
result.add(grade);
}
return result;
}
// @Override
// public List<LimitProbabilityVO> limitProbabilityData(LimitProbabilityQueryParam param) {
// List<LimitProbabilityVO> result = new ArrayList<>();
// List<RStatLimitRateDetailDPO> detailList = this.list(new LambdaQueryWrapper<RStatLimitRateDetailDPO>()
// .eq(RStatLimitRateDetailDPO::getLineId, param.getLineId())
// .ge(StrUtil.isNotBlank(param.getSearchBeginTime()), RStatLimitRateDetailDPO::getTime, param.getSearchBeginTime())
// .le(StrUtil.isNotBlank(param.getSearchEndTime()), RStatLimitRateDetailDPO::getTime, param.getSearchEndTime())
// .orderByAsc(RStatLimitRateDetailDPO::getTime)
// );
// CsLinePO linePO = csLineFeignClient.getById(param.getLineId()).getData();
// List<Overlimit> overlimitList = overLimitClient.getOverLimitByLineIds(Collections.singletonList(linePO.getLineId())).getData();
// JSONObject overlimitJSON = null;
// if (CollUtil.isNotEmpty(overlimitList)) {
// overlimitJSON = JSONUtil.parseObj(overlimitList.get(0));
// }
// LimitProbabilityVO probabilityVO;
// for (Map.Entry<String, String> indexEntry : indexMap.entrySet()) {
// String indexCode = indexEntry.getKey();
// probabilityVO = new LimitProbabilityVO();
// probabilityVO.setIndexName(indexEntry.getValue());
// probabilityVO.setIndexCode(indexCode);
// probabilityVO.setLineId(linePO.getLineId());
// probabilityVO.setLineName(linePO.getName());
// // 计算越限程度
// List<Double> extentValuesList = new ArrayList<>();
// for (RStatLimitRateDetailDPO detail : detailList) {
// JSONObject entries = JSONUtil.parseObj(detail);
// for (Map.Entry<String, Object> dayEntry : entries.entrySet()) {
// String key = dayEntry.getKey();
// if (shouldProcess(key, indexCode)) {
// double extentValue = 0;
// Object data = dayEntry.getValue();
// if (ObjectUtil.isNotEmpty(data) && overlimitJSON != null) {
// float maxValue = parseMaxValueFromJsonArray(data);
// String itemKey = StrUtil.sub(key, 0, key.length() - 8);
// double limitValue = overlimitJSON.getDouble(itemKey);
// if (limitValue != 0) {
// extentValue = calculatePercentage(maxValue - limitValue, limitValue);
// }
// }
// extentValuesList.add(extentValue);
// }
// }
//
// }
// List<Map<Integer, Integer>> extentGrades = new ArrayList<>();
// for (int i = 0; i < extentPeriodList.size(); i++) {
// Map<Integer, Integer> grade = new HashMap<>();
// int times = 0;
// for (Double extentValue : extentValuesList) {
// List<Integer> period = extentPeriodList.get(i);
// Integer start = period.get(0);
// Integer end = period.get(1);
// if (extentValue > start && extentValue <= end) {
// times++;
// }
// if ((i == extentPeriodList.size() - 1) && extentValue > 100.0) {
// times++;
// }
// }
// grade.put(i, times);
// extentGrades.add(grade);
// }
// probabilityVO.setExtentGrades(extentGrades);
// result.add(probabilityVO);
// }
// return result;
// }
private boolean shouldProcess(String key, String indexCode) {
return (key.endsWith("Overtime") && key.startsWith(indexCode)) ||
(Objects.equals(indexCode, "uharm") && key.startsWith("uaberrance"));
@@ -435,20 +553,34 @@ public class RStatLimitRateDetailDServiceImpl extends ServiceImpl<RStatLimitRate
RStatLimitRateDetailDPO voltageDevMaxDetail = null;
float voltageDevMaxValue = 0.0000F;
RStatLimitRateDetailDPO ubalanceMaxDetail = null;
float ubalanceMaxValue = 0.0000F;
RStatLimitRateDetailDPO uaberranceMaxDetail = null;
float uaberranceMaxValue = 0.0000F;
RStatLimitRateDetailDPO freqDevMaxDetail = null;
float freqDevMaxValue = 0.0000F;
RStatLimitRateDetailDPO uharmMaxDetail = null;
float uharmMaxValue = 0.0000F;
String uharmMaxKey = ""; // 记录uharm最大值对应的key
// 记录uharm最大值对应的key
String uharmMaxKey = "";
RStatLimitRateDetailDPO iharmMaxDetail = null;
float iharmMaxValue = 0.0000F;
String iharmMaxKey = ""; // 记录iharm最大值对应的key
// 记录iharm最大值对应的key
String iharmMaxKey = "";
for (RStatLimitRateDetailDPO po : detailList) {
String flickerOvertime = po.getFlickerOvertime();
String voltageDevOvertime = po.getVoltageDevOvertime();
String ubalanceOvertime = po.getUbalanceOvertime();
String uaberranceOvertime = po.getUaberranceOvertime();
String freqDevOvertime = po.getFreqDevOvertime();
if (StrUtil.isNotBlank(flickerOvertime)) {
float dayFlickerMaxValue = parseMaxValueFromJsonArray(flickerOvertime);
if (dayFlickerMaxValue > flickerMaxValue) {
@@ -470,11 +602,30 @@ public class RStatLimitRateDetailDServiceImpl extends ServiceImpl<RStatLimitRate
ubalanceMaxDetail = po;
}
}
if (StrUtil.isNotBlank(uaberranceOvertime)) {
float dayuaberranceMaxValue = parseMaxValueFromJsonArray(uaberranceOvertime);
if (dayuaberranceMaxValue > uaberranceMaxValue) {
uaberranceMaxValue = dayuaberranceMaxValue;
uaberranceMaxDetail = po;
}
}
if (StrUtil.isNotBlank(freqDevOvertime)) {
float dayFreqDevMaxValue = parseMaxValueFromJsonArray(freqDevOvertime);
if (dayFreqDevMaxValue > freqDevMaxValue) {
freqDevMaxValue = dayFreqDevMaxValue;
freqDevMaxDetail = po;
}
}
JSONObject entries = JSONUtil.parseObj(po);
float dayUharmMaxValue = 0.0000F;
String dayUharmMaxKey = ""; // 当前记录中uharm的最大值key
// 当前记录中uharm的最大值key
String dayUharmMaxKey = "";
float dayIharmMaxValue = 0.0000F;
String dayIharmMaxKey = ""; // 当前记录中iharm的最大值key
// 当前记录中iharm的最大值key
String dayIharmMaxKey = "";
for (Map.Entry<String, Object> entry : entries.entrySet()) {
String key = entry.getKey();
@@ -502,17 +653,21 @@ public class RStatLimitRateDetailDServiceImpl extends ServiceImpl<RStatLimitRate
if (dayUharmMaxValue > uharmMaxValue) {
uharmMaxValue = dayUharmMaxValue;
uharmMaxDetail = po;
uharmMaxKey = dayUharmMaxKey; // 记录产生最大值的key
// 记录产生最大值的key
uharmMaxKey = dayUharmMaxKey;
}
if (dayIharmMaxValue > iharmMaxValue) {
iharmMaxValue = dayIharmMaxValue;
iharmMaxDetail = po;
iharmMaxKey = dayIharmMaxKey; // 记录产生最大值的key
// 记录产生最大值的key
iharmMaxKey = dayIharmMaxKey;
}
}
result.put("flicker", Pair.of(flickerMaxValue, flickerMaxDetail));
result.put("voltageDev", Pair.of(voltageDevMaxValue, voltageDevMaxDetail));
result.put("ubalance", Pair.of(ubalanceMaxValue, ubalanceMaxDetail));
result.put("uaberrance", Pair.of(uaberranceMaxValue, uaberranceMaxDetail));
result.put("freqDev", Pair.of(freqDevMaxValue, freqDevMaxDetail));
result.put(uharmMaxKey.isEmpty() ? "uharm" : uharmMaxKey, Pair.of(uharmMaxValue, uharmMaxDetail));
result.put(iharmMaxKey.isEmpty() ? "iharm" : iharmMaxKey, Pair.of(iharmMaxValue, iharmMaxDetail));

View File

@@ -137,7 +137,8 @@ public class StatisticsDataDataServiceImpl implements IStatisticsDataDataService
vo.setOperationalTime(dev.getCreateTime());
vo.setOperationalStatus(dev.getUsageStatus() == 0 ? "停运" : "在运");
if (Objects.equals(line.getName(),"治理监测点")) {
vo.setLineName(line.getName() + "(" + map.get(dev.getId()).getModuleNumber() + "模块)");
int moduleNumber = Objects.isNull(map.get(dev.getId()).getModuleNumber()) ? 0 : map.get(dev.getId()).getModuleNumber();
vo.setLineName(line.getName() + "(" + moduleNumber + "模块)");
} else {
vo.setLineName(line.getName());
}