From a2b4314c590248f3826764ac0ea63dcecc6fb20b Mon Sep 17 00:00:00 2001 From: 潘志宝 <979469083@qq.com> Date: 星期五, 21 三月 2025 09:16:51 +0800 Subject: [PATCH] 预测值模拟调整 --- iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/PredictResultHandler.java | 43 +++++++++++++++++++++++++++---------------- 1 files changed, 27 insertions(+), 16 deletions(-) diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/PredictResultHandler.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/PredictResultHandler.java index 89c3866..bea9b0a 100644 --- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/PredictResultHandler.java +++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/PredictResultHandler.java @@ -4,11 +4,11 @@ import com.iailab.module.model.common.enums.CommonDict; import com.iailab.module.model.mcs.pre.entity.MmItemOutputEntity; import com.iailab.module.model.mcs.pre.service.MmItemResultService; +import com.iailab.module.model.mcs.sche.service.StAdjustResultService; import com.iailab.module.model.mdk.factory.ItemEntityFactory; import com.iailab.module.model.mdk.vo.DataValueVO; import com.iailab.module.model.mdk.vo.PredictResultVO; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; @@ -23,6 +23,9 @@ @Autowired private ItemEntityFactory itemEntityFactory; + @Autowired + private StAdjustResultService stAdjustResultService; + /** * convertToPredictData * @@ -31,38 +34,33 @@ */ public Map<String, List<DataValueVO>> convertToPredictData(PredictResultVO predictResult) { Map<String, List<DataValueVO>> resultMap = new HashMap<>(); -// List<MmItemOutputEntity> itemOutPutList = itemEntityFactory.getOutPutByItemId(predictResult.getPredictId()); -// -// if (!CollectionUtils.isEmpty(predictResult.getPredictList())) { -// resultMap.put(itemOutPutList.get(0).getId(), predictResult.getPredictList()); -// return resultMap; -// } - Map<com.iailab.module.model.mcs.pre.entity.MmItemOutputEntity, double[]> predictMatrixs = predictResult.getPredictMatrixs(); - HashMap<String,List<DataValueVO>> predictLists = new HashMap<>(); - for (Map.Entry<com.iailab.module.model.mcs.pre.entity.MmItemOutputEntity, double[]> entry : predictMatrixs.entrySet()) { + Map<MmItemOutputEntity, double[]> predictMatrixs = predictResult.getPredictMatrixs(); + HashMap<String, List<DataValueVO>> predictLists = new HashMap<>(); + for (Map.Entry<MmItemOutputEntity, double[]> entry : predictMatrixs.entrySet()) { Integer rows = entry.getValue().length; List<DataValueVO> predictDataList = new ArrayList<>(); Calendar calendar = Calendar.getInstance(); calendar.setTime(predictResult.getPredictTime()); for (Integer i = 0; i < rows; i++) { + // 从下个时间粒度开始 + calendar.add(Calendar.SECOND, predictResult.getGranularity()); + DataValueVO predictData = new DataValueVO(); predictData.setDataTime(calendar.getTime()); predictData.setDataValue(Double.valueOf(entry.getValue()[i])); predictDataList.add(predictData); - - calendar.add(Calendar.SECOND, predictResult.getGranularity()); } resultMap.put(entry.getKey().getId(), predictDataList); predictLists.put(entry.getKey().getResultstr(), predictDataList); //处理累计计算 if (entry.getKey().getIscumulant() == 1) { - resultMap.put(entry.getKey().getId() + CommonDict.CUMULANT_SUFFIX, new ArrayList<DataValueVO>(){{ + resultMap.put(entry.getKey().getId() + CommonDict.CUMULANT_SUFFIX, new ArrayList<DataValueVO>() {{ DataValueVO predictData = new DataValueVO(); // 时间 预测时间+预测长度*粒度 Calendar calendar = Calendar.getInstance(); calendar.setTime(predictResult.getPredictTime()); - calendar.add(Calendar.SECOND, predictResult.getGranularity() * (rows - 1)); + calendar.add(Calendar.SECOND, predictResult.getGranularity() * rows); predictData.setDataTime(calendar.getTime()); //值 所有值相加/除数 BigDecimal sum = BigDecimal.valueOf(Arrays.stream(entry.getValue()).sum()); @@ -88,12 +86,13 @@ Calendar calendar = Calendar.getInstance(); calendar.setTime(predictResult.getPredictTime()); for (Integer i = 0; i < rows; i++) { + // 从下个时间粒度开始 + calendar.add(Calendar.SECOND, predictResult.getGranularity()); + DataValueVO predictData = new DataValueVO(); predictData.setDataTime(calendar.getTime()); predictData.setDataValue(Double.valueOf(entry.getValue()[i])); predictDataList.add(predictData); - - calendar.add(Calendar.SECOND, predictResult.getGranularity()); } predictLists.put(entry.getKey().getResultstr(), predictDataList); } @@ -111,6 +110,18 @@ mmItemResultService.savePredictValue(resultMap, predictResult.getLt(), "n", predictResult.getPredictTime()); } + /** + * savePredictAdjustResult + * + * @param predictResult + * @param configId + */ + @DSTransactional + public void savePredictAdjustResult(PredictResultVO predictResult, String adjustValue, String scheduleModelId, String configId) { + Map<String, List<DataValueVO>> resultMap = convertToPredictData(predictResult); + stAdjustResultService.saveResult(resultMap, predictResult.getPredictTime(), adjustValue, scheduleModelId,configId); + } + public List<DataValueVO> getPredictValueByItemNo(String itemNo, Date start, Date end) { String itemId = itemEntityFactory.getItemByItemNo(itemNo).getId(); List<MmItemOutputEntity> outputList = itemEntityFactory.getOutPutByItemId(itemId); -- Gitblit v1.9.3