From 271fed395d4d3e4ab8cdb44ccf466859ba485e46 Mon Sep 17 00:00:00 2001 From: 潘志宝 <979469083@qq.com> Date: 星期四, 09 一月 2025 17:45:33 +0800 Subject: [PATCH] Merge branch 'master' of http://dlindusit.com:53929/r/iailab-plat --- iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/SampleInfoConstructor.java | 145 +++++++++++++++++++++++------------------------ 1 files changed, 71 insertions(+), 74 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 c86dc27..45273aa 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,19 +1,21 @@ package com.iailab.module.model.mdk.sample; -import com.iailab.module.data.api.point.DataPointApi; +import com.iailab.module.data.api.ind.IndItemApi; +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.data.enums.DataPointFreq; -import com.iailab.module.model.mdk.factory.ItemEntityFactory; +import com.iailab.module.data.enums.DataPointFreqEnum; +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.sample.dto.ColumnItem; -import com.iailab.module.model.mdk.sample.dto.ColumnItemPort; import com.iailab.module.model.mdk.sample.dto.SampleInfo; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; +import org.springframework.util.CollectionUtils; -import java.sql.Timestamp; import java.util.Calendar; import java.util.Date; -import java.util.List; +import java.util.Map; /** * @author PanZhibao @@ -23,10 +25,10 @@ abstract class SampleInfoConstructor { @Autowired - private DataPointApi dataPointApi; + private IndItemApi indItemApi; @Autowired - private ItemEntityFactory itemEntityFactory; + private MmPredictItemService mmPredictItemService; /** * prepareSampleInfo @@ -35,15 +37,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, Map<Integer, Integer> dynamicDataLength) { //样本的列信息 - sampleInfo.setColumnInfo(getColumnInfo(modelId, predictTime)); - //样本的采样周期 - sampleInfo.setSampleCycle(getSampleCycle(modelId)); - return sampleInfo; + return getColumnInfo(modelId, predictTime, dynamicDataLength); } /** @@ -53,6 +49,24 @@ * @return */ protected abstract Integer getSampleColumn(String modelId); + + + /** + * 样本的列信息 + * + * @param modelId + * @param predictTime + * @return + */ + protected abstract SampleInfo getColumnInfo(String modelId, Date predictTime, Map<Integer, Integer> dynamicDataLength); + + /** + * 样本的采样周期 + * + * @param modelId + * @return + */ + protected abstract Integer getSampleCycle(String modelId); /** * 获取开始时间 @@ -66,21 +80,14 @@ Date dateTime = new Date(); Calendar calendar = Calendar.getInstance(); calendar.setTime(originalTime); - switch (columnItem.getParamType()) { - case "DATAPOINT": - ApiPointDTO dataPoint = dataPointApi.getPointById(columnItem.getParamId()); - if (dataPoint == null) { - return null; - } - dateTime = calculateTime(originalTime, true, columnItem.getDataLength(), DataPointFreq.getEumByCode(dataPoint.getMinfreqid()).getValue()); + switch (ModelParamType.getEumByCode(columnItem.getParamType())) { + case DATAPOINT: + case IND: + case PLAN: + dateTime = calculateTime(originalTime, true, columnItem.getDataLength(), columnItem.getGranularity()); break; - case "PREDICTITEM": - dateTime = calendar.getTime(); - break; - case "IND-HIS": - dateTime = calculateTime(originalTime, true, columnItem.getDataLength(), 60); - break; - case "IND-PLAN": + case NORMALITEM: + case MERGEITEM: dateTime = calendar.getTime(); break; default: @@ -101,22 +108,15 @@ Date dateTime = new Date(); Calendar calendar = Calendar.getInstance(); calendar.setTime(originalTime); - switch (columnItem.getParamType()) { - case "DATAPOINT": - ApiPointDTO dataPoint = dataPointApi.getPointById(columnItem.getParamId()); - if (dataPoint == null) { - return null; - } - calendar.add(Calendar.SECOND, DataPointFreq.getEumByCode(dataPoint.getMinfreqid()).getValue() * -1); - break; - case "PREDICTITEM": - dateTime = calculateTime(originalTime, false, columnItem.getDataLength(), 60); - break; - case "IND-HIS": + switch (ModelParamType.getEumByCode(columnItem.getParamType())) { + case DATAPOINT: + case IND: + case PLAN: dateTime = calendar.getTime(); break; - case "IND-PLAN": - dateTime = calculateTime(originalTime, false, columnItem.getDataLength(), 60); + case NORMALITEM: + case MERGEITEM: + dateTime = calculateTime(originalTime, false, columnItem.getDataLength(), columnItem.getGranularity()); break; default: break; @@ -131,44 +131,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.getPointById(columnItem.getParamId()); - granularity = DataPointFreq.getEumByCode(dataPoint.getMinfreqid()).getValue(); + 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); /** * 计算取值的时间 @@ -184,7 +171,7 @@ if (backward) { timeLength = (-1) * dataLength; } else { - timeLength = dataLength - 1; + timeLength = dataLength; } Date desTime = originalTime; Calendar calendar = Calendar.getInstance(); @@ -194,4 +181,14 @@ calendar.add(Calendar.SECOND, timeLength * granularity); return calendar.getTime(); } + + protected int getDataLength(Map<Integer, Integer> dynamicDataLength, Integer port, Integer dataLength) { + if (CollectionUtils.isEmpty(dynamicDataLength)) { + return dataLength; + } + if (dynamicDataLength.containsKey(port)) { + return dynamicDataLength.get(port); + } + return dataLength; + } } \ No newline at end of file -- Gitblit v1.9.3