dengzedong
2 天以前 fde993948625751908d4e67bd5e77e8e2ce47d05
计算预测项
已修改4个文件
42 ■■■■ 文件已修改
iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/api/MdkApiImpl.java 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmPredictItemServiceImpl.java 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/PredictModuleHandler.java 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/impl/PredictItemMergeHandlerImpl.java 21 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/api/MdkApiImpl.java
@@ -102,9 +102,9 @@
                List<ItemVO> normalItems = predictItemList.stream().filter(e -> e.getItemType().equals("NormalItem")).collect(Collectors.toList());
                if (!CollectionUtils.isEmpty(normalItems)) {
                    predictModuleHandler.predict(normalItems, reqDTO.getPredictTime(), intervalTime,predictResultMap);
                    List<ItemVO> mergeItem = predictItemList.stream().filter(e -> e.getItemType().equals("MergeItem")).collect(Collectors.toList());
                    if (!CollectionUtils.isEmpty(mergeItem)) {
                        predictModuleHandler.predict(mergeItem, reqDTO.getPredictTime(), intervalTime,predictResultMap);
                    List<ItemVO> mergeItems = predictItemList.stream().filter(e -> e.getItemType().equals("MergeItem")).collect(Collectors.toList());
                    if (!CollectionUtils.isEmpty(mergeItems)) {
                        predictModuleHandler.predict(mergeItems, reqDTO.getPredictTime(), intervalTime,predictResultMap);
                    }
                }
                // 更新Module时间
iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmPredictItemServiceImpl.java
@@ -123,6 +123,7 @@
            MmItemOutputEntity entity = new MmItemOutputEntity();
            entity.setPointid(mmPredictItemDto.getPointId());
            entity.setResultName(mmPredictItemDto.getMmPredictItem().getItemname());
            entity.setResultstr("result");
            mergeItemOutput.add(entity);
            mmPredictItemDto.setMmItemOutputList(mergeItemOutput);
        }
@@ -168,8 +169,19 @@
            MmPredictMergeItemEntity mMmPredictMergeItem = mmPredictItemDto.getMmPredictMergeItem();
            mmPredictMergeItemService.update(mMmPredictMergeItem);
            // 修改默认output
            List<MmItemOutputEntity> mmItemOutputList = mmPredictItemDto.getMmItemOutputList();
            if (CollectionUtils.isEmpty(mmItemOutputList)) {
                mmItemOutputList = new ArrayList<>(1);
                MmItemOutputEntity entity = new MmItemOutputEntity();
                entity.setPointid(mmPredictItemDto.getPointId());
                entity.setResultName(mmPredictItemDto.getMmPredictItem().getItemname());
                entity.setResultstr("result");
                mmItemOutputList.add(entity);
                mmPredictItemDto.setMmItemOutputList(mmItemOutputList);
            } else {
            mmPredictItemDto.getMmItemOutputList().forEach(e -> e.setPointid(mmPredictItemDto.getPointId()));
        }
        }
        DmModuleItemEntity dmModuleItem = mmPredictItemDto.getDmModuleItem();
        if (!"".equals(dmModuleItem.getId()) && dmModuleItem.getId() != null) {
            dmModuleItemService.update(dmModuleItem);
iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/PredictModuleHandler.java
@@ -50,7 +50,6 @@
     * @return
     */
    public void predict(List<ItemVO> predictItemList, Date predictTime, int intervalTime,Map<String, PredictResultVO> predictResultMap) {
        PredictResultVO predictResult;
        Map<String, double[]> predictValueMap = null;
        if (!CollectionUtils.isEmpty(predictResultMap)) {
            // 将predictResultMap处理成Map<outPutId, double[]>
@@ -62,6 +61,7 @@
            }
        }
        for (ItemVO predictItem : predictItemList) {
            PredictResultVO predictResult;
            if (!predictItem.getStatus().equals(ItemStatus.STATUS1.getCode())) {
                continue;
            }
@@ -108,7 +108,6 @@
                e.printStackTrace();
                log.error(MessageFormat.format("预测项编号:{0},预测项名称:{1},预测失败:{2} 预测时刻:{3}",
                        predictItem.getId(), predictItem.getItemName(), e.getMessage(), predictTime));
                itemRunStatusEnum = ItemRunStatusEnum.FAIL;
            } finally {
                mmItemStatusService.recordStatus(predictItem.getId(), itemRunStatusEnum, totalDur, predictTime);
            }
iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/impl/PredictItemMergeHandlerImpl.java
@@ -1,19 +1,15 @@
package com.iailab.module.model.mdk.predict.impl;
import com.alibaba.fastjson.JSON;
import com.iailab.module.data.api.point.DataPointApi;
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;
import com.iailab.module.model.mdk.common.exceptions.ItemInvokeException;
import com.iailab.module.model.mdk.factory.ItemEntityFactory;
import com.iailab.module.model.mdk.factory.PredictItemFactory;
import com.iailab.module.model.mdk.predict.PredictItemHandler;
import com.iailab.module.model.mdk.predict.PredictResultHandler;
import com.iailab.module.model.mdk.vo.DataValueVO;
import com.iailab.module.model.mdk.vo.ItemVO;
import com.iailab.module.model.mdk.vo.PredictResultVO;
import lombok.extern.slf4j.Slf4j;
@@ -21,9 +17,7 @@
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.sql.Timestamp;
import java.util.*;
import java.util.stream.Collectors;
/**
 * @author PanZhibao
@@ -64,7 +58,6 @@
    public PredictResultVO predict(Date predictTime, ItemVO predictItemDto, Map<String, double[]> predictValueMap)
            throws ItemInvokeException {
        PredictResultVO predictResult = new PredictResultVO();
        ItemPredictStatus itemStatus = ItemPredictStatus.PREDICTING;
        String itemId = predictItemDto.getId();
        try {
            String expression = itemEntityFactory.getMergeItem(itemId).getExpression();
@@ -136,24 +129,20 @@
//                }
//                predictResult.setPredictMatrix(matrix);
//            }
            log.info("计算预测模型结果:" + predictResultMat);
            predictResult.setPredictId(itemId);
            List<MmItemOutputEntity> outputServiceByItemid = mmItemOutputService.getByItemid(itemId);
            if (CollectionUtils.isEmpty(outputServiceByItemid)) {
            if (!CollectionUtils.isEmpty(outputServiceByItemid)) {
                Map<MmItemOutputEntity, double[]> predictMatrixs = new HashMap<>();
                predictMatrixs.put(outputServiceByItemid.get(0),predictResultMat);
                predictResult.setPredictMatrixs(predictMatrixs);
            }
            predictResult.setPredictTime(predictTime);
            //预测项预测成功的状态
            itemStatus = ItemPredictStatus.SUCCESS;
        } catch (Exception e) {
            //预测项预测失败的状态
            itemStatus = ItemPredictStatus.FAILED;
            log.debug("merge项预测失败,itemId:" + itemId);
            log.error("merge项预测失败,itemId:" + itemId);
            e.printStackTrace();
            throw e;
        }
        log.debug("预测完成,itemId:" + itemId + ",itemStatus:" + itemStatus.getValue());
        log.info("merge项预测完成,itemId:" + itemId + ",结果:" + JSON.toJSONString(predictResult));
        return predictResult;
    }
}