فهرست منبع

预测总氮 采用xsy1和xsy2平均 真实值也从化验室获取

wangmiaomiao 9 ماه پیش
والد
کامیت
b760a647b3

+ 46 - 9
slibra-quartz/src/main/java/com/slibra/quartz/task/AsyncTask.java

@@ -128,7 +128,8 @@ public class AsyncTask {
                             tXinyiForecastComparison.setYyErrorRateOne((csSs.subtract(yyForecastOne)).divide(csSs, NUMBER_SCALE_4, RoundingMode.HALF_UP));
                     }
                 }
-                if("tn".equals(tXinyiForecastComparison.getCategory())){
+                //2024年6月21日16:28:56 tn总氮的预测用xsy1和xsy2计算 并从化验库获取
+                /*if("tn".equals(tXinyiForecastComparison.getCategory())){
                     tXinyiForecastComparison.setRealOne(csTn);
                     if(!Objects.isNull(csTn) && csTn.compareTo(BigDecimal.ZERO) > 0){
                         if(!Objects.isNull(hsForecastOne))
@@ -136,7 +137,7 @@ public class AsyncTask {
                         if(!Objects.isNull(yyForecastOne))
                             tXinyiForecastComparison.setYyErrorRateOne((csTn.subtract(yyForecastOne)).divide(csTn, NUMBER_SCALE_4, RoundingMode.HALF_UP));
                     }
-                }
+                }*/
                 //2024年6月20日11:16:55 出水总磷的真实值从化验室获取
                 /*if("tp".equals(tXinyiForecastComparison.getCategory())){
                     tXinyiForecastComparison.setRealOne(csTp);
@@ -181,7 +182,7 @@ public class AsyncTask {
                             tXinyiForecastComparison.setYyErrorRateTwo((csSs.subtract(yyForecastTwo)).divide(csSs, NUMBER_SCALE_4, RoundingMode.HALF_UP));
                     }
                 }
-                if("tn".equals(tXinyiForecastComparison.getCategory())){
+                /*if("tn".equals(tXinyiForecastComparison.getCategory())){
                     tXinyiForecastComparison.setRealTwo(csTn);
                     if(!Objects.isNull(csTn) && csTn.compareTo(BigDecimal.ZERO) > 0){
                         if(!Objects.isNull(hsForecastTwo))
@@ -189,7 +190,7 @@ public class AsyncTask {
                         if(!Objects.isNull(yyForecastTwo))
                             tXinyiForecastComparison.setYyErrorRateTwo((csTn.subtract(yyForecastTwo)).divide(csTn, NUMBER_SCALE_4, RoundingMode.HALF_UP));
                     }
-                }
+                }*/
                 //2024年6月20日11:16:55 出水总磷的真实值从化验室获取
                 /*if("tp".equals(tXinyiForecastComparison.getCategory())){
                     tXinyiForecastComparison.setRealTwo(csTp);
@@ -234,7 +235,7 @@ public class AsyncTask {
                             tXinyiForecastComparison.setYyErrorRateThree((csSs.subtract(yyForecastThree)).divide(csSs, NUMBER_SCALE_4, RoundingMode.HALF_UP));
                     }
                 }
-                if("tn".equals(tXinyiForecastComparison.getCategory())){
+                /*if("tn".equals(tXinyiForecastComparison.getCategory())){
                     tXinyiForecastComparison.setRealThree(csTn);
                     if(!Objects.isNull(csTn) && csTn.compareTo(BigDecimal.ZERO) > 0){
                         if(!Objects.isNull(hsForecastThree))
@@ -242,7 +243,7 @@ public class AsyncTask {
                         if(!Objects.isNull(yyForecastThree))
                             tXinyiForecastComparison.setYyErrorRateThree((csTn.subtract(yyForecastThree)).divide(csTn, NUMBER_SCALE_4, RoundingMode.HALF_UP));
                     }
-                }
+                }*/
                 //2024年6月20日11:16:55 出水总磷的真实值从化验室获取
                 /*if("tp".equals(tXinyiForecastComparison.getCategory())){
                     tXinyiForecastComparison.setRealThree(csTp);
@@ -277,12 +278,15 @@ public class AsyncTask {
 
         BigDecimal tpRccJqr = tXinyiRobot.getTpRccJqr();
         BigDecimal csTp = null;
+        BigDecimal csTn = null;
         if(!Objects.isNull(tpRccJqr)){
             csTp = tpRccJqr.divide(ROBOT_HY_DIVIDE, NUMBER_SCALE_4, RoundingMode.HALF_UP);
             //2024年6月20日13:44:26  先不计算,结果会更准确
             //2024年6月21日14:23:14  就是要 除以0.8
 //            csTp = tpRccJqr;
         }
+        if(!Objects.isNull(no3Hlj1Jqr) && !Objects.isNull(no3Hlj2Jqr))
+            csTn = (no3Hlj1Jqr.add(no3Hlj2Jqr)).divide(new BigDecimal(2), NUMBER_SCALE_4, RoundingMode.HALF_UP).divide(ROBOT_HY_DIVIDE, NUMBER_SCALE_4, RoundingMode.HALF_UP);
 
         //时间段1
         List<TXinyiForecastComparison> tXinyiForecastComparisons1 = this.xinyiForecastComparisonMapper.selectTXinyiForecastComparisonList(TXinyiForecastComparison.builder().forecastTimeOne(testHour).build());
@@ -290,7 +294,7 @@ public class AsyncTask {
             for (TXinyiForecastComparison tXinyiForecastComparison : tXinyiForecastComparisons1) {
                 BigDecimal hsForecastOne = tXinyiForecastComparison.getHsForecastOne();
                 BigDecimal yyForecastOne = tXinyiForecastComparison.getYyForecastOne();
-                if("xsy1".equals(tXinyiForecastComparison.getCategory())){
+                /*if("xsy1".equals(tXinyiForecastComparison.getCategory())){
                     tXinyiForecastComparison.setRealOne(no3Hlj1Jqr);
                     if(!Objects.isNull(no3Hlj1Jqr) && no3Hlj1Jqr.compareTo(BigDecimal.ZERO) > 0){
                         if(!Objects.isNull(hsForecastOne))
@@ -307,7 +311,18 @@ public class AsyncTask {
                         if(!Objects.isNull(yyForecastOne))
                             tXinyiForecastComparison.setYyErrorRateOne((no3Hlj2Jqr.subtract(yyForecastOne)).divide(no3Hlj2Jqr, NUMBER_SCALE_4, RoundingMode.HALF_UP));
                     }
+                }*/
+                //2024年6月21日17:04:01  总磷的真实值也从化验室获取
+                if("tn".equals(tXinyiForecastComparison.getCategory())){
+                    tXinyiForecastComparison.setRealOne(csTn);
+                    if(!Objects.isNull(csTn) && csTn.compareTo(BigDecimal.ZERO) > 0){
+                        if(!Objects.isNull(hsForecastOne))
+                            tXinyiForecastComparison.setHsErrorRateOne((csTn.subtract(hsForecastOne)).divide(csTn, NUMBER_SCALE_4, RoundingMode.HALF_UP));
+                        if(!Objects.isNull(yyForecastOne))
+                            tXinyiForecastComparison.setYyErrorRateOne((csTn.subtract(yyForecastOne)).divide(csTn, NUMBER_SCALE_4, RoundingMode.HALF_UP));
+                    }
                 }
+
                 //2024年6月20日11:14:42  总磷的真实值也从化验室获取
                 if("tp".equals(tXinyiForecastComparison.getCategory())){
                     tXinyiForecastComparison.setRealOne(csTp);
@@ -327,7 +342,7 @@ public class AsyncTask {
             for (TXinyiForecastComparison tXinyiForecastComparison : tXinyiForecastComparisons2) {
                 BigDecimal hsForecastTwo = tXinyiForecastComparison.getHsForecastTwo();
                 BigDecimal yyForecastTwo = tXinyiForecastComparison.getYyForecastTwo();
-                if("xsy1".equals(tXinyiForecastComparison.getCategory())){
+                /*if("xsy1".equals(tXinyiForecastComparison.getCategory())){
                     tXinyiForecastComparison.setRealTwo(no3Hlj1Jqr);
                     if(!Objects.isNull(no3Hlj1Jqr) && no3Hlj1Jqr.compareTo(BigDecimal.ZERO) > 0){
                         if(!Objects.isNull(hsForecastTwo))
@@ -344,7 +359,18 @@ public class AsyncTask {
                         if(!Objects.isNull(yyForecastTwo))
                             tXinyiForecastComparison.setYyErrorRateTwo((no3Hlj2Jqr.subtract(yyForecastTwo)).divide(no3Hlj2Jqr, NUMBER_SCALE_4, RoundingMode.HALF_UP));
                     }
+                }*/
+                //2024年6月21日17:04:01  总磷的真实值也从化验室获取
+                if("tn".equals(tXinyiForecastComparison.getCategory())){
+                    tXinyiForecastComparison.setRealTwo(csTn);
+                    if(!Objects.isNull(csTn) && csTn.compareTo(BigDecimal.ZERO) > 0){
+                        if(!Objects.isNull(hsForecastTwo))
+                            tXinyiForecastComparison.setHsErrorRateTwo((csTn.subtract(hsForecastTwo)).divide(csTn, NUMBER_SCALE_4, RoundingMode.HALF_UP));
+                        if(!Objects.isNull(yyForecastTwo))
+                            tXinyiForecastComparison.setYyErrorRateTwo((csTn.subtract(yyForecastTwo)).divide(csTn, NUMBER_SCALE_4, RoundingMode.HALF_UP));
+                    }
                 }
+
                 //2024年6月20日11:14:42  总磷的真实值也从化验室获取
                 if("tp".equals(tXinyiForecastComparison.getCategory())){
                     tXinyiForecastComparison.setRealTwo(csTp);
@@ -364,7 +390,7 @@ public class AsyncTask {
             for (TXinyiForecastComparison tXinyiForecastComparison : tXinyiForecastComparisons3) {
                 BigDecimal hsForecastThree = tXinyiForecastComparison.getHsForecastThree();
                 BigDecimal yyForecastThree = tXinyiForecastComparison.getYyForecastThree();
-                if("xsy1".equals(tXinyiForecastComparison.getCategory())){
+                /*if("xsy1".equals(tXinyiForecastComparison.getCategory())){
                     tXinyiForecastComparison.setRealThree(no3Hlj1Jqr);
                     if(!Objects.isNull(no3Hlj1Jqr) && no3Hlj1Jqr.compareTo(BigDecimal.ZERO) > 0){
                         if(!Objects.isNull(hsForecastThree))
@@ -381,7 +407,18 @@ public class AsyncTask {
                         if(!Objects.isNull(yyForecastThree))
                             tXinyiForecastComparison.setYyErrorRateThree((no3Hlj2Jqr.subtract(yyForecastThree)).divide(no3Hlj2Jqr, NUMBER_SCALE_4, RoundingMode.HALF_UP));
                     }
+                }*/
+                //2024年6月21日17:04:01  总磷的真实值也从化验室获取
+                if("tn".equals(tXinyiForecastComparison.getCategory())){
+                    tXinyiForecastComparison.setRealThree(csTn);
+                    if(!Objects.isNull(csTn) && csTn.compareTo(BigDecimal.ZERO) > 0){
+                        if(!Objects.isNull(hsForecastThree))
+                            tXinyiForecastComparison.setHsErrorRateThree((csTn.subtract(hsForecastThree)).divide(csTn, NUMBER_SCALE_4, RoundingMode.HALF_UP));
+                        if(!Objects.isNull(yyForecastThree))
+                            tXinyiForecastComparison.setYyErrorRateThree((csTn.subtract(yyForecastThree)).divide(csTn, NUMBER_SCALE_4, RoundingMode.HALF_UP));
+                    }
                 }
+
                 //2024年6月20日11:14:42  总磷的真实值也从化验室获取
                 if("tp".equals(tXinyiForecastComparison.getCategory())){
                     tXinyiForecastComparison.setRealThree(csTp);

+ 144 - 3
slibra-quartz/src/main/java/com/slibra/quartz/task/RyTask.java

@@ -103,7 +103,8 @@ public class RyTask
      * 出水总氮 的预测:使用 (xsy1 + xsy2) /2 /0.8 做为出水总氮的结果
      *
      */
-    public static final String[] predictorArr = {"出水COD", "出水SS", "出水总磷", "出水氨氮", "xsy1", "xsy2"};
+    public static final String[] predictorArr = {"出水COD", "出水SS", "出水总磷", "出水氨氮"};
+    public static final String[] predictorArrSpecial = {"xsy1", "xsy2"};
 
     /**
      * 定时从工业库获取数据
@@ -1279,6 +1280,8 @@ public class RyTask
         //获取最新的6条工业科数据
         List<TXinyiIndustry> tXinyiIndustries6 = this.xinyiIndustryMapper.selectNIndustry(6);
         List<TXinyiRobot> tXinyiRobots6 = this.xinyiRobotMapper.selectNRobot(6);
+        //先处理xsy1 和 xsy2 合并成一个数据
+        this.predictorSpecial(tXinyiIndustries6, tXinyiRobots6);
         for (int i = 0; i < predictorArr.length; i++) {
             String result = getPredictor(predictorArr[i]);
             if(StringUtils.isBlank(result) || "error".equals(result)){
@@ -1312,6 +1315,138 @@ public class RyTask
         }
     }
 
+    private void predictorSpecial(List<TXinyiIndustry> tXinyiIndustries6, List<TXinyiRobot> tXinyiRobots6) {
+        //数据1
+        String result1 = getPredictor(predictorArrSpecial[0]);
+        if(StringUtils.isBlank(result1) || "error".equals(result1)){
+            log.info("预测数据返回结果不符合解析条件,返回结果为{}", result1);
+            return;
+        }
+        JSONObject jsonObject1 = null;
+        try {
+            jsonObject1 = JSON.parseObject(result1);
+        } catch (Exception e) {
+            log.error("[转JSON的时候]预测数据返回结果不符合解析条件,返回结果为{}", result1);
+            return;
+        }
+        String hour1 = jsonObject1.getString("hour");
+        String pred1 = jsonObject1.getString("pred");
+        String date1 = jsonObject1.getString("date");
+
+        //数据2
+        String result2 = getPredictor(predictorArrSpecial[0]);
+        if(StringUtils.isBlank(result2) || "error".equals(result2)){
+            log.info("预测数据返回结果不符合解析条件,返回结果为{}", result2);
+            return;
+        }
+        JSONObject jsonObject2 = null;
+        try {
+            jsonObject2 = JSON.parseObject(result2);
+        } catch (Exception e) {
+            log.error("[转JSON的时候]预测数据返回结果不符合解析条件,返回结果为{}", result2);
+            return;
+        }
+        String pred2 = jsonObject2.getString("pred");
+
+        if(StringUtils.isNotBlank(pred1) && pred1.contains(",") && StringUtils.isNotBlank(pred2) && pred2.contains(",")){
+            String[] split1 = pred1.split(",");
+            String[] split2 = pred2.split(",");
+            if(split1.length != 3 || split2.length != 3){
+                return;
+            }
+            //构建两个的平均值
+            String[] splitNew = new String[3];
+            for (int i = 0; i < split1.length; i++) {
+                splitNew[i] = String.valueOf((Double.parseDouble(split1[i]) + Double.parseDouble(split2[i]))/2/0.8);
+            }
+            log.info("取完平均值再组装的数组为{}", Arrays.toString(splitNew));
+            //解析数据 处理报警 调研prompt 保存等
+            this.handlePredictorWarningSpecialTn(splitNew, hour1, "tn", tXinyiIndustries6, tXinyiRobots6, date1);
+        }else {
+            log.error("预测数据返回结果为{}和{},无法正常解析", result1, result2);
+        }
+    }
+
+
+    private void handlePredictorWarningSpecialTn(String[] split, String hour, String task, List<TXinyiIndustry> tXinyiIndustries6, List<TXinyiRobot> tXinyiRobots6, String date) {
+        String[] hours = hour.split(",");
+        //2024年6月18日13:41:10 统一格式,否则查询不到结果
+        date = date.replaceAll("-", "/");
+        //2024年6月18日10:36:49 增加预测记录,预测准确度计算等
+        TXinyiForecastComparison tXinyiForecastComparison = new TXinyiForecastComparison();
+        tXinyiForecastComparison.setCategory(task);
+        tXinyiForecastComparison.setForecastTimeOne(date + " " + hours[0]);
+        tXinyiForecastComparison.setForecastTimeTwo(date + " " + hours[1]);
+        tXinyiForecastComparison.setForecastTimeThree(date + " " + hours[2]);
+        tXinyiForecastComparison.setHsForecastOne(new BigDecimal(split[0]));
+        tXinyiForecastComparison.setHsForecastTwo(new BigDecimal(split[1]));
+        tXinyiForecastComparison.setHsForecastThree(new BigDecimal(split[2]));
+        //2024年6月20日14:28:31  增加字段,方便查询
+        tXinyiForecastComparison.setRemark(DateUtil.format(DateUtils.getNowDate(), DateUtils.YYYYMMDDHH_TS));
+
+        //防止工业库挂掉以后持续预测同一数据
+        //2024年6月20日14:59:23 因为预测bug 判断是否生成过了否则不生成
+        String remark = tXinyiForecastComparison.getRemark();
+        String category = tXinyiForecastComparison.getCategory();
+        TXinyiForecastComparison tXinyiForecastComparisonReq = new TXinyiForecastComparison();
+        tXinyiForecastComparisonReq.setRemark(remark);
+        tXinyiForecastComparisonReq.setCategory(category);
+        List<TXinyiForecastComparison> tXinyiForecastComparisons = this.xinyiForecastComparisonService.selectTXinyiForecastComparisonList(tXinyiForecastComparisonReq);
+        if(!CollectionUtils.isEmpty(tXinyiForecastComparisons)){
+            log.error("预测已经进行过了,无需重复运行~~~~~~~~~~~@@@@@@@,时间为{}\n类型为{}", remark, category);
+            return;
+        }
+
+        //获取配置表
+        List<TXinyiNormConfig> tXinyiNormConfigs = this.xinyiNormConfigMapper.selectTXinyiNormConfigList(null);
+        if(CollectionUtils.isEmpty(tXinyiNormConfigs)) {
+            log.error( "未查询到配置信息");
+            return;
+        }
+        TXinyiNormConfig normConfig = tXinyiNormConfigs.get(0);
+        //获取最新的工业库的数据
+        TXinyiIndustry tXinyiIndustry = this.xinyiIndustryMapper.selectTXinyiIndustryNewest();
+        List<ChartBasic> chartsDataList = new ArrayList<>(9);
+            //同时调用跃渊的预测接口 保存记录值
+            try {
+                String result = HttpUtil.get("http://10.0.3.52:10003/system/forecast?type=3&time=" + DateUtil.format(DateUtils.getNowDate(), DateUtils.YYYY_MM_DD_HH));
+                if(!StringUtils.isBlank(result)){
+                    JSONArray array = JSON.parseArray(result);
+                    tXinyiForecastComparison.setYyForecastOne(array.getBigDecimal(6));
+                    tXinyiForecastComparison.setYyForecastTwo(array.getBigDecimal(7));
+                    tXinyiForecastComparison.setYyForecastThree(array.getBigDecimal(8));
+                }
+            } catch (Exception e) {
+                log.error("调用跃渊的预测接口出现异常,异常信息为{}", e.getMessage());
+            }
+            // this.xinyiForecastComparisonService.insertTXinyiForecastComparison(tXinyiForecastComparison);
+            BigDecimal cscodBzz = normConfig.getCscodBzz();
+            BigDecimal cscodGkz = normConfig.getCscodGkz();
+            //处理展示数据
+            for (int i = 0; i < tXinyiIndustries6.size(); i++) {
+                TXinyiIndustry tXinyiIndustryTemp = tXinyiIndustries6.get(5 - i);
+                ChartBasic chartBasic = new ChartBasic();
+                chartBasic.setTime(tXinyiIndustryTemp.getTestHour().substring(11));
+                chartBasic.setVal(tXinyiIndustryTemp.getCsCod());
+                chartsDataList.add(chartBasic);
+            }
+            for (int i = 0; i < split.length; i++) {
+                String val = split[i];
+                ChartBasic chartBasic = new ChartBasic();
+                chartBasic.setTime(hours[i]);
+                chartBasic.setVal(new BigDecimal(val));
+                chartsDataList.add(chartBasic);
+            }
+            handleXinYiWarningsYC(cscodBzz, split, cscodGkz, BusinessEnum.WarningCategoryEnum.CS_TN_YC.getCode(), hour, normConfig,tXinyiIndustry.getCsCod(), tXinyiIndustry, chartsDataList, date);
+        //插入到数据库
+        //2024年6月21日14:18:55  如果红杉预测和跃渊预测都有数据再保存
+        if(Objects.isNull(tXinyiForecastComparison.getHsForecastOne()) || Objects.isNull(tXinyiForecastComparison.getHsForecastTwo()) ||Objects.isNull(tXinyiForecastComparison.getHsForecastThree())
+                || Objects.isNull(tXinyiForecastComparison.getYyForecastOne()) || Objects.isNull(tXinyiForecastComparison.getYyForecastTwo()) || Objects.isNull(tXinyiForecastComparison.getYyForecastThree())){
+            log.error("保存预测对比数据时,有存在不满足条件的数据,不再保存数据,数据为{}", JSON.toJSONString(tXinyiForecastComparison));
+        }else
+            this.xinyiForecastComparisonService.insertTXinyiForecastComparison(tXinyiForecastComparison);
+        }
+
     private void handlePredictorWarning(String[] split, String hour, String task, List<TXinyiIndustry> tXinyiIndustries6, List<TXinyiRobot> tXinyiRobots6, String date) {
         String[] hours = hour.split(",");
         //2024年6月18日13:41:10 统一格式,否则查询不到结果
@@ -1511,7 +1646,7 @@ public class RyTask
                 chartsDataList.add(chartBasic);
             }
             handleXinYiWarningsYC(csadBzz, split, csadGkz, BusinessEnum.WarningCategoryEnum.CS_AD_YC.getCode(), hour, normConfig,tXinyiIndustry.getCsCod(), tXinyiIndustry, chartsDataList, date);
-        }else if("xsy1".equals(task)){
+        }/*else if("xsy1".equals(task)){
             //2024年6月21日14:57:02 红杉的出水总氮预测改成 不用工业库的,用化验科的两个xsy 相关指标
             //同时调用跃渊的预测接口 保存记录值
             try {
@@ -1564,7 +1699,7 @@ public class RyTask
                 chartsDataList.add(chartBasic);
             }
             handleXinYiWarningsYC(cscodBzz, split, cscodGkz, BusinessEnum.WarningCategoryEnum.CS_XSY_2_YC.getCode(), hour, normConfig,tXinyiIndustry.getCsCod(), tXinyiIndustry, chartsDataList, date);
-        }else {
+        }*/else {
             log.error("暂未支持的类型{}", task);
         }
         //插入到数据库
@@ -1973,6 +2108,12 @@ public class RyTask
         System.out.println(HttpUtil.get("http://10.0.3.52:10003/system/forecast?type=2&time=" + date));*/
 
         System.out.println("2024-06-18 14".replaceAll("-", "/"));
+
+        String[] splitNew = new String[3];
+        splitNew[0] = "0";
+        splitNew[1] = "1";
+        splitNew[2] = "2";
+        System.out.println(Arrays.toString(splitNew));
     }