From bab43330bf6f48bdb7bfb258611f51bb05ef56fe Mon Sep 17 00:00:00 2001 From: 潘志宝 <979469083@qq.com> Date: 星期一, 06 一月 2025 09:02:21 +0800 Subject: [PATCH] 动态数据长度 --- iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/SampleConstructor.java | 16 +------ iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/PredictSampleDataConstructor.java | 6 +- iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/ScheduleSampleInfoConstructor.java | 8 ++- iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/PredictSampleInfoConstructor.java | 18 ++++---- iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/SampleInfoConstructor.java | 17 +++++++- iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/api/MdkApiImpl.java | 1 6 files changed, 35 insertions(+), 31 deletions(-) diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/api/MdkApiImpl.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/api/MdkApiImpl.java index 642212b..eddf082 100644 --- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/api/MdkApiImpl.java +++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/api/MdkApiImpl.java @@ -216,6 +216,7 @@ resp.setScheduleTime(reqDTO.getScheduleTime()); try { log.info("调度计算开始: " + System.currentTimeMillis()); + log.info("reqDTO=" + JSON.toJSONString(reqDTO)); ScheduleResultVO scheduleResult = scheduleModelHandler.doSchedule(reqDTO.getScheduleCode(), reqDTO.getScheduleTime(), reqDTO.getDynamicDataLength(), reqDTO.getDynamicSettings()); resp.setStatusCode(scheduleResult.getResultCode()); diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/PredictSampleDataConstructor.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/PredictSampleDataConstructor.java index e4539bf..21c9b82 100644 --- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/PredictSampleDataConstructor.java +++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/PredictSampleDataConstructor.java @@ -66,7 +66,7 @@ * @return */ @Override - public List<SampleData> prepareSampleData(SampleInfo sampleInfo) throws Exception { + public List<SampleData> prepareSampleData(SampleInfo sampleInfo) throws Exception { List<SampleData> sampleDataList = new ArrayList<>(); Map<String, ApiPointDTO> pointMap = sampleInfo.getPointMap(); Map<String, ApiPlanItemDTO> planMap = sampleInfo.getPlanMap(); @@ -91,11 +91,11 @@ //对每一项依次进行数据查询,然后将查询出的值赋给matrix对应的位置 for (int i = 0; i < entry.getColumnItemList().size(); i++) { try { - List<DataValueVO> dataEntityList = getData(entry.getColumnItemList().get(i),pointMap,planMap); + List<DataValueVO> dataEntityList = getData(entry.getColumnItemList().get(i), pointMap, planMap); //补全数据 ColumnItem columnItem = entry.getColumnItemList().get(i); dataEntityList = super.completionData(matrix.length, dataEntityList, columnItem.startTime, columnItem.endTime, - columnItem.paramId, columnItem.getParamType(),pointMap,planMap); + columnItem.paramId, columnItem.getParamType(), pointMap, planMap); /** 如果数据取不满,把缺失的数据点放在后面 */ if (dataEntityList != null && dataEntityList.size() != 0) { diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/PredictSampleInfoConstructor.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/PredictSampleInfoConstructor.java index 4104e2d..ae066fe 100644 --- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/PredictSampleInfoConstructor.java +++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/PredictSampleInfoConstructor.java @@ -62,7 +62,7 @@ * @return */ @Override - protected SampleInfo getColumnInfo(String modelId, Date predictTime) { + protected SampleInfo getColumnInfo(String modelId, Date predictTime, Map<Integer, Integer> dynamicDataLength) { SampleInfo sampleInfo = new SampleInfo(); List<ColumnItemPort> resultList = new ArrayList<>(); List<ColumnItem> columnItemList = new ArrayList<>(); @@ -75,28 +75,28 @@ //设置当前端口号,初始值为最小端口(查询结果按端口号从小到达排列) int curPortOrder = modelInputParamEntityList.get(0).getModelparamportorder(); //设置当前查询数据长度,初始值为最小端口数据长度 - int curDataLength = modelInputParamEntityList.get(0).getDatalength(); + int curDataLength = super.getDataLength(dynamicDataLength, curPortOrder, modelInputParamEntityList.get(0).getDatalength()); // 统一获取测点的信息 Set<String> pointIds = modelInputParamEntityList.stream().filter(e -> ModelParamType.getEumByCode(e.getModelparamtype()).equals(ModelParamType.DATAPOINT)).map(MmModelParamEntity::getModelparamid).collect(Collectors.toSet()); List<ApiPointDTO> points = dataPointApi.getInfoByIds(pointIds); - Map<String, ApiPointDTO> pointMap = points.stream().collect(Collectors.toMap(ApiPointDTO::getId, Function.identity(), (e1,e2) -> e1)); + Map<String, ApiPointDTO> pointMap = points.stream().collect(Collectors.toMap(ApiPointDTO::getId, Function.identity(), (e1, e2) -> e1)); // 统一获取计划数据的信息 Set<String> planIds = modelInputParamEntityList.stream().filter(e -> ModelParamType.getEumByCode(e.getModelparamtype()).equals(ModelParamType.PLAN)).map(MmModelParamEntity::getModelparamid).collect(Collectors.toSet()); List<ApiPlanItemDTO> plans = planItemApi.getInfoByIds(planIds); - Map<String, ApiPlanItemDTO> planMap = plans.stream().collect(Collectors.toMap(ApiPlanItemDTO::getId, Function.identity(), (e1,e2) -> e1)); + Map<String, ApiPlanItemDTO> planMap = plans.stream().collect(Collectors.toMap(ApiPlanItemDTO::getId, Function.identity(), (e1, e2) -> e1)); for (MmModelParamEntity entry : modelInputParamEntityList) { columnInfo.setParamType(entry.getModelparamtype()); columnInfo.setParamId(entry.getModelparamid()); - columnInfo.setDataLength(entry.getDatalength()); + columnInfo.setDataLength(super.getDataLength(dynamicDataLength, entry.getModelparamportorder(), entry.getDatalength())); columnInfo.setModelParamOrder(entry.getModelparamorder()); columnInfo.setModelParamPortOrder(entry.getModelparamportorder()); - columnInfo.setStartTime(getStartTime(columnInfo, predictTime,pointMap,planMap)); - columnInfo.setEndTime(getEndTime(columnInfo, predictTime,pointMap,planMap)); - columnInfo.setGranularity(super.getGranularity(columnInfo,pointMap,planMap)); + columnInfo.setStartTime(getStartTime(columnInfo, predictTime, pointMap, planMap)); + columnInfo.setEndTime(getEndTime(columnInfo, predictTime, pointMap, planMap)); + columnInfo.setGranularity(super.getGranularity(columnInfo, pointMap, planMap)); //对每一个爪进行数据项归并 - if (curPortOrder != entry.getModelparamportorder()){ + if (curPortOrder != entry.getModelparamportorder()) { //当数据项端口号不为当前端口号时,封装上一个端口类,操作下一个端口类 curPort.setColumnItemList(columnItemList); curPort.setDataLength(curDataLength); diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/SampleConstructor.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/SampleConstructor.java index b4a0756..32e0930 100644 --- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/SampleConstructor.java +++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/SampleConstructor.java @@ -28,21 +28,11 @@ @Autowired private SampleFactory sampleFactory; - public List<SampleData> constructSample(String typeA, String modelId, Date runTime,String itemName, Map<Integer, Integer> dynamicDataLength) throws ModelInvokeException { + public List<SampleData> constructSample(String typeA, String modelId, Date runTime,String itemName, + Map<Integer, Integer> dynamicDataLength) throws ModelInvokeException { try { SampleInfoConstructor sampleInfoConstructor = sampleFactory.createSampleInfo(typeA, modelId); - SampleInfo sampleInfo = sampleInfoConstructor.prepareSampleInfo(modelId, runTime); - if (!CollectionUtils.isEmpty(dynamicDataLength) && sampleInfo.getColumnInfo() != null) { - for(ColumnItemPort columnInfo : sampleInfo.getColumnInfo()) { - if (!dynamicDataLength.containsKey(columnInfo.getPortOrder())) { - continue; - } - columnInfo.setDataLength(dynamicDataLength.get(columnInfo.getPortOrder())); - columnInfo.getColumnItemList().forEach(columnItem -> { - columnItem.setDataLength(columnInfo.getDataLength()); - }); - } - } + SampleInfo sampleInfo = sampleInfoConstructor.prepareSampleInfo(modelId, runTime, dynamicDataLength); SampleDataConstructor sampleDataConstructor = sampleFactory.createSampleData(typeA); return sampleDataConstructor.prepareSampleData(sampleInfo); } catch (Exception e) { 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 0d6431e..ce370a3 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 @@ -11,6 +11,7 @@ import com.iailab.module.model.mdk.sample.dto.ColumnItem; 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; @@ -36,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); } /** @@ -57,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); /** * 样本的采样周期 @@ -196,4 +197,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 diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/ScheduleSampleInfoConstructor.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/ScheduleSampleInfoConstructor.java index bc58d7b..7ecd931 100644 --- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/ScheduleSampleInfoConstructor.java +++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/ScheduleSampleInfoConstructor.java @@ -36,7 +36,7 @@ } @Override - protected SampleInfo getColumnInfo(String modelId, Date predictTime) { + protected SampleInfo getColumnInfo(String modelId, Date predictTime, Map<Integer, Integer> dynamicDataLength) { SampleInfo sampleInfo = new SampleInfo(); List<ColumnItemPort> resultList = new ArrayList<>(); List<ColumnItem> columnItemList = new ArrayList<>(); @@ -49,7 +49,7 @@ //设置当前端口号,初始值为最小端口(查询结果按端口号从小到达排列) int curPortOrder = modelInputParamEntityList.get(0).getModelparamportorder(); //设置当前查询数据长度,初始值为最小端口数据长度 - int curDataLength = modelInputParamEntityList.get(0).getDatalength(); + int curDataLength = super.getDataLength(dynamicDataLength, curPortOrder, modelInputParamEntityList.get(0).getDatalength()); // 统一获取测点的信息 Set<String> pointIds = modelInputParamEntityList.stream().filter(e -> ModelParamType.getEumByCode(e.getModelparamtype()).equals(ModelParamType.DATAPOINT)).map(StScheduleModelParamEntity::getModelparamid).collect(Collectors.toSet()); List<ApiPointDTO> points = dataPointApi.getInfoByIds(pointIds); @@ -62,7 +62,7 @@ for (StScheduleModelParamEntity entry : modelInputParamEntityList) { columnInfo.setParamType(entry.getModelparamtype()); columnInfo.setParamId(entry.getModelparamid()); - columnInfo.setDataLength(entry.getDatalength()); + columnInfo.setDataLength(super.getDataLength(dynamicDataLength, entry.getModelparamportorder(), entry.getDatalength())); columnInfo.setModelParamOrder(entry.getModelparamorder()); columnInfo.setModelParamPortOrder(entry.getModelparamportorder()); columnInfo.setStartTime(getStartTime(columnInfo, predictTime,pointMap,planMap)); @@ -101,4 +101,6 @@ return null; } + + } -- Gitblit v1.9.3