Commit db2eabb5 authored by caotao's avatar caotao

1.优化健康指数按照时刻生成预计记录的效率

parent 3f7ae5d3
......@@ -1286,9 +1286,7 @@ public class CommonServiceImpl {
queryBuilder.should(QueryBuilders.wildcardQuery(key, shouldQuerCondtion.get(key)));
}
}
Query query = new NativeSearchQueryBuilder()
.withQuery(queryBuilder)
.build();
Query query = new NativeSearchQueryBuilder().withQuery(queryBuilder).build();
query.setTrackTotalHits(true);
SearchHits search = elasticsearchTemplate.search(query, tClass);
if (search.hasSearchHits()) {
......@@ -1452,8 +1450,8 @@ public class CommonServiceImpl {
}
// @Scheduled(cron = "0 0/10 * * * ?")
@Async("async")
// @Scheduled(cron = "0 0/10 * * * ?")
// @Async("async")
public void healthWarningMinuteByFan() {
if (!openHealth) {
......@@ -1461,7 +1459,7 @@ public class CommonServiceImpl {
}
String format = DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:00");
Date time = DateUtil.parse(format, "yyyy-MM-dd HH:mm:00");
logger.info("风机---------------------健康指数时间----"+time);
logger.info("风机---------------------健康指数时间----" + time);
Calendar calendar = Calendar.getInstance();
List<IdxBizFanPointProcessVariableClassificationDto> data = idxBizFanPointProcessVariableClassificationMapper.getInfluxDBData();
Map<String, List<IdxBizFanPointProcessVariableClassificationDto>> maps = data.stream().collect(Collectors.groupingBy(IdxBizFanPointProcessVariableClassificationDto::getGatewayId));
......@@ -1512,11 +1510,16 @@ public class CommonServiceImpl {
// // TODO: handle exception
// }
// }
Map<String, Float> indicatorDataListAllMap = indicatorDataListAll.stream().collect(Collectors.toMap(indicatorData -> indicatorData.getAddress() +"_"+ indicatorData.getGatewayId(), IndicatorData::getValueF));
Map<String, Float> indicatorDataListAllMap = indicatorDataListAll.stream().collect(Collectors.toMap(indicatorData -> indicatorData.getAddress() + "_" + indicatorData.getGatewayId(), IndicatorData::getValueF));
//将测点id与值处理成map
HashMap<String, Double> idxBizFanPointProcessVariableClassificationDtoIdValueMap = new HashMap<>();
for (IdxBizFanPointProcessVariableClassificationDto datum : data) {
Double currentValue = Double.valueOf(indicatorDataListAllMap.get(datum.getIndexAddress() + "_" + datum.getGatewayId()));
if (!ObjectUtils.isEmpty(currentValue)) {
datum.setCurrentValue(currentValue);
idxBizFanPointProcessVariableClassificationDtoIdValueMap.put(datum.getSequenceNbr(), currentValue);
} else {
idxBizFanPointProcessVariableClassificationDtoIdValueMap.put(datum.getSequenceNbr(), 0.0);
}
// for (ESEquipments equipment : equipments) {
// if (equipment.getAddress().equals(datum.getIndexAddress()) && equipment.getGatewayId().equals(datum.getGatewayId())) {
......@@ -1545,31 +1548,53 @@ public class CommonServiceImpl {
List<String> ProcessPoint2Id = new ArrayList<>();
List<String> ProcessPoint3Id = new ArrayList<>();
List<String> analysisVariableIds = new ArrayList<>();
for (IdxBizFanPointVarCentralValue idxBizUhef : idxBizUhefs) {
double value1 = 0.00;
double value2 = 0.00;
double value3 = 0.00;
double value4 = 0.00;
for (IdxBizFanPointProcessVariableClassificationDto datum : data) {
if (idxBizUhef.getProcessPoint1Id().equals(datum.getSequenceNbr())) {
value1 = datum.getCurrentValue() == null ? 0.0 : datum.getCurrentValue();
idxBizUhefs.forEach(idxBizFanPointVarCentralValue -> {
if (ObjectUtils.isEmpty(idxBizFanPointVarCentralValue.getProcess1Min())) {
idxBizFanPointVarCentralValue.setProcess1Min(Double.NEGATIVE_INFINITY);
}
if (idxBizUhef.getProcessPoint2Id().equals(datum.getSequenceNbr())) {
value2 = datum.getCurrentValue() == null ? 0.0 : datum.getCurrentValue();
if (ObjectUtils.isEmpty(idxBizFanPointVarCentralValue.getProcess2Min())) {
idxBizFanPointVarCentralValue.setProcess2Min(Double.NEGATIVE_INFINITY);
}
if (idxBizUhef.getProcessPoint3Id().equals(datum.getSequenceNbr())) {
value3 = datum.getCurrentValue() == null ? 0.0 : datum.getCurrentValue();
if (ObjectUtils.isEmpty(idxBizFanPointVarCentralValue.getProcess3Min())) {
idxBizFanPointVarCentralValue.setProcess3Min(Double.NEGATIVE_INFINITY);
}
if (idxBizUhef.getAnalysisPointId().equals(datum.getSequenceNbr())) {
value4 = datum.getCurrentValue() == null ? 0.0 : datum.getCurrentValue();
if (ObjectUtils.isEmpty(idxBizFanPointVarCentralValue.getProcess1Max())) {
idxBizFanPointVarCentralValue.setProcess1Max(Double.POSITIVE_INFINITY);
}
if (ObjectUtils.isEmpty(idxBizFanPointVarCentralValue.getPorcess2Max())) {
idxBizFanPointVarCentralValue.setPorcess2Max(Double.POSITIVE_INFINITY);
}
if ((null == idxBizUhef.getProcess1Min() || idxBizUhef.getProcess1Min() <= value1) && (null == idxBizUhef.getProcess1Max() || value1 <= idxBizUhef.getProcess1Max())
&& (null == idxBizUhef.getProcess2Min() || idxBizUhef.getProcess2Min() <= value2) && (null == idxBizUhef.getPorcess2Max() || value2 <= idxBizUhef.getPorcess2Max())
&& (null == idxBizUhef.getProcess3Min() || idxBizUhef.getProcess3Min() <= value3) && (null == idxBizUhef.getProcess3Max() || value3 <= idxBizUhef.getProcess3Max())) {
if (ObjectUtils.isEmpty(idxBizFanPointVarCentralValue.getProcess3Max())) {
idxBizFanPointVarCentralValue.setProcess3Max(Double.POSITIVE_INFINITY);
}
});
for (IdxBizFanPointVarCentralValue idxBizUhef : idxBizUhefs) {
double value1 = 0.00;
double value2 = 0.00;
double value3 = 0.00;
double value4 = 0.00;
// for (IdxBizFanPointProcessVariableClassificationDto datum : data) {
// if (idxBizUhef.getProcessPoint1Id().equals(datum.getSequenceNbr())) {
// value1 = datum.getCurrentValue() == null ? 0.0 : datum.getCurrentValue();
// }
// if (idxBizUhef.getProcessPoint2Id().equals(datum.getSequenceNbr())) {
// value2 = datum.getCurrentValue() == null ? 0.0 : datum.getCurrentValue();
// }
// if (idxBizUhef.getProcessPoint3Id().equals(datum.getSequenceNbr())) {
// value3 = datum.getCurrentValue() == null ? 0.0 : datum.getCurrentValue();
// }
// if (idxBizUhef.getAnalysisPointId().equals(datum.getSequenceNbr())) {
// value4 = datum.getCurrentValue() == null ? 0.0 : datum.getCurrentValue();
// }
// }
value1 = idxBizFanPointProcessVariableClassificationDtoIdValueMap.get(idxBizUhef.getProcessPoint1Id());
value2 = idxBizFanPointProcessVariableClassificationDtoIdValueMap.get(idxBizUhef.getProcessPoint2Id());
value3 = idxBizFanPointProcessVariableClassificationDtoIdValueMap.get(idxBizUhef.getProcessPoint3Id());
value4 = idxBizFanPointProcessVariableClassificationDtoIdValueMap.get(idxBizUhef.getAnalysisPointId());
if (
idxBizUhef.getProcess1Min() <= value1 && value1 <= idxBizUhef.getProcess1Max()
&& idxBizUhef.getProcess2Min() <= value2 && value2 <= idxBizUhef.getPorcess2Max()
&& idxBizUhef.getProcess3Min() <= value3 && value3 <= idxBizUhef.getProcess3Max()) {
if (!analysisVariableIdList.contains(idxBizUhef.getAnalysisPointId())) {
analysisVariableList.add(value4);
analysisVariable.add(value4);
......@@ -1601,16 +1626,7 @@ public class CommonServiceImpl {
requestMap.put("analysisVariableId", analysisVariableIdList);
Table healthData = Table.create("healthData");
healthData.addColumns(DoubleColumn.create("analysisVariable", analysisVariable),
DoubleColumn.create("stdDev", stdDev),
DoubleColumn.create("centerValue", centerValue),
StringColumn.create("ProcessPoint1Id", ProcessPoint1Id),
DoubleColumn.create("ProcessPoint1", ProcessPoint1),
StringColumn.create("ProcessPoint2Id", ProcessPoint2Id),
DoubleColumn.create("ProcessPoint2", ProcessPoint2),
StringColumn.create("ProcessPoint3Id", ProcessPoint3Id),
DoubleColumn.create("ProcessPoint3", ProcessPoint3),
StringColumn.create("analysisVariableId", analysisVariableIds));
healthData.addColumns(DoubleColumn.create("analysisVariable", analysisVariable), DoubleColumn.create("stdDev", stdDev), DoubleColumn.create("centerValue", centerValue), StringColumn.create("ProcessPoint1Id", ProcessPoint1Id), DoubleColumn.create("ProcessPoint1", ProcessPoint1), StringColumn.create("ProcessPoint2Id", ProcessPoint2Id), DoubleColumn.create("ProcessPoint2", ProcessPoint2), StringColumn.create("ProcessPoint3Id", ProcessPoint3Id), DoubleColumn.create("ProcessPoint3", ProcessPoint3), StringColumn.create("analysisVariableId", analysisVariableIds));
logger.info("------------------------------------------开始调用健康指数计算算法开始----------------------------------------");
String response = HttpUtil.createPost(baseUrlZSFX).body(JSON.toJSONString(requestMap)).execute().body();
......@@ -1624,8 +1640,7 @@ public class CommonServiceImpl {
List<Double> scoreValue = JSONObject.parseArray(scoreValueArray.toJSONString(), Double.class);
List<Double> indexValue = JSONObject.parseArray(indexValueArray.toJSONString(), Double.class);
// Table resultTable = Table.create("healthData");
healthData.addColumns(StringColumn.create("analysisVariableIdResult", jsonArrayToStringList),
DoubleColumn.create("indexValue", indexValue), DoubleColumn.create("scoreValue", scoreValue));
healthData.addColumns(StringColumn.create("analysisVariableIdResult", jsonArrayToStringList), DoubleColumn.create("indexValue", indexValue), DoubleColumn.create("scoreValue", scoreValue));
System.out.println(healthData.print());
try {
healthData.write().csv(new Date().getTime() + "fj.csv");
......@@ -1638,7 +1653,6 @@ public class CommonServiceImpl {
queryWrapper.in(IdxBizFanPointProcessVariableClassification::getSequenceNbr, jsonArrayToStringList);
List<IdxBizFanPointProcessVariableClassification> list = idxBizFanPointProcessVariableClassificationMapper.selectList(queryWrapper);
List<IdxBizFanHealthIndex> idxBizFanHealthIndexs = new ArrayList<>();
Set<String> stations = list.stream().map(IdxBizFanPointProcessVariableClassification::getStation).collect(Collectors.toSet());
LambdaQueryWrapper<IdxBizFanHealthLevel> query = new LambdaQueryWrapper<>();
......@@ -1659,8 +1673,7 @@ public class CommonServiceImpl {
idxBizFanHealthIndex.setWeigth(1.0);
//获取健康指数对应等级
for (IdxBizFanHealthLevel idxBizFanHealthLevel : idxBizFanHealthLevels) {
if (indexValueArray.getDoubleValue(i) <= idxBizFanHealthLevel.getGroupUpperLimit()
&& indexValueArray.getDoubleValue(i) >= idxBizFanHealthLevel.getGroupLowerLimit()) {
if (indexValueArray.getDoubleValue(i) <= idxBizFanHealthLevel.getGroupUpperLimit() && indexValueArray.getDoubleValue(i) >= idxBizFanHealthLevel.getGroupLowerLimit()) {
idxBizFanHealthIndex.setHealthLevel(idxBizFanHealthLevel.getHealthLevel());
}
......@@ -1739,15 +1752,15 @@ public class CommonServiceImpl {
// @Scheduled(cron = "0 0/10 * * * ?")
@Async("async")
// @Async("async")
public void healthWarningMinuteByPv() {
if (!openHealth) {
return;
}
Calendar calendar = Calendar.getInstance();
String format = DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:00");
Date time = DateUtil.parse(format, "yyyy-MM-dd HH:mm:00");
logger.info("光伏---------------------健康指数时间----"+time);
String format = DateUtil.format(new Date(), "yyyy-MM-dd HH:m0:00");
Date time = DateUtil.parse(format, "yyyy-MM-dd HH:m0:00");
logger.info("光伏---------------------健康指数时间----" + time);
List<IdxBizPvPointProcessVariableClassificationDto> data = idxBizPvPointProcessVariableClassificationMapper.getInfluxDBData();
Map<String, List<IdxBizPvPointProcessVariableClassificationDto>> maps = data.stream().collect(Collectors.groupingBy(IdxBizPvPointProcessVariableClassificationDto::getGatewayId));
// BoolQueryBuilder boolMustAll = QueryBuilders.boolQuery();
......@@ -1780,13 +1793,17 @@ public class CommonServiceImpl {
// } catch (Exception e) {
// // TODO: handle exception
// }
Map<String, Float> indicatorDataListAllMap = indicatorDataListAll.stream().collect(Collectors.toMap(indicatorData -> indicatorData.getAddress() +"_"+indicatorData.getGatewayId(), IndicatorData::getValueF));
Map<String, Float> indicatorDataListAllMap = indicatorDataListAll.stream().collect(Collectors.toMap(indicatorData -> indicatorData.getAddress() + "_" + indicatorData.getGatewayId(), IndicatorData::getValueF));
HashMap<String, Double> idxBizPvPointProcessVariableClassificationDtoIdValueMap = new HashMap<>();
for (IdxBizPvPointProcessVariableClassificationDto datum : data) {
// for (ESEquipments equipment : equipments) {
// if (equipment.getAddress().equals(datum.getIndexAddress()) && equipment.getGatewayId().equals(datum.getGatewayId())) {
Double currentValue = Double.valueOf(indicatorDataListAllMap.get(datum.getIndexAddress() + "_" + datum.getGatewayId()));
if (!ObjectUtils.isEmpty(currentValue)) {
datum.setCurrentValue(currentValue);
idxBizPvPointProcessVariableClassificationDtoIdValueMap.put(datum.getSequenceNbr(),currentValue);
}else {
idxBizPvPointProcessVariableClassificationDtoIdValueMap.put(datum.getSequenceNbr(),0.0);
}
// }
// }
......@@ -1811,29 +1828,50 @@ public class CommonServiceImpl {
List<String> ProcessPoint2Id = new ArrayList<>();
List<String> ProcessPoint3Id = new ArrayList<>();
List<String> analysisVariableIds = new ArrayList<>();
for (IdxBizPvPointVarCentralValue idxBizUhef : idxBizUhefs) {
double value1 = 0.00;
double value2 = 0.00;
double value3 = 0.00;
double value4 = 0.00;
for (IdxBizPvPointProcessVariableClassificationDto datum : data) {
if (idxBizUhef.getProcessPoint1Id().equals(datum.getSequenceNbr())) {
value1 = datum.getCurrentValue();
idxBizUhefs.forEach(idxBizPvPointVarCentralValue -> {
if (ObjectUtils.isEmpty(idxBizPvPointVarCentralValue.getProcess1Min())) {
idxBizPvPointVarCentralValue.setProcess1Min(Double.NEGATIVE_INFINITY);
}
if (idxBizUhef.getProcessPoint2Id().equals(datum.getSequenceNbr())) {
value2 = datum.getCurrentValue();
if (ObjectUtils.isEmpty(idxBizPvPointVarCentralValue.getProcess2Min())) {
idxBizPvPointVarCentralValue.setProcess2Min(Double.NEGATIVE_INFINITY);
}
if (idxBizUhef.getProcessPoint3Id().equals(datum.getSequenceNbr())) {
value3 = datum.getCurrentValue();
if (ObjectUtils.isEmpty(idxBizPvPointVarCentralValue.getProcess3Min())) {
idxBizPvPointVarCentralValue.setProcess3Min(Double.NEGATIVE_INFINITY);
}
if (idxBizUhef.getAnalysisPointId().equals(datum.getSequenceNbr())) {
value4 = datum.getCurrentValue();
if (ObjectUtils.isEmpty(idxBizPvPointVarCentralValue.getProcess1Max())) {
idxBizPvPointVarCentralValue.setProcess1Max(Double.POSITIVE_INFINITY);
}
if (ObjectUtils.isEmpty(idxBizPvPointVarCentralValue.getProcess2Max())) {
idxBizPvPointVarCentralValue.setProcess2Max(Double.POSITIVE_INFINITY);
}
if (ObjectUtils.isEmpty(idxBizPvPointVarCentralValue.getProcess3Max())) {
idxBizPvPointVarCentralValue.setProcess3Max(Double.POSITIVE_INFINITY);
}
if ((null == idxBizUhef.getProcess1Min() || idxBizUhef.getProcess1Min() <= value1) && (null == idxBizUhef.getProcess1Max() || value1 <= idxBizUhef.getProcess1Max())
&& (null == idxBizUhef.getProcess2Min() || idxBizUhef.getProcess2Min() <= value2) && (null == idxBizUhef.getProcess2Max() || value2 <= idxBizUhef.getProcess2Max())
&& (null == idxBizUhef.getProcess3Min() || idxBizUhef.getProcess3Min() <= value3) && (null == idxBizUhef.getProcess3Max() || value3 <= idxBizUhef.getProcess3Max())) {
});
for (IdxBizPvPointVarCentralValue idxBizUhef : idxBizUhefs) {
double value1 = 0.00;
double value2 = 0.00;
double value3 = 0.00;
double value4 = 0.00;
// for (IdxBizPvPointProcessVariableClassificationDto datum : data) {
// if (idxBizUhef.getProcessPoint1Id().equals(datum.getSequenceNbr())) {
// value1 = datum.getCurrentValue();
// }
// if (idxBizUhef.getProcessPoint2Id().equals(datum.getSequenceNbr())) {
// value2 = datum.getCurrentValue();
// }
// if (idxBizUhef.getProcessPoint3Id().equals(datum.getSequenceNbr())) {
// value3 = datum.getCurrentValue();
// }
// if (idxBizUhef.getAnalysisPointId().equals(datum.getSequenceNbr())) {
// value4 = datum.getCurrentValue();
// }
// }
value1 = idxBizPvPointProcessVariableClassificationDtoIdValueMap.get(idxBizUhef.getProcessPoint1Id());
value2 = idxBizPvPointProcessVariableClassificationDtoIdValueMap.get(idxBizUhef.getProcessPoint2Id());
value3 = idxBizPvPointProcessVariableClassificationDtoIdValueMap.get(idxBizUhef.getProcessPoint3Id());
value4 = idxBizPvPointProcessVariableClassificationDtoIdValueMap.get(idxBizUhef.getAnalysisPointId());
if ( idxBizUhef.getProcess1Min() <= value1 && value1 <= idxBizUhef.getProcess1Max() && idxBizUhef.getProcess2Min() <= value2 && value2 <= idxBizUhef.getProcess2Max() && idxBizUhef.getProcess3Min() <= value3 && value3 <= idxBizUhef.getProcess3Max()) {
if (!analysisVariableIdList.contains(idxBizUhef.getAnalysisPointId())) {
analysisVariableList.add(value4);
analysisVariable.add(value4);
......@@ -1865,16 +1903,7 @@ public class CommonServiceImpl {
requestMap.put("analysisVariableId", analysisVariableIdList);
Table healthData = Table.create("healthData");
healthData.addColumns(DoubleColumn.create("analysisVariable", analysisVariable),
DoubleColumn.create("stdDev", stdDev),
DoubleColumn.create("centerValue", centerValue),
StringColumn.create("ProcessPoint1Id", ProcessPoint1Id),
DoubleColumn.create("ProcessPoint1", ProcessPoint1),
StringColumn.create("ProcessPoint2Id", ProcessPoint2Id),
DoubleColumn.create("ProcessPoint2", ProcessPoint2),
StringColumn.create("ProcessPoint3Id", ProcessPoint3Id),
DoubleColumn.create("ProcessPoint3", ProcessPoint3),
StringColumn.create("analysisVariableId", analysisVariableIds));
healthData.addColumns(DoubleColumn.create("analysisVariable", analysisVariable), DoubleColumn.create("stdDev", stdDev), DoubleColumn.create("centerValue", centerValue), StringColumn.create("ProcessPoint1Id", ProcessPoint1Id), DoubleColumn.create("ProcessPoint1", ProcessPoint1), StringColumn.create("ProcessPoint2Id", ProcessPoint2Id), DoubleColumn.create("ProcessPoint2", ProcessPoint2), StringColumn.create("ProcessPoint3Id", ProcessPoint3Id), DoubleColumn.create("ProcessPoint3", ProcessPoint3), StringColumn.create("analysisVariableId", analysisVariableIds));
logger.info("------------------------------------------开始调用健康指数计算算法开始----------------------------------------");
String response = HttpUtil.createPost(baseUrlZSFX).body(JSON.toJSONString(requestMap)).execute().body();
JSONObject jsonObject = JSON.parseObject(response);
......@@ -1886,8 +1915,7 @@ public class CommonServiceImpl {
List<Double> scoreValue = JSONObject.parseArray(scoreValueArray.toJSONString(), Double.class);
List<Double> indexValue = JSONObject.parseArray(indexValueArray.toJSONString(), Double.class);
// Table resultTable = Table.create("healthData");
healthData.addColumns(StringColumn.create("analysisVariableIdResult", jsonArrayToStringList),
DoubleColumn.create("indexValue", indexValue), DoubleColumn.create("scoreValue", scoreValue));
healthData.addColumns(StringColumn.create("analysisVariableIdResult", jsonArrayToStringList), DoubleColumn.create("indexValue", indexValue), DoubleColumn.create("scoreValue", scoreValue));
System.out.println(healthData.print());
try {
healthData.write().csv(new Date().getTime() + "gf.csv");
......@@ -1924,8 +1952,7 @@ public class CommonServiceImpl {
//获取健康指数对应等级
for (IdxBizPvHealthLevel idxBizFanHealthLevel : idxBizFanHealthLevels) {
if (indexValueArray.getDoubleValue(i) <= idxBizFanHealthLevel.getGroupUpperLimit()
&& indexValueArray.getDoubleValue(i) >= idxBizFanHealthLevel.getGroupLowerLimit()) {
if (indexValueArray.getDoubleValue(i) <= idxBizFanHealthLevel.getGroupUpperLimit() && indexValueArray.getDoubleValue(i) >= idxBizFanHealthLevel.getGroupLowerLimit()) {
idxBizPvHealthIndex.setHealthLevel(idxBizFanHealthLevel.getHealthLevel());
}
......
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