From afd6dfbd0029e9a758d7896500d54d265f4185fc Mon Sep 17 00:00:00 2001 From: 潘志宝 <979469083@qq.com> Date: 星期一, 17 三月 2025 16:22:37 +0800 Subject: [PATCH] long oneMin = granularity * 1000L --- iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/PredictSampleDataConstructor.java | 122 +++++++++++++++++++++++++--------------- 1 files changed, 75 insertions(+), 47 deletions(-) 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 6668705..b08e5a7 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 @@ -13,6 +13,7 @@ import com.iailab.module.data.api.point.dto.ApiPointValueQueryDTO; import com.iailab.module.data.common.ApiDataQueryDTO; import com.iailab.module.data.common.ApiDataValueDTO; +import com.iailab.module.model.common.utils.ASCIIUtil; import com.iailab.module.model.mcs.pre.service.MmItemOutputService; import com.iailab.module.model.mcs.pre.service.MmItemResultJsonService; import com.iailab.module.model.mcs.pre.service.MmItemResultService; @@ -77,68 +78,90 @@ Map<String, ApiPointDTO> pointMap = sampleInfo.getPointMap(); Map<String, ApiPlanItemDTO> planMap = sampleInfo.getPlanMap(); Map<String, ApiIndItemDTO> indMap = sampleInfo.getIndMap(); - int deviationIndex = 0; + // 校验数据 + for (ColumnItemPort itemPort : sampleInfo.getColumnInfo()) { + for (ColumnItem columnItem : itemPort.getColumnItemList()) { + if (columnItem.getParamType().equals(ModelParamType.IND_ASCII.getCode())) { + if (columnItem.getModelParamOrder() != 1 || itemPort.getColumnItemList().size() != 1) { + throw new RuntimeException("模型输入数据异常:IND_ASCII类型输入独占一个端口;ParamPortOrder:" + columnItem.getModelParamPortOrder() + ",ParamOrder:" + columnItem.getModelParamOrder()); + } + } + } + } + int portIdx = 1; //对每个爪分别进行计算 for (ColumnItemPort entry : sampleInfo.getColumnInfo()) { - //先依据爪内数据项的modelParamOrder进行排序——重写comparator匿名函数 - Collections.sort(entry.getColumnItemList(), new Comparator<ColumnItem>() { - @Override - public int compare(ColumnItem o1, ColumnItem o2) { - return o1.getModelParamOrder() - o2.getModelParamOrder(); + double[][] matrix = new double[0][0]; + // 特殊处理IND_ASCII类型 + if (entry.getColumnItemList().get(0).getParamType().equals(ModelParamType.IND_ASCII.getCode())) { + // 获取指标数据 + ColumnItem columnItem = entry.getColumnItemList().get(0); + ApiIndItemQueryDTO queryIndItemDTO = new ApiIndItemQueryDTO(); + ApiIndItemDTO intItem = indMap.get(columnItem.getParamId()); + queryIndItemDTO.setItemNo(intItem.getItemNo()); + queryIndItemDTO.setStart(columnItem.getStartTime()); + queryIndItemDTO.setEnd(columnItem.getEndTime()); + List<ApiIndItemValueDTO> indItemValueList = indItemApi.queryIndItemHistoryValue(queryIndItemDTO); + if (!CollectionUtils.isEmpty(indItemValueList)) { + matrix = new double[entry.getDataLength()][0]; + if (indItemValueList.size() > entry.getDataLength()) { + indItemValueList = indItemValueList.subList(0, entry.getDataLength()); + } + for (int i = 0; i < indItemValueList.size(); i++) { + String stringValue = indItemValueList.get(i).getDataValue().toString(); + double[] asciiArray = ASCIIUtil.stringToAsciiArray(stringValue); + matrix[i] = asciiArray; + } } - }); + } else { + //先依据爪内数据项的modelParamOrder进行排序——重写comparator匿名函数 + Collections.sort(entry.getColumnItemList(), new Comparator<ColumnItem>() { + @Override + public int compare(ColumnItem o1, ColumnItem o2) { + return o1.getModelParamOrder() - o2.getModelParamOrder(); + } + }); - //默认都是double类型的数据,且按列向量进行拼接,默认初始值为0.0 - double[][] matrix = new double[entry.getDataLength()][entry.getColumnItemList().size()]; - for (int i = 0; i < entry.getColumnItemList().size(); i++) { - for (int j = 0; j < entry.getDataLength(); j++) { - matrix[j][i] = -2.0; + //默认都是double类型的数据,且按列向量进行拼接,默认初始值为0.0 + matrix = new double[entry.getDataLength()][entry.getColumnItemList().size()]; + for (int i = 0; i < entry.getColumnItemList().size(); i++) { + for (int j = 0; j < entry.getDataLength(); j++) { + matrix[j][i] = -2.0; + } } - } - //找出对应的调整值 - double[] deviationItem = null; - if (sampleInfo.getDeviation() != null && sampleInfo.getDeviation().length > 0) { - deviationItem = sampleInfo.getDeviation()[deviationIndex]; - } - deviationIndex ++; + //对每一项依次进行数据查询,然后将查询出的值赋给matrix对应的位置 + for (int i = 0; i < entry.getColumnItemList().size(); i++) { + try { + List<DataValueVO> dataEntityList = getData(entry.getColumnItemList().get(i), pointMap, planMap, indMap); - //对每一项依次进行数据查询,然后将查询出的值赋给matrix对应的位置 - for (int i = 0; i < entry.getColumnItemList().size(); i++) { - try { - List<DataValueVO> dataEntityList = getData(entry.getColumnItemList().get(i), pointMap, planMap,indMap); + //补全数据 + ColumnItem columnItem = entry.getColumnItemList().get(i); + dataEntityList = super.completionData(matrix.length, dataEntityList, columnItem.startTime, columnItem.endTime, columnItem.getParamType(), columnItem.getGranularity()); - //设置调整值 - if (deviationItem != null && deviationItem.length > 0) { - logger.info("设置调整值, i = " + i); - if (deviationItem[i] <= 0) { + /** 如果数据取不满,把缺失的数据点放在后面 */ + if (CollectionUtils.isEmpty(dataEntityList)) { continue; } - for(int dataKey = 1; dataKey < dataEntityList.size(); dataKey ++) { - DataValueVO item = dataEntityList.get(dataKey); - item.setDataValue(item.getDataValue() + deviationItem[i]); - } - } - - // 补全数据 - 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; + if (null == dataValue) { + continue; } + // 用BigDecimal计算,解决double精度问题 + matrix[k][i] = BigDecimal.valueOf(dataValue).add(BigDecimal.valueOf(adjustVal)).doubleValue(); } + } catch (Exception e) { + e.printStackTrace(); + throw e; } - } catch (Exception e) { - e.printStackTrace(); - throw e; } + + portIdx++; } SampleData sampleData = new SampleData(); sampleData.setMatrix(matrix); @@ -179,8 +202,12 @@ break; case NORMALITEM: case MERGEITEM: - List<DataValueVO> predictValue = mmItemResultService.getPredictValue(columnItem.getParamId(), columnItem.getStartTime(), columnItem.getEndTime()); - + List<DataValueVO> predictValue = new ArrayList<>(); + if (columnItem.getStartTime().getTime() == columnItem.getEndTime().getTime()) { + predictValue = mmItemResultService.getPredictValueLast(columnItem.getParamId(), columnItem.getStartTime(), 2); + } else { + predictValue = mmItemResultService.getPredictValue(columnItem.getParamId(), columnItem.getStartTime(), columnItem.getEndTime()); + } if (CollectionUtils.isEmpty(predictValue)) { break; } @@ -216,9 +243,10 @@ dataList = indItemValueList.stream().map(t -> { DataValueVO vo = new DataValueVO(); vo.setDataTime(DateUtil.parse(t.getDataTime())); - vo.setDataValue(t.getDataValue()); + vo.setDataValue(Double.valueOf(t.getDataValue().toString())); return vo; }).collect(Collectors.toList()); + break; default: break; } -- Gitblit v1.9.3