Bladeren bron

五损状态计算之受累电状态

xushili 1 jaar geleden
bovenliggende
commit
46f53f65ab

+ 1 - 0
state/cause/src/main/java/com/gyee/gaia/cause/config/AppConfig.java

@@ -18,6 +18,7 @@ public class AppConfig {
      * 统一编码名,统一编码
      */
     private Map<String, String> uniformcode;
+    private int faulttime;
 
 
     @Override

+ 124 - 35
state/cause/src/main/java/com/gyee/gaia/cause/service/CalculateService.java

@@ -1,8 +1,10 @@
 package com.gyee.gaia.cause.service;
 
 import com.gyee.gaia.cause.adapter.AdapterApi;
+import com.gyee.gaia.cause.config.AppConfig;
 import com.gyee.gaia.cause.entity.PointData;
 import com.gyee.gaia.cause.entity.StateCause;
+import com.gyee.gaia.common.data.point.TestingPoint;
 import com.gyee.gaia.common.data.power.ModelPower;
 import com.gyee.gaia.init.CacheContext;
 import lombok.extern.slf4j.Slf4j;
@@ -19,26 +21,27 @@ public class CalculateService {
     @Resource
     private AdapterApi adapterApi;
     @Resource
+    private AppConfig appConfig;
+    @Resource
     private IStateCauseService stateCauseService;
 
-    private Map<String,Map<String, List<PointData>>> pointDatas;
+    /**
+     * 设备id,状态点列表
+     */
+    private Map<String, List<PointData>> stateDatas;
 
     public void refresh(long starttime, long endtime){
         log.info("刷新测点值!");
-        CacheContext.pointsMap.forEach((ucname,pointList)->{
-            pointList.forEach(point->{
-                List<PointData> rawByKey = adapterApi.getRawByKey(point.getCode(), starttime, endtime);
-                Map<String, List<PointData>> tppdl = new HashMap<>();
-                tppdl.put(point.getCode(), rawByKey);
-                pointDatas.put(ucname, tppdl);
-            });
+        CacheContext.pointMapMap.get("state8").forEach((k,v)->{
+            List<PointData> rawByKey = adapterApi.getRawByKey(v.getCode(), starttime, endtime);
+            stateDatas.put(k, rawByKey);
         });
     }
 
     //风机的8种原始状态:0-停机、 1-上电、2-待机、3-启动、4-并网、5-故障、6-维护、 7-离线
     public void calculate() {
         List<StateCause> stateCauseList = new ArrayList<>();
-        pointDatas.get("风机8种状态").forEach((key,value)->{
+        stateDatas.forEach((key,value)->{
             //事前状态
             double advanceState = value.get(0).getDoubleValue();
             //事前时间
@@ -57,25 +60,39 @@ public class CalculateService {
                 if(advanceState==4){
                     //计算限电
                     calcElectricityRation(stateCauseList,key,advanceTime,ts,doubleValue);
-                }else if(advanceState==0){
+                //TODO 判断限停
+                }else if(advanceState==2){
                     StateCause cause = new StateCause();
                     cause.setStationId(CacheContext.equipPointsMap.get(key).getWindpowerstationId());
                     cause.setEquipmentId(CacheContext.equipPointsMap.get(key).getId());
-                    cause.setEvent("机");
+                    cause.setEvent("机");
                     cause.setStartTime(new Date(advanceTime));
                     cause.setEndTime(new Date(ts));
-                    cause.setAdvanceState("机");
+                    cause.setAdvanceState("机");
                     cause.setAfterState(CacheContext.stateMap.get(doubleValue));
                     cause.setTime(ts -advanceTime);
                     stateCauseList.add(cause);
-                }else if(advanceState==2){
+                }else if(advanceState==6){
+                    if(isHasFaultEvent()){
+                        //故障
+                    }else {
+                        //计划检修
+                    }
+                }else if(advanceState==5){
+                    if(ts-advanceTime<appConfig.getFaulttime()*60000) continue;
+                    //计算受累、故障、计划检修
+                    calcBurdened(stateCauseList,key,advanceTime, ts,5,doubleValue);
+                }else if(advanceState==7){
+                    //计算受累、故障、计划检修
+                    calcBurdened(stateCauseList,key,advanceTime, ts,7,doubleValue);
+                }else if(advanceState==0){
                     StateCause cause = new StateCause();
                     cause.setStationId(CacheContext.equipPointsMap.get(key).getWindpowerstationId());
                     cause.setEquipmentId(CacheContext.equipPointsMap.get(key).getId());
-                    cause.setEvent("待机");
+                    cause.setEvent("机");
                     cause.setStartTime(new Date(advanceTime));
                     cause.setEndTime(new Date(ts));
-                    cause.setAdvanceState("待机");
+                    cause.setAdvanceState("机");
                     cause.setAfterState(CacheContext.stateMap.get(doubleValue));
                     cause.setTime(ts -advanceTime);
                     stateCauseList.add(cause);
@@ -89,42 +106,114 @@ public class CalculateService {
     }
 
     /**
-     *
-     *
-     * @param stateCauseList
+     * 计算受累
+     */
+    private void calcBurdened(List<StateCause> stateCauseList, String equipment, long start, long end, double starteventstate, double endeventstate) {
+        //全站故障或者离线
+        Map<String, TestingPoint> state8 = CacheContext.pointMapMap.get("state8");
+        String station = state8.get(equipment).getStationId();
+
+        List<List<PointData>> stationState = new ArrayList<>();
+        //当前风机的场站所有风机
+        List<TestingPoint> points = state8.values().stream().filter(tp -> station.equals(tp.getStationId())).collect(Collectors.toList());
+        points.forEach(tp->{
+            List<PointData> valuesByKey = adapterApi.getValuesByKey(state8.get(tp.getThingId()).getCode(), start, end, 30);
+            stationState.add(valuesByKey);
+        });
+        int size = stationState.get(0).size();
+
+        //是否受累
+        boolean isBurdened = false;
+        //受累开始时间
+        long t1 = 0;
+        //是否有故障
+        boolean isHasFault = false;
+        //故障开始时间
+        long t2 = 0;
+        //全场故障或离线次数
+        int k = 0;
+        for (int i = 0; i < size; i++) {
+            int finalI = i;
+            boolean b = stationState.stream().filter(pds -> pds.get(finalI).getDoubleValue() == starteventstate).count() == stationState.size();
+            //boolean c = stationState.stream().filter(pds -> pds.get(finalI).getDoubleValue() == 7).count() == stationState.size();
+            long ts = stationState.get(0).get(finalI).getTs();
+            if(b){
+                k++;
+            }
+            /*if(b){
+                //受累首次时间
+                if(!isBurdened){
+                    t1 = ts;
+                }
+                isBurdened = true;
+            }else if(isBurdened) {
+                StateCause cause = new StateCause();
+                cause.setStationId(station);
+                cause.setEquipmentId(equipment);
+                cause.setEvent(CacheContext.stateMap.get(10.0));
+                cause.setStartTime(new Date(t1));
+                cause.setEndTime(new Date(ts));
+                cause.setAdvanceState(CacheContext.stateMap.get(starteventstate));
+                if(i==size-1){
+                    cause.setAfterState(CacheContext.stateMap.get(endeventstate));
+                }else {
+                    cause.setAfterState(CacheContext.stateMap.get(starteventstate));
+                }
+                cause.setTime(ts - t1);
+                stateCauseList.add(cause);
+
+                isBurdened = false;
+            }*/
+        }
+        if(k/size>9.5){
+            //受累
+        }else if(isHasFaultEvent()){
+            //故障
+        }else {
+            //计划检修
+        }
+    }
+
+    private boolean isHasFaultEvent() {
+        return false;
+    }
+
+    /**
+     * 计算限电
      * @param equipment 设备id
      * @param start 并网开始时间
      * @param end 并网结束时间
      * @param endeventstate 事后状态
-     * @return
      */
     private void calcElectricityRation(List<StateCause> stateCauseList, String equipment, long start, long end, double endeventstate) {
-        //满发功率和最小风速
+        //满发功率和满发最小风速
         ModelPower modelPower = CacheContext.fullSpeeds.get(CacheContext.equipPointsMap.get(equipment).getModelId());
         //并网时间内的风速列表
-        List<PointData> speedList = pointDatas.get("风速").get(equipment).stream()
-                .filter(pointData -> pointData.getTs() >= start || pointData.getTs() < end).collect(Collectors.toList());
+        List<PointData> speedList = adapterApi.getValuesByKey(CacheContext.pointMapMap.get("speed").get(equipment).getCode(), start, end, 30);
+        List<PointData> bladeAngleList = adapterApi.getValuesByKey(CacheContext.pointMapMap.get("blade-angle").get(equipment).getCode(), start, end, 30);
+        List<PointData> activePowerList = adapterApi.getValuesByKey(CacheContext.pointMapMap.get("active-power").get(equipment).getCode(), start, end, 30);
         //是否限电
         boolean isElectricityRation = false;
         //限电开始时间
         long t1 = 0;
 
-        for (PointData data : speedList) {
-            long ts = data.getTs();
-            //TODO 当前时间戳的桨叶角度
-            PointData bladeAnglePd = pointDatas.get("桨叶1角度").get(equipment).stream().filter(pointData -> pointData.getTs() <= ts).findFirst().get();
-            //TODO 当前时间戳的有功功率
-            PointData powerPd = pointDatas.get("有功功率").get(equipment).stream().filter(pointData -> pointData.getTs() <= ts).findFirst().get();
+        for (int i = 0; i < speedList.size(); i++) {
+            long ts = speedList.get(i).getTs();
+            double speedPd = speedList.get(i).getDoubleValue();
+            //当前时间戳的桨叶角度
+            double bladeAnglePd = bladeAngleList.get(i).getDoubleValue();
+            //当前时间戳的有功功率
+            double activePowerPd = activePowerList.get(i).getDoubleValue();
 
             //风速小于11并且桨叶角度大于2
-            if (data.getDoubleValue() <= modelPower.getSpeed() && bladeAnglePd.getDoubleValue() > 2) {
+            if (speedPd <= modelPower.getSpeed() && bladeAnglePd > 2) {
                 //限电首次时间
                 if(!isElectricityRation){
                     t1 = ts;
                 }
                 isElectricityRation = true;
-            //风速大于11并且有功功率小于满发功率减100
-            } else if (data.getDoubleValue() > modelPower.getSpeed() && powerPd.getDoubleValue() < modelPower.getTheoryPower()-100) {
+                //风速大于11并且有功功率小于满发功率减100
+            } else if (speedPd > modelPower.getSpeed() && activePowerPd < modelPower.getTheoryPower()-100) {
                 //限电首次时间
                 if(!isElectricityRation){
                     t1 = ts;
@@ -134,14 +223,14 @@ public class CalculateService {
                 StateCause cause = new StateCause();
                 cause.setStationId(CacheContext.equipPointsMap.get(equipment).getWindpowerstationId());
                 cause.setEquipmentId(equipment);
-                cause.setEvent("限电");
+                cause.setEvent(CacheContext.stateMap.get(8.0));
                 cause.setStartTime(new Date(t1));
                 cause.setEndTime(new Date(ts));
-                cause.setAdvanceState("并网");
-                if(data==speedList.get(speedList.size()-1)){
+                cause.setAdvanceState(CacheContext.stateMap.get(4.0));
+                if(i==speedList.size()-1){
                     cause.setAfterState(CacheContext.stateMap.get(endeventstate));
                 }else {
-                    cause.setAfterState("并网");
+                    cause.setAfterState(CacheContext.stateMap.get(4.0));
                 }
                 cause.setTime(ts - t1);
                 stateCauseList.add(cause);

+ 13 - 10
state/cause/src/main/java/com/gyee/gaia/init/CacheContext.java

@@ -3,12 +3,10 @@ package com.gyee.gaia.init;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.gyee.gaia.cause.config.AppConfig;
 import com.gyee.gaia.common.data.point.TestingPoint;
-import com.gyee.gaia.common.data.point.UniformCode;
 import com.gyee.gaia.common.data.power.ModelPower;
 import com.gyee.gaia.common.data.windturbine.Equipment;
 import com.gyee.gaia.dao.sql.Windturbine.IEquipmentService;
 import com.gyee.gaia.dao.sql.point.ITestingPointService;
-import com.gyee.gaia.dao.sql.point.IUniformCodeService;
 import com.gyee.gaia.dao.sql.power.IModelPowerService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.boot.CommandLineRunner;
@@ -30,18 +28,18 @@ public class CacheContext implements CommandLineRunner {
     @Resource
     private ITestingPointService testingPointService;
     @Resource
-    IUniformCodeService uniformCodeService;
-    @Resource
     private IModelPowerService modelPowerService;
     @Resource
     private IEquipmentService equipmentService;
+    @Resource
+    private AppConfig appConfig;
 
     public static Map<String, ModelPower> fullSpeeds;
     public static Map<Double, String> stateMap;
     /**
-     * 统一编码描述,测点列表
+     * 统一编码名称,设备id,测点
      */
-    public static Map<String,List<TestingPoint>> pointsMap;
+    public static Map<String, Map<String, TestingPoint>> pointMapMap;
     /**
      * 风机号,TestingPoint
      */
@@ -50,13 +48,13 @@ public class CacheContext implements CommandLineRunner {
     @Override
     public void run(String... args) throws Exception {
         log.info("加载统一编码!");
-        QueryWrapper<UniformCode> ucWrapper = new QueryWrapper<>();
+        /*QueryWrapper<UniformCode> ucWrapper = new QueryWrapper<>();
         ucWrapper.eq("spare1", "计算五损");
         List<UniformCode> uniformCodeList = uniformCodeService.list(ucWrapper);
-        Map<String, String> uniformCodeMap = uniformCodeList.stream().collect(Collectors.toMap(UniformCode::getDescription, UniformCode::getNemCode));
+        Map<String, String> uniformCodeMap = uniformCodeList.stream().collect(Collectors.toMap(UniformCode::getDescription, UniformCode::getNemCode));*/
 
         log.info("加载状态测点!");
-        loadPoints(uniformCodeMap);
+        loadPoints(appConfig.getUniformcode());
 
         log.info("加载机型满发最低风速!");
         QueryWrapper<ModelPower> mpWrapper = new QueryWrapper<>();
@@ -75,6 +73,10 @@ public class CacheContext implements CommandLineRunner {
         stateMap.put(6.0, "维护");
         stateMap.put(7.0, "离线");
 
+        stateMap.put(8.0, "限电");
+        stateMap.put(9.0, "计划检修");
+        stateMap.put(10.0, "受累");
+
         log.info("加载风机!");
         List<Equipment> emList = equipmentService.list();
         equipPointsMap=emList.stream().collect(Collectors.toMap(Equipment::getId, Function.identity()));
@@ -85,7 +87,8 @@ public class CacheContext implements CommandLineRunner {
             QueryWrapper<TestingPoint> tpWrapper = new QueryWrapper<>();
             tpWrapper.eq("thing_type","windturbine").eq("uniform_code", v);
             List<TestingPoint> list = testingPointService.list(tpWrapper);
-            pointsMap.put(k, list);
+            Map<String, TestingPoint> collect = list.stream().collect(Collectors.toMap(TestingPoint::getThingId, Function.identity()));
+            pointMapMap.put(k, collect);
         });
     }
 }

+ 5 - 0
state/cause/src/main/resources/bootstrap.yaml

@@ -46,6 +46,8 @@ spring:
 meter:
   stations: MHS_FDC,NSS_FDC
   adapter-url: http://192.168.10.18:8011
+  #多长时间计算故障损失,单位分钟
+  faulttime: 3
   uniformcode:
     #8种状态
     state8: FJZT8
@@ -53,6 +55,9 @@ meter:
     blade-angle: AI082
     #功率-有功功率
     active-power: AI130
+    #风速
+    speed:
+
 
 mybatis-plus:
   typeAliasesPackage: com.gyee.gaia.meter.entity