| | |
| | | @Operation(summary = "执行单独预测") |
| | | MdkPredictItemRespDTO predictItem(@Valid @RequestBody MdkPredictReqDTO reqDTO); |
| | | |
| | | @PostMapping(PREFIX + "/predict-sim-adjust") |
| | | @Operation(summary = "模拟调整") |
| | | Boolean predictSimAdjust(@Valid @RequestBody MdkPredictSimAdjustReqDTO reqDTO); |
| | | |
| | | @PostMapping(PREFIX + "/predict-adjust") |
| | | @Operation(summary = "预测自动调整") |
| | | Boolean predictAutoAdjust(@Valid @RequestBody MdkPredictReqDTO reqDTO); |
对比新文件 |
| | |
| | | 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; |
| | | |
| | | import javax.validation.constraints.NotNull; |
| | | import java.util.Date; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * @author PanZhibao |
| | | * @Description |
| | | * @createTime 2025年02月24日 |
| | | */ |
| | | @Schema(description = "RPC 模型 - 模拟调整 DTO") |
| | | @Data |
| | | public class MdkPredictSimAdjustReqDTO { |
| | | |
| | | @Schema(description = "预测时间") |
| | | @NotNull(message="预测时间不能为空") |
| | | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") |
| | | private Date predictTime; |
| | | |
| | | @Schema(description = "调度方案编号") |
| | | @NotNull(message="调度方案编号不能为空") |
| | | private String scheduleCode; |
| | | |
| | | @Schema(description = "调度模型结果") |
| | | @NotNull(message="调度模型结果不能为空") |
| | | private Map<String, Object> modelResult; |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.enums; |
| | | |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.Getter; |
| | | |
| | | /** |
| | | * @author PanZhibao |
| | | * @Description |
| | | * @createTime 2025年02月24日 |
| | | */ |
| | | @Getter |
| | | @AllArgsConstructor |
| | | public enum PredictItemTypeEnum { |
| | | |
| | | NormalItem("48dffaa8-ac91-42f4-9369-79c9c2080ef5", "com.iailab.predictHandler.impl.PredictItemImpl"), |
| | | MergeItem("773ed6fb-3929-47c0-8749-0d6d11111111", "com.iailab.predictHandler.impl.PredictMergeItemImpl"); |
| | | |
| | | private String id; |
| | | private String type; |
| | | |
| | | public static PredictItemTypeEnum getEumById(String id) { |
| | | if (id == null) { |
| | | return null; |
| | | } |
| | | |
| | | for (PredictItemTypeEnum statusEnum : PredictItemTypeEnum.values()) { |
| | | if (statusEnum.getId().equals(id)) { |
| | | return statusEnum; |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | } |
| | |
| | | package com.iailab.module.model.api; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.iailab.module.data.api.point.DataPointApi; |
| | | import com.iailab.module.data.api.point.dto.ApiPointValueWriteDTO; |
| | | import com.iailab.module.model.api.mcs.dto.StScheduleModelOutDTO; |
| | |
| | | import com.iailab.module.model.api.mdk.dto.*; |
| | | import com.iailab.module.model.common.enums.IsWriteEnum; |
| | | import com.iailab.module.model.common.enums.ModelOutResultType; |
| | | import com.iailab.module.model.common.enums.OutResultType; |
| | | import com.iailab.module.model.enums.CommonConstant; |
| | | import com.iailab.module.model.enums.PredictItemTypeEnum; |
| | | import com.iailab.module.model.mcs.pre.entity.DmModuleEntity; |
| | | import com.iailab.module.model.mcs.pre.service.DmModuleService; |
| | | import com.iailab.module.model.mcs.pre.service.MmPredictItemService; |
| | | import com.iailab.module.model.mcs.sche.entity.StAdjustConfigDetEntity; |
| | | import com.iailab.module.model.mcs.sche.entity.StScheduleSchemeEntity; |
| | | import com.iailab.module.model.mcs.sche.service.StAdjustConfigService; |
| | | import com.iailab.module.model.mcs.sche.service.StScheduleModelOutService; |
| | | import com.iailab.module.model.mcs.sche.service.StScheduleRecordService; |
| | | import com.iailab.module.model.mcs.sche.service.StScheduleSchemeService; |
| | | import com.iailab.module.model.mdk.predict.PredictModuleHandler; |
| | | import com.iailab.module.model.mdk.predict.PredictResultHandler; |
| | | import com.iailab.module.model.mdk.schedule.ScheduleModelHandler; |
| | | 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 com.iailab.module.model.mdk.vo.ScheduleResultVO; |
| | | import com.iailab.module.model.mdk.vo.*; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.*; |
| | | import java.util.concurrent.TimeUnit; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import static com.iailab.module.model.common.enums.ModelOutResultType.D; |
| | | |
| | | /** |
| | | * @author PanZhibao |
| | |
| | | |
| | | @Autowired |
| | | private DataPointApi dataPointApi; |
| | | |
| | | @Autowired |
| | | private StAdjustConfigService stAdjustConfigService; |
| | | |
| | | @Autowired |
| | | private RedisTemplate<String, Object> redisTemplate; |
| | |
| | | return resp; |
| | | } |
| | | |
| | | @Override |
| | | public Boolean predictSimAdjust(MdkPredictSimAdjustReqDTO reqDTO) { |
| | | StScheduleSchemeEntity scheduleScheme = stScheduleSchemeService.getByCode(reqDTO.getScheduleCode()); |
| | | List<StAdjustConfigDetEntity> detList = stAdjustConfigService.getDetByModelId(scheduleScheme.getModelId()); |
| | | if (CollectionUtils.isEmpty(detList)) { |
| | | return Boolean.FALSE; |
| | | } |
| | | for (StAdjustConfigDetEntity det : detList) { |
| | | ItemVO predictItem = mmPredictItemService.getItemById(det.getPredictItemId()); |
| | | List<StAdjustDeviationDTO> deviationList = new ArrayList<>(); |
| | | switch (PredictItemTypeEnum.getEumById(det.getItemTypeId())) { |
| | | case NormalItem: |
| | | double adjustValue = new BigDecimal(reqDTO.getModelResult().get(det.getOutKey()).toString()).doubleValue(); |
| | | StAdjustDeviationDTO deviationItem = new StAdjustDeviationDTO(); |
| | | deviationItem.setPortIdx(det.getModelParamPortOrder()); |
| | | deviationItem.setParamIdx(det.getModelParamPortOrder()); |
| | | deviationItem.setValue(adjustValue); |
| | | deviationList.add(deviationItem); |
| | | break; |
| | | case MergeItem: |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | // 开始预测 |
| | | predictModuleHandler.predictAdjust(predictItem, reqDTO.getPredictTime(), deviationList, scheduleScheme.getModelId()); |
| | | } |
| | | return Boolean.TRUE; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 预测调整 |
| | | * |
| | |
| | | List<MmItemOutputEntity> getByItemid(String itemId); |
| | | |
| | | MmItemOutputEntity getByItemid(String itemid, String resultstr, String resultIndex); |
| | | |
| | | List<MmItemOutputEntity> getByItemid(String itemid, String resultstr, List<Integer> resultIndexs); |
| | | |
| | | void deleteByItemId(String itemId); |
| | |
| | | |
| | | List<Object[]> getData(String outputId, Date predictTime, String timeFormat, int scale); |
| | | |
| | | double[] getSimpleData(String outputId, Date predictTime, int predictLength); |
| | | |
| | | void insert(List<MmItemResultJsonEntity> resultJsonList); |
| | | |
| | | void cleanResultJson(Map<String, Date> tMap); |
| | |
| | | package com.iailab.module.model.mcs.pre.service; |
| | | |
| | | import com.iailab.module.model.mcs.pre.entity.MmItemOutputEntity; |
| | | import com.iailab.module.model.mdk.vo.DataValueVO; |
| | | |
| | | import java.util.Date; |
| | |
| | | } |
| | | |
| | | @Override |
| | | public double[] getSimpleData(String outputId, Date predictTime, int predictLength) { |
| | | double[] result = new double[predictLength]; |
| | | QueryWrapper<MmItemResultJsonEntity> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("outputid", outputId) |
| | | .eq("predicttime", DateUtils.format(predictTime, DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)); |
| | | MmItemResultJsonEntity data = baseDao.selectOne(wrapper); |
| | | if (data == null || StringUtils.isBlank(data.getJsonvalue())) { |
| | | return null; |
| | | } |
| | | List<Double> valueList = JSONArray.parseArray(data.getJsonvalue(), Double.class); |
| | | if (CollectionUtils.isEmpty(valueList)) { |
| | | return result; |
| | | } |
| | | for (int i = 0; i < predictLength; i++) { |
| | | result[i] = valueList.get(i); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | | public void insert(List<MmItemResultJsonEntity> resultJsonList) { |
| | | baseDao.insertBatch(resultJsonList); |
| | | } |
| | |
| | | |
| | | import com.iailab.framework.common.service.BaseService; |
| | | import com.iailab.module.model.mcs.sche.entity.StAdjustResultEntity; |
| | | import com.iailab.module.model.mdk.vo.DataValueVO; |
| | | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * @author PanZhibao |
| | |
| | | * @createTime 2025年02月23日 |
| | | */ |
| | | public interface StAdjustResultService extends BaseService<StAdjustResultEntity> { |
| | | |
| | | void saveResult(Map<String, List<DataValueVO>> resultMap, Date predictTime, String adjustValue, String scheduleModelId); |
| | | |
| | | double[] getSimpleData(String outputId, Date predictTime, int predictLength); |
| | | } |
| | |
| | | package com.iailab.module.model.mcs.sche.service.impl; |
| | | |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.iailab.framework.common.service.impl.BaseServiceImpl; |
| | | import com.iailab.framework.common.util.date.DateUtils; |
| | | import com.iailab.module.model.mcs.sche.dao.StAdjustResultDao; |
| | | import com.iailab.module.model.mcs.sche.entity.StAdjustResultEntity; |
| | | import com.iailab.module.model.mcs.sche.service.StAdjustResultService; |
| | | import com.iailab.module.model.mdk.vo.DataValueVO; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.UUID; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * @author PanZhibao |
| | |
| | | @Slf4j |
| | | @Service |
| | | public class StAdjustResultServiceImpl extends BaseServiceImpl<StAdjustResultDao, StAdjustResultEntity> implements StAdjustResultService { |
| | | |
| | | @Override |
| | | public void saveResult(Map<String, List<DataValueVO>> resultMap, Date predictTime, String adjustValue, String scheduleModelId) { |
| | | for (Map.Entry<String, List<DataValueVO>> entry : resultMap.entrySet()) { |
| | | StAdjustResultEntity entity = new StAdjustResultEntity(); |
| | | entity.setId(UUID.randomUUID().toString()); |
| | | entity.setScheduleModelId(scheduleModelId); |
| | | entity.setAdjustTime(predictTime); |
| | | entity.setAdjustValue(adjustValue); |
| | | entity.setOutputId(entry.getKey()); |
| | | List<Double> jsonValueList = entry.getValue().stream().map(valueVO -> valueVO.getDataValue()).collect(Collectors.toList()); |
| | | entity.setAdjustValue(JSONArray.toJSONString(jsonValueList)); |
| | | baseDao.insert(entity); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public double[] getSimpleData(String outputId, Date predictTime, int predictLength) { |
| | | double[] result = new double[predictLength]; |
| | | QueryWrapper<StAdjustResultEntity> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("output_id", outputId) |
| | | .eq("adjust_time", DateUtils.format(predictTime, DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)); |
| | | StAdjustResultEntity data = baseDao.selectOne(wrapper); |
| | | if (data == null || StringUtils.isBlank(data.getAdjustValue())) { |
| | | return null; |
| | | } |
| | | List<Double> valueList = JSONArray.parseArray(data.getAdjustValue(), Double.class); |
| | | if (CollectionUtils.isEmpty(valueList)) { |
| | | return result; |
| | | } |
| | | for (int i = 0; i < predictLength; i++) { |
| | | result[i] = valueList.get(i); |
| | | } |
| | | return result; |
| | | } |
| | | } |
| | |
| | | package com.iailab.module.model.mdk.predict; |
| | | |
| | | import com.iailab.module.model.common.exception.ModelResultErrorException; |
| | | 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 com.iailab.module.model.mdk.vo.StAdjustDeviationDTO; |
| | | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | |
| | | * |
| | | * @param predictTime |
| | | * @param predictItemDto |
| | | * @param predictValueMap |
| | | * @return |
| | | * @throws ItemInvokeException |
| | | */ |
| | | PredictResultVO predict(Date predictTime, ItemVO predictItemDto, Map<String, double[]> predictValueMap) throws ItemInvokeException; |
| | | |
| | | /** |
| | | * 单个预测项预测(模拟调整) |
| | | * |
| | | * @param predictTime |
| | | * @param predictItemDto |
| | | * @param deviationList |
| | | * @return |
| | | * @throws ItemInvokeException |
| | | * @throws ModelResultErrorException |
| | | */ |
| | | PredictResultVO predictAdjust(Date predictTime, ItemVO predictItemDto, List<StAdjustDeviationDTO> deviationList) throws ItemInvokeException, ModelResultErrorException; |
| | | } |
| | |
| | | package com.iailab.module.model.mdk.predict; |
| | | |
| | | import com.iailab.module.model.mdk.vo.StAdjustDeviationDTO; |
| | | 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; |
| | | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @author PanZhibao |
| | |
| | | * @param predictModel |
| | | * @param itemName |
| | | * @param itemNo |
| | | * @param deviation |
| | | * @param adjustValList |
| | | * @return |
| | | */ |
| | | PredictResultVO predictByModel(Date predictTime, MmPredictModelEntity predictModel,String itemName,String itemNo, double[][] deviation) throws ModelInvokeException; |
| | | PredictResultVO predictByModel(Date predictTime, MmPredictModelEntity predictModel,String itemName,String itemNo, List<StAdjustDeviationDTO> adjustValList) throws ModelInvokeException; |
| | | } |
| | |
| | | package com.iailab.module.model.mdk.predict; |
| | | |
| | | import com.alibaba.fastjson.JSONArray; |
| | | 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.mdk.factory.PredictItemFactory; |
| | | import com.iailab.module.model.mdk.vo.ItemVO; |
| | | import com.iailab.module.model.mdk.vo.PredictResultVO; |
| | | import com.iailab.module.model.mdk.vo.StAdjustDeviationDTO; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | |
| | | * @param intervalTime |
| | | * @return |
| | | */ |
| | | public void predict(List<ItemVO> predictItemList, Date predictTime, int intervalTime,Map<String, PredictResultVO> predictResultMap) { |
| | | public void predict(List<ItemVO> predictItemList, Date predictTime, int intervalTime, Map<String, PredictResultVO> predictResultMap) { |
| | | 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()); |
| | | predictValueMap.put(mmItemOutputEntityEntry.getKey().getId(), mmItemOutputEntityEntry.getValue()); |
| | | } |
| | | } |
| | | } |
| | |
| | | calendar.set(Calendar.MILLISECOND, 0); |
| | | calendar.set(Calendar.SECOND, 0); |
| | | if (PredGranularityEnum.H1.getCode().equals(predictItem.getGranularity())) { |
| | | calendar.set(Calendar.MINUTE,0); |
| | | }else if (PredGranularityEnum.D1.getCode().equals(predictItem.getGranularity())) { |
| | | calendar.set(Calendar.MINUTE,0); |
| | | calendar.set(Calendar.HOUR_OF_DAY,0); |
| | | calendar.set(Calendar.MINUTE, 0); |
| | | } else if (PredGranularityEnum.D1.getCode().equals(predictItem.getGranularity())) { |
| | | calendar.set(Calendar.MINUTE, 0); |
| | | calendar.set(Calendar.HOUR_OF_DAY, 0); |
| | | } |
| | | PredictResultVO predictResult; |
| | | if (!predictItem.getStatus().equals(ItemStatus.STATUS1.getCode())) { |
| | |
| | | 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}", |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | public void predictAdjust(ItemVO predictItem, Date predictTime, List<StAdjustDeviationDTO> deviationList, String scheduleModelId) { |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTime(predictTime); |
| | | calendar.set(Calendar.MILLISECOND, 0); |
| | | calendar.set(Calendar.SECOND, 0); |
| | | if (PredGranularityEnum.H1.getCode().equals(predictItem.getGranularity())) { |
| | | calendar.set(Calendar.MINUTE, 0); |
| | | } else if (PredGranularityEnum.D1.getCode().equals(predictItem.getGranularity())) { |
| | | calendar.set(Calendar.MINUTE, 0); |
| | | calendar.set(Calendar.HOUR_OF_DAY, 0); |
| | | } |
| | | |
| | | try { |
| | | PredictItemHandler predictItemHandler = predictItemFactory.create(predictItem.getId()); |
| | | PredictResultVO predictResult = predictItemHandler.predictAdjust(calendar.getTime(), predictItem, deviationList); |
| | | |
| | | // 保存预测结果 |
| | | predictResultHandler.savePredictAdjustResult(predictResult, JSONArray.toJSONString(deviationList), scheduleModelId); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | log.error(MessageFormat.format("预测项编号:{0},预测项名称:{1},预测失败:{2} 预测时刻:{3}", |
| | | predictItem.getId(), predictItem.getItemName(), e.getMessage(), predictTime)); |
| | | } |
| | | } |
| | | } |
| | |
| | | import com.iailab.module.model.common.enums.CommonDict; |
| | | import com.iailab.module.model.mcs.pre.entity.MmItemOutputEntity; |
| | | import com.iailab.module.model.mcs.pre.service.MmItemResultService; |
| | | import com.iailab.module.model.mcs.sche.service.StAdjustResultService; |
| | | import com.iailab.module.model.mdk.factory.ItemEntityFactory; |
| | | import com.iailab.module.model.mdk.vo.DataValueVO; |
| | | import com.iailab.module.model.mdk.vo.PredictResultVO; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.scheduling.annotation.Async; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | |
| | | @Autowired |
| | | private ItemEntityFactory itemEntityFactory; |
| | | |
| | | @Autowired |
| | | private StAdjustResultService stAdjustResultService; |
| | | |
| | | /** |
| | | * convertToPredictData |
| | | * |
| | |
| | | */ |
| | | public Map<String, List<DataValueVO>> convertToPredictData(PredictResultVO predictResult) { |
| | | Map<String, List<DataValueVO>> resultMap = new HashMap<>(); |
| | | // List<MmItemOutputEntity> itemOutPutList = itemEntityFactory.getOutPutByItemId(predictResult.getPredictId()); |
| | | // |
| | | // if (!CollectionUtils.isEmpty(predictResult.getPredictList())) { |
| | | // resultMap.put(itemOutPutList.get(0).getId(), predictResult.getPredictList()); |
| | | // return resultMap; |
| | | // } |
| | | Map<com.iailab.module.model.mcs.pre.entity.MmItemOutputEntity, double[]> predictMatrixs = predictResult.getPredictMatrixs(); |
| | | HashMap<String,List<DataValueVO>> predictLists = new HashMap<>(); |
| | | for (Map.Entry<com.iailab.module.model.mcs.pre.entity.MmItemOutputEntity, double[]> entry : predictMatrixs.entrySet()) { |
| | | Map<MmItemOutputEntity, double[]> predictMatrixs = predictResult.getPredictMatrixs(); |
| | | HashMap<String, List<DataValueVO>> predictLists = new HashMap<>(); |
| | | for (Map.Entry<MmItemOutputEntity, double[]> entry : predictMatrixs.entrySet()) { |
| | | Integer rows = entry.getValue().length; |
| | | List<DataValueVO> predictDataList = new ArrayList<>(); |
| | | Calendar calendar = Calendar.getInstance(); |
| | |
| | | |
| | | //处理累计计算 |
| | | if (entry.getKey().getIscumulant() == 1) { |
| | | resultMap.put(entry.getKey().getId() + CommonDict.CUMULANT_SUFFIX, new ArrayList<DataValueVO>(){{ |
| | | resultMap.put(entry.getKey().getId() + CommonDict.CUMULANT_SUFFIX, new ArrayList<DataValueVO>() {{ |
| | | DataValueVO predictData = new DataValueVO(); |
| | | // 时间 预测时间+预测长度*粒度 |
| | | Calendar calendar = Calendar.getInstance(); |
| | |
| | | mmItemResultService.savePredictValue(resultMap, predictResult.getLt(), "n", predictResult.getPredictTime()); |
| | | } |
| | | |
| | | /** |
| | | * savePredictAdjustResult |
| | | * |
| | | * @param predictResult |
| | | */ |
| | | @DSTransactional |
| | | public void savePredictAdjustResult(PredictResultVO predictResult, String adjustValue, String scheduleModelId) { |
| | | Map<String, List<DataValueVO>> resultMap = convertToPredictData(predictResult); |
| | | stAdjustResultService.saveResult(resultMap, predictResult.getPredictTime(), adjustValue, scheduleModelId); |
| | | } |
| | | |
| | | public List<DataValueVO> getPredictValueByItemNo(String itemNo, Date start, Date end) { |
| | | String itemId = itemEntityFactory.getItemByItemNo(itemNo).getId(); |
| | | List<MmItemOutputEntity> outputList = itemEntityFactory.getOutPutByItemId(itemId); |
| | |
| | | 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.model.mcs.pre.entity.MmItemOutputEntity; |
| | | import com.iailab.module.model.mcs.pre.service.MmItemOutputService; |
| | | import com.iailab.module.model.mcs.pre.service.MmItemResultService; |
| | | import com.iailab.module.model.mcs.pre.service.MmItemResultJsonService; |
| | | import com.iailab.module.model.mcs.sche.service.StAdjustResultService; |
| | | 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.ItemVO; |
| | | import com.iailab.module.model.mdk.vo.PredictResultVO; |
| | | import com.iailab.module.model.mdk.vo.StAdjustDeviationDTO; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | |
| | | private ItemEntityFactory itemEntityFactory; |
| | | |
| | | @Autowired |
| | | private DataPointApi dataPointApi; |
| | | |
| | | @Autowired |
| | | private PredictItemFactory predictItemFactory; |
| | | |
| | | @Autowired |
| | | private PredictResultHandler predictResultHandler; |
| | | |
| | | @Autowired |
| | | private MmItemResultService mmItemResultService; |
| | | private MmItemResultJsonService mmItemResultJsonService; |
| | | |
| | | @Autowired |
| | | private MmItemOutputService mmItemOutputService; |
| | | |
| | | @Autowired |
| | | private StAdjustResultService stAdjustResultService; |
| | | |
| | | /** |
| | | * MergeItem预测 |
| | |
| | | String[] mathOutPutId = expression.split("[\\+ \\-]"); |
| | | ArrayList<Character> operator = new ArrayList<>(); |
| | | for (int i = 0; i < expression.length(); i++) { |
| | | if (expression.charAt(i)=='+' || expression.charAt(i)=='-'){ |
| | | if (expression.charAt(i) == '+' || expression.charAt(i) == '-') { |
| | | operator.add(expression.charAt(i)); |
| | | } |
| | | } |
| | | // String[] compositionItem = expression.split(String.valueOf("&".toCharArray())); |
| | | //是否为计算预测项 |
| | | if (mathOutPutId.length > 1) { |
| | | // 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); |
| | | // } |
| | | // } |
| | | |
| | | for (Integer i = 0; i < predictLength; i++) { |
| | | double sum =0.0; |
| | | double sum = 0.0; |
| | | sum = predictValueMap.get(mathOutPutId[0])[i]; |
| | | for (int j = 1; j < mathOutPutId.length; j++) { |
| | | if (operator.get(j-1)=='+') |
| | | {sum += predictValueMap.get(mathOutPutId[j])[i];} |
| | | if (operator.get(j-1)=='-') |
| | | {sum -= predictValueMap.get(mathOutPutId[j])[i];} |
| | | if (operator.get(j - 1) == '+') { |
| | | sum += predictValueMap.get(mathOutPutId[j])[i]; |
| | | } |
| | | if (operator.get(j - 1) == '-') { |
| | | sum -= predictValueMap.get(mathOutPutId[j])[i]; |
| | | } |
| | | } |
| | | predictResultMat[i] = 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); |
| | | // } |
| | | predictResult.setPredictId(itemId); |
| | | List<MmItemOutputEntity> outputServiceByItemid = mmItemOutputService.getByItemid(itemId); |
| | | if (!CollectionUtils.isEmpty(outputServiceByItemid)) { |
| | | Map<MmItemOutputEntity, double[]> predictMatrixs = new HashMap<>(); |
| | | predictMatrixs.put(outputServiceByItemid.get(0),predictResultMat); |
| | | predictMatrixs.put(outputServiceByItemid.get(0), predictResultMat); |
| | | predictResult.setPredictMatrixs(predictMatrixs); |
| | | } |
| | | predictResult.setPredictTime(predictTime); |
| | | } catch (Exception e) { |
| | | log.error("merge项预测失败,itemId:" + itemId); |
| | | e.printStackTrace(); |
| | | throw e; |
| | | } |
| | | log.info("merge项预测完成,itemId:" + itemId + ",结果:" + JSON.toJSONString(predictResult)); |
| | | return predictResult; |
| | | } |
| | | |
| | | @Override |
| | | public PredictResultVO predictAdjust(Date predictTime, ItemVO predictItemDto, List<StAdjustDeviationDTO> deviationList) |
| | | throws ItemInvokeException { |
| | | PredictResultVO predictResult = new PredictResultVO(); |
| | | String itemId = predictItemDto.getId(); |
| | | try { |
| | | String expression = itemEntityFactory.getMergeItem(itemId).getExpression(); |
| | | int predictLength = itemEntityFactory.getItemById(itemId).getPredictLength(); |
| | | double[] predictResultMat = new double[predictLength]; |
| | | String[] mathOutPutId = expression.split("[\\+ \\-]"); |
| | | ArrayList<Character> operator = new ArrayList<>(); |
| | | for (int i = 0; i < expression.length(); i++) { |
| | | if (expression.charAt(i) == '+' || expression.charAt(i) == '-') { |
| | | operator.add(expression.charAt(i)); |
| | | } |
| | | } |
| | | Map<String, double[]> predictValueMap = new HashMap<>(); |
| | | for (int k = 0; k < mathOutPutId.length; k++) { |
| | | String outPutId = mathOutPutId[k]; |
| | | double[] outPutValue = stAdjustResultService.getSimpleData(outPutId, predictTime, predictLength); |
| | | if (outPutValue == null) { |
| | | outPutValue = mmItemResultJsonService.getSimpleData(outPutId, predictTime, predictLength); |
| | | } |
| | | predictValueMap.put(outPutId, outPutValue); |
| | | } |
| | | |
| | | //是否为计算预测项 |
| | | if (mathOutPutId.length > 1) { |
| | | for (int i = 0; i < predictLength; i++) { |
| | | double sum = predictValueMap.get(mathOutPutId[0])[i]; |
| | | for (int j = 1; j < mathOutPutId.length; j++) { |
| | | if (operator.get(j - 1) == '+') { |
| | | sum += predictValueMap.get(mathOutPutId[j])[i]; |
| | | } |
| | | if (operator.get(j - 1) == '-') { |
| | | sum -= predictValueMap.get(mathOutPutId[j])[i]; |
| | | } |
| | | } |
| | | predictResultMat[i] = sum; |
| | | } |
| | | } |
| | | predictResult.setPredictId(itemId); |
| | | 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); |
| | |
| | | import com.iailab.module.model.mdk.predict.PredictModelHandler; |
| | | import com.iailab.module.model.mdk.vo.ItemVO; |
| | | import com.iailab.module.model.mdk.vo.PredictResultVO; |
| | | import com.iailab.module.model.mdk.vo.StAdjustDeviationDTO; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.text.MessageFormat; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | |
| | | } |
| | | return predictResult; |
| | | } |
| | | |
| | | /** |
| | | * NormalItem预测 |
| | | * |
| | | * @param predictTime |
| | | * @param predictItemDto |
| | | * @return |
| | | * @throws ItemInvokeException |
| | | */ |
| | | @Override |
| | | public PredictResultVO predictAdjust(Date predictTime, ItemVO predictItemDto, List<StAdjustDeviationDTO> deviationList) throws ItemInvokeException,ModelResultErrorException { |
| | | PredictResultVO predictResult = new PredictResultVO(); |
| | | String itemId = predictItemDto.getId(); |
| | | try { |
| | | MmPredictModelEntity predictModel = mmPredictModelService.getActiveModelByItemId(itemId); |
| | | if (predictModel == null) { |
| | | throw new ModelInvokeException(MessageFormat.format("{0},itemId={1}", |
| | | ModelInvokeException.errorGetModelEntity, itemId)); |
| | | } |
| | | predictResult = predictModelHandler.predictByModel(predictTime, predictModel,predictItemDto.getItemName(),predictItemDto.getItemNo(), deviationList); |
| | | predictResult.setPredictId(itemId); |
| | | } catch (ModelResultErrorException ex) { |
| | | throw ex; |
| | | } catch (Exception ex) { |
| | | throw new ItemInvokeException(MessageFormat.format("{0},itemId={1}", |
| | | ItemInvokeException.errorItemFailed, itemId)); |
| | | } |
| | | return predictResult; |
| | | } |
| | | } |
| | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.iail.model.IAILModel; |
| | | import com.iailab.module.model.mdk.vo.StAdjustDeviationDTO; |
| | | import com.iailab.module.model.enums.CommonConstant; |
| | | import com.iailab.module.model.common.enums.OutResultType; |
| | | import com.iailab.module.model.common.exception.ModelResultErrorException; |
| | |
| | | * @throws ModelInvokeException |
| | | */ |
| | | @Override |
| | | public synchronized PredictResultVO predictByModel(Date predictTime, MmPredictModelEntity predictModel,String itemName,String itemNo) throws ModelInvokeException { |
| | | public PredictResultVO predictByModel(Date predictTime, MmPredictModelEntity predictModel, String itemName, String itemNo) throws ModelInvokeException { |
| | | PredictResultVO result = new PredictResultVO(); |
| | | if (predictModel == null) { |
| | | throw new ModelInvokeException("modelEntity is null"); |
| | |
| | | HashMap<String, Object> settings = getPredictSettingsByModelId(modelId); |
| | | // 校验setting必须有pyFile,否则可能导致程序崩溃 |
| | | if (!settings.containsKey(MdkConstant.PY_FILE_KEY)) { |
| | | throw new RuntimeException("模型设置参数缺少必要信息【" + MdkConstant.PY_FILE_KEY + "】,请重新上传模型!"); |
| | | throw new RuntimeException("模型设置参数缺少必要信息【" + MdkConstant.PY_FILE_KEY + "】,请重新上传模型!"); |
| | | } |
| | | |
| | | if (settings == null) { |
| | |
| | | param2Values[portLength] = newModelBean.getDataMap().get("models"); |
| | | param2Values[portLength + 1] = settings; |
| | | |
| | | log.info("####################### 预测模型 "+ "【itemId:" + predictModel.getItemid() + ",itemName:" + itemName + ",itemNo:" + itemNo + "】 ##########################"); |
| | | // JSONObject jsonObjNewModelBean = new JSONObject(); |
| | | // jsonObjNewModelBean.put("newModelBean", newModelBean); |
| | | // log.info(String.valueOf(jsonObjNewModelBean)); |
| | | // JSONObject jsonObjParam2Values = new JSONObject(); |
| | | // jsonObjParam2Values.put("param2Values", param2Values); |
| | | log.info("####################### 预测模型 " + "【itemId:" + predictModel.getItemid() + ",itemName:" + itemName + ",itemNo:" + itemNo + "】 ##########################"); |
| | | log.info("参数: " + JSON.toJSONString(param2Values)); |
| | | |
| | | //IAILMDK.run |
| | |
| | | * @param predictModel |
| | | * @param itemName |
| | | * @param itemNo |
| | | * @param deviationList |
| | | * @return |
| | | * @throws ModelInvokeException |
| | | */ |
| | | @Override |
| | | public synchronized PredictResultVO predictByModel(Date predictTime, MmPredictModelEntity predictModel,String itemName,String itemNo, double[][] deviation) throws ModelInvokeException { |
| | | public PredictResultVO predictByModel(Date predictTime, MmPredictModelEntity predictModel, String itemName, String itemNo, List<StAdjustDeviationDTO> deviationList) throws ModelInvokeException { |
| | | PredictResultVO result = new PredictResultVO(); |
| | | if (predictModel == null) { |
| | | throw new ModelInvokeException("modelEntity is null"); |
| | | } |
| | | String modelId = predictModel.getId(); |
| | | try { |
| | | List<SampleData> sampleDataList = sampleConstructor.constructSample(TypeA.Predict.name(), modelId, predictTime, itemName, new HashMap<>()); |
| | | List<SampleData> sampleDataList = sampleConstructor.constructSample(TypeA.Predict.name(), modelId, predictTime, itemName, new HashMap<>(), deviationList); |
| | | String modelPath = predictModel.getModelpath(); |
| | | if (modelPath == null) { |
| | | log.info("模型路径不存在,modelId=" + modelId); |
| | |
| | | HashMap<String, Object> settings = getPredictSettingsByModelId(modelId); |
| | | // 校验setting必须有pyFile,否则可能导致程序崩溃 |
| | | if (!settings.containsKey(MdkConstant.PY_FILE_KEY)) { |
| | | throw new RuntimeException("模型设置参数缺少必要信息【" + MdkConstant.PY_FILE_KEY + "】,请重新上传模型!"); |
| | | throw new RuntimeException("模型设置参数缺少必要信息【" + MdkConstant.PY_FILE_KEY + "】,请重新上传模型!"); |
| | | } |
| | | |
| | | if (settings == null) { |
| | |
| | | param2Values[portLength] = newModelBean.getDataMap().get("models"); |
| | | param2Values[portLength + 1] = settings; |
| | | |
| | | log.info("####################### 模拟调整 "+ "【itemId:" + predictModel.getItemid() + ",itemName:" + itemName + ",itemNo:" + itemNo + "】 ##########################"); |
| | | log.info("####################### 模拟调整 " + "【itemId:" + predictModel.getItemid() + ",itemName:" + itemName + ",itemNo:" + itemNo + "】 ##########################"); |
| | | log.info("参数: " + JSON.toJSONString(param2Values)); |
| | | |
| | | //IAILMDK.run |
| | |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * 构造IAILMDK.run()方法的newModelBean参数 |
| | | * |
| | |
| | | } |
| | | } |
| | | |
| | | int deviationIndex = 0; |
| | | |
| | | int portIdx = 0; |
| | | //对每个爪分别进行计算 |
| | | for (ColumnItemPort entry : sampleInfo.getColumnInfo()) { |
| | | double[][] matrix = new double[0][0]; |
| | |
| | | if (!CollectionUtils.isEmpty(indItemValueList)) { |
| | | matrix = new double[entry.getDataLength()][0]; |
| | | if (indItemValueList.size() > entry.getDataLength()) { |
| | | indItemValueList = indItemValueList.subList(0,entry.getDataLength()); |
| | | indItemValueList = indItemValueList.subList(0, entry.getDataLength()); |
| | | } |
| | | for (int i = 0; i < indItemValueList.size(); i++) { |
| | | String stringValue = indItemValueList.get(i).getDataValue().toString(); |
| | |
| | | matrix[i] = asciiArray; |
| | | } |
| | | } |
| | | }else { |
| | | } else { |
| | | //先依据爪内数据项的modelParamOrder进行排序——重写comparator匿名函数 |
| | | Collections.sort(entry.getColumnItemList(), new Comparator<ColumnItem>() { |
| | | @Override |
| | |
| | | } |
| | | } |
| | | |
| | | //找出对应的调整值 |
| | | double[] deviationItem = null; |
| | | if (sampleInfo.getDeviation() != null && sampleInfo.getDeviation().length > 0) { |
| | | deviationItem = sampleInfo.getDeviation()[deviationIndex]; |
| | | } |
| | | deviationIndex ++; |
| | | |
| | | //对每一项依次进行数据查询,然后将查询出的值赋给matrix对应的位置 |
| | | for (int i = 0; i < entry.getColumnItemList().size(); i++) { |
| | | try { |
| | | List<DataValueVO> dataEntityList = getData(entry.getColumnItemList().get(i), pointMap, planMap,indMap); |
| | | List<DataValueVO> dataEntityList = getData(entry.getColumnItemList().get(i), pointMap, planMap, indMap); |
| | | |
| | | //设置调整值 |
| | | if (deviationItem != null && deviationItem.length > 0) { |
| | | logger.info("设置调整值, i = " + i); |
| | | if (deviationItem[i] <= 0) { |
| | | continue; |
| | | } |
| | | for(int dataKey = 1; dataKey < dataEntityList.size(); dataKey ++) { |
| | | double adjustVal = SampleInfo.getAdjustValueFromDeviation(portIdx, i, sampleInfo.getDeviation()); |
| | | if (adjustVal != 0) { |
| | | logger.info("设置调整值adjustVal:" + adjustVal); |
| | | for (int dataKey = 1; dataKey < dataEntityList.size(); dataKey++) { |
| | | DataValueVO item = dataEntityList.get(dataKey); |
| | | item.setDataValue(item.getDataValue() + deviationItem[i]); |
| | | item.setDataValue(item.getDataValue() + adjustVal); |
| | | } |
| | | } |
| | | |
| | | //补全数据 |
| | | ColumnItem columnItem = entry.getColumnItemList().get(i); |
| | | dataEntityList = super.completionData(matrix.length, dataEntityList, columnItem.startTime, columnItem.endTime, columnItem.getParamType(),columnItem.getGranularity()); |
| | | dataEntityList = super.completionData(matrix.length, dataEntityList, columnItem.startTime, columnItem.endTime, columnItem.getParamType(), columnItem.getGranularity()); |
| | | |
| | | /** 如果数据取不满,把缺失的数据点放在后面 */ |
| | | if (dataEntityList != null && dataEntityList.size() != 0) { |
| | |
| | | throw e; |
| | | } |
| | | } |
| | | |
| | | portIdx++; |
| | | } |
| | | SampleData sampleData = new SampleData(); |
| | | sampleData.setMatrix(matrix); |
| | |
| | | package com.iailab.module.model.mdk.sample; |
| | | |
| | | import com.iailab.module.model.mdk.vo.StAdjustDeviationDTO; |
| | | import com.iailab.module.model.mdk.common.exceptions.ModelInvokeException; |
| | | import com.iailab.module.model.mdk.sample.dto.ColumnItemPort; |
| | | import com.iailab.module.model.mdk.sample.dto.SampleData; |
| | | import com.iailab.module.model.mdk.sample.dto.SampleInfo; |
| | | 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.util.Date; |
| | |
| | | } |
| | | |
| | | public List<SampleData> constructSample(String typeA, String modelId, Date runTime,String itemName, |
| | | Map<Integer, Integer> dynamicDataLength, double[][] deviation) throws ModelInvokeException { |
| | | Map<Integer, Integer> dynamicDataLength, List<StAdjustDeviationDTO> deviationList) throws ModelInvokeException { |
| | | try { |
| | | SampleInfoConstructor sampleInfoConstructor = sampleFactory.createSampleInfo(typeA, modelId); |
| | | SampleInfo sampleInfo = sampleInfoConstructor.prepareSampleInfo(modelId, runTime, dynamicDataLength); |
| | | sampleInfo.setDeviation(deviation); |
| | | sampleInfo.setDeviation(deviationList); |
| | | SampleDataConstructor sampleDataConstructor = sampleFactory.createSampleData(typeA); |
| | | return sampleDataConstructor.prepareSampleData(sampleInfo); |
| | | } catch (Exception e) { |
| | |
| | | import com.iailab.module.data.api.ind.dto.ApiIndItemDTO; |
| | | import com.iailab.module.data.api.plan.dto.ApiPlanItemDTO; |
| | | import com.iailab.module.data.api.point.dto.ApiPointDTO; |
| | | import com.iailab.module.model.mdk.vo.StAdjustDeviationDTO; |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.Builder; |
| | | import lombok.Data; |
| | | import lombok.NoArgsConstructor; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.sql.Timestamp; |
| | |
| | | private Integer sampleCycle; |
| | | |
| | | // 调整值 |
| | | private double[][] deviation; |
| | | private List<StAdjustDeviationDTO> deviation; |
| | | // 所有测点信息,避免重复查询 |
| | | private Map<String, ApiPointDTO> pointMap; |
| | | // 所有计划数据信息,避免重复查询 |
| | | private Map<String, ApiPlanItemDTO> planMap; |
| | | // 所有计划数据信息,避免重复查询 |
| | | private Map<String, ApiIndItemDTO> indMap; |
| | | |
| | | public static double getAdjustValueFromDeviation(int portIdx, int paramIdx, List<StAdjustDeviationDTO> deviation) { |
| | | if (CollectionUtils.isEmpty(deviation)) { |
| | | return 0; |
| | | } |
| | | for (StAdjustDeviationDTO deviationItem : deviation) { |
| | | if (deviationItem.getPortIdx() == portIdx && deviationItem.getParamIdx() == paramIdx) { |
| | | return deviationItem.getValue(); |
| | | } |
| | | } |
| | | return 0; |
| | | } |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.mdk.vo; |
| | | |
| | | import io.swagger.v3.oas.annotations.media.Schema; |
| | | import lombok.Data; |
| | | |
| | | /** |
| | | * @author PanZhibao |
| | | * @Description |
| | | * @createTime 2025年02月24日 |
| | | */ |
| | | @Schema(description = "模型服务 - 模拟调整值 DTO") |
| | | @Data |
| | | public class StAdjustDeviationDTO { |
| | | |
| | | private int portIdx; |
| | | |
| | | private int paramIdx; |
| | | |
| | | private double value; |
| | | } |