From 7f0bcd00c556889ba890e5e68c681f1b5d4267e1 Mon Sep 17 00:00:00 2001 From: dengzedong <dengzedong@email> Date: 星期四, 19 十二月 2024 18:07:20 +0800 Subject: [PATCH] 预测项状态添加模型结果异常 --- iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/impl/PredictItemMergeHandlerImpl.java | 95 ++++++++++++++++++++++++----------------------- 1 files changed, 49 insertions(+), 46 deletions(-) diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/impl/PredictItemMergeHandlerImpl.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/impl/PredictItemMergeHandlerImpl.java index ef85630..dd8b826 100644 --- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/impl/PredictItemMergeHandlerImpl.java +++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/impl/PredictItemMergeHandlerImpl.java @@ -4,6 +4,7 @@ import com.iailab.module.data.api.point.dto.ApiPointDTO; import com.iailab.module.data.enums.DataPointFreqEnum; import com.iailab.module.model.mcs.pre.entity.MmItemOutputEntity; +import com.iailab.module.model.mcs.pre.enums.ItemRunStatusEnum; import com.iailab.module.model.mcs.pre.service.MmItemOutputService; import com.iailab.module.model.mcs.pre.service.MmItemResultService; import com.iailab.module.model.mdk.common.enums.ItemPredictStatus; @@ -21,6 +22,7 @@ import java.sql.Timestamp; import java.util.*; +import java.util.stream.Collectors; /** * @author PanZhibao @@ -58,7 +60,7 @@ * @throws ItemInvokeException */ @Override - public PredictResultVO predict(Date predictTime, ItemVO predictItemDto) + public PredictResultVO predict(Date predictTime, ItemVO predictItemDto, Map<String, double[]> predictValueMap, ItemRunStatusEnum itemRunStatusEnum) throws ItemInvokeException { PredictResultVO predictResult = new PredictResultVO(); ItemPredictStatus itemStatus = ItemPredictStatus.PREDICTING; @@ -67,7 +69,6 @@ String expression = itemEntityFactory.getMergeItem(itemId).getExpression(); int predictLength = itemEntityFactory.getItemById(itemId).getPredictLength(); double[][] predictResultMat = new double[predictLength][1]; - Map<String, List<DataValueVO>> predictValueMap = new HashMap<>(); String[] mathOutPutId = expression.split("[\\+ \\-]"); ArrayList<Character> operator = new ArrayList<>(); for (int i = 0; i < expression.length(); i++) { @@ -75,63 +76,65 @@ operator.add(expression.charAt(i)); } } - String[] compositionItem = expression.split(String.valueOf("&".toCharArray())); +// String[] compositionItem = expression.split(String.valueOf("&".toCharArray())); //是否为计算预测项 if (mathOutPutId.length > 1) { - for (String outPutId : mathOutPutId) { - if (outPutId.length() > 4) { - Date endTime = predictTime; -// ItemVO itemEntity = itemEntityFactory.getItemByItemNo(itemNo); -// List<MmItemOutputEntity> outPutList = itemEntityFactory.getOutPutByItemId(itemEntity.getId()); - MmItemOutputEntity outPut = mmItemOutputService.getOutPutById(outPutId); - ApiPointDTO pointEntity = dataPointApi.getInfoById(outPut.getPointid()); +// Map<String, List<DataValueVO>> predictValueMap = new HashMap<>(); +// for (String outPutId : mathOutPutId) { +// if (outPutId.length() > 4) { +// Date endTime = predictTime; +//// ItemVO itemEntity = itemEntityFactory.getItemByItemNo(itemNo); +//// List<MmItemOutputEntity> outPutList = itemEntityFactory.getOutPutByItemId(itemEntity.getId()); +// MmItemOutputEntity outPut = mmItemOutputService.getOutPutById(outPutId); +// ApiPointDTO pointEntity = dataPointApi.getInfoById(outPut.getPointid()); +// +// Calendar calendar = Calendar.getInstance(); +// calendar.setTime(endTime); +// calendar.add(Calendar.SECOND, (predictLength - 1) * DataPointFreqEnum.getEumByCode(pointEntity.getMinfreqid()).getValue()); +// endTime = new Timestamp(calendar.getTime().getTime()); +//// List<DataValueVO> predictValueList = predictResultHandler.getPredictValueByItemNo(itemNo, predictTime, endTime); +// List<DataValueVO> predictValueList = mmItemResultService.getPredictValue(outPutId, predictTime, endTime); +// if (predictValueList.size() != predictLength) { +// log.debug("merge项融合失败:缺少子项预测数据,对应子项outPutId=" + outPutId); +// return null; +// } +// predictValueMap.put(outPutId, predictValueList); +// } +// } - Calendar calendar = Calendar.getInstance(); - calendar.setTime(endTime); - calendar.add(Calendar.SECOND, (predictLength - 1) * DataPointFreqEnum.getEumByCode(pointEntity.getMinfreqid()).getValue()); - endTime = new Timestamp(calendar.getTime().getTime()); -// List<DataValueVO> predictValueList = predictResultHandler.getPredictValueByItemNo(itemNo, predictTime, endTime); - List<DataValueVO> predictValueList = mmItemResultService.getPredictValue(outPutId, predictTime, endTime); - if (predictValueList.size() != predictLength) { - log.debug("merge项融合失败:缺少子项预测数据,对应子项outPutId=" + outPutId); - return null; - } - predictValueMap.put(outPutId, predictValueList); - } - } for (Integer i = 0; i < predictLength; i++) { double sum =0.0; - sum = predictValueMap.get(mathOutPutId[0]).get(i).getDataValue(); + sum = predictValueMap.get(mathOutPutId[0])[i]; for (int j = 1; j < mathOutPutId.length; j++) { if (operator.get(j-1)=='+') - {sum += predictValueMap.get(mathOutPutId[j]).get(i).getDataValue();} + {sum += predictValueMap.get(mathOutPutId[j])[i];} if (operator.get(j-1)=='-') - {sum -= predictValueMap.get(mathOutPutId[j]).get(i).getDataValue();} + {sum -= predictValueMap.get(mathOutPutId[j])[i];} } predictResultMat[i][0] = sum; } } //是否为组合预测项 - if (compositionItem.length > 1) { - Map<String, PredictResultVO> predictResultMap = new HashMap<>(); - Integer columnTotalNumber = 0; - Integer rowNumber = 0; - for (String itemNo : compositionItem) { - PredictItemHandler predictItem = (PredictItemHandler) predictItemFactory.create(itemEntityFactory. - getItemByItemNo(itemNo).getId()); - predictResult = predictItem.predict(predictTime, predictItemDto); - columnTotalNumber += Integer.valueOf(predictResult.getPredictMatrix().length); - predictResultMap.put(itemNo, predictItem.predict(predictTime, predictItemDto)); - } - double[][] matrix = new double[columnTotalNumber][1]; - for (String itemNo : compositionItem) { - for (Integer i = 0; i < predictResultMap.get(itemNo).getPredictMatrix().length; i++) { - matrix[rowNumber][0] = predictResultMap.get(itemNo).getPredictMatrix()[i][0]; - rowNumber++; - } - } - predictResult.setPredictMatrix(matrix); - } +// if (compositionItem.length > 1) { +// Map<String, PredictResultVO> predictResultMap = new HashMap<>(); +// Integer columnTotalNumber = 0; +// Integer rowNumber = 0; +// for (String itemNo : compositionItem) { +// PredictItemHandler predictItem = (PredictItemHandler) predictItemFactory.create(itemEntityFactory. +// getItemByItemNo(itemNo).getId()); +// predictResult = predictItem.predict(predictTime, predictItemDto); +// columnTotalNumber += Integer.valueOf(predictResult.getPredictMatrix().length); +// predictResultMap.put(itemNo, predictItem.predict(predictTime, predictItemDto)); +// } +// double[][] matrix = new double[columnTotalNumber][1]; +// for (String itemNo : compositionItem) { +// for (Integer i = 0; i < predictResultMap.get(itemNo).getPredictMatrix().length; i++) { +// matrix[rowNumber][0] = predictResultMap.get(itemNo).getPredictMatrix()[i][0]; +// rowNumber++; +// } +// } +// predictResult.setPredictMatrix(matrix); +// } predictResult.setPredictId(itemId); predictResult.setPredictMatrix(predictResultMat); predictResult.setPredictTime(predictTime); -- Gitblit v1.9.3