predictItem
MODELRESULTERROR
| | |
| | | @Override |
| | | public MdkPredictItemRespDTO predictItem(MdkPredictReqDTO reqDTO) { |
| | | MdkPredictItemRespDTO resp = new MdkPredictItemRespDTO(); |
| | | |
| | | try { |
| | | log.info("预测计算开始: " + System.currentTimeMillis()); |
| | | Map<String, List<MdkPredictDataDTO>> predictData = new HashMap<>(); |
| | | ItemVO predictItem = itemEntityFactory.getItemByItemNo(reqDTO.getItemNo()); |
| | | PredictItemHandler predictItemHandler = predictItemFactory.create(predictItem.getId()); |
| | | PredictResultVO predictResult = predictItemHandler.predict(reqDTO.getPredictTime(), predictItem,null,null); |
| | | Map<String, List<DataValueVO>> resultMap = predictResultHandler.convertToPredictData(predictResult); |
| | | if (!CollectionUtils.isEmpty(resultMap)) { |
| | | for (Map.Entry<String, List<DataValueVO>> entry : resultMap.entrySet()) { |
| | | List<MdkPredictDataDTO> data = ConvertUtils.sourceToTarget(entry.getValue(), MdkPredictDataDTO.class); |
| | | predictData.put(entry.getKey(), data); |
| | | |
| | | ItemVO itemByItemNo = mmPredictItemService.getItemByItemNo(reqDTO.getItemNo()); |
| | | List<ItemVO> predictItemList = new ArrayList<>(); |
| | | predictItemList.add(itemByItemNo); |
| | | Map<String, PredictResultVO> predictResultMap = new HashMap<>(predictItemList.size()); |
| | | predictModuleHandler.predict(predictItemList, reqDTO.getPredictTime(), 0,predictResultMap); |
| | | |
| | | Map<String, List<MdkPredictDataDTO>> itemPredictData = new HashMap<>(); |
| | | |
| | | Map<String, List<DataValueVO>> predictLists = predictResultHandler.convertToPredictData2(predictResultMap.get(reqDTO.getItemNo())); |
| | | for (Map.Entry<String, List<DataValueVO>> dataListEntry : predictLists.entrySet()) { |
| | | List<MdkPredictDataDTO> predictData = dataListEntry.getValue().stream().map(t -> { |
| | | MdkPredictDataDTO dto1 = new MdkPredictDataDTO(); |
| | | dto1.setDataTime(t.getDataTime()); |
| | | dto1.setDataValue(t.getDataValue()); |
| | | return dto1; |
| | | }).collect(Collectors.toList()); |
| | | itemPredictData.put(dataListEntry.getKey(), predictData); |
| | | } |
| | | } |
| | | resp.setPredictData(predictData); |
| | | resp.setItemId(predictItem.getId()); |
| | | resp.setItemId(reqDTO.getItemNo()); |
| | | resp.setPredictTime(reqDTO.getPredictTime()); |
| | | log.info("预测计算结束: " + System.currentTimeMillis()); |
| | | } catch (Exception ex) { |
| | | log.info("预测计算异常: " + System.currentTimeMillis(), ex); |
| | | return resp; |
| | | resp.setPredictData(itemPredictData); |
| | | } catch (Exception e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | |
| | | return resp; |
对比新文件 |
| | |
| | | package com.iailab.module.model.common.exception; |
| | | |
| | | /** |
| | | * 模型结果错误异常 |
| | | */ |
| | | public class ModelResultErrorException extends RuntimeException { |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | private String msg; |
| | | private int code = 200; |
| | | |
| | | public ModelResultErrorException(String msg) { |
| | | super(msg); |
| | | this.msg = msg; |
| | | } |
| | | |
| | | public ModelResultErrorException(String msg, Throwable e) { |
| | | super(msg, e); |
| | | this.msg = msg; |
| | | } |
| | | |
| | | public ModelResultErrorException(String msg, int code) { |
| | | super(msg); |
| | | this.msg = msg; |
| | | this.code = code; |
| | | } |
| | | |
| | | public ModelResultErrorException(String msg, int code, Throwable e) { |
| | | super(msg, e); |
| | | this.msg = msg; |
| | | this.code = code; |
| | | } |
| | | |
| | | public String getMsg() { |
| | | return msg; |
| | | } |
| | | |
| | | public void setMsg(String msg) { |
| | | this.msg = msg; |
| | | } |
| | | |
| | | public int getCode() { |
| | | return code; |
| | | } |
| | | |
| | | public void setCode(int code) { |
| | | this.code = code; |
| | | } |
| | | |
| | | |
| | | } |
| | |
| | | private List<MmModelParamEntity> mmModelParamList; |
| | | |
| | | private List<MmItemResultEntity> mmItemResultList; |
| | | |
| | | /** |
| | | * 计算预测项真实数据点 |
| | | */ |
| | | private String pointId; |
| | | } |
| | |
| | | PROCESSING(1, "处理中"), |
| | | SUCCESS(2, "成功"), |
| | | FAIL(3, "失败"), |
| | | MODELRESULTERROR(4, "模型结果异常"); |
| | | MODELRESULTERROR(4, "模型结果异常"), |
| | | MODELRESULTSAVEERROR(5, "模型结果保存异常"); |
| | | |
| | | private Integer code; |
| | | private String desc; |
| | |
| | | * @return |
| | | * @throws ItemInvokeException |
| | | */ |
| | | PredictResultVO predict(Date predictTime, ItemVO predictItemDto, Map<String, double[]> predictValueMap, ItemRunStatusEnum itemRunStatusEnum) throws ItemInvokeException; |
| | | PredictResultVO predict(Date predictTime, ItemVO predictItemDto, Map<String, double[]> predictValueMap) throws ItemInvokeException; |
| | | } |
| | |
| | | * @return |
| | | * @throws ModelInvokeException |
| | | */ |
| | | PredictResultVO predictByModel(Date predictTime, MmPredictModelEntity predictModel,String itemName, ItemRunStatusEnum itemRunStatusEnum) throws ModelInvokeException; |
| | | PredictResultVO predictByModel(Date predictTime, MmPredictModelEntity predictModel,String itemName) throws ModelInvokeException; |
| | | } |
| | |
| | | package com.iailab.module.model.mdk.predict; |
| | | |
| | | import com.iailab.module.model.common.exception.ModelResultErrorException; |
| | | 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.enums.ItemStatus; |
| | |
| | | long start = System.currentTimeMillis(); |
| | | try { |
| | | // 预测项开始预测 |
| | | predictResult = predictItemHandler.predict(predictTime, predictItem, predictValueMap,itemRunStatusEnum); |
| | | predictResult = predictItemHandler.predict(predictTime, predictItem, predictValueMap); |
| | | } catch (ModelResultErrorException e) { |
| | | itemRunStatusEnum = ItemRunStatusEnum.MODELRESULTERROR; |
| | | continue; |
| | | } catch (Exception e) { |
| | | itemRunStatusEnum = ItemRunStatusEnum.FAIL; |
| | | continue; |
| | | } |
| | | long end = System.currentTimeMillis(); |
| | | Long drtPre = end - start; |
| | | log.info(MessageFormat.format("预测项:{0},预测时间:{1}ms", predictItem.getItemName(), drtPre)); |
| | | totalDur = totalDur + drtPre; |
| | | |
| | | predictResult.setGranularity(predictItem.getGranularity()); |
| | | predictResult.setT(intervalTime); |
| | | predictResult.setSaveIndex(predictItem.getSaveIndex()); |
| | | predictResult.setLt(1); |
| | | predictResultMap.put(predictItem.getItemNo(), predictResult); |
| | | |
| | | // 保存预测结果 |
| | | try { |
| | | predictResultHandler.savePredictResult(predictResult); |
| | | long endSave = System.currentTimeMillis(); |
| | | Long drtSave = endSave - end; |
| | | log.info(MessageFormat.format("预测项:{0},保存时间:{1}ms", predictItem.getItemName(), |
| | | drtSave)); |
| | | totalDur = totalDur + drtSave; |
| | | predictResultMap.put(predictItem.getItemNo(), predictResult); |
| | | } catch (Exception e) { |
| | | itemRunStatusEnum = ItemRunStatusEnum.MODELRESULTSAVEERROR; |
| | | throw new RuntimeException("模型结果保存异常,result:" + predictResult); |
| | | } |
| | | itemRunStatusEnum = ItemRunStatusEnum.SUCCESS; |
| | | // long endSave = System.currentTimeMillis(); |
| | | // Long drtSave = endSave - end; |
| | | // log.info(MessageFormat.format("预测项:{0},保存时间:{1}ms", predictItem.getItemName(), |
| | | // drtSave)); |
| | | // totalDur = totalDur + drtSave; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | log.error(MessageFormat.format("预测项编号:{0},预测项名称:{1},预测失败:{2} 预测时刻:{3}", |
| | |
| | | * @throws ItemInvokeException |
| | | */ |
| | | @Override |
| | | public PredictResultVO predict(Date predictTime, ItemVO predictItemDto, Map<String, double[]> predictValueMap, ItemRunStatusEnum itemRunStatusEnum) |
| | | public PredictResultVO predict(Date predictTime, ItemVO predictItemDto, Map<String, double[]> predictValueMap) |
| | | throws ItemInvokeException { |
| | | PredictResultVO predictResult = new PredictResultVO(); |
| | | ItemPredictStatus itemStatus = ItemPredictStatus.PREDICTING; |
| | |
| | | // } |
| | | // predictResult.setPredictMatrix(matrix); |
| | | // } |
| | | log.info("计算预测模型结果:" + predictResultMat); |
| | | predictResult.setPredictId(itemId); |
| | | predictResult.setPredictMatrix(predictResultMat); |
| | | predictResult.setPredictTime(predictTime); |
| | |
| | | * @throws ItemInvokeException |
| | | */ |
| | | @Override |
| | | public PredictResultVO predict(Date predictTime, ItemVO predictItemDto, Map<String, double[]> predictValueMap, ItemRunStatusEnum itemRunStatusEnum) throws ItemInvokeException { |
| | | public PredictResultVO predict(Date predictTime, ItemVO predictItemDto, Map<String, double[]> predictValueMap) throws ItemInvokeException { |
| | | PredictResultVO predictResult = new PredictResultVO(); |
| | | String itemId = predictItemDto.getId(); |
| | | try { |
| | |
| | | throw new ModelInvokeException(MessageFormat.format("{0},itemId={1}", |
| | | ModelInvokeException.errorGetModelEntity, itemId)); |
| | | } |
| | | predictResult = predictModelHandler.predictByModel(predictTime, predictModel,predictItemDto.getItemName(),itemRunStatusEnum); |
| | | predictResult = predictModelHandler.predictByModel(predictTime, predictModel,predictItemDto.getItemName()); |
| | | predictResult.setPredictId(itemId); |
| | | } catch (Exception ex) { |
| | | throw new ItemInvokeException(MessageFormat.format("{0},itemId={1}", |
| | |
| | | import com.iail.model.IAILModel; |
| | | import com.iailab.module.model.common.enums.CommonConstant; |
| | | import com.iailab.module.model.common.enums.OutResultType; |
| | | import com.iailab.module.model.common.exception.ModelResultErrorException; |
| | | import com.iailab.module.model.mcs.pre.entity.MmItemOutputEntity; |
| | | import com.iailab.module.model.mcs.pre.entity.MmModelArithSettingsEntity; |
| | | import com.iailab.module.model.mcs.pre.entity.MmPredictModelEntity; |
| | |
| | | * @throws ModelInvokeException |
| | | */ |
| | | @Override |
| | | public synchronized PredictResultVO predictByModel(Date predictTime, MmPredictModelEntity predictModel,String itemName, ItemRunStatusEnum itemRunStatusEnum) throws ModelInvokeException { |
| | | public synchronized PredictResultVO predictByModel(Date predictTime, MmPredictModelEntity predictModel,String itemName) throws ModelInvokeException { |
| | | PredictResultVO result = new PredictResultVO(); |
| | | if (predictModel == null) { |
| | | throw new ModelInvokeException("modelEntity is null"); |
| | |
| | | HashMap<String, Object> modelResult = DllUtils.run(newModelBean, param2Values, predictModel.getMpkprojectid()); |
| | | if (!modelResult.containsKey(CommonConstant.MDK_STATUS_CODE) || !modelResult.containsKey(CommonConstant.MDK_RESULT) || |
| | | !modelResult.get(CommonConstant.MDK_STATUS_CODE).toString().equals(CommonConstant.MDK_STATUS_100)) { |
| | | itemRunStatusEnum = ItemRunStatusEnum.MODELRESULTERROR; |
| | | throw new RuntimeException("模型结果异常:" + modelResult); |
| | | throw new ModelResultErrorException("模型结果异常:" + modelResult); |
| | | } |
| | | modelResult = (HashMap<String, Object>) modelResult.get(CommonConstant.MDK_RESULT); |
| | | //打印结果 |