Преглед изворни кода

Merge remote-tracking branch 'origin/master'

malijun пре 1 година
родитељ
комит
7b0d0ef399

+ 36 - 108
common/data/src/main/java/com/gyee/gaia/common/data/taos/RealtimeAverageTarget.java

@@ -1,6 +1,7 @@
 package com.gyee.gaia.common.data.taos;
 
 import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Data;
 
 import java.io.Serializable;
 import java.sql.Timestamp;
@@ -13,6 +14,7 @@ import java.sql.Timestamp;
  * @author gfhd
  * @since 2023-05-18
  */
+@Data
 @TableName("realtime_average_target")
 public class RealtimeAverageTarget implements Serializable {
 
@@ -22,128 +24,54 @@ public class RealtimeAverageTarget implements Serializable {
 
     private Timestamp time;
 
+    /**
+     * 平均风速
+     */
     private Float windSpeed;
 
+    /**
+     * 实际功率
+     */
     private Float power;
 
+    /**
+     * 发电机转速
+     */
     private Float generatorSpeed;
 
+    /**
+     * 叶轮转速
+     */
     private Float impellerSpeed;
 
+    /**
+     * 风向
+     */
     private Float windDirection;
 
+    /**
+     * 理论发电量
+     */
     private Float theoryGeneration;
 
+    /**
+     * 桨叶角度
+     */
+    private Float bladeAngle;
+
+    /**
+     * 机舱方向
+     */
+    private Float engineDirection;
+
+    /**
+     * 对风误差
+     */
+    private Float windDeviation;
+
+
     private String stationId;
     private String equipmentId;
     private String uniformCode;
     private String description;
-
-    public String getTbname() {
-        return tbname;
-    }
-
-    public void setTbname(String tbname) {
-        this.tbname = tbname;
-    }
-
-    public Timestamp getTime() {
-        return time;
-    }
-
-    public void setTime(Timestamp time) {
-        this.time = time;
-    }
-
-    public String getEquipmentId() {
-        return equipmentId;
-    }
-
-    public void setEquipmentId(String equipmentId) {
-        this.equipmentId = equipmentId;
-    }
-
-    public Float getWindSpeed() {
-        return windSpeed;
-    }
-
-    public void setWindSpeed(Float windSpeed) {
-        this.windSpeed = windSpeed;
-    }
-
-    public Float getPower() {
-        return power;
-    }
-
-    public void setPower(Float power) {
-        this.power = power;
-    }
-
-    public Float getGeneratorSpeed() {
-        return generatorSpeed;
-    }
-
-    public void setGeneratorSpeed(Float generatorSpeed) {
-        this.generatorSpeed = generatorSpeed;
-    }
-
-    public Float getImpellerSpeed() {
-        return impellerSpeed;
-    }
-
-    public void setImpellerSpeed(Float impellerSpeed) {
-        this.impellerSpeed = impellerSpeed;
-    }
-
-    public Float getWindDirection() {
-        return windDirection;
-    }
-
-    public void setWindDirection(Float windDirection) {
-        this.windDirection = windDirection;
-    }
-
-    public Float getTheoryGeneration() {
-        return theoryGeneration;
-    }
-
-    public void setTheoryGeneration(Float theoryGeneration) {
-        this.theoryGeneration = theoryGeneration;
-    }
-
-    public String getStationId() {
-        return stationId;
-    }
-
-    public void setStationId(String stationId) {
-        this.stationId = stationId;
-    }
-
-    public String getUniformCode() {
-        return uniformCode;
-    }
-
-    public void setUniformCode(String uniformCode) {
-        this.uniformCode = uniformCode;
-    }
-
-    public String getDescription() {
-        return description;
-    }
-
-    public void setDescription(String description) {
-        this.description = description;
-    }
-
-    @Override
-    public String toString() {
-        return "RealtimeAverageTarget{" +
-                "time = " + time +
-                ", equipmentId = " + equipmentId +
-                ", windSpeed = " + windSpeed +
-                ", generatorSpeed = " + generatorSpeed +
-                ", impellerSpeed = " + impellerSpeed +
-                ", windDirection = " + windDirection +
-                "}";
-    }
 }

+ 1 - 0
electricity/wind/src/main/java/com/gyee/gaia/electricity/wind/serviceimpl/RealtimeAverageTargetServiceImpl.java

@@ -22,6 +22,7 @@ import java.util.List;
 @Service
 public class RealtimeAverageTargetServiceImpl extends ServiceImpl<RealtimeAverageTargetMapper, RealtimeAverageTarget> implements IRealtimeAverageTargetService {
 
+    @Override
     public int saveBatch(List<RealtimeAverageTarget> entityList) {
         List<List<RealtimeAverageTarget>> split = ListUtil.split(entityList, 3000);
         int count = 0;

+ 39 - 59
realtime/wind/src/main/java/com/gyee/gaia/realtime/wind/job/CauseJobHandler.java

@@ -16,6 +16,7 @@ import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
 import org.springframework.stereotype.Component;
 
 import javax.annotation.Resource;
+import java.math.RoundingMode;
 import java.util.*;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.stream.Collectors;
@@ -35,46 +36,37 @@ public class CauseJobHandler implements ApplicationRunner {
 
     private final Map<String, ArrayDeque<PointData>> pdaqMap = new ConcurrentHashMap<>();
 
-    private boolean isload = false;
-
-    //@Resource
-    //private DataFillJobHandler dataFillJobHandler;
 
     @Override
     public void run(ApplicationArguments args) throws Exception {
-
-        //dataFillJobHandler.calcEquipPowerGenDay();
         init();
         taskExecutor.submit(this::refreshQueue);
-        isload = true;
     }
 
     private void init() throws InterruptedException {
-
         //缓存1分钟的值填满pdaqMap
         for (int i = 0; i < 60; i++) {
             Map<String, PointData> latest = adapterApi.getLatest(CacheContext.pointCodes);
             if (i == 0) {
                 latest.forEach((k, v) -> {
                     ArrayDeque<PointData> pdaq = new ArrayDeque<>(60);
-                    pdaq.offer(v);
+                    pdaq.offerFirst(v);
                     pdaqMap.put(k, pdaq);
                 });
             } else {
-                latest.forEach((k, v) -> pdaqMap.get(k).offer(v));
+                latest.forEach((k, v) -> pdaqMap.get(k).offerFirst(v));
             }
             Thread.sleep(1000);
         }
     }
 
     private void refreshQueue() {
-
         while (true) {
             try {
                 Map<String, PointData> latest = adapterApi.getLatest(CacheContext.pointCodes);
                 latest.forEach((k, v) -> {
-                    pdaqMap.get(k).poll();
-                    pdaqMap.get(k).offer(v);
+                    pdaqMap.get(k).pollLast();
+                    pdaqMap.get(k).offerFirst(v);
                 });
                 Thread.sleep(1000);
             } catch (InterruptedException e) {
@@ -83,80 +75,69 @@ public class CauseJobHandler implements ApplicationRunner {
         }
     }
 
-    @Scheduled(fixedRate = 60000)
+    /**
+     * 计算常用测点的1分钟平均数据,第一次执行延时60s
+     */
+    @Scheduled(initialDelay = 60000, fixedRate = 60000)
     private void calcRealtimeAverageTarget() {
-
-        if (!isload) return;
         try {
-            String pointCode;
-            RealtimeAverageTarget target;
-            double v;
             //uniformcode,点名
-            Map<String, String> entryValue;
             Map<String, String> uniformcodeOne = appConfig.getUniformcodeOne();
-            double speed;
-            Double power;
 
             List<RealtimeAverageTarget> targets = new ArrayList<>();
             for (Map.Entry<String, Map<String, String>> entry : CacheContext.equipUcMap.entrySet()) {
-
-                entryValue = entry.getValue();
-
-                target = new RealtimeAverageTarget();
+                Map<String, String> entryValue = entry.getValue();
+                RealtimeAverageTarget target = new RealtimeAverageTarget();
                 target.setTime(DateUtil.beginOfMinute(DateUtil.date()).toTimestamp());
-                //target.setEquipmentId(entry.getKey());
                 target.setTbname(CacheContext.pjzb1fzMap.get(entry.getKey()));
 
-                pointCode = entryValue.get(uniformcodeOne.get("wind-speed"));
+                String pointCode = entryValue.get(uniformcodeOne.get("wind-speed"));
                 if (pointCode != null) {
                     //风速
-                    ArrayDeque<PointData> pointData = pdaqMap.get(pointCode);
-                    v = pointData.stream().mapToDouble(PointData::getDoubleValue).average().orElse(0);
-                    if (System.currentTimeMillis()-pointData.getFirst().getTs()>30*60*1000) {
-                        //如果离线或者别的原因获取不到风速,从全场实时平均风速获取
-                        Map<String, PointData> latest = adapterApi.getLatest(CacheContext.stationRealMeanSpeedMap.get(CacheContext.equipMap.get(entry.getKey()).getWindpowerstationId()));
-                        Iterator<PointData> iterator = latest.values().iterator();
-                        double doubleValue = 0;
-                        if (iterator.hasNext()) doubleValue = iterator.next().getDoubleValue();
-                        if (doubleValue > 3) v = doubleValue;
-                    }
-                    speed = NumberUtil.round(v, 2).doubleValue();
+                    double v = pdaqMap.get(pointCode).stream().mapToDouble(PointData::getDoubleValue).average().orElse(0);
+                    double speed = NumberUtil.round(v, 2, RoundingMode.DOWN).doubleValue();
                     target.setWindSpeed((float) speed);
-
-                    if (speed < 3) {
+                    Double power = CacheContext.mpdsMapMap.get(CacheContext.equipModelMap.get(entry.getKey())).get(speed);
+                    if (power == null || speed <= 3){
                         power = 0.0;
-                    } else {
-                        /*Map<Double, Double> map = CacheContext.powerModelMap.get(entry.getKey());
-                        if (map != null && map.size() > 0) {
-                            power = map.get(speed);
-                        } else {
-                            power = CacheContext.mpdsMapMap.get(CacheContext.equipModelMap.get(entry.getKey())).get(speed);
-                        }*/
-                        power = CacheContext.mpdsMapMap.get(CacheContext.equipModelMap.get(entry.getKey())).get(speed);
                     }
-                    if (power == null) power = 0.0;
-                    target.setTheoryGeneration(NumberUtil.round(power, 2).floatValue());
+                    target.setTheoryGeneration(NumberUtil.round(power, 2, RoundingMode.DOWN).floatValue());
                 }
                 pointCode = entryValue.get(uniformcodeOne.get("active-power"));
                 if (pointCode != null) {
-                    v = pdaqMap.get(pointCode).stream().mapToDouble(PointData::getDoubleValue).average().orElse(0);
-                    target.setPower(NumberUtil.round(v, 2).floatValue());
+                    double v = pdaqMap.get(pointCode).stream().mapToDouble(PointData::getDoubleValue).average().orElse(0);
+                    target.setPower(NumberUtil.round(v, 2, RoundingMode.DOWN).floatValue());
                 }
                 pointCode = entryValue.get(uniformcodeOne.get("generator_speed"));
                 if (pointCode != null) {
-                    v = pdaqMap.get(pointCode).stream().mapToDouble(PointData::getDoubleValue).average().orElse(0);
-                    target.setGeneratorSpeed(NumberUtil.round(v, 2).floatValue());
+                    double v = pdaqMap.get(pointCode).stream().mapToDouble(PointData::getDoubleValue).average().orElse(0);
+                    target.setGeneratorSpeed(NumberUtil.round(v, 2, RoundingMode.DOWN).floatValue());
                 }
                 pointCode = entryValue.get(uniformcodeOne.get("impeller_speed"));
                 if (pointCode != null) {
-                    v = pdaqMap.get(pointCode).stream().mapToDouble(PointData::getDoubleValue).average().orElse(0);
-                    target.setImpellerSpeed(NumberUtil.round(v, 2).floatValue());
+                    double v = pdaqMap.get(pointCode).stream().mapToDouble(PointData::getDoubleValue).average().orElse(0);
+                    target.setImpellerSpeed(NumberUtil.round(v, 2, RoundingMode.DOWN).floatValue());
                 }
                 pointCode = entryValue.get(uniformcodeOne.get("wind_direction"));
                 if (pointCode != null) {
-                    v = pdaqMap.get(pointCode).stream().mapToDouble(PointData::getDoubleValue).average().orElse(0);
+                    double v = pdaqMap.get(pointCode).stream().mapToDouble(PointData::getDoubleValue).average().orElse(0);
                     target.setWindDirection(NumberUtil.round(v, 2).floatValue());
                 }
+                pointCode = entryValue.get(uniformcodeOne.get("blade_angle"));
+                if (pointCode != null) {
+                    double v = pdaqMap.get(pointCode).stream().mapToDouble(PointData::getDoubleValue).average().orElse(0);
+                    target.setBladeAngle(NumberUtil.round(v, 2).floatValue());
+                }
+                pointCode = entryValue.get(uniformcodeOne.get("engine_direction"));
+                if (pointCode != null) {
+                    double v = pdaqMap.get(pointCode).stream().mapToDouble(PointData::getDoubleValue).average().orElse(0);
+                    target.setEngineDirection(NumberUtil.round(v, 2).floatValue());
+                }
+                pointCode = entryValue.get(uniformcodeOne.get("wind_deviation"));
+                if (pointCode != null) {
+                    double v = pdaqMap.get(pointCode).stream().mapToDouble(PointData::getDoubleValue).average().orElse(0);
+                    target.setWindDeviation(NumberUtil.round(v, 2).floatValue());
+                }
                 targets.add(target);
             }
             targets = targets.stream().peek(t -> {
@@ -168,7 +149,6 @@ public class CauseJobHandler implements ApplicationRunner {
         } catch (Exception e) {
             e.printStackTrace();
         }
-
     }
 
 }

+ 17 - 17
realtime/wind/src/main/java/com/gyee/gaia/realtime/wind/job/DataFillJobHandler.java

@@ -33,9 +33,9 @@ public class DataFillJobHandler {
     private AppConfig appConfig;
 
     /**
+     * 计算常用测点的1分钟平均数据
      * 风机id,uniformcode,平均数据
      */
-    //private Map<String, Map<String, List<PointData>>> dsdlssMap;
 
     @XxlJob("DataFilling")
     public void calcEquipPowerGenDay() {
@@ -56,8 +56,6 @@ public class DataFillJobHandler {
             endDate = DateUtil.parse(end);
         }
 
-        //getDatas(startDate.getTime(), endDate.getTime());
-
         List<RealtimeAverageTarget> realtimeAverageTargetList = new ArrayList<>();
         QueryWrapper<RealtimeAverageTarget> ratWrapper = new QueryWrapper<>();
         ratWrapper.select("tbname", "time", "station_id", "equipment_id").eq("uniform_code", "1FZPJZB")
@@ -76,7 +74,6 @@ public class DataFillJobHandler {
                     List<PointData> rawByKey = adapterApi.getRawByKey(point, startDate.getTime(), endDate.getTime());
                     lpdsMap.put(uc, rawByKey);
                 });
-                int i = 0;
                 for (DateTime minute = DateUtil.beginOfMinute(startDate); minute.isBefore(endDate); minute.offset(DateField.MINUTE, 1)) {
                     RealtimeAverageTarget rat = new RealtimeAverageTarget();
                     rat.setTime(new Timestamp(minute.getTime()));
@@ -84,7 +81,6 @@ public class DataFillJobHandler {
                     setRats(rat, equipmentId, minute.getTime(), minute.getTime() + 59999L, lpdsMap);
                     realtimeAverageTargetList.add(rat);
                 }
-
             }
         }else {
             //按风机分组
@@ -116,18 +112,7 @@ public class DataFillJobHandler {
 
         realtimeAverageTargetService.saveBatch(realtimeAverageTargetList);
     }
-/*
-    private void getDatas(long time1, long time2) {
-        dsdlssMap = new HashMap<>();
-        CacheContext.equipUcMap.forEach((equipId, ucode) -> {
-            Map<String, List<PointData>> map = new HashMap<>();
-            ucode.forEach((uc, point) -> {
-                List<PointData> rawByKey = adapterApi.getRawByKey(point, time1, time2);
-                map.put(uc, rawByKey);
-            });
-            dsdlssMap.put(equipId, map);
-        });
-    }*/
+
 
     private void setRats(RealtimeAverageTarget rat, String equipId, long time1, long time2, Map<String, List<PointData>> lpdsMap) {
 
@@ -136,12 +121,18 @@ public class DataFillJobHandler {
         List<PointData> generator_speeds = lpdsMap.get(appConfig.getUniformcodeOne().get("generator_speed"));
         List<PointData> impeller_speeds = lpdsMap.get(appConfig.getUniformcodeOne().get("impeller_speed"));
         List<PointData> wind_directions = lpdsMap.get(appConfig.getUniformcodeOne().get("wind_direction"));
+        List<PointData> blade_angle = lpdsMap.get(appConfig.getUniformcodeOne().get("blade_angle"));
+        List<PointData> engine_direction = lpdsMap.get(appConfig.getUniformcodeOne().get("engine_direction"));
+        List<PointData> wind_deviation = lpdsMap.get(appConfig.getUniformcodeOne().get("wind_deviation"));
 
         double wsdv = 0;
         double apdv = 0;
         double gsdv = 0;
         double isdv = 0;
         double wddv = 0;
+        double badv = 0;
+        double eddv = 0;
+        double wtdv = 0;
 
         if (wind_speeds != null && wind_speeds.size() > 0)
             wsdv = wind_speeds.stream().filter(pd -> pd.getTs() >= time1 && pd.getTs() <= time2).mapToDouble(PointData::getDoubleValue).average().orElse(0);
@@ -153,6 +144,12 @@ public class DataFillJobHandler {
             isdv = impeller_speeds.stream().filter(pd -> pd.getTs() >= time1 && pd.getTs() <= time2).mapToDouble(PointData::getDoubleValue).average().orElse(0);
         if (wind_directions != null && wind_directions.size() > 0)
             wddv = wind_directions.stream().filter(pd -> pd.getTs() >= time1 && pd.getTs() <= time2).mapToDouble(PointData::getDoubleValue).average().orElse(0);
+        if (blade_angle != null && blade_angle.size() > 0)
+            badv = blade_angle.stream().filter(pd -> pd.getTs() >= time1 && pd.getTs() <= time2).mapToDouble(PointData::getDoubleValue).average().orElse(0);
+        if (engine_direction != null && engine_direction.size() > 0)
+            eddv = engine_direction.stream().filter(pd -> pd.getTs() >= time1 && pd.getTs() <= time2).mapToDouble(PointData::getDoubleValue).average().orElse(0);
+        if (wind_deviation != null && wind_deviation.size() > 0)
+            wtdv = wind_deviation.stream().filter(pd -> pd.getTs() >= time1 && pd.getTs() <= time2).mapToDouble(PointData::getDoubleValue).average().orElse(0);
 
         double speed = NumberUtil.round(wsdv, 2).doubleValue();
 
@@ -161,6 +158,9 @@ public class DataFillJobHandler {
         rat.setGeneratorSpeed(NumberUtil.round(gsdv, 2).floatValue());
         rat.setImpellerSpeed(NumberUtil.round(isdv, 2).floatValue());
         rat.setWindDirection(NumberUtil.round(wddv, 2).floatValue());
+        rat.setBladeAngle(NumberUtil.round(badv, 2).floatValue());
+        rat.setEngineDirection(NumberUtil.round(eddv, 2).floatValue());
+        rat.setWindDeviation(NumberUtil.round(wtdv, 2).floatValue());
         if (speed < 3) {
             rat.setTheoryGeneration(0f);
         } else {

+ 1 - 0
realtime/wind/src/main/java/com/gyee/gaia/realtime/wind/service/impl/RealtimeAverageTargetServiceImpl.java

@@ -22,6 +22,7 @@ import java.util.List;
 @Service
 public class RealtimeAverageTargetServiceImpl extends ServiceImpl<RealtimeAverageTargetMapper, RealtimeAverageTarget> implements IRealtimeAverageTargetService {
 
+    @Override
     public int saveBatch(List<RealtimeAverageTarget> entityList) {
         List<List<RealtimeAverageTarget>> split = ListUtil.split(entityList, 3000);
 

+ 3 - 0
realtime/wind/src/main/resources/bootstrap.yaml

@@ -63,6 +63,9 @@ meter:
     generator_speed: AI128  #发电机转速
     impeller_speed: AI012  #叶轮转速
     wind_direction: AI010  #风向
+    blade_angle: AI085  #桨叶角度
+    engine_direction: AI034  #机舱方向
+    wind_deviation: AI036  #对风误差
 
 
 mybatis-plus: