From 82e98b24e0871366a5fc8bddab07bbabfc321eb3 Mon Sep 17 00:00:00 2001
From: 潘志宝 <979469083@qq.com>
Date: 星期一, 17 三月 2025 14:54:29 +0800
Subject: [PATCH] 构造样本优化

---
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmItemResultServiceImpl.java |   41 +++++++++++++++++++++++++----------------
 1 files changed, 25 insertions(+), 16 deletions(-)

diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmItemResultServiceImpl.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmItemResultServiceImpl.java
index 2eb99cf..ce85a55 100644
--- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmItemResultServiceImpl.java
+++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmItemResultServiceImpl.java
@@ -8,13 +8,13 @@
 import com.iailab.module.model.influxdb.pojo.InfluxModelResultSimPOJO;
 import com.iailab.module.model.influxdb.service.InfluxDBService;
 import com.iailab.module.model.influxdb.vo.InfluxModelResultVO;
-import com.iailab.module.model.mcs.pre.entity.MmItemOutputEntity;
 import com.iailab.module.model.mcs.pre.entity.MmItemResultJsonEntity;
 import com.iailab.module.model.mcs.pre.service.MmItemResultJsonService;
 import com.iailab.module.model.mcs.pre.service.MmItemResultService;
 import com.iailab.module.model.mdk.vo.DataValueVO;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.util.CollectionUtils;
 
 import java.math.BigDecimal;
 import java.util.*;
@@ -77,6 +77,7 @@
             resultJson.setPredicttime(predictTime);
             List<Double> jsonValueList = entry.getValue().stream().map(valueVO -> valueVO.getDataValue()).collect(Collectors.toList());
             resultJson.setJsonvalue(JSONArray.toJSONString(jsonValueList));
+            resultJson.setCumulant("");
             resultJsonList.add(resultJson);
         }
         // json结果存入mysql
@@ -102,6 +103,28 @@
     }
 
     @Override
+    public List<DataValueVO> getPredictValueLast(String outputid, Date startTime, int mins) {
+        List<DataValueVO> result = new ArrayList<>();
+        Calendar calendar = Calendar.getInstance();
+        calendar.setTime(startTime);
+        calendar.add(Calendar.MINUTE, mins * -1);
+        Date startTimeNew = calendar.getTime();
+        Date endTimeNew = new Date();
+        InfluxModelResultPOJO pojo = new InfluxModelResultPOJO();
+        pojo.setType(DataTypeEnum.FLOAT.getCode());
+        pojo.setOutPutId(outputid);
+        List<InfluxModelResultVO> influxModelResultVOS = influxDBService.queryModelResults(pojo, startTimeNew, endTimeNew);
+        if (!CollectionUtils.isEmpty(influxModelResultVOS)) {
+            InfluxModelResultVO t = influxModelResultVOS.get(influxModelResultVOS.size() - 1);
+            DataValueVO dv = new DataValueVO();
+            dv.setDataTime(Date.from(t.getTimestamp()));
+            dv.setDataValue(Double.valueOf(t.getValue().toString()));
+            result.add(dv);
+        }
+        return result;
+    }
+
+    @Override
     public List<Object[]> getData(String outputid, Date startTime, Date endTime, String timeFormat) {
         List<Object[]> result = new ArrayList<>();
         InfluxModelResultPOJO pojo = new InfluxModelResultPOJO();
@@ -111,23 +134,9 @@
         influxModelResultVOS.forEach(item -> {
             Object[] dataItem = new Object[2];
             dataItem[0] = DateUtils.format(Date.from(item.getTimestamp()), timeFormat);
-            dataItem[1] = BigDecimal.valueOf(Double.valueOf(item.getValue().toString())).setScale(2, BigDecimal.ROUND_HALF_UP);
+            dataItem[1] = BigDecimal.valueOf(Double.valueOf(item.getValue().toString())).setScale(3, BigDecimal.ROUND_HALF_UP);
             result.add(dataItem);
         });
         return result;
-    }
-
-    @Override
-    public void savePredictValue(Map<MmItemOutputEntity, Double> predictDoubleValues, Date predictTime) {
-        List<InfluxModelResultPOJO> list = new ArrayList<>();
-        for (Map.Entry<MmItemOutputEntity, Double> entry : predictDoubleValues.entrySet()) {
-            InfluxModelResultSimPOJO pojo = new InfluxModelResultSimPOJO();
-            pojo.setValue(entry.getValue());
-            pojo.setTimestamp(predictTime.toInstant());
-            pojo.setOutPutId(entry.getKey().getId());
-            pojo.setType(DataTypeEnum.FLOAT.getCode());
-            list.add(pojo);
-        }
-        influxDBService.asyncWriteModelResults(list);
     }
 }

--
Gitblit v1.9.3