From f7819b4bc08d3ee2fc391b79da8480e7c85d64fd Mon Sep 17 00:00:00 2001
From: 潘志宝 <979469083@qq.com>
Date: 星期五, 28 三月 2025 13:57:25 +0800
Subject: [PATCH] ASDC

---
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/PredictSampleDataConstructor.java |   70 ++++++++++++++++++++++-------------
 1 files changed, 44 insertions(+), 26 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 c2bfd25..7723944 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
@@ -14,10 +14,8 @@
 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;
-import com.iailab.module.model.mcs.pre.service.MmItemTypeService;
+import com.iailab.module.model.mcs.sche.service.StAdjustResultService;
 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;
@@ -31,6 +29,7 @@
 import org.springframework.stereotype.Component;
 import org.springframework.util.CollectionUtils;
 
+import java.math.BigDecimal;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -56,13 +55,7 @@
     private MmItemResultService mmItemResultService;
 
     @Autowired
-    private MmItemResultJsonService mmItemResultJsonService;
-
-    @Autowired
-    private MmItemTypeService mmItemTypeService;
-
-    @Autowired
-    private MmItemOutputService mmItemOutputService;
+    private StAdjustResultService stAdjustResultService;
 
     /**
      * alter by zfc 2020.11.24 修改数据样本构造方案:sampleInfo中数据已按爪子进行分类,但爪内数据为无序的,
@@ -88,6 +81,16 @@
             }
         }
 
+        // 判断要调整的列
+        for (ColumnItemPort itemPort : sampleInfo.getColumnInfo()) {
+
+            for (ColumnItem columnItem : itemPort.getColumnItemList()) {
+
+            }
+        }
+
+
+        int portIdx = 1;
         //对每个爪分别进行计算
         for (ColumnItemPort entry : sampleInfo.getColumnInfo()) {
             double[][] matrix = new double[0][0];
@@ -104,7 +107,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();
@@ -112,7 +115,7 @@
                         matrix[i] = asciiArray;
                     }
                 }
-            }else {
+            } else {
                 //先依据爪内数据项的modelParamOrder进行排序——重写comparator匿名函数
                 Collections.sort(entry.getColumnItemList(), new Comparator<ColumnItem>() {
                     @Override
@@ -132,29 +135,35 @@
                 //对每一项依次进行数据查询,然后将查询出的值赋给matrix对应的位置
                 for (int i = 0; i < entry.getColumnItemList().size(); i++) {
                     try {
-                        List<DataValueVO> dataEntityList = getData(entry.getColumnItemList().get(i), pointMap, planMap,indMap);
+                        List<DataValueVO> dataEntityList = getData(sampleInfo, 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);
             sampleDataList.add(sampleData);
@@ -165,6 +174,7 @@
     /**
      * getData
      *
+     * @param sampleInfo
      * @param columnItem
      * @param pointMap
      * @param planMap
@@ -172,7 +182,8 @@
      * @return
      * @throws Exception
      */
-    private List<DataValueVO> getData(ColumnItem columnItem, Map<String, ApiPointDTO> pointMap, Map<String, ApiPlanItemDTO> planMap, Map<String, ApiIndItemDTO> indMap) throws Exception {
+    private List<DataValueVO> getData(SampleInfo sampleInfo, ColumnItem columnItem, Map<String, ApiPointDTO> pointMap, Map<String, ApiPlanItemDTO> planMap,
+                                      Map<String, ApiIndItemDTO> indMap) throws Exception {
         List<DataValueVO> dataList = new ArrayList<>();
         String paramType = columnItem.getParamType();
         switch (ModelParamType.getEumByCode(paramType)) {
@@ -194,12 +205,19 @@
                 break;
             case NORMALITEM:
             case MERGEITEM:
-                List<DataValueVO> predictValue = mmItemResultService.getPredictValue(columnItem.getParamId(), columnItem.getStartTime(), columnItem.getEndTime());
-
+                List<DataValueVO> predictValue = new ArrayList<>();
+                if (sampleInfo.getIsAdjust()) {
+                    // 如果模拟调整先查调整结果
+                    predictValue = stAdjustResultService.getPredictValue(columnItem.getParamId(), sampleInfo.getPredictTime());
+                }
+                if (CollectionUtils.isEmpty(predictValue)) {
+                    predictValue = mmItemResultService.getPredictValue(columnItem.getParamId(), columnItem.getStartTime(), columnItem.getEndTime());
+                }
                 if (CollectionUtils.isEmpty(predictValue)) {
                     break;
                 }
                 dataList = predictValue;
+
                 break;
             case PLAN:
                 ApiDataQueryDTO queryPlanItemDto = new ApiDataQueryDTO();

--
Gitblit v1.9.3