dengzedong
2 天以前 1178da30ca701da465bf7bc1342b539b2df03c7d
predictItem
MODELRESULTERROR
已修改9个文件
已添加1个文件
144 ■■■■ 文件已修改
iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/api/MdkApiImpl.java 40 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/common/exception/ModelResultErrorException.java 51 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/dto/MmPredictItemDTO.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/enums/ItemRunStatusEnum.java 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/PredictItemHandler.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/PredictModelHandler.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/PredictModuleHandler.java 28 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/impl/PredictItemMergeHandlerImpl.java 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/impl/PredictItemNormalHandlerImpl.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/impl/PredictModelHandlerImpl.java 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/api/MdkApiImpl.java
@@ -150,27 +150,31 @@
    @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;
iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/common/exception/ModelResultErrorException.java
对比新文件
@@ -0,0 +1,51 @@
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;
    }
}
iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/dto/MmPredictItemDTO.java
@@ -32,4 +32,9 @@
    private List<MmModelParamEntity> mmModelParamList;
    private List<MmItemResultEntity> mmItemResultList;
    /**
     * 计算预测项真实数据点
     */
    private String pointId;
}
iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/enums/ItemRunStatusEnum.java
@@ -14,7 +14,8 @@
    PROCESSING(1, "处理中"),
    SUCCESS(2, "成功"),
    FAIL(3, "失败"),
    MODELRESULTERROR(4, "模型结果异常");
    MODELRESULTERROR(4, "模型结果异常"),
    MODELRESULTSAVEERROR(5, "模型结果保存异常");
    private Integer code;
    private String desc;
iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/PredictItemHandler.java
@@ -23,5 +23,5 @@
     * @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;
}
iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/PredictModelHandler.java
@@ -22,5 +22,5 @@
     * @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;
}
iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/PredictModuleHandler.java
@@ -1,5 +1,6 @@
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;
@@ -72,28 +73,37 @@
                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);
                // 保存预测结果
                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);
                try {
                    predictResultHandler.savePredictResult(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}",
iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/impl/PredictItemMergeHandlerImpl.java
@@ -60,7 +60,7 @@
     * @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;
@@ -135,6 +135,7 @@
//                }
//                predictResult.setPredictMatrix(matrix);
//            }
            log.info("计算预测模型结果:" + predictResultMat);
            predictResult.setPredictId(itemId);
            predictResult.setPredictMatrix(predictResultMat);
            predictResult.setPredictTime(predictTime);
iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/impl/PredictItemNormalHandlerImpl.java
@@ -39,7 +39,7 @@
     * @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 {
@@ -48,7 +48,7 @@
                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}",
iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/impl/PredictModelHandlerImpl.java
@@ -6,6 +6,7 @@
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;
@@ -56,7 +57,7 @@
     * @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");
@@ -100,8 +101,7 @@
            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);
            //打印结果