From b270a07828a9627f1a42e254a430c9921fec4e95 Mon Sep 17 00:00:00 2001
From: 潘志宝 <979469083@qq.com>
Date: 星期三, 26 三月 2025 16:14:37 +0800
Subject: [PATCH] Merge branch 'master' of http://dlindusit.com:53929/r/iailab-plat

---
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/PredictSampleDataConstructor.java |   74 +++++++++++++++++++++----------------
 1 files changed, 42 insertions(+), 32 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 c7792e8..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;
@@ -57,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中数据已按爪子进行分类,但爪内数据为无序的,
@@ -89,8 +81,16 @@
             }
         }
 
-        int deviationIndex = 0;
+        // 判断要调整的列
+        for (ColumnItemPort itemPort : sampleInfo.getColumnInfo()) {
 
+            for (ColumnItem columnItem : itemPort.getColumnItemList()) {
+
+            }
+        }
+
+
+        int portIdx = 1;
         //对每个爪分别进行计算
         for (ColumnItemPort entry : sampleInfo.getColumnInfo()) {
             double[][] matrix = new double[0][0];
@@ -107,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();
@@ -115,7 +115,7 @@
                         matrix[i] = asciiArray;
                     }
                 }
-            }else {
+            } else {
                 //先依据爪内数据项的modelParamOrder进行排序——重写comparator匿名函数
                 Collections.sort(entry.getColumnItemList(), new Comparator<ColumnItem>() {
                     @Override
@@ -132,36 +132,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);
+                        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);
@@ -173,6 +174,7 @@
     /**
      * getData
      *
+     * @param sampleInfo
      * @param columnItem
      * @param pointMap
      * @param planMap
@@ -180,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)) {
@@ -202,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