Bläddra i källkod

refactor(ruoyi-admin): 优化数据处理和计算逻辑- 重构 getLatestByEntity 方法,提高数据获取效率
-优化 calcStationLlglKyglSjglAgcMin 方法中的数据处理逻辑
- 改进 calcStationSjglAgcPjfsHjwdDlMin 方法的数据计算方式
- 优化 calcXdRate 和 calcStationXdTest 方法的实现
- 删除未使用的代码和注释

xushili 6 månader sedan
förälder
incheckning
b73a3a6121

+ 70 - 52
ruoyi-admin/src/main/java/com/ruoyi/web/controller/JavaFunctionJobHandler.java

@@ -1,10 +1,15 @@
 package com.ruoyi.web.controller;
 
-import cn.hutool.core.collection.*;
-import cn.hutool.core.date.*;
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.collection.ListUtil;
+import cn.hutool.core.date.DateField;
+import cn.hutool.core.date.DateRange;
+import cn.hutool.core.date.DateTime;
+import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.text.StrBuilder;
 import cn.hutool.core.thread.ThreadUtil;
-import cn.hutool.core.util.*;
+import cn.hutool.core.util.NumberUtil;
+import cn.hutool.core.util.StrUtil;
 import com.alibaba.fastjson2.JSON;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.ruoyi.quartz.handler.IJobHandler;
@@ -2133,6 +2138,7 @@ public class JavaFunctionJobHandler extends IJobHandler {
         getSectionDataByEntity(entitys, uri, start, end);
         return entitys.stream().collect(Collectors.toMap(function, Function.identity()));
     }
+
     public void getSectionDataByEntity(List<PointInfo> entitys, URI uri, Date end) {
         String collect = entitys.stream().map(PointInfo::getPointKey).collect(Collectors.joining(","));
         Map<String, PointData> section1 = adapter.getHistorySection(uri, collect, end.getTime());
@@ -2147,6 +2153,23 @@ public class JavaFunctionJobHandler extends IJobHandler {
         return entitys.stream().collect(Collectors.toMap(function, Function.identity()));
     }
 
+    private Map<String, PointInfo> getLatestByEntity(List<PointInfo> entitys, URI uri, Function<PointInfo, String> function) {
+        getLatestByEntity(entitys, uri);
+        return entitys.stream().collect(Collectors.toMap(function, Function.identity()));
+    }
+
+    public void getLatestByEntity(List<PointInfo> entity, URI uri) {
+        String collect = entity.stream().map(PointInfo::getPointKey).collect(Collectors.joining(","));
+        Map<String, PointData> latest = adapter.getLatest(uri, collect);
+        entity.forEach(e -> {
+            e.setPointDatas(Collections.singletonList(latest.get(e.getPointKey())));
+        });
+    }
+
+    public void getLatestByEntity(List<PointInfo> entity) {
+        getLatestByEntity(entity, goldenUri());
+    }
+
     public void getSnapDataByEntity(List<PointInfo> entity, URI uri, Date start, Date end, int interval) {
         for (PointInfo info : entity) {
             getSnapDataByEntity(info, uri, start, end, interval);
@@ -3500,14 +3523,6 @@ public class JavaFunctionJobHandler extends IJobHandler {
         return entity;
     }
 
-    public void getLatestByEntity(List<PointInfo> entity) {
-        String collect = entity.stream().map(PointInfo::getPointKey).collect(Collectors.joining(","));
-        Map<String, PointData> latest = adapter.getLatest(goldenUri(), collect);
-        entity.forEach(e -> {
-            e.setPointDatas(Collections.singletonList(latest.get(e.getPointKey())));
-        });
-    }
-
     public List<PointInfo> calcRealtimeTurbineDizt() {
         List<PointInfo> entity = new ArrayList<>();
         List<PointInfo> result = new ArrayList<>();
@@ -4344,21 +4359,21 @@ public class JavaFunctionJobHandler extends IJobHandler {
         Map<String, PointInfo> rawMapZt = getRawDataByEntity(entityZt, taosUri(), start, date, PointInfo::getTurbineId);
         //发电量
         List<PointInfo> entityFdl = getEntity("AI121", "turbine");
-        getSectionDataByEntity(entityFdl,goldenUri(),start,date);
+        getSectionDataByEntity(entityFdl, goldenUri(), start, date);
 
         List<TurbineInfoMin> mins = getTurbineinfoByMin(date, entityFs);
         for (TurbineInfoMin min : mins) {
             String tbId = min.getTurbineId();
             List<PointData> fsDatas = rawMapFs.get(tbId).getPointDatas();
             List<PointData> ztDatas = rawMapZt.get(tbId).getPointDatas();
-            ztDatas = doublePointDatasFull(2, ztDatas, start.getTime()-1000, date.getTime(), 1);
+            ztDatas = doublePointDatasFull(2, ztDatas, start.getTime() - 1000, date.getTime(), 1);
             Map<Long, Double> ztMap = ztDatas.stream().collect(Collectors.toMap(PointData::getTs, PointData::getValue));
             double pjfs = fsDatas.stream().mapToDouble(PointData::getValue).average().orElse(0.0);
             fsDatas = fsDatas.stream().peek(pd -> pd.setDoubleValue(pd.getValue() >= 23 ? 23.0 : pd.getValue() < 0 ? 0 :
                     NumberUtil.round(pd.getValue(), 2).doubleValue())).collect(Collectors.toList());
             double llgl = fsDatas.stream().mapToDouble(pd -> CalcCache.fitcoef.get(tbId).get(pd.getValue())).average().orElse(0.0);
             List<PointData> kyFsDatas = fsDatas.stream().filter(pd -> {
-                if(ztMap.get(pd.getTs())==null) System.out.println(pd.getTs());
+                if (ztMap.get(pd.getTs()) == null) System.out.println(pd.getTs());
                 return ztMap.get(pd.getTs()) != 4 || ztMap.get(pd.getTs()) != 6;
             }).collect(Collectors.toList());
             double kygl = kyFsDatas.stream().mapToDouble(pd -> CalcCache.fitcoef.get(tbId).get(pd.getValue())).average().orElse(0.0);
@@ -4434,16 +4449,17 @@ public class JavaFunctionJobHandler extends IJobHandler {
         }
     }
 
-    public void calcStationLlglKyglSjglAgcMin(Date date, int granularity) {
-        date = DateUtil.beginOfMinute(date);
-        DateTime start = DateUtil.offsetMinute(date, -granularity);
-
+    public void calcStationLlglKyglSjglAgcMin(Date time) {
+        DateTime date = DateUtil.beginOfMinute(time);
+        int i = Math.floorDiv(date.minute(), 15) * 15;
+        date.setMinutes(i);
+        DateTime start = DateUtil.offsetMinute(date, -15);
         //AGC
         List<PointInfo> entityAgc = getEntity("AGC002", "booster");
-        Map<String, PointInfo> statMapAgc = getStatDataByEntity(entityAgc, goldenUri(), start, date, PointInfo::getStationId);
+        Map<String, PointInfo> statMapAgc = getLatestByEntity(entityAgc, goldenUri(), PointInfo::getStationId);
         //出线
         List<PointInfo> entityCx = getEntity("AGC001", "booster");
-        Map<String, PointInfo> statMapCx = getStatDataByEntity(entityCx, goldenUri(), start, date, PointInfo::getStationId);
+        Map<String, PointInfo> statMapCx = getSnapDataByEntity(entityCx, goldenUri(), start, date, 15, PointInfo::getStationId);
 
         QueryWrapper<TurbineInfoMin> wrapper = new QueryWrapper<>();
         wrapper.select("sum(llgl) llgl,sum(kygl) kygl,avg(pjfs) pjfs,station_id").eq("record_date", date).groupBy("station_id");
@@ -4455,9 +4471,13 @@ public class JavaFunctionJobHandler extends IJobHandler {
             String stId = day.getStationId();
             TurbineInfoMin min = minMap.get(stId);
             PointInfo agcInfo = statMapAgc.get(stId);
-            PointInfo cxInfo = statMapCx.get(stId); double pjgl = cxInfo.getPointDatas().get(0).getValue() * cxInfo.getCoef();
-            day.setKygl(Math.max(min.getKygl(),pjgl));
-            day.setLlgl(Math.max(min.getKygl(),min.getLlgl()));
+            PointInfo cxInfo = statMapCx.get(stId);
+            double cxgl = cxInfo.getPointDatas().stream().mapToDouble(PointData::getValue).average().orElse(0);
+            double pjgl = cxgl * cxInfo.getCoef();
+            day.setKygl(Math.max(min.getKygl(), pjgl));
+            double llgl = min.getLlgl();
+            if (llgl < pjgl) llgl = pjgl * 1.0005;
+            day.setLlgl(llgl);
             day.setAgc(agcInfo.getPointDatas().get(0).getValue() * agcInfo.getCoef());
             day.setPjgl(pjgl);
             day.setPjfs(min.getPjfs());
@@ -4570,7 +4590,7 @@ public class JavaFunctionJobHandler extends IJobHandler {
         return entityAiZt;
     }
 
-    public void calcStationSjglAgcPjfsHjwdDlMin(Date time) {
+    public void calcStationSjglAgcPjfsHjwdDlMin(Date time,Map<String, Double> fjhjwd) {
         DateTime end = DateUtil.beginOfMinute(time);
         int i = Math.floorDiv(end.minute(), 15) * 15;
         end.setMinutes(i);
@@ -4581,14 +4601,10 @@ public class JavaFunctionJobHandler extends IJobHandler {
         Map<String, PointInfo> mapAgc = entityAgc.stream().collect(Collectors.toMap(PointInfo::getStationId, Function.identity()));
         //出线
         List<PointInfo> entityCx = getEntity("AGC001", "booster");
-        Map<String, PointInfo> statMapCx = getRawDataByEntity(entityCx, goldenUri(), begin, end, PointInfo::getStationId);
-        //风速
-        List<PointInfo> entityFs = getEntity("AI066", "turbine");
-        getRawDataByEntity(entityFs, goldenUri(), begin, end);
-        Map<String, List<PointInfo>> fssMap = entityFs.stream().collect(Collectors.groupingBy(PointInfo::getStationId));
+        Map<String, PointInfo> statMapCx = getSnapDataByEntity(entityCx, goldenUri(), begin, end,15, PointInfo::getStationId);
         //环境温度
         List<PointInfo> entityHjwd = getEntity("AI072", "turbine");
-        getRawDataByEntity(entityHjwd, goldenUri(), begin, end);
+        getSnapDataByEntity(entityHjwd, goldenUri(), begin, end,15);
         Map<String, List<PointInfo>> hjwdsMap = entityHjwd.stream().collect(Collectors.groupingBy(PointInfo::getStationId));
         //日发电量
         List<PointInfo> entity = getEntity("Z-ZXYG-JX", "meter");
@@ -4606,13 +4622,12 @@ public class JavaFunctionJobHandler extends IJobHandler {
             String id = day.getStationId();
             TurbineInfoMin min = minMap.get(id);
             Map<Double, Long> map = zttsMap.get(id);
-            List<PointInfo> fsInfos = fssMap.get(id);
-            double pjfs = fsInfos.stream().mapToDouble(pi -> pi.getPointDatas().stream().mapToDouble(PointData::getValue).average().orElse(0.0)).average().orElse(0);
-            day.setPjfs(pjfs);
+            day.setPjfs(min.getPjfs());
             PointInfo cxInfo = statMapCx.get(id);
             double cxgl = cxInfo.getPointDatas().stream().mapToDouble(PointData::getValue).average().orElse(0.0);
             cxgl = cxgl * cxInfo.getCoef();
             if (cxgl > 169600 && day.getPjfs() < 3) cxgl = 0;
+            if (cxgl > 169600) cxgl = 169600;
             day.setPjgl(cxgl);
             PointInfo agcInfo = mapAgc.get(id);
             double agc = agcInfo.getPointDatas().get(0).getValue() * agcInfo.getCoef();
@@ -4624,7 +4639,7 @@ public class JavaFunctionJobHandler extends IJobHandler {
                 if (v < 0) v = 0;
                 return v;
             }).sum();
-            if ((rfdl < 660 && day.getPjgl() > 0) || rfdl >= 45500) rfdl = day.getPjgl() / 4.0;
+            if (rfdl >= 42400.0) rfdl = day.getPjgl() / 4.0;
             day.setRfdl(rfdl);
             if (day.getPjgl() == 169600.0 && rfdl != 42400.0) {
                 day.setPjgl(rfdl * 4);
@@ -5738,17 +5753,17 @@ public class JavaFunctionJobHandler extends IJobHandler {
                     if (ts >= b0 && ts < e0) {
                         List<Double> doubles = ztMap.computeIfAbsent(DateUtil.date(b0), k -> new ArrayList<>());
                         doubles.add(pd.getValue());
-                    } else if(ts>=e0&&ts<e0 + 15 * 60 * 1000){
+                    } else if (ts >= e0 && ts < e0 + 15 * 60 * 1000) {
                         List<Double> doubles = ztMap.computeIfAbsent(DateUtil.date(e0), k -> new ArrayList<>());
                         doubles.add(pd.getValue());
                         b0 = e0;
                         e0 += 15 * 60 * 1000;
-                    }else {
+                    } else {
                         b0 = e0;
                         e0 += 15 * 60 * 1000;
                     }
                 }
-                if(pi.getPointDatas().size()==0){
+                if (pi.getPointDatas().size() == 0) {
                     b0 = e0;
                     e0 += 15 * 60 * 1000;
                 }
@@ -5783,20 +5798,22 @@ public class JavaFunctionJobHandler extends IJobHandler {
         //超短期
         // 标准准确率
         final List<Double> WIND_STANDARD = Arrays.asList(0.80, 0.75, 0.70, 0.65);
-        List<PredictExamin2> peList = new ArrayList<>();        DateTime hpBegin = DateUtil.offsetMinute(begin, -15);
+        List<PredictExamin2> peList = new ArrayList<>();
+        DateTime hpBegin = DateUtil.offsetMinute(begin, -15);
         for (int i = 0; i < 6; i++) {
             DateTime hour = DateUtil.offsetHour(hpBegin, 4 * i);
             DateTime hour2 = DateUtil.offsetHour(hour, 4);
             QueryWrapper<HistoryPredict> wrapper = new QueryWrapper<>();
             wrapper.eq("device_type", "station").eq("predict_type", "CDQ").eq("data_time", hour)
-                    .between("predict_time", hour,hour2).orderByAsc("data_time");
+                    .between("predict_time", hour, hour2).orderByAsc("data_time");
             List<HistoryPredict> predicts = historyPredictService.list(wrapper);
             Map<String, List<HistoryPredict>> cdqMap = predicts.stream().collect(Collectors.groupingBy(HistoryPredict::getSiteId));
             int finalI = i;
             cdqMap.forEach((stId, hps) -> {
                 List<StationInfoMin> minGl = minMap.get(stId);
                 PredictExamin2 examin2 = new PredictExamin2();
-                Double capacity = glpisMap.get(stId) * 1000;                Date pdtHour = hps.get(0).getPredictTime();
+                Double capacity = glpisMap.get(stId) * 1000;
+                Date pdtHour = hps.get(0).getPredictTime();
                 examin2.setModelId("1");
                 examin2.setPredictType("CDQ");
                 examin2.setDeviceType("station");
@@ -5946,13 +5963,13 @@ public class JavaFunctionJobHandler extends IJobHandler {
         return K;
     }
 
-//    private double calculateWeightedSum(double[] integralDifferences, double weight) {
-//        double sum = 0;
-//        for (double diff : integralDifferences) {
-//            sum += diff;
-//        }
-//        return sum * weight;
-//    }
+    //    private double calculateWeightedSum(double[] integralDifferences, double weight) {
+    //        double sum = 0;
+    //        for (double diff : integralDifferences) {
+    //            sum += diff;
+    //        }
+    //        return sum * weight;
+    //    }
 
     /**
      * 计算超短期预测考核总分
@@ -6017,14 +6034,14 @@ public class JavaFunctionJobHandler extends IJobHandler {
             sumrn += abs;
             sum += Math.abs(Pi_r / (Pi_r + Pi_n) - 0.5) * abs;
         }
-        return sumrn==0?0.99:(1 - 2 * sum / sumrn);
+        return sumrn == 0 ? 0.99 : (1 - 2 * sum / sumrn);
     }
 
     /**
      * 可用电量计算过滤
      */
     public void calcKydlFilter(PredictExamin2 examin2, List<StationInfoMin> mins, double capacity, Map<DateTime, List<Double>> dtlMap) {
-        double actualPower = 0, availablePower = 0,pjgl=0;
+        double actualPower = 0, availablePower = 0, pjgl = 0;
         for (StationInfoMin min : mins) {
             List<Double> doubles = dtlMap.get(min.getRecordDate());
             //限电
@@ -6045,7 +6062,7 @@ public class JavaFunctionJobHandler extends IJobHandler {
     }
 
     public double calcXdRate(List<Double> doubles) {
-        if(CollUtil.isEmpty(doubles)) return 0; // 计算1.0的数量
+        if (CollUtil.isEmpty(doubles)) return 0; // 计算1.0的数量
         long countOfOnes = doubles.stream().filter(number -> number == 1.0).count();
         // 计算1.0在列表中的占比
         return (double) countOfOnes / doubles.size();
@@ -6070,9 +6087,10 @@ public class JavaFunctionJobHandler extends IJobHandler {
         //万kWh
         return v / 10000;
     }
-    public void calcStationXdTest(Date date,String stId){
+
+    public void calcStationXdTest(Date date, String stId) {
         DateTime end = DateUtil.beginOfDay(date);
-        DateTime start = DateUtil.offsetDay(end,-1);
+        DateTime start = DateUtil.offsetDay(end, -1);
         //AGC
         List<PointInfo> entityAgc = getEntity("AGC002", "booster");
         entityAgc = filterPointInfo(entityAgc, stId, PointInfo::getStationId);