dengzedong
2 天以前 fde993948625751908d4e67bd5e77e8e2ce47d05
iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/impl/PredictItemMergeHandlerImpl.java
@@ -1,28 +1,23 @@
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;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.sql.Timestamp;
import java.util.*;
import java.util.stream.Collectors;
/**
 * @author PanZhibao
@@ -63,12 +58,11 @@
    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();
            int predictLength = itemEntityFactory.getItemById(itemId).getPredictLength();
            double[][] predictResultMat = new double[predictLength][1];
            double[] predictResultMat = new double[predictLength];
            String[] mathOutPutId = expression.split("[\\+ \\-]");
            ArrayList<Character> operator = new ArrayList<>();
            for (int i = 0; i < expression.length(); i++) {
@@ -111,7 +105,7 @@
                        if (operator.get(j-1)=='-')
                        {sum -= predictValueMap.get(mathOutPutId[j])[i];}
                    }
                    predictResultMat[i][0] = sum;
                    predictResultMat[i] = sum;
                }
            }
            //是否为组合预测项
@@ -135,19 +129,20 @@
//                }
//                predictResult.setPredictMatrix(matrix);
//            }
            log.info("计算预测模型结果:" + predictResultMat);
            predictResult.setPredictId(itemId);
            predictResult.setPredictMatrix(predictResultMat);
            List<MmItemOutputEntity> outputServiceByItemid = mmItemOutputService.getByItemid(itemId);
            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;
    }
}