From 52725f177acbe4ccf6b1fab059353890c4b55814 Mon Sep 17 00:00:00 2001
From: 潘志宝 <979469083@qq.com>
Date: 星期二, 18 三月 2025 09:13:36 +0800
Subject: [PATCH] 样本构建修改

---
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/PredictSampleDataConstructor.java |   52 +++++++++++++++++++---------------------------------
 1 files changed, 19 insertions(+), 33 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 cfe224f..f5d23e7 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
@@ -89,8 +89,7 @@
             }
         }
 
-        int deviationIndex = 0;
-
+        int portIdx = 1;
         //对每个爪分别进行计算
         for (ColumnItemPort entry : sampleInfo.getColumnInfo()) {
             double[][] matrix = new double[0][0];
@@ -107,7 +106,7 @@
                 if (!CollectionUtils.isEmpty(indItemValueList)) {
                     matrix = new double[entry.getDataLength()][0];
                     if (indItemValueList.size() > entry.getDataLength()) {
-                        indItemValueList = indItemValueList.subList(0,entry.getDataLength());
+                        indItemValueList = indItemValueList.subList(0, entry.getDataLength());
                     }
                     for (int i = 0; i < indItemValueList.size(); i++) {
                         String stringValue = indItemValueList.get(i).getDataValue().toString();
@@ -115,7 +114,7 @@
                         matrix[i] = asciiArray;
                     }
                 }
-            }else {
+            } else {
                 //先依据爪内数据项的modelParamOrder进行排序——重写comparator匿名函数
                 Collections.sort(entry.getColumnItemList(), new Comparator<ColumnItem>() {
                     @Override
@@ -132,49 +131,37 @@
                     }
                 }
 
-                //找出对应的调整值
-                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);
-
-                        //设置调整值
-                        if (deviationItem != null && deviationItem.length > 0) {
-                            logger.info("设置调整值, i = " + i);
-                            if (deviationItem[i] <= 0) {
-                                continue;
-                            }
-                            for(int dataKey = 1; dataKey < dataEntityList.size(); dataKey ++) {
-                                DataValueVO item = dataEntityList.get(dataKey);
-                                item.setDataValue(item.getDataValue() + deviationItem[i]);
-                            }
-                        }
+                        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());
+                        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());
-                            for (int k = 0; k < dataEntityList.size(); k++) {
-                                Double dataValue = dataEntityList.get(k).getDataValue();
-                                if (null != dataValue) {
-                                    matrix[k][i] = dataValue;
-                                }
+                        if (CollectionUtils.isEmpty(dataEntityList)) {
+                            continue;
+                        }
+                        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) {
+                                continue;
                             }
+                            // 用BigDecimal计算,解决double精度问题
+                            matrix[k][i] = BigDecimal.valueOf(dataValue).add(BigDecimal.valueOf(adjustVal)).doubleValue();
                         }
                     } catch (Exception e) {
                         e.printStackTrace();
                         throw e;
                     }
                 }
+
+                portIdx++;
             }
             SampleData sampleData = new SampleData();
             sampleData.setMatrix(matrix);
@@ -216,7 +203,6 @@
             case NORMALITEM:
             case MERGEITEM:
                 List<DataValueVO> predictValue = mmItemResultService.getPredictValue(columnItem.getParamId(), columnItem.getStartTime(), columnItem.getEndTime());
-
                 if (CollectionUtils.isEmpty(predictValue)) {
                     break;
                 }

--
Gitblit v1.9.3