From c9dd12a0042b50af36edf2ae710d33430542385d Mon Sep 17 00:00:00 2001 From: dengzedong <dengzedong@email> Date: 星期二, 24 十二月 2024 10:15:43 +0800 Subject: [PATCH] 预测值 开始时间计算bug,数据补全bug --- iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/SampleInfoConstructor.java | 115 +++++++++++++++++++++++++++++++-------------------------- 1 files changed, 63 insertions(+), 52 deletions(-) diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/SampleInfoConstructor.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/SampleInfoConstructor.java index 5ca85de..6057a7b 100644 --- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/SampleInfoConstructor.java +++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/SampleInfoConstructor.java @@ -1,13 +1,16 @@ package com.iailab.module.model.mdk.sample; +import com.iailab.module.data.api.ind.IndItemApi; +import com.iailab.module.data.api.ind.dto.ApiIndItemDTO; import com.iailab.module.data.api.plan.PlanItemApi; import com.iailab.module.data.api.plan.dto.ApiPlanItemDTO; 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.data.enums.TimeGranularityEnum; +import com.iailab.module.data.enums.TimeGranularitySecEnum; +import com.iailab.module.model.mcs.pre.service.MmPredictItemService; import com.iailab.module.model.mdk.common.enums.ModelParamType; -import com.iailab.module.model.mdk.factory.ItemEntityFactory; import com.iailab.module.model.mdk.sample.dto.ColumnItem; import com.iailab.module.model.mdk.sample.dto.ColumnItemPort; import com.iailab.module.model.mdk.sample.dto.SampleInfo; @@ -16,6 +19,7 @@ import java.util.Calendar; import java.util.Date; import java.util.List; +import java.util.Map; /** * @author PanZhibao @@ -28,10 +32,13 @@ private DataPointApi dataPointApi; @Autowired - private ItemEntityFactory itemEntityFactory; + private PlanItemApi planItemApi; @Autowired - private PlanItemApi planItemApi; + private IndItemApi indItemApi; + + @Autowired + private MmPredictItemService mmPredictItemService; /** * prepareSampleInfo @@ -40,15 +47,9 @@ * @param predictTime * @return */ - public SampleInfo prepareSampleInfo(String modelId, Date predictTime) { - SampleInfo sampleInfo = new SampleInfo(); - //调用样本列数的方法 - sampleInfo.setSampleColumn(getSampleColumn(modelId)); + protected SampleInfo prepareSampleInfo(String modelId, Date predictTime) { //样本的列信息 - sampleInfo.setColumnInfo(getColumnInfo(modelId, predictTime)); - //样本的采样周期 - sampleInfo.setSampleCycle(getSampleCycle(modelId)); - return sampleInfo; + return getColumnInfo(modelId, predictTime); } /** @@ -59,6 +60,24 @@ */ protected abstract Integer getSampleColumn(String modelId); + + /** + * 样本的列信息 + * + * @param modelId + * @param predictTime + * @return + */ + protected abstract SampleInfo getColumnInfo(String modelId, Date predictTime); + + /** + * 样本的采样周期 + * + * @param modelId + * @return + */ + protected abstract Integer getSampleCycle(String modelId); + /** * 获取开始时间 * @@ -67,26 +86,31 @@ * @return * @throws Exception */ - protected Date getStartTime(ColumnItem columnItem, Date originalTime) { + protected Date getStartTime(ColumnItem columnItem, Date originalTime, Map<String, ApiPointDTO> pointMap, Map<String, ApiPlanItemDTO> planMap) { 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; } dateTime = calculateTime(originalTime, true, columnItem.getDataLength(), DataPointFreqEnum.getEumByCode(dataPoint.getMinfreqid()).getValue()); break; - case PREDICTITEM: - dateTime = calendar.getTime(); + case NORMALITEM: + case MERGEITEM: + dateTime = calculateTime(originalTime, true, columnItem.getDataLength(), 60); break; case IND: dateTime = calculateTime(originalTime, true, columnItem.getDataLength(), 60); break; case PLAN: - dateTime = calendar.getTime(); + ApiPlanItemDTO apiPlanItemDTO = planMap.get(columnItem.getParamId()); + if (apiPlanItemDTO == null) { + return null; + } + dateTime = calculateTime(originalTime, true, columnItem.getDataLength(), TimeGranularitySecEnum.getEumByCode(apiPlanItemDTO.getTimeGranularity()).getValue()); break; default: break; @@ -102,31 +126,31 @@ * @return * @throws Exception */ - protected Date getEndTime(ColumnItem columnItem, Date originalTime) { + protected Date getEndTime(ColumnItem columnItem, Date originalTime,Map<String, ApiPointDTO> pointMap, Map<String, ApiPlanItemDTO> planMap) { 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; } - calendar.add(Calendar.SECOND, DataPointFreqEnum.getEumByCode(dataPoint.getMinfreqid()).getValue() * -1); + dateTime = calendar.getTime(); break; - case PREDICTITEM: - dateTime = calculateTime(originalTime, false, columnItem.getDataLength(), 60); + case NORMALITEM: + case MERGEITEM: + dateTime = calendar.getTime(); break; case IND: dateTime = calendar.getTime(); break; case PLAN: - ApiPlanItemDTO planItem = planItemApi.getInfoByNo(columnItem.getParamId()); - if (planItem == null) { + ApiPlanItemDTO apiPlanItemDTO = planMap.get(columnItem.getParamId()); + if (apiPlanItemDTO == null) { return null; } - dateTime = calculateDate(originalTime, false, columnItem.getDataLength(), - TimeGranularityEnum.getEumByCode(planItem.getTimeGranularity()).getValue()); + dateTime = calculateDate(originalTime, false, columnItem.getDataLength(), TimeGranularitySecEnum.getEumByCode(apiPlanItemDTO.getTimeGranularity()).getValue()); break; default: break; @@ -141,44 +165,31 @@ * @return * @throws Exception */ - protected Integer getGranularity(ColumnItem columnItem) { + protected Integer getGranularity(ColumnItem columnItem,Map<String, ApiPointDTO> pointMap, Map<String, ApiPlanItemDTO> planMap) { + // 默认60s Integer granularity = 60; - switch (columnItem.getParamType()) { - case "DATAPOINT": - ApiPointDTO dataPoint = dataPointApi.getInfoById(columnItem.getParamId()); + switch (ModelParamType.getEumByCode(columnItem.getParamType())) { + case DATAPOINT: + ApiPointDTO dataPoint = pointMap.get(columnItem.getParamId()); granularity = DataPointFreqEnum.getEumByCode(dataPoint.getMinfreqid()).getValue(); break; - case "PREDICTITEM": - granularity = itemEntityFactory.getItemById(columnItem.getParamId()).getGranularity(); + case NORMALITEM: + case MERGEITEM: + granularity = mmPredictItemService.getItemByOutPutId(columnItem.getParamId()).getGranularity(); break; - case "IND-HIS": - granularity = 60; + case IND: + ApiIndItemDTO indItemDTO = indItemApi.getInfoById(columnItem.getParamId()); + granularity = TimeGranularitySecEnum.getEumByCode(indItemDTO.getTimeGranularity()).getValue();; break; - case "IND-PLAN": - granularity = 60; + case PLAN: + ApiPlanItemDTO apiPlanItemDTO = planMap.get(columnItem.getParamId()); + granularity = TimeGranularitySecEnum.getEumByCode(apiPlanItemDTO.getTimeGranularity()).getValue(); break; default: break; } return granularity; } - - /** - * 样本的列信息 - * - * @param modelId - * @param predictTime - * @return - */ - protected abstract List<ColumnItemPort> getColumnInfo(String modelId, Date predictTime); - - /** - * 样本的采样周期 - * - * @param modelId - * @return - */ - protected abstract Integer getSampleCycle(String modelId); /** * 计算取值的时间 -- Gitblit v1.9.3