| | |
| | | @Operation(summary = "根据测点ID查询测点信息") |
| | | ApiPointDTO getInfoById(@PathVariable("pointId") String pointId); |
| | | |
| | | @PostMapping(PREFIX + "/info/ids") |
| | | @Operation(summary = "根据多个测点ID查询测点信息") |
| | | List<ApiPointDTO> getInfoByIds(@RequestParam("pointNos") List<String> pointIds); |
| | | |
| | | @PostMapping(PREFIX + "/query-points/real-value") |
| | | @Operation(summary = "查询多个测点当前值") |
| | | Map<String, Object> queryPointsRealValue(@RequestParam("pointNos") List<String> pointNos); |
| | |
| | | public class ApiPointDTO implements Serializable { |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | @Schema(description = "id", required = true) |
| | | private String id; |
| | | |
| | | @Schema(description = "测点编码", required = true) |
| | | private String pointNo; |
| | | |
| | |
| | | |
| | | @Override |
| | | public ApiPointDTO getInfoById(String pointId) { |
| | | return ConvertUtils.sourceToTarget(daPointService.getSimpleInfoById(pointId), ApiPointDTO.class); |
| | | return daPointService.getSimpleInfoById(pointId); |
| | | } |
| | | |
| | | @Override |
| | | public List<ApiPointDTO> getInfoByIds(List<String> pointIds) { |
| | | List<ApiPointDTO> result = new ArrayList<>(pointIds.size()); |
| | | for (String pointId : pointIds) { |
| | | result.add(daPointService.getSimpleInfoById(pointId)); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | |
| | | package com.iailab.module.data.point.service; |
| | | |
| | | import com.iailab.framework.common.pojo.PageResult; |
| | | import com.iailab.module.data.api.point.dto.ApiPointDTO; |
| | | import com.iailab.module.data.point.dto.DaPointDTO; |
| | | import com.iailab.module.data.point.vo.*; |
| | | |
| | |
| | | |
| | | DaPointDTO info(String id); |
| | | |
| | | DaPointDTO getSimpleInfoById(String id); |
| | | ApiPointDTO getSimpleInfoById(String id); |
| | | |
| | | DaPointDTO getSimpleInfoByNo(String no); |
| | | |
| | |
| | | import com.iailab.framework.common.pojo.PageResult; |
| | | import com.iailab.framework.common.util.object.BeanUtils; |
| | | import com.iailab.framework.common.util.object.ConvertUtils; |
| | | import com.iailab.module.data.api.point.dto.ApiPointDTO; |
| | | import com.iailab.module.data.channel.common.service.ChannelSourceService; |
| | | import com.iailab.module.data.common.enums.CommonConstant; |
| | | import com.iailab.module.data.common.enums.IsEnableEnum; |
| | |
| | | @Resource |
| | | private DaPointCollectStatusService daPointCollectStatusService; |
| | | |
| | | private static Map<String, DaPointDTO> pointIdMap = new ConcurrentHashMap<>(); |
| | | private static Map<String, ApiPointDTO> pointIdMap = new ConcurrentHashMap<>(); |
| | | |
| | | private static Map<String, DaPointDTO> pointNoMap = new ConcurrentHashMap<>(); |
| | | |
| | |
| | | } |
| | | |
| | | @Override |
| | | public DaPointDTO getSimpleInfoById(String id) { |
| | | public ApiPointDTO getSimpleInfoById(String id) { |
| | | if (pointIdMap.containsKey(id)) { |
| | | return pointIdMap.get(id); |
| | | } |
| | | DaPointDTO dto = ConvertUtils.sourceToTarget(daPointDao.selectById(id), DaPointDTO.class); |
| | | ApiPointDTO dto = ConvertUtils.sourceToTarget(daPointDao.selectById(id), ApiPointDTO.class); |
| | | if (dto == null) { |
| | | return null; |
| | | } |
| | | pointIdMap.put(id, dto); |
| | | return pointIdMap.get(id); |
| | | return dto; |
| | | } |
| | | |
| | | @Override |
| | |
| | | package com.iailab.module.model.api.mdk.dto; |
| | | |
| | | import com.fasterxml.jackson.annotation.JsonFormat; |
| | | import io.swagger.v3.oas.annotations.media.Schema; |
| | | import lombok.Data; |
| | | |
| | |
| | | |
| | | @Schema(description = "调度方案时间") |
| | | @NotNull(message="调度方案时间不能为空") |
| | | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") |
| | | private Date scheduleTime; |
| | | } |
| | |
| | | @Override |
| | | public PreDataItemChartRespVO getPreDataItemChart(PreDataItemChartReqVO reqVO) { |
| | | PreDataItemChartRespVO result = new PreDataItemChartRespVO(); |
| | | ItemVO predictItem = mmPredictItemService.getItemByIdFromCache(reqVO.getItemId()); |
| | | ItemVO predictItem = mmPredictItemService.getItemById(reqVO.getItemId()); |
| | | if (predictItem == null) { |
| | | return result; |
| | | } |
| | |
| | | for (MmItemOutputEntity out : outs) { |
| | | legend.add(out.getResultName()); |
| | | PreDataSampleViewRespDTO viewDto = new PreDataSampleViewRespDTO(); |
| | | viewDto.setRealData(getHisData(out.getPointid(), startTime, endTime)); |
| | | if (StringUtils.isNotBlank(out.getPointid())) { |
| | | viewDto.setRealData(getHisData(out.getPointid(), startTime, endTime)); |
| | | } |
| | | viewDto.setPreDataN(mmItemResultService.getData(out.getId(), startTime, endTime, DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)); |
| | | viewMap.put(out.getResultName(), viewDto); |
| | | } |
| | |
| | | intervalTime = (int) (reqDTO.getPredictTime().getTime() - module.getPredicttime().getTime()) / (1000 * 60); |
| | | } |
| | | List<ItemVO> predictItemList = mmPredictItemService.getByModuleId(module.getId()); |
| | | Map<String, PredictResultVO> predictResultMap = predictModuleHandler.predict(predictItemList, reqDTO.getPredictTime(), intervalTime); |
| | | Map<String, PredictResultVO> predictResultMap = new HashMap<>(predictItemList.size()); |
| | | // 分组,先运行normal预测项,再将结果传递给merge预测项 |
| | | 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); |
| | | } |
| | | } |
| | | // 更新Module时间 |
| | | dmModuleService.updatePredictTime(module.getId(), reqDTO.getPredictTime()); |
| | | if (reqDTO.getIsResult() == null || !reqDTO.getIsResult()) { |
| | |
| | | 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); |
| | | 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()) { |
| | |
| | | log.info("预测计算结束: " + System.currentTimeMillis()); |
| | | } catch (Exception ex) { |
| | | log.info("调度计算异常: " + System.currentTimeMillis()); |
| | | ex.printStackTrace(); |
| | | // ex.printStackTrace(); |
| | | return resp; |
| | | } |
| | | return resp; |
| | |
| | | public enum ItemRunStatusEnum { |
| | | PROCESSING(1, "处理中"), |
| | | SUCCESS(2, "成功"), |
| | | FAIL(3, "失败"); |
| | | FAIL(3, "失败"), |
| | | MODELRESULTERROR(4, "模型结果异常"); |
| | | |
| | | private Integer code; |
| | | private String desc; |
| | |
| | | package com.iailab.module.model.mdk.predict; |
| | | |
| | | import com.iailab.module.model.mcs.pre.enums.ItemRunStatusEnum; |
| | | import com.iailab.module.model.mdk.common.exceptions.ItemInvokeException; |
| | | import com.iailab.module.model.mdk.vo.ItemVO; |
| | | import com.iailab.module.model.mdk.vo.PredictResultVO; |
| | | |
| | | import java.util.Date; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * @author PanZhibao |
| | |
| | | * @return |
| | | * @throws ItemInvokeException |
| | | */ |
| | | PredictResultVO predict(Date predictTime, ItemVO predictItemDto) throws ItemInvokeException; |
| | | PredictResultVO predict(Date predictTime, ItemVO predictItemDto, Map<String, double[]> predictValueMap, ItemRunStatusEnum itemRunStatusEnum) throws ItemInvokeException; |
| | | } |
| | |
| | | package com.iailab.module.model.mdk.predict; |
| | | |
| | | import com.iailab.module.model.mcs.pre.entity.MmPredictModelEntity; |
| | | import com.iailab.module.model.mcs.pre.enums.ItemRunStatusEnum; |
| | | import com.iailab.module.model.mdk.common.exceptions.ModelInvokeException; |
| | | import com.iailab.module.model.mdk.vo.PredictResultVO; |
| | | |
| | |
| | | * @return |
| | | * @throws ModelInvokeException |
| | | */ |
| | | PredictResultVO predictByModel(Date predictTime, MmPredictModelEntity predictModel,String itemName) throws ModelInvokeException; |
| | | PredictResultVO predictByModel(Date predictTime, MmPredictModelEntity predictModel,String itemName, ItemRunStatusEnum itemRunStatusEnum) throws ModelInvokeException; |
| | | } |
| | |
| | | package com.iailab.module.model.mdk.predict; |
| | | |
| | | 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; |
| | | import com.iailab.module.model.mcs.pre.service.MmItemStatusService; |
| | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.text.MessageFormat; |
| | | import java.time.Duration; |
| | |
| | | * @param intervalTime |
| | | * @return |
| | | */ |
| | | public Map<String, PredictResultVO> predict(List<ItemVO> predictItemList, Date predictTime, int intervalTime) { |
| | | Map<String, PredictResultVO> result = new HashMap<>(); |
| | | |
| | | PredictResultVO predictResult = new PredictResultVO(); |
| | | 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[]> |
| | | predictValueMap = new HashMap<>(); |
| | | for (Map.Entry<String, PredictResultVO> entry : predictResultMap.entrySet()) { |
| | | for (Map.Entry<MmItemOutputEntity, double[]> mmItemOutputEntityEntry : entry.getValue().getPredictMatrixs().entrySet()) { |
| | | predictValueMap.put(mmItemOutputEntityEntry.getKey().getId(),mmItemOutputEntityEntry.getValue()); |
| | | } |
| | | } |
| | | } |
| | | for (ItemVO predictItem : predictItemList) { |
| | | if (!predictItem.getStatus().equals(ItemStatus.STATUS1.getCode())) { |
| | | continue; |
| | | } |
| | | Long totalDur = 0L; |
| | | ItemRunStatusEnum itemRunStatusEnum = ItemRunStatusEnum.PROCESSING; |
| | | try { |
| | | mmItemStatusService.recordStatus(predictItem.getId(), ItemRunStatusEnum.PROCESSING, totalDur, predictTime); |
| | | mmItemStatusService.recordStatus(predictItem.getId(), itemRunStatusEnum, totalDur, predictTime); |
| | | PredictItemHandler predictItemHandler = predictItemFactory.create(predictItem.getId()); |
| | | long start = System.currentTimeMillis(); |
| | | try { |
| | | // 预测项开始预测 |
| | | predictResult = predictItemHandler.predict(predictTime, predictItem); |
| | | predictResult = predictItemHandler.predict(predictTime, predictItem, predictValueMap,itemRunStatusEnum); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | log.error(String.valueOf(e)); |
| | | mmItemStatusService.recordStatus(predictItem.getId(), ItemRunStatusEnum.FAIL, totalDur, predictTime); |
| | | continue; |
| | | } |
| | | long end = System.currentTimeMillis(); |
| | |
| | | log.info(MessageFormat.format("预测项:{0},保存时间:{1}ms", predictItem.getItemName(), |
| | | drtSave)); |
| | | totalDur = totalDur + drtSave; |
| | | mmItemStatusService.recordStatus(predictItem.getId(), ItemRunStatusEnum.SUCCESS, totalDur, predictTime); |
| | | result.put(predictItem.getItemNo(), predictResult); |
| | | predictResultMap.put(predictItem.getItemNo(), predictResult); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | log.error(MessageFormat.format("预测项编号:{0},预测项名称:{1},预测失败:{2} 预测时刻:{3}", |
| | | predictItem.getId(), predictItem.getItemName(), e.getMessage(), predictTime)); |
| | | mmItemStatusService.recordStatus(predictItem.getId(), ItemRunStatusEnum.FAIL, totalDur, predictTime); |
| | | itemRunStatusEnum = ItemRunStatusEnum.FAIL; |
| | | } finally { |
| | | mmItemStatusService.recordStatus(predictItem.getId(), itemRunStatusEnum, totalDur, predictTime); |
| | | } |
| | | } |
| | | return result; |
| | | } |
| | | } |
| | |
| | | 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 java.sql.Timestamp; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * @author PanZhibao |
| | |
| | | * @throws ItemInvokeException |
| | | */ |
| | | @Override |
| | | public PredictResultVO predict(Date predictTime, ItemVO predictItemDto) |
| | | public PredictResultVO predict(Date predictTime, ItemVO predictItemDto, Map<String, double[]> predictValueMap, ItemRunStatusEnum itemRunStatusEnum) |
| | | throws ItemInvokeException { |
| | | PredictResultVO predictResult = new PredictResultVO(); |
| | | ItemPredictStatus itemStatus = ItemPredictStatus.PREDICTING; |
| | |
| | | String expression = itemEntityFactory.getMergeItem(itemId).getExpression(); |
| | | int predictLength = itemEntityFactory.getItemById(itemId).getPredictLength(); |
| | | double[][] predictResultMat = new double[predictLength][1]; |
| | | Map<String, List<DataValueVO>> predictValueMap = new HashMap<>(); |
| | | String[] mathOutPutId = expression.split("[\\+ \\-]"); |
| | | ArrayList<Character> operator = new ArrayList<>(); |
| | | for (int i = 0; i < expression.length(); i++) { |
| | |
| | | operator.add(expression.charAt(i)); |
| | | } |
| | | } |
| | | String[] compositionItem = expression.split(String.valueOf("&".toCharArray())); |
| | | // String[] compositionItem = expression.split(String.valueOf("&".toCharArray())); |
| | | //是否为计算预测项 |
| | | if (mathOutPutId.length > 1) { |
| | | for (String outPutId : mathOutPutId) { |
| | | if (outPutId.length() > 4) { |
| | | Date endTime = predictTime; |
| | | // ItemVO itemEntity = itemEntityFactory.getItemByItemNo(itemNo); |
| | | // List<MmItemOutputEntity> outPutList = itemEntityFactory.getOutPutByItemId(itemEntity.getId()); |
| | | MmItemOutputEntity outPut = mmItemOutputService.getOutPutById(outPutId); |
| | | ApiPointDTO pointEntity = dataPointApi.getInfoById(outPut.getPointid()); |
| | | // Map<String, List<DataValueVO>> predictValueMap = new HashMap<>(); |
| | | // for (String outPutId : mathOutPutId) { |
| | | // if (outPutId.length() > 4) { |
| | | // Date endTime = predictTime; |
| | | //// ItemVO itemEntity = itemEntityFactory.getItemByItemNo(itemNo); |
| | | //// List<MmItemOutputEntity> outPutList = itemEntityFactory.getOutPutByItemId(itemEntity.getId()); |
| | | // MmItemOutputEntity outPut = mmItemOutputService.getOutPutById(outPutId); |
| | | // ApiPointDTO pointEntity = dataPointApi.getInfoById(outPut.getPointid()); |
| | | // |
| | | // Calendar calendar = Calendar.getInstance(); |
| | | // calendar.setTime(endTime); |
| | | // calendar.add(Calendar.SECOND, (predictLength - 1) * DataPointFreqEnum.getEumByCode(pointEntity.getMinfreqid()).getValue()); |
| | | // endTime = new Timestamp(calendar.getTime().getTime()); |
| | | //// List<DataValueVO> predictValueList = predictResultHandler.getPredictValueByItemNo(itemNo, predictTime, endTime); |
| | | // List<DataValueVO> predictValueList = mmItemResultService.getPredictValue(outPutId, predictTime, endTime); |
| | | // if (predictValueList.size() != predictLength) { |
| | | // log.debug("merge项融合失败:缺少子项预测数据,对应子项outPutId=" + outPutId); |
| | | // return null; |
| | | // } |
| | | // predictValueMap.put(outPutId, predictValueList); |
| | | // } |
| | | // } |
| | | |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTime(endTime); |
| | | calendar.add(Calendar.SECOND, (predictLength - 1) * DataPointFreqEnum.getEumByCode(pointEntity.getMinfreqid()).getValue()); |
| | | endTime = new Timestamp(calendar.getTime().getTime()); |
| | | // List<DataValueVO> predictValueList = predictResultHandler.getPredictValueByItemNo(itemNo, predictTime, endTime); |
| | | List<DataValueVO> predictValueList = mmItemResultService.getPredictValue(outPutId, predictTime, endTime); |
| | | if (predictValueList.size() != predictLength) { |
| | | log.debug("merge项融合失败:缺少子项预测数据,对应子项outPutId=" + outPutId); |
| | | return null; |
| | | } |
| | | predictValueMap.put(outPutId, predictValueList); |
| | | } |
| | | } |
| | | for (Integer i = 0; i < predictLength; i++) { |
| | | double sum =0.0; |
| | | sum = predictValueMap.get(mathOutPutId[0]).get(i).getDataValue(); |
| | | sum = predictValueMap.get(mathOutPutId[0])[i]; |
| | | for (int j = 1; j < mathOutPutId.length; j++) { |
| | | if (operator.get(j-1)=='+') |
| | | {sum += predictValueMap.get(mathOutPutId[j]).get(i).getDataValue();} |
| | | {sum += predictValueMap.get(mathOutPutId[j])[i];} |
| | | if (operator.get(j-1)=='-') |
| | | {sum -= predictValueMap.get(mathOutPutId[j]).get(i).getDataValue();} |
| | | {sum -= predictValueMap.get(mathOutPutId[j])[i];} |
| | | } |
| | | predictResultMat[i][0] = sum; |
| | | } |
| | | } |
| | | //是否为组合预测项 |
| | | if (compositionItem.length > 1) { |
| | | Map<String, PredictResultVO> predictResultMap = new HashMap<>(); |
| | | Integer columnTotalNumber = 0; |
| | | Integer rowNumber = 0; |
| | | for (String itemNo : compositionItem) { |
| | | PredictItemHandler predictItem = (PredictItemHandler) predictItemFactory.create(itemEntityFactory. |
| | | getItemByItemNo(itemNo).getId()); |
| | | predictResult = predictItem.predict(predictTime, predictItemDto); |
| | | columnTotalNumber += Integer.valueOf(predictResult.getPredictMatrix().length); |
| | | predictResultMap.put(itemNo, predictItem.predict(predictTime, predictItemDto)); |
| | | } |
| | | double[][] matrix = new double[columnTotalNumber][1]; |
| | | for (String itemNo : compositionItem) { |
| | | for (Integer i = 0; i < predictResultMap.get(itemNo).getPredictMatrix().length; i++) { |
| | | matrix[rowNumber][0] = predictResultMap.get(itemNo).getPredictMatrix()[i][0]; |
| | | rowNumber++; |
| | | } |
| | | } |
| | | predictResult.setPredictMatrix(matrix); |
| | | } |
| | | // if (compositionItem.length > 1) { |
| | | // Map<String, PredictResultVO> predictResultMap = new HashMap<>(); |
| | | // Integer columnTotalNumber = 0; |
| | | // Integer rowNumber = 0; |
| | | // for (String itemNo : compositionItem) { |
| | | // PredictItemHandler predictItem = (PredictItemHandler) predictItemFactory.create(itemEntityFactory. |
| | | // getItemByItemNo(itemNo).getId()); |
| | | // predictResult = predictItem.predict(predictTime, predictItemDto); |
| | | // columnTotalNumber += Integer.valueOf(predictResult.getPredictMatrix().length); |
| | | // predictResultMap.put(itemNo, predictItem.predict(predictTime, predictItemDto)); |
| | | // } |
| | | // double[][] matrix = new double[columnTotalNumber][1]; |
| | | // for (String itemNo : compositionItem) { |
| | | // for (Integer i = 0; i < predictResultMap.get(itemNo).getPredictMatrix().length; i++) { |
| | | // matrix[rowNumber][0] = predictResultMap.get(itemNo).getPredictMatrix()[i][0]; |
| | | // rowNumber++; |
| | | // } |
| | | // } |
| | | // predictResult.setPredictMatrix(matrix); |
| | | // } |
| | | predictResult.setPredictId(itemId); |
| | | predictResult.setPredictMatrix(predictResultMat); |
| | | predictResult.setPredictTime(predictTime); |
| | |
| | | package com.iailab.module.model.mdk.predict.impl; |
| | | |
| | | import com.iailab.module.model.mcs.pre.entity.MmPredictModelEntity; |
| | | import com.iailab.module.model.mcs.pre.enums.ItemRunStatusEnum; |
| | | import com.iailab.module.model.mcs.pre.service.MmPredictModelService; |
| | | import com.iailab.module.model.mdk.common.exceptions.ItemInvokeException; |
| | | import com.iailab.module.model.mdk.common.exceptions.ModelInvokeException; |
| | |
| | | |
| | | import java.text.MessageFormat; |
| | | import java.util.Date; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * @author PanZhibao |
| | |
| | | * @throws ItemInvokeException |
| | | */ |
| | | @Override |
| | | public PredictResultVO predict(Date predictTime, ItemVO predictItemDto) throws ItemInvokeException { |
| | | public PredictResultVO predict(Date predictTime, ItemVO predictItemDto, Map<String, double[]> predictValueMap, ItemRunStatusEnum itemRunStatusEnum) 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()); |
| | | predictResult = predictModelHandler.predictByModel(predictTime, predictModel,predictItemDto.getItemName(),itemRunStatusEnum); |
| | | predictResult.setPredictId(itemId); |
| | | } catch (Exception ex) { |
| | | throw new ItemInvokeException(MessageFormat.format("{0},itemId={1}", |
| | |
| | | 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; |
| | | 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.MmModelArithSettingsService; |
| | | import com.iailab.module.model.mdk.common.enums.TypeA; |
| | |
| | | * @throws ModelInvokeException |
| | | */ |
| | | @Override |
| | | public synchronized PredictResultVO predictByModel(Date predictTime, MmPredictModelEntity predictModel,String itemName) throws ModelInvokeException { |
| | | public synchronized PredictResultVO predictByModel(Date predictTime, MmPredictModelEntity predictModel,String itemName, ItemRunStatusEnum itemRunStatusEnum) 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); |
| | | } |
| | | modelResult = (HashMap<String, Object>) modelResult.get(CommonConstant.MDK_RESULT); |
| | |
| | | package com.iailab.module.model.mdk.sample; |
| | | |
| | | import com.iailab.module.data.api.point.DataPointApi; |
| | | import com.iailab.module.data.api.point.dto.ApiPointDTO; |
| | | import com.iailab.module.model.mcs.pre.entity.MmModelParamEntity; |
| | | import com.iailab.module.model.mcs.pre.service.MmModelParamService; |
| | | import com.iailab.module.model.mcs.pre.service.MmPredictItemService; |
| | | import com.iailab.module.model.mcs.pre.service.MmPredictModelService; |
| | | import com.iailab.module.model.mdk.common.enums.ModelParamType; |
| | | import com.iailab.module.model.mdk.sample.dto.ColumnItem; |
| | | import com.iailab.module.model.mdk.sample.dto.ColumnItemPort; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.function.Function; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * @author PanZhibao |
| | |
| | | |
| | | @Autowired |
| | | private MmPredictItemService mmPredictItemService; |
| | | |
| | | @Autowired |
| | | private DataPointApi dataPointApi; |
| | | |
| | | /** |
| | | * 返回样本矩阵的列数 |
| | |
| | | int curPortOrder = modelInputParamEntityList.get(0).getModelparamportorder(); |
| | | //设置当前查询数据长度,初始值为最小端口数据长度 |
| | | int curDataLength = modelInputParamEntityList.get(0).getDatalength(); |
| | | // 统一获取测点的信息 |
| | | List<String> pointIds = modelInputParamEntityList.stream().filter(e -> ModelParamType.getEumByCode(e.getModelparamtype()).equals(ModelParamType.DATAPOINT)).map(MmModelParamEntity::getModelparamid).collect(Collectors.toList()); |
| | | List<ApiPointDTO> points = dataPointApi.getInfoByIds(pointIds); |
| | | Map<String, ApiPointDTO> pointMap = points.stream().collect(Collectors.toMap(ApiPointDTO::getId, Function.identity())); |
| | | |
| | | for (MmModelParamEntity entry : modelInputParamEntityList) { |
| | | columnInfo.setParamType(entry.getModelparamtype()); |
| | | columnInfo.setParamId(entry.getModelparamid()); |
| | | columnInfo.setDataLength(entry.getDatalength()); |
| | | columnInfo.setModelParamOrder(entry.getModelparamorder()); |
| | | columnInfo.setModelParamPortOrder(entry.getModelparamportorder()); |
| | | columnInfo.setStartTime(getStartTime(columnInfo, predictTime)); |
| | | columnInfo.setEndTime(getEndTime(columnInfo, predictTime)); |
| | | columnInfo.setStartTime(getStartTime(columnInfo, predictTime,pointMap)); |
| | | columnInfo.setEndTime(getEndTime(columnInfo, predictTime,pointMap)); |
| | | columnInfo.setGranularity(super.getGranularity(columnInfo)); |
| | | |
| | | //对每一个爪进行数据项归并 |
| | |
| | | import java.util.Calendar; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * @author PanZhibao |
| | |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | protected Date getStartTime(ColumnItem columnItem, Date originalTime) { |
| | | protected Date getStartTime(ColumnItem columnItem, Date originalTime, Map<String, ApiPointDTO> pointMap) { |
| | | Date dateTime = new Date(); |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTime(originalTime); |
| | | switch (ModelParamType.getEumByCode(columnItem.getParamType())) { |
| | | case DATAPOINT: |
| | | ApiPointDTO dataPoint = dataPointApi.getInfoById(columnItem.getParamId()); |
| | | ApiPointDTO dataPoint = pointMap.get(columnItem.getParamId()); |
| | | if (dataPoint == null) { |
| | | return null; |
| | | } |
| | |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | protected Date getEndTime(ColumnItem columnItem, Date originalTime) { |
| | | protected Date getEndTime(ColumnItem columnItem, Date originalTime,Map<String, ApiPointDTO> pointMap) { |
| | | Date dateTime = new Date(); |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTime(originalTime); |
| | | switch (ModelParamType.getEumByCode(columnItem.getParamType())) { |
| | | case DATAPOINT: |
| | | ApiPointDTO dataPoint = dataPointApi.getInfoById(columnItem.getParamId()); |
| | | ApiPointDTO dataPoint = pointMap.get(columnItem.getParamId()); |
| | | if (dataPoint == null) { |
| | | return null; |
| | | } |
| | |
| | | package com.iailab.module.model.mdk.sample; |
| | | |
| | | import com.iailab.module.data.api.point.DataPointApi; |
| | | import com.iailab.module.data.api.point.dto.ApiPointDTO; |
| | | import com.iailab.module.model.mcs.pre.entity.MmModelParamEntity; |
| | | import com.iailab.module.model.mcs.sche.entity.StScheduleModelParamEntity; |
| | | import com.iailab.module.model.mcs.sche.service.StScheduleModelParamService; |
| | | import com.iailab.module.model.mdk.common.enums.ModelParamType; |
| | | import com.iailab.module.model.mdk.sample.dto.ColumnItem; |
| | | import com.iailab.module.model.mdk.sample.dto.ColumnItemPort; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.function.Function; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Component |
| | | public class ScheduleSampleInfoConstructor extends SampleInfoConstructor { |
| | | |
| | | @Autowired |
| | | private StScheduleModelParamService stScheduleModelParamService; |
| | | |
| | | @Autowired |
| | | private DataPointApi dataPointApi; |
| | | |
| | | @Override |
| | | protected Integer getSampleColumn(String modelId) { |
| | |
| | | int curPortOrder = modelInputParamEntityList.get(0).getModelparamportorder(); |
| | | //设置当前查询数据长度,初始值为最小端口数据长度 |
| | | int curDataLength = modelInputParamEntityList.get(0).getDatalength(); |
| | | // 统一获取测点的信息 |
| | | List<String> pointIds = modelInputParamEntityList.stream().filter(e -> ModelParamType.getEumByCode(e.getModelparamtype()).equals(ModelParamType.DATAPOINT)).map(StScheduleModelParamEntity::getModelparamid).collect(Collectors.toList()); |
| | | List<ApiPointDTO> points = dataPointApi.getInfoByIds(pointIds); |
| | | Map<String, ApiPointDTO> pointMap = points.stream().collect(Collectors.toMap(ApiPointDTO::getId, Function.identity())); |
| | | |
| | | for (StScheduleModelParamEntity entry : modelInputParamEntityList) { |
| | | columnInfo.setParamType(entry.getModelparamtype()); |
| | | columnInfo.setParamId(entry.getModelparamid()); |
| | | columnInfo.setDataLength(entry.getDatalength()); |
| | | columnInfo.setModelParamOrder(entry.getModelparamorder()); |
| | | columnInfo.setModelParamPortOrder(entry.getModelparamportorder()); |
| | | columnInfo.setStartTime(getStartTime(columnInfo, predictTime)); |
| | | columnInfo.setEndTime(getEndTime(columnInfo, predictTime)); |
| | | columnInfo.setStartTime(getStartTime(columnInfo, predictTime,pointMap)); |
| | | columnInfo.setEndTime(getEndTime(columnInfo, predictTime,pointMap)); |
| | | columnInfo.setGranularity(super.getGranularity(columnInfo)); |
| | | |
| | | //对每一个爪进行数据项归并 |
| | |
| | | package com.iailab.module.model.mdk.schedule.impl; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.iail.model.IAILModel; |
| | |
| | | String modelId = scheduleModel.getId(); |
| | | try { |
| | | //1.根据模型id构造模型输入样本 |
| | | long now = System.currentTimeMillis(); |
| | | List<SampleData> sampleDataList = sampleConstructor.constructSample(TypeA.Schedule.name(), modelId, scheduleTime); |
| | | log.info("构造模型输入样本消耗时长:" + (System.currentTimeMillis() - now) / 1000 + "秒"); |
| | | if (CollectionUtils.isEmpty(sampleDataList)) { |
| | | log.info("调度模型构造样本失败,schemeCode=" + schemeCode); |
| | | return null; |
| | |
| | | param2Values[portLength] = settings; |
| | | |
| | | log.info("#######################调度模型 " + scheduleModel.getModelName() + " ##########################"); |
| | | JSONObject jsonObjNewModelBean = new JSONObject(); |
| | | jsonObjNewModelBean.put("newModelBean", newModelBean); |
| | | log.info(String.valueOf(jsonObjNewModelBean)); |
| | | JSONObject jsonObjParam2Values = new JSONObject(); |
| | | jsonObjParam2Values.put("param2Values", param2Values); |
| | | log.info(String.valueOf(jsonObjParam2Values)); |
| | | // JSONObject jsonObjNewModelBean = new JSONObject(); |
| | | // jsonObjNewModelBean.put("newModelBean", newModelBean); |
| | | // log.info(String.valueOf(jsonObjNewModelBean)); |
| | | // JSONObject jsonObjParam2Values = new JSONObject(); |
| | | // jsonObjParam2Values.put("param2Values", param2Values); |
| | | log.info("参数: " + JSON.toJSONString(param2Values)); |
| | | |
| | | //IAILMDK.run |
| | | HashMap<String, Object> modelResult = DllUtils.run(newModelBean, param2Values, scheduleScheme.getMpkprojectid()); |
| | |
| | | * 统一预测入口的预测类型(循环调用、手动调用) Map<MmItemOutputEntity,double[]> |
| | | */ |
| | | private Map<MmItemOutputEntity, double[]> predictMatrixs; |
| | | |
| | | /** |
| | | * double类型的模型输出 |
| | | */ |
| | | private Map<MmItemOutputEntity, Double> predictDoubleValues; |
| | | |
| | | /** |