predictAdjust 模拟调整预测
setAdjData 模拟调制预测曲线查询
| | |
| | | PreDataBarLineRespVO getPreDataCharts(@RequestBody PreDataBarLineReqVO reqVO); |
| | | |
| | | @PostMapping(PREFIX + "/predict-data/item-chart") |
| | | @Operation(summary = "预测数据图表") |
| | | @Operation(summary = "预测数据图表-预测项首页图表") |
| | | PreDataItemChartRespVO getPreDataItemChart(@RequestBody PreDataItemChartReqVO reqVO); |
| | | |
| | | @PostMapping(PREFIX + "/predict-data/single-chart") |
| | |
| | | |
| | | @Schema(description = "累计预测值") |
| | | private List<Object[]> cumulantPreData; |
| | | |
| | | @Schema(description = "调整预测值") |
| | | private List<Object[]> adjData; |
| | | } |
| | |
| | | @Schema(description = "当时预测值") |
| | | private List<Object[]> curData; |
| | | |
| | | @Schema(description = "调整值") |
| | | @Schema(description = "调整预测值") |
| | | private List<Object[]> adjData; |
| | | |
| | | @Schema(description = "预警信息") |
| | |
| | | CREATE TABLE `t_st_adjust_result` ( |
| | | `id` varchar(36) NOT NULL COMMENT 'ID', |
| | | `config_id` varchar(36) DEFAULT NULL COMMENT '配置ID', |
| | | `output_id` varchar(36) DEFAULT NULL COMMENT '预测项输出ID', |
| | | `output_id` varchar(50) DEFAULT NULL COMMENT '预测项输出ID', |
| | | `schedule_model_id` varchar(36) DEFAULT NULL COMMENT '调度模型ID', |
| | | `adjust_time` datetime NULL DEFAULT NULL COMMENT '模拟调整时间', |
| | | `adjust_value` varchar(500) DEFAULT NULL COMMENT '模拟调整值', |
| | |
| | | private MmItemResultJsonService mmItemResultJsonService; |
| | | |
| | | @Autowired |
| | | private StAdjustResultService stAdjustResultService; |
| | | |
| | | @Autowired |
| | | private ChartService chartService; |
| | | |
| | | @Autowired |
| | |
| | | viewDto.setRealData(getHisData(output.getPointid(), startTime, endTime)); |
| | | viewDto.setPreDataN(mmItemResultService.getData(output.getId(), startTime, endTime, DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)); |
| | | viewDto.setPreDataL(mmItemResultLastPointService.getData(output.getId(), startTime, endTime, DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)); |
| | | viewDto.setCurData(mmItemResultJsonService.getData(output.getId(), predictTime, DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND, 3)); |
| | | viewDto.setCurData(mmItemResultJsonService.getData(output.getId(), predictTime, DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)); |
| | | // 模拟调整曲线 |
| | | viewDto.setAdjData(stAdjustResultService.getData(output.getId(), predictTime, DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)); |
| | | |
| | | List<Double> values = new ArrayList<>(); |
| | | if (!CollectionUtils.isEmpty(viewDto.getRealData())) { |
| | | List<Double> hisValues = new ArrayList<>(); |
| | |
| | | } |
| | | viewDto.setCumulantPreData(mmItemResultService.getData(out.getId() + CommonDict.CUMULANT_SUFFIX, startTime, endTime, DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)); |
| | | } |
| | | // 调整预测值 |
| | | viewDto.setAdjData(stAdjustResultService.getData(out.getId(),predictItem.getLastTime(), DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)); |
| | | |
| | | viewMap.put(out.getResultName(), viewDto); |
| | | } |
| | |
| | | dataView.setRealData(new ArrayList<>()); |
| | | } |
| | | dataView.setCurData(mmItemResultJsonService.getData(outPut.getId(), predictTime, timeFormat, 3)); |
| | | // 调整预测值 |
| | | dataView.setAdjData(stAdjustResultService.getData(outPut.getId(),predictTime,timeFormat)); |
| | | dataView.setLineType(lineType.getCode()); |
| | | switch (lineType) { |
| | | case TN: |
| | |
| | | break; |
| | | } |
| | | // 开始预测 |
| | | predictModuleHandler.predictAdjust(predictItem, reqDTO.getPredictTime(), deviationList, scheduleScheme.getModelId()); |
| | | predictModuleHandler.predictAdjust(predictItem, reqDTO.getPredictTime(), deviationList, scheduleScheme.getModelId(), det.getConfigId()); |
| | | } |
| | | return Boolean.TRUE; |
| | | } |
| | |
| | | */ |
| | | public interface StAdjustResultService extends BaseService<StAdjustResultEntity> { |
| | | |
| | | void saveResult(Map<String, List<DataValueVO>> resultMap, Date predictTime, String adjustValue, String scheduleModelId); |
| | | void saveResult(Map<String, List<DataValueVO>> resultMap, Date predictTime, String adjustValue, String scheduleModelId, String configId); |
| | | |
| | | double[] getSimpleData(String outputId, Date predictTime, int predictLength); |
| | | |
| | | List<Object[]> getData(String outputId, Date predictTime, String timeFormat); |
| | | |
| | | StAdjustResultRespVO getInfo(String id); |
| | | |
| | | PageResult<StAdjustResultRespVO> page(@Valid StAdjustResultPageReqVO pageVO); |
| | |
| | | } |
| | | |
| | | public StAdjustConfigEntity getByModelId(String modelId) { |
| | | return baseDao.selectOne("schedule_model_id", modelId); |
| | | return baseDao.selectOne("schedule_model_id", modelId,"status",1); |
| | | } |
| | | |
| | | |
| | | public List<StAdjustConfigDetEntity> getDetByModelId(String modelId) { |
| | | StAdjustConfigEntity configEntity = getByModelId(modelId); |
| | | if (null == configEntity) { |
| | | return null; |
| | | } |
| | | return stAdjustConfigDetService.getListByConfigId(configEntity.getId()); |
| | | } |
| | | } |
| | |
| | | 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.mcs.sche.vo.StAdjustConfigRespVO; |
| | | import com.iailab.module.model.mcs.sche.vo.StAdjustResultPageReqVO; |
| | | import com.iailab.module.model.mcs.sche.vo.StAdjustResultRespVO; |
| | | import com.iailab.module.model.mcs.sche.vo.StScheduleRecordDetailRespVO; |
| | | 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.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | private MmItemOutputService mmItemOutputService; |
| | | |
| | | @Override |
| | | public void saveResult(Map<String, List<DataValueVO>> resultMap, Date predictTime, String adjustValue, String scheduleModelId) { |
| | | public void saveResult(Map<String, List<DataValueVO>> resultMap, Date predictTime, String adjustValue, String scheduleModelId, String configId) { |
| | | List<StAdjustResultEntity> list = new ArrayList<>(resultMap.size()); |
| | | for (Map.Entry<String, List<DataValueVO>> entry : resultMap.entrySet()) { |
| | | StAdjustResultEntity entity = new StAdjustResultEntity(); |
| | | entity.setId(UUID.randomUUID().toString()); |
| | | entity.setConfigId(configId); |
| | | entity.setOutputId(entry.getKey()); |
| | | 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); |
| | | List<Double> jsonValueList = entry.getValue().stream().map(DataValueVO::getDataValue).collect(Collectors.toList()); |
| | | entity.setJsonValue(JSONArray.toJSONString(jsonValueList)); |
| | | list.add(entity); |
| | | } |
| | | baseDao.insert(list); |
| | | } |
| | | |
| | | @Override |
| | |
| | | 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())) { |
| | | if (data == null || StringUtils.isBlank(data.getJsonValue())) { |
| | | return null; |
| | | } |
| | | List<Double> valueList = JSONArray.parseArray(data.getAdjustValue(), Double.class); |
| | | List<Double> valueList = JSONArray.parseArray(data.getJsonValue(), Double.class); |
| | | if (CollectionUtils.isEmpty(valueList)) { |
| | | return result; |
| | | } |
| | |
| | | } |
| | | |
| | | @Override |
| | | public List<Object[]> getData(String outputId, Date predictTime, String timeFormat) { |
| | | List<Object[]> result = new ArrayList<>(); |
| | | 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.getJsonValue())) { |
| | | return result; |
| | | } |
| | | List<Double> valueList = JSONArray.parseArray(data.getJsonValue(), Double.class); |
| | | if (CollectionUtils.isEmpty(valueList)) { |
| | | return result; |
| | | } |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTime(predictTime); |
| | | valueList.forEach(value -> { |
| | | Object[] dv = {DateUtils.format(calendar.getTime(), timeFormat), value}; |
| | | calendar.add(Calendar.MINUTE, 1); |
| | | result.add(dv); |
| | | }); |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | | public StAdjustResultRespVO getInfo(String id) { |
| | | StAdjustResultEntity entity = baseDao.selectById(id); |
| | | StAdjustResultRespVO result = ConvertUtils.sourceToTarget(entity, StAdjustResultRespVO.class); |
| | |
| | | } |
| | | } |
| | | |
| | | public void predictAdjust(ItemVO predictItem, Date predictTime, List<StAdjustDeviationDTO> deviationList, String scheduleModelId) { |
| | | public void predictAdjust(ItemVO predictItem, Date predictTime, List<StAdjustDeviationDTO> deviationList, String scheduleModelId, String configId) { |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTime(predictTime); |
| | | calendar.set(Calendar.MILLISECOND, 0); |
| | |
| | | try { |
| | | PredictItemHandler predictItemHandler = predictItemFactory.create(predictItem.getId()); |
| | | PredictResultVO predictResult = predictItemHandler.predictAdjust(calendar.getTime(), predictItem, deviationList); |
| | | predictResult.setGranularity(predictItem.getGranularity()); |
| | | predictResult.setSaveIndex(predictItem.getSaveIndex()); |
| | | |
| | | // 保存预测结果 |
| | | predictResultHandler.savePredictAdjustResult(predictResult, JSONArray.toJSONString(deviationList), scheduleModelId); |
| | | predictResultHandler.savePredictAdjustResult(predictResult, JSONArray.toJSONString(deviationList), scheduleModelId,configId); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | log.error(MessageFormat.format("预测项编号:{0},预测项名称:{1},预测失败:{2} 预测时刻:{3}", |
| | |
| | | * savePredictAdjustResult |
| | | * |
| | | * @param predictResult |
| | | * @param configId |
| | | */ |
| | | @DSTransactional |
| | | public void savePredictAdjustResult(PredictResultVO predictResult, String adjustValue, String scheduleModelId) { |
| | | public void savePredictAdjustResult(PredictResultVO predictResult, String adjustValue, String scheduleModelId, String configId) { |
| | | Map<String, List<DataValueVO>> resultMap = convertToPredictData(predictResult); |
| | | stAdjustResultService.saveResult(resultMap, predictResult.getPredictTime(), adjustValue, scheduleModelId); |
| | | stAdjustResultService.saveResult(resultMap, predictResult.getPredictTime(), adjustValue, scheduleModelId,configId); |
| | | } |
| | | |
| | | public List<DataValueVO> getPredictValueByItemNo(String itemNo, Date start, Date end) { |
| | |
| | | } |
| | | } |
| | | |
| | | int portIdx = 0; |
| | | int portIdx = 1; |
| | | //对每个爪分别进行计算 |
| | | for (ColumnItemPort entry : sampleInfo.getColumnInfo()) { |
| | | double[][] matrix = new double[0][0]; |
| | |
| | | try { |
| | | List<DataValueVO> dataEntityList = getData(entry.getColumnItemList().get(i), pointMap, planMap, indMap); |
| | | |
| | | 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() + adjustVal); |
| | | } |
| | | } |
| | | |
| | | //补全数据 |
| | | ColumnItem columnItem = entry.getColumnItemList().get(i); |
| | | dataEntityList = super.completionData(matrix.length, dataEntityList, columnItem.startTime, columnItem.endTime, columnItem.getParamType(), columnItem.getGranularity()); |
| | | |
| | | |
| | | /** 如果数据取不满,把缺失的数据点放在后面 */ |
| | | if (dataEntityList != null && dataEntityList.size() != 0) { |
| | | logger.info("设置matrix, i = " + i + ", size = " + dataEntityList.size()); |
| | | // 调整值 |
| | | double adjustVal = SampleInfo.getAdjustValueFromDeviation(portIdx, i + 1, sampleInfo.getDeviation()); |
| | | for (int k = 0; k < dataEntityList.size(); k++) { |
| | | Double dataValue = dataEntityList.get(k).getDataValue(); |
| | | if (null != dataValue) { |
| | | matrix[k][i] = dataValue; |
| | | // 用BigDecimal计算,解决double精度问题 |
| | | matrix[k][i] = BigDecimal.valueOf(dataValue).add(BigDecimal.valueOf(adjustVal)).doubleValue(); |
| | | } |
| | | } |
| | | } |