From e691b98e02153c9c439d7f5acb468924572d75d9 Mon Sep 17 00:00:00 2001 From: dengzedong <dengzedong@email> Date: 星期四, 09 一月 2025 17:31:17 +0800 Subject: [PATCH] item动态时间粒度 --- iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/SampleInfoConstructor.java | 80 ++++++++++------------------------------ 1 files changed, 20 insertions(+), 60 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 3f8f72b..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 @@ -2,23 +2,19 @@ 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.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.util.CollectionUtils; import java.util.Calendar; import java.util.Date; -import java.util.List; import java.util.Map; /** @@ -27,12 +23,6 @@ * @createTime 2024年09月03日 */ abstract class SampleInfoConstructor { - - @Autowired - private DataPointApi dataPointApi; - - @Autowired - private PlanItemApi planItemApi; @Autowired private IndItemApi indItemApi; @@ -47,9 +37,9 @@ * @param predictTime * @return */ - protected SampleInfo prepareSampleInfo(String modelId, Date predictTime) { + protected SampleInfo prepareSampleInfo(String modelId, Date predictTime, Map<Integer, Integer> dynamicDataLength) { //样本的列信息 - return getColumnInfo(modelId, predictTime); + return getColumnInfo(modelId, predictTime, dynamicDataLength); } /** @@ -68,7 +58,7 @@ * @param predictTime * @return */ - protected abstract SampleInfo getColumnInfo(String modelId, Date predictTime); + protected abstract SampleInfo getColumnInfo(String modelId, Date predictTime, Map<Integer, Integer> dynamicDataLength); /** * 样本的采样周期 @@ -86,31 +76,19 @@ * @return * @throws Exception */ - protected Date getStartTime(ColumnItem columnItem, Date originalTime, Map<String, ApiPointDTO> pointMap, Map<String, ApiPlanItemDTO> planMap) { + protected Date getStartTime(ColumnItem columnItem, Date originalTime) { Date dateTime = new Date(); Calendar calendar = Calendar.getInstance(); calendar.setTime(originalTime); switch (ModelParamType.getEumByCode(columnItem.getParamType())) { case DATAPOINT: - ApiPointDTO dataPoint = pointMap.get(columnItem.getParamId()); - if (dataPoint == null) { - return null; - } - dateTime = calculateTime(originalTime, true, columnItem.getDataLength(), DataPointFreqEnum.getEumByCode(dataPoint.getMinfreqid()).getValue()); + case IND: + case PLAN: + dateTime = calculateTime(originalTime, true, columnItem.getDataLength(), columnItem.getGranularity()); break; case NORMALITEM: case MERGEITEM: dateTime = calendar.getTime(); - break; - case IND: - dateTime = calculateTime(originalTime, true, columnItem.getDataLength(), 60); - break; - case PLAN: - 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; @@ -126,31 +104,19 @@ * @return * @throws Exception */ - protected Date getEndTime(ColumnItem columnItem, Date originalTime,Map<String, ApiPointDTO> pointMap, Map<String, ApiPlanItemDTO> planMap) { + protected Date getEndTime(ColumnItem columnItem, Date originalTime) { Date dateTime = new Date(); Calendar calendar = Calendar.getInstance(); calendar.setTime(originalTime); switch (ModelParamType.getEumByCode(columnItem.getParamType())) { case DATAPOINT: - ApiPointDTO dataPoint = pointMap.get(columnItem.getParamId()); - if (dataPoint == null) { - return null; - } + case IND: + case PLAN: dateTime = calendar.getTime(); break; case NORMALITEM: case MERGEITEM: - dateTime = calendar.getTime(); - break; - case IND: - dateTime = calendar.getTime(); - break; - case PLAN: - ApiPlanItemDTO apiPlanItemDTO = planMap.get(columnItem.getParamId()); - if (apiPlanItemDTO == null) { - return null; - } - dateTime = calculateDate(originalTime, false, columnItem.getDataLength(), TimeGranularitySecEnum.getEumByCode(apiPlanItemDTO.getTimeGranularity()).getValue()); + dateTime = calculateTime(originalTime, false, columnItem.getDataLength(), columnItem.getGranularity()); break; default: break; @@ -205,7 +171,7 @@ if (backward) { timeLength = (-1) * dataLength; } else { - timeLength = dataLength - 1; + timeLength = dataLength; } Date desTime = originalTime; Calendar calendar = Calendar.getInstance(); @@ -216,19 +182,13 @@ return calendar.getTime(); } - public Date calculateDate(Date originalTime, Boolean backward, int dataLength, int field) { - int timeLength; - if (backward) { - timeLength = (-1) * dataLength; - } else { - timeLength = dataLength - 1; + protected int getDataLength(Map<Integer, Integer> dynamicDataLength, Integer port, Integer dataLength) { + if (CollectionUtils.isEmpty(dynamicDataLength)) { + return dataLength; } - Date desTime = originalTime; - Calendar calendar = Calendar.getInstance(); - calendar.setTime(desTime); - calendar.set(Calendar.MILLISECOND, 0); - // 数据长度 * 粒度 - calendar.add(Calendar.SECOND, timeLength); - return calendar.getTime(); + if (dynamicDataLength.containsKey(port)) { + return dynamicDataLength.get(port); + } + return dataLength; } } \ No newline at end of file -- Gitblit v1.9.3