Browse Source

优化与bug修复

xushili 1 year atrás
parent
commit
4ca8c146ce

+ 1 - 9
electricity/wind/README.md

@@ -1,11 +1,3 @@
-### cause 分析原因,故障损失,计划检修损失,受累损失,限电损失,性能损失等
-
-状态为: 并网--是否限电--风速小于11并且桨叶角度大于2;风速大于11并且有功功率小于满发功率减100 待机-- 是否限停-- 有故障--故障 无故障--有功设定小于出线功率;有功设定小于应发的85% 并且
-出线功率大于有功设定94%;有功设定小于应发的70% 并且 出线功率大于有功设定80% 并且 当前场站限电台数大于等于3--限停 待机 维护-- 有故障--故障 无故障--计划检修 故障--小于?(3)分钟故障忽略
-是否受累--全站故障或者离线 故障 离线-- 是否受累--全站故障或者离线 故障
-
-青山华创风机在停机的状态下应该算故障损失
-
-
+### 日电量计算
 
 

+ 3 - 3
electricity/wind/src/main/java/com/gyee/gaia/electricity/wind/init/CacheContext.java

@@ -30,8 +30,8 @@ public class CacheContext implements ApplicationRunner {
     private IEquipmentService equipmentService;
     @Resource
     private IPowerstationService powerstationService;
-    @Resource
-    private CalcEquipPowerGenDay calcEquipPowerGenDay;
+    //@Resource
+    //private CalcEquipPowerGenDay calcEquipPowerGenDay;
 
     public static Map<String, Map<Double, Double>> modelPowerMap;
     /**
@@ -81,6 +81,6 @@ public class CacheContext implements ApplicationRunner {
         projectEquipidMap = emCollect.stream().collect(Collectors.groupingBy(Equipment::getProjectId,Collectors.mapping(Equipment::getId,Collectors.toList())));
         lineEquipidMap = emCollect.stream().collect(Collectors.groupingBy(Equipment::getLineId,Collectors.mapping(Equipment::getId,Collectors.toList())));
 
-        calcEquipPowerGenDay.calcEquipPowerGenDay();
+        //calcEquipPowerGenDay.calcEquipPowerGenDay();
     }
 }

+ 25 - 6
electricity/wind/src/main/java/com/gyee/gaia/electricity/wind/job/CalcEquipPowerGenDay.java

@@ -2,6 +2,8 @@ package com.gyee.gaia.electricity.wind.job;
 
 import cn.hutool.core.date.DateTime;
 import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.util.StrUtil;
+import com.alibaba.fastjson.JSON;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.gyee.gaia.common.data.point.PointData;
 import com.gyee.gaia.common.data.point.TestingPoint;
@@ -14,6 +16,7 @@ import com.gyee.gaia.electricity.wind.entity.StateCause;
 import com.gyee.gaia.electricity.wind.init.CacheContext;
 import com.gyee.gaia.electricity.wind.iservice.IEquipPowerGenDayService;
 import com.gyee.gaia.electricity.wind.iservice.IStateCauseService;
+import com.xxl.job.core.context.XxlJobHelper;
 import com.xxl.job.core.handler.annotation.XxlJob;
 import org.springframework.stereotype.Component;
 
@@ -21,10 +24,7 @@ import javax.annotation.Resource;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
 import java.time.LocalDate;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.function.Function;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
@@ -55,17 +55,36 @@ public class CalcEquipPowerGenDay {
     @XxlJob("CalcEquipPowerGenDay")
     public void calcEquipPowerGenDay() {
 
+        String command = XxlJobHelper.getJobParam();
+        Map<String, String> map = new HashMap<>();
+        if (StrUtil.isNotBlank(command)) {
+            map = JSON.parseObject(command, Map.class);
+        }
+        String start = map.get("date");
+        DateTime date;
+        if (start == null) {
+            date = DateUtil.yesterday();
+        } else {
+            date = DateUtil.parse(start);
+        }
+
         //2,获取当前日期,当日开始时间
-        DateTime startDateTime = DateUtil.beginOfDay(DateUtil.yesterday());
-        DateTime endDateTime = DateUtil.endOfDay(DateUtil.yesterday());
+        DateTime startDateTime = DateUtil.beginOfDay(date);
+        DateTime endDateTime = DateUtil.endOfDay(date);
 
         calcGeneratingCapacity(startDateTime, endDateTime);
         calcTheoryGeneration(startDateTime, endDateTime);
         calcLossPower(startDateTime, endDateTime);
 
+        //删除旧数据
+        QueryWrapper<EquipPowerGenDay> epgdWrapper = new QueryWrapper<>();
+        epgdWrapper.eq("date", startDateTime.toLocalDateTime());
+        equipPowerGenDayService.remove(epgdWrapper);
+        //保存风机数据
         equipPowerGenDayService.saveBatch(sepgdMap.values());
 
         List<EquipPowerGenDay> clpsw = calcLineProjectStationWindpower(startDateTime.toLocalDateTime().toLocalDate());
+        //保存线路、期次、场站,风电数据
         equipPowerGenDayService.saveBatch(clpsw);
     }
 

+ 1 - 1
electricity/wind/src/main/resources/bootstrap.yaml

@@ -99,7 +99,7 @@ mybatis-plus:
     #配置JdbcTypeForNull, oracle数据库必须配置
     jdbc-type-for-null: 'null'
     callSettersOnNulls: true
-    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
+    #log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
 
 xxl:
   job:

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

@@ -60,13 +60,15 @@ public class DataFillJobHandler {
 
         List<RealtimeAverageTarget> realtimeAverageTargetList = new ArrayList<>();
         QueryWrapper<RealtimeAverageTarget> ratWrapper = new QueryWrapper<>();
-        ratWrapper.select("time", "station_id", "equipment_id").eq("uniform_code", "1FZPJZB")
+        ratWrapper.select("tbname", "time", "station_id", "equipment_id").eq("uniform_code", "1FZPJZB")
                 .between("time", startDate.getTime(), endDate.getTime());
         List<RealtimeAverageTarget> ratList = realtimeAverageTargetService.list(ratWrapper);
         //按风机分组
         Map<String, List<RealtimeAverageTarget>> ratslMap = ratList.stream().collect(Collectors.groupingBy(RealtimeAverageTarget::getEquipmentId));
         for (List<RealtimeAverageTarget> value : ratslMap.values()) {
             String equipmentId = value.get(0).getEquipmentId();
+            String tbname = value.get(0).getTbname();
+
             Map<String, List<PointData>> lpdsMap = new HashMap<>();
             CacheContext.equipUcMap.get(equipmentId).forEach((uc, point) -> {
                 List<PointData> rawByKey = adapterApi.getRawByKey(point, startDate.getTime(), endDate.getTime());
@@ -74,10 +76,11 @@ public class DataFillJobHandler {
             });
             int i = 0;
             for (DateTime minute = DateUtil.beginOfMinute(startDate); minute.isBefore(endDate); minute.offset(DateField.MINUTE, 1)) {
-                if (i>=value.size() || (minute.getTime() != value.get(i).getTime().getTime())) {
+                if (i >= value.size() || (minute.getTime() != value.get(i).getTime().getTime())) {
                     RealtimeAverageTarget rat = new RealtimeAverageTarget();
                     rat.setTime(new Timestamp(minute.getTime()));
-                    setRats(rat, equipmentId, minute.getTime(), minute.getTime() + 59999L,lpdsMap);
+                    rat.setTbname(tbname);
+                    setRats(rat, equipmentId, minute.getTime(), minute.getTime() + 59999L, lpdsMap);
                     realtimeAverageTargetList.add(rat);
                 } else {
                     i++;
@@ -113,15 +116,15 @@ public class DataFillJobHandler {
         double isdv = 0;
         double wddv = 0;
 
-        if (!wind_speeds.isEmpty())
+        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);
-        if (!active_powers.isEmpty())
+        if (active_powers != null && active_powers.size() > 0)
             apdv = active_powers.stream().filter(pd -> pd.getTs() >= time1 && pd.getTs() <= time2).mapToDouble(PointData::getDoubleValue).average().orElse(0);
-        if (!generator_speeds.isEmpty())
+        if (generator_speeds != null && generator_speeds.size() > 0)
             gsdv = generator_speeds.stream().filter(pd -> pd.getTs() >= time1 && pd.getTs() <= time2).mapToDouble(PointData::getDoubleValue).average().orElse(0);
-        if (!impeller_speeds.isEmpty())
+        if (impeller_speeds != null && impeller_speeds.size() > 0)
             isdv = impeller_speeds.stream().filter(pd -> pd.getTs() >= time1 && pd.getTs() <= time2).mapToDouble(PointData::getDoubleValue).average().orElse(0);
-        if (!wind_directions.isEmpty())
+        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);
 
         double speed = NumberUtil.round(wsdv, 2).doubleValue();

+ 1 - 1
realtime/wind/src/main/resources/bootstrap.yaml

@@ -96,7 +96,7 @@ mybatis-plus:
     #配置JdbcTypeForNull, oracle数据库必须配置
     jdbc-type-for-null: 'null'
     callSettersOnNulls: true
-    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
+#    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
 
 xxl:
   job:

+ 1 - 1
state/cause/src/main/java/com/gyee/gaia/cause/entity/StateCause.java

@@ -119,7 +119,7 @@ public class StateCause implements Serializable {
         this.startTime = startTime;
     }
 
-    public Date getEndTime() {
+    public Timestamp getEndTime() {
         return endTime;
     }
 

+ 1 - 0
state/cause/src/main/java/com/gyee/gaia/cause/init/CacheContext.java

@@ -144,5 +144,6 @@ public class CacheContext implements ApplicationRunner {
         ratWrapper.select("tbname", "equipment_id");
         List<StateCause> ratList = stateCauseService.list(ratWrapper);
         scEquipTbMap = ratList.stream().collect(Collectors.toMap(StateCause::getEquipmentId, StateCause::getTbname));
+
     }
 }

+ 12 - 9
state/cause/src/main/java/com/gyee/gaia/cause/job/CauseJobHandler.java

@@ -15,9 +15,7 @@ import org.springframework.core.annotation.Order;
 import org.springframework.stereotype.Component;
 
 import javax.annotation.Resource;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 
 import static com.xxl.job.core.biz.model.ReturnT.SUCCESS_CODE;
 
@@ -35,24 +33,29 @@ public class CauseJobHandler {
         //String command = XxlJobHelper.getJobParam();
         //Map<String, String> map = JSON.parseObject(command, Map.class);
 
-       run();
+        run();
         return new ReturnT(SUCCESS_CODE, "调度成功!");
     }
 
     public synchronized void run() {
         //获取最新更新时间
         QueryWrapper<StateCause> scWrapper = new QueryWrapper<>();
-        scWrapper.select("last_row(*)");
-        StateCause list = stateCauseService.getOne(scWrapper);
+        scWrapper.select("last_row(*)").groupBy("equipment_id");
+        List<StateCause> list = stateCauseService.list(scWrapper);
         Date max;
-        if(list==null){
+        if(list.isEmpty()){
             max = DateUtil.yesterday();
         }else {
-            max = list.getEndTime();
+            Optional<StateCause> sco = list.stream().min(Comparator.comparing(StateCause::getEndTime));
+            if(sco.isPresent()){
+                max = sco.get().getEndTime();
+            }else {
+                max = DateUtil.yesterday();
+            }
         }
 
         //CalculateService calculateService = new CalculateService();
-        calculateService.refresh(max.getTime(), System.currentTimeMillis());
+        calculateService. refresh(max.getTime(), System.currentTimeMillis());
         calculateService.calculate();
 
     }

+ 4 - 0
state/cause/src/main/java/com/gyee/gaia/cause/service/CalculateService.java

@@ -101,6 +101,7 @@ public class CalculateService {
                         stateCauseList.add(cause);
                     }
                 } else if (advanceState == 2) {
+                    if (ts - advanceTime < 30000) continue;
                     //计算限停
                     if (judgmentStop(thingId, advanceTime, ts)) {
                         StateCause cause = new StateCause(CacheContext.scEquipTbMap.get(thingId), stateMap.get(8.0),
@@ -112,6 +113,7 @@ public class CalculateService {
                         stateCauseList.add(cause);
                     }
                 } else if (advanceState == 6) {
+                    if (ts - advanceTime < 30000) continue;
                     if (hasFaultEvent(thingId, advanceTime, ts)) {
                         //故障
                         StateCause cause = new StateCause(CacheContext.scEquipTbMap.get(thingId), stateMap.get(5.0),
@@ -124,10 +126,12 @@ public class CalculateService {
                         stateCauseList.add(cause);
                     }
                 } else if (advanceState == 5) {
+                    if (ts - advanceTime < 30000) continue;
                     if (ts - advanceTime < appConfig.getLongTime().get("fault-min")) continue;
                     //计算受累、故障
                     calcBurdened(stateCauseList, thingId, advanceTime, ts, 5, doubleValue);
                 } else if (advanceState == 7) {
+                    if (ts - advanceTime < 30000) continue;
                     //计算受累、故障、计划检修
                     calcBurdened(stateCauseList, thingId, advanceTime, ts, 7, doubleValue);
                 } else if (advanceState == 0) {

BIN
资源文件/日电量计算说明.xlsx