Browse Source

读功率曲线、拟合功率(自算)

xushili 9 months ago
parent
commit
b1c35874eb

+ 28 - 0
ruoyi-admin/src/main/java/com/ruoyi/web/runner/LoadDataSourceRunner.java

@@ -2,20 +2,31 @@ package com.ruoyi.web.runner;
 
 import cn.hutool.core.bean.BeanUtil;
 import com.alibaba.druid.pool.DruidDataSource;
+import com.alibaba.fastjson2.JSONObject;
+import com.alibaba.fastjson2.TypeReference;
 import com.ruoyi.framework.datasource.DynamicDataSource;
 import com.ruoyi.quartz.glue.GlueFactory;
 import com.ruoyi.quartz.handler.impl.MyJobHandler;
+import com.ruoyi.quartz.task.ChangedSave;
 import com.ruoyi.ucp.entity.Formula;
 import com.ruoyi.ucp.entity.Method;
+import com.ruoyi.ucp.entity.ProEconWtCurveFittingMonth;
 import com.ruoyi.ucp.entity.UcpDataSource;
 import com.ruoyi.ucp.feign.AdapterApi;
 import com.ruoyi.quartz.handler.IJobHandler;
 import com.ruoyi.ucp.service.*;
+import com.ruoyi.ucp.util.CalcCache;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.CommandLineRunner;
+import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
+import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Component;
 
 import javax.annotation.Resource;
 import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
 
 @Component
 public class LoadDataSourceRunner implements CommandLineRunner {
@@ -40,6 +51,9 @@ public class LoadDataSourceRunner implements CommandLineRunner {
     private ILineInfoDayService lineInfoDayService;
     @Resource
     private IFormulaService formulaService;
+    @Resource
+    @Autowired
+    private RedisTemplate redisTemplate;
 
     @Override
     public void run(String... args) {
@@ -70,5 +84,19 @@ public class LoadDataSourceRunner implements CommandLineRunner {
         } catch (Exception e) {
             e.printStackTrace();
         }
+
+        LettuceConnectionFactory factory = (LettuceConnectionFactory) redisTemplate.getConnectionFactory();
+        factory.setDatabase(9);
+        redisTemplate.setConnectionFactory(factory);
+        Set<String> keys = redisTemplate.keys("monthCurve_");
+        for (String key : keys) {
+            //redis缓存中获取到字符串
+            String o = (String) redisTemplate.opsForValue().get(key);
+            //字符串类型转换为list月拟合曲线集合
+            List<ProEconWtCurveFittingMonth> powerList = JSONObject.parseObject(o, new TypeReference<List<ProEconWtCurveFittingMonth>>() {});
+            Map<Double, Double> collect = powerList.stream().collect(Collectors.toMap(ProEconWtCurveFittingMonth::getSpeed, ProEconWtCurveFittingMonth::getActualPower));
+            CalcCache.wtCurveFittingMonthMap.put(powerList.get(0).getWindturbineId(), collect);
+        }
+        factory.setDatabase(5);
     }
 }

+ 99 - 22
ruoyi-admin/src/test/java/com/ruoyi/JavaFunctionJobHandler.java

@@ -31,6 +31,8 @@ public class JavaFunctionJobHandler extends IJobHandler {
     @Resource
     private IStateAiService stateAiService;
     @Resource
+    private RedisTemplate redisTemplate;
+    @Resource
     private IEquipmentModelService equipmentModelService;
 
     @Override
@@ -348,34 +350,109 @@ public class JavaFunctionJobHandler extends IJobHandler {
         //redisTemplate.opsForHash().put("state_point",key,value);
 
     }
-    public void calcStationXd(){
-        DateTime time = DateUtil.date();
-        DateTime time5 = DateUtil.offsetMinute(DateUtil.date(), -5);
+    public void calcStationXd(boolean priorRation){
         //限电状态
-        PointInfo pi = new PointInfo();
-        pi.setUniformCode("AGC009");
-        pi.setInstitutionType("booster");
-        List<PointInfo> entity = pointService.getByEntity(pi);
-        Map<String, PointInfo> collect = entity.stream().collect(Collectors.toMap(PointInfo::getTurbineId, Function.identity()));
-        String keys = pointInfos2Keys(entity);
+        PointInfo piAgc = new PointInfo();
+        //AGC
+        piAgc.setUniformCode("AGC002");
+        piAgc.setInstitutionType("booster");
+        List<PointInfo> entityAgc = pointService.getByEntity(piAgc);
+        Map<String, PointInfo> collectAgc = entityAgc.stream().collect(Collectors.toMap(PointInfo::getTurbineId, Function.identity()));
+        String keysAgc = pointInfos2Keys(entityAgc);
+
+        //出线
+        PointInfo piCx = new PointInfo();
+        piCx.setUniformCode("AGC001");
+        piCx.setInstitutionType("booster");
+        List<PointInfo> entityCx = pointService.getByEntity(piCx);
+        Map<String, PointInfo> collectCx = entityCx.stream().collect(Collectors.toMap(PointInfo::getTurbineId, Function.identity()));
+        String keysCx = pointInfos2Keys(entityCx);
+
+        Map<String, PointData> statAgc = adapter.getLatest(goldenUri(), keysAgc);
+        Map<String, PointData> statCx = adapter.getLatest(goldenUri(), keysCx);
+        DateTime time5 = DateUtil.offsetMinute(DateUtil.date(), -5);
+        List<DoubleStatData> statAgc5 = adapter.getHistoryStat(goldenUri(), keysAgc, time5.getTime(), DateUtil.date().getTime());
+        List<DoubleStatData> statCx5 = adapter.getHistoryStat(goldenUri(), keysCx, time5.getTime(), DateUtil.date().getTime());
 
-        //自算功率
-        PointInfo piZg = new PointInfo();
-        piZg.setUniformCode("AGC010");
-        piZg.setInstitutionType("booster");
-        List<PointInfo> entityZg = pointService.getByEntity(piZg);
-        Map<String, PointInfo> collectZg = entityZg.stream().collect(Collectors.toMap(PointInfo::getTurbineId, Function.identity()));
-        String keysZg = pointInfos2Keys(entityZg);
+        //AI066
+        for (PointInfo info : entityAgc) {
+            //如果场站限电状态为0
+            /*if (priorRation) {
+                if (zsgl5 >= sub.getCapacity() * 0.4) {
+                    if (zsgl / agc > 1.15) {
+                        b = true;
+                    }
+                    if (agc5 <= cxgl5) {
+                        b = true;
+                    }
+                    if (zsgl > agc && agc5 - cxgl5 < 4) {
+                        b = true;
+                    }
+                }
+            } else {
 
-        Map<String, PointData> latest = adapter.getLatest(taosGoldenUriTest(), keys);
-        List<DoubleStatData> statZg = adapter.getHistoryStat(taosGoldenUriTest(), keysZg, time5.getTime(), time.getTime());
+                if (zsgl5 >= sub.getCapacity() * 0.4) {
+                    if (zsgl / agc >= 1.2 && agc - cxgl <= 2) {
+                        b = true;
+                    }
+                    if (agc5 <= cxgl5) {
+                        b = true;
+                    }
+                } else {
+                    if (k) {
+                        if (agc5 <= cxgl5) {
+                            b = true;
+                        }
+                        if (zsgl / agc >= 1.1 && agc5 - cxgl5 <= 2) {
+                            b = true;
+                        }
+                    }
+                }
+            }*/
+        }
+    }
 
-        for (PointInfo info : entity) {
-            PointData xdzt = latest.get(info.getPointKey());
-            //如果场站限电状态为0
-            if(xdzt==null||xdzt.getDoubleValue()==0.0){
 
+    public void calcNhglZs(boolean priorRation){
+        //拟合功率(自算)
+        //实时风速
+        PointInfo piFs = new PointInfo();
+        piFs.setUniformCode("AI066");
+        piFs.setInstitutionType("turbine");
+        List<PointInfo> entityFs = pointService.getByEntity(piFs);
+        Map<String, PointInfo> collectFs = entityFs.stream().collect(Collectors.toMap(PointInfo::getTurbineId, Function.identity()));
+        String keysFs = pointInfos2Keys(entityFs);
+        //设备拟合功率(自算)
+        PointInfo piFjzsgl = new PointInfo();
+        piFjzsgl.setUniformCode("ZSGL");
+        piFjzsgl.setInstitutionType("turbine");
+        List<PointInfo> entityFjzsgl = pointService.getByEntity(piFjzsgl);
+        Map<String, PointInfo> collectFjzsgl = entityFjzsgl.stream().collect(Collectors.toMap(PointInfo::getTurbineId, Function.identity()));
+        String keysFjzsgl = pointInfos2Keys(entityFjzsgl);
+        //场站自算功率
+        PointInfo piCzzsgl = new PointInfo();
+        piCzzsgl.setUniformCode("AGC010");
+        piCzzsgl.setInstitutionType("booster");
+        List<PointInfo> entityCzzsgl = pointService.getByEntity(piCzzsgl);
+        Map<String, PointInfo> collectCzzsgl = entityCzzsgl.stream().collect(Collectors.toMap(PointInfo::getTurbineId, Function.identity()));
+        String keysCzzsgl = pointInfos2Keys(entityCzzsgl);
+
+        DateTime time = DateUtil.beginOfMinute(DateUtil.date());
+        DateTime time5 = DateUtil.offsetMinute(time, -5);
+        List<DoubleStatData> statFs5;
+        PointData avg;
+        for (PointInfo info : entityFs) {
+            statFs5 = adapter.getHistoryStat(goldenUri(), keysFs, time5.getTime(), time.getTime());
+            if(!statFs5.isEmpty()){
+                avg = statFs5.get(0).getAvg();
+                avg.setTs(time.getTime());
+                avg.setTagName(info.getPointKey());
+                adapter.writeHistory(taosUri(), avg);
             }
         }
     }
+
+    public URI goldenUri(){
+        return URI.create("http://172.16.12.103:8011/ts");
+    }
 }

+ 64 - 0
universal-computing-platform/src/main/java/com/ruoyi/ucp/entity/ProEconWtCurveFittingMonth.java

@@ -0,0 +1,64 @@
+package com.ruoyi.ucp.entity;
+
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.extension.activerecord.Model;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+/**
+ * <p>
+ * 风电机月拟合曲线
+ * </p>
+ *
+ * @author shilin
+ * @since 2022-10-21
+ */
+@Data
+@EqualsAndHashCode(callSuper = true)
+public class ProEconWtCurveFittingMonth extends Model {
+
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * 编号
+     */
+    @TableId(value = "ID",type = IdType.ASSIGN_ID)
+    private Long id;
+
+    /**
+     * 风机编号
+     */
+    private String windturbineId;
+
+    /**
+     * 风速
+     */
+    private Double speed;
+
+    /**
+     * 实际拟合功率
+     */
+    private Double actualPower;
+
+    /**
+     * 最优拟合功率
+     */
+    private Double optimalPower;
+
+    /**
+     * 年
+     */
+    private String year;
+
+    /**
+     * 月
+     */
+    private String month;
+
+    /**
+     * 主表编号
+     */
+    private String mainId;
+}

+ 10 - 0
universal-computing-platform/src/main/java/com/ruoyi/ucp/util/CalcCache.java

@@ -0,0 +1,10 @@
+package com.ruoyi.ucp.util;
+
+import com.ruoyi.ucp.entity.ProEconWtCurveFittingMonth;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+public class CalcCache {
+    public static Map<String, Map<Double, Double>> wtCurveFittingMonthMap= new ConcurrentHashMap<>();
+}