|
@@ -0,0 +1,255 @@
|
|
|
+package com.gyee.regionrealtime.service;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.gyee.common.contant.Contant;
|
|
|
+import com.gyee.common.model.PointData;
|
|
|
+import com.gyee.common.model.algorithm.PointVo;
|
|
|
+
|
|
|
+import com.gyee.common.util.CommonUtils;
|
|
|
+import com.gyee.common.util.DateUtils;
|
|
|
+import com.gyee.common.util.DoubleUtils;
|
|
|
+import com.gyee.common.util.algorithm.LineBuild;
|
|
|
+
|
|
|
+import com.gyee.regionrealtime.init.CacheContext;
|
|
|
+import com.gyee.regionrealtime.model.auto.*;
|
|
|
+import com.gyee.regionrealtime.service.auto.IWindturbinepowerService;
|
|
|
+import com.gyee.regionrealtime.util.realtimesource.IEdosUtil;
|
|
|
+import com.gyee.regionrealtime.util.redis.RedisService;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.*;
|
|
|
+import java.util.concurrent.atomic.AtomicReference;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @ClassName : TheorypowerService
|
|
|
+ * @Author : xieshengjie
|
|
|
+ * @Date: 2022/4/26 10:37
|
|
|
+ * @Description : 理论功率,保证功率
|
|
|
+ */
|
|
|
+@Service
|
|
|
+@Slf4j
|
|
|
+public class TheorypowerService {
|
|
|
+ @Resource
|
|
|
+ private IEdosUtil edosUtil;
|
|
|
+ @Resource
|
|
|
+ private RedisService redisService;
|
|
|
+ @Resource
|
|
|
+ private IWindturbinepowerService windturbinepowerService;
|
|
|
+ private List<Windpowerstation> wpls;
|
|
|
+ private Map<String, List<Project>> wppromap;
|
|
|
+ private Map<String, List<Line>> prolinemap;
|
|
|
+ private Map<String, List<Windturbine>> linewtmap;
|
|
|
+ private Date currentDate;
|
|
|
+ private Map<String, Map<String, Windpowerstationpointnew>> wppointmap;
|
|
|
+ private Map<String, Map<String, Windpowerstationpointnew>> linepointmap;
|
|
|
+ private Map<String, Map<String, Windpowerstationpointnew>> propointmap;
|
|
|
+ private Map<String, Map<String, Windturbinetestingpointnew>> wtpAimap;
|
|
|
+
|
|
|
+ private void init(){
|
|
|
+ wpls = CacheContext.wpls;
|
|
|
+ wppromap = CacheContext.wppromap;
|
|
|
+ prolinemap = CacheContext.prolinemap;
|
|
|
+ linewtmap = CacheContext.linewtmap;
|
|
|
+ wppointmap = CacheContext.wppointmap;
|
|
|
+ linepointmap = CacheContext.linepointmap;
|
|
|
+ propointmap = CacheContext.propointmap;
|
|
|
+ wtpAimap = CacheContext.wtpAimap;
|
|
|
+ currentDate = DateUtils.getCurrentDate();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 理论功率,保证功率
|
|
|
+ */
|
|
|
+ public void theropower() throws Exception {
|
|
|
+ long begin = System.currentTimeMillis();
|
|
|
+ init();
|
|
|
+ Map<String, Map<Double, Double>> zbzglMap = CacheContext.zbzglMap;
|
|
|
+ Map<String, Map<Double, Double>> zzsglMap = CacheContext.zzsglMap;
|
|
|
+ List<PointData> resultList = new ArrayList<>();
|
|
|
+ wpls.stream().forEach(wp->{
|
|
|
+ Map<String, Windpowerstationpointnew> wppointnewMap = wppointmap.get(wp.getId());
|
|
|
+ Windpowerstationpointnew wpbzglpoint = wppointnewMap.get(Contant.ZBZGL);
|
|
|
+ Windpowerstationpointnew wpzsglpoint = wppointnewMap.get(Contant.ZZSGL);
|
|
|
+ AtomicReference<Double> wpbzgl = new AtomicReference<>(0.0);
|
|
|
+ AtomicReference<Double> wpzsgl = new AtomicReference<>(0.0);
|
|
|
+ wppromap.get(wp.getId()).stream().forEach(project -> {
|
|
|
+ Map<String, Windpowerstationpointnew> projectpointnewMap = propointmap.get(project.getId());
|
|
|
+ Windpowerstationpointnew projectbzglpoint = projectpointnewMap.get(Contant.ZBZGL);
|
|
|
+ Windpowerstationpointnew projectzsglpoint = projectpointnewMap.get(Contant.ZZSGL);
|
|
|
+ AtomicReference<Double> projectbzgl = new AtomicReference<>(0.0);
|
|
|
+ AtomicReference<Double> projectzsgl = new AtomicReference<>(0.0);
|
|
|
+ prolinemap.get(project.getId()).stream().forEach(line -> {
|
|
|
+ AtomicReference<Double> linebzgl = new AtomicReference<>(0.0);
|
|
|
+ AtomicReference<Double> linezsgl = new AtomicReference<>(0.0);
|
|
|
+ Map<String, Windpowerstationpointnew> linepointnewMap = linepointmap.get(line.getId());
|
|
|
+ Windpowerstationpointnew linebzglpoint = linepointnewMap.get(Contant.ZBZGL);
|
|
|
+ Windpowerstationpointnew linezsglpoint = linepointnewMap.get(Contant.ZZSGL);
|
|
|
+ linewtmap.get(line.getId()).stream().forEach(wt->{
|
|
|
+// String zzsglString = redisService.get("ZZSGL");
|
|
|
+// Map<String,Map<Double, Double>> zszglMap = JSONObject.parseObject(zzsglString, new TypeReference<Map<String,Map<Double,Double>>>() {
|
|
|
+// });
|
|
|
+ Map<Double, Double> zsglMap = zzsglMap.get(wt.getId());
|
|
|
+ Map<String, Windturbinetestingpointnew> windturbinetestingpointnewMap = wtpAimap.get(wt.getId());
|
|
|
+ Windturbinetestingpointnew speedPointnew = windturbinetestingpointnewMap.get(Contant.AI022);
|
|
|
+ Windturbinetestingpointnew ztmxPointnew = windturbinetestingpointnewMap.get(Contant.FJ5T);
|
|
|
+ Windturbinetestingpointnew wtzsgl = windturbinetestingpointnewMap.get(Contant.ZSGL);
|
|
|
+ Windturbinetestingpointnew wtbzgl = windturbinetestingpointnewMap.get(Contant.BZGL);
|
|
|
+ Double zzsgl = 0.0;
|
|
|
+ Double zbzgl = 0.0;
|
|
|
+ try {
|
|
|
+ Double wtztmx = DoubleUtils.keepPrecision(edosUtil.getRealData(ztmxPointnew).getPointValueInDouble(),2);
|
|
|
+ Double wtspeed = DoubleUtils.keepPrecision(edosUtil.getRealData(speedPointnew).getPointValueInDouble(),2);
|
|
|
+ if (wtztmx==2 || wtztmx==4 || wtztmx==0 || wtztmx==3){
|
|
|
+ zbzgl = 0.0;
|
|
|
+ zzsgl = 0.0;
|
|
|
+ }else {
|
|
|
+ if (zbzglMap.containsKey(wt.getModelid())){
|
|
|
+ Map<Double, Double> doubleDoubleMap = zbzglMap.get(wt.getModelid());
|
|
|
+ if(doubleDoubleMap.containsKey(wtspeed)){
|
|
|
+ zbzgl = doubleDoubleMap.get(wtspeed);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (zsglMap!=null){
|
|
|
+ if (zsglMap.containsKey(wtspeed)){
|
|
|
+ zzsgl = zsglMap.get(wtspeed);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ Double finalZbzgl = zbzgl;
|
|
|
+ linebzgl.updateAndGet(v -> v + finalZbzgl);
|
|
|
+ Double finalZzsgl = zzsgl;
|
|
|
+ linezsgl.updateAndGet(v -> v + finalZzsgl);
|
|
|
+ PointData wtbzglpoint = createPointData(wtbzgl, zbzgl);
|
|
|
+ resultList.add(wtbzglpoint);
|
|
|
+ PointData wtzsglpoint = createPointData(wtzsgl, zzsgl);
|
|
|
+ resultList.add(wtzsglpoint);
|
|
|
+ });
|
|
|
+ PointData linebzglpointdata = createWpPointData(linebzglpoint, linebzgl.get());
|
|
|
+ resultList.add(linebzglpointdata);
|
|
|
+ PointData linezsglpointdata = createWpPointData(linezsglpoint, linezsgl.get());
|
|
|
+ resultList.add(linezsglpointdata);
|
|
|
+ Double finallineZbzgl = linebzgl.get();
|
|
|
+ projectbzgl.updateAndGet(v -> v + finallineZbzgl);
|
|
|
+ Double finallineZzsgl = linezsgl.get();
|
|
|
+ projectzsgl.updateAndGet(v -> v + finallineZzsgl);
|
|
|
+ });
|
|
|
+ PointData projectbzglpointdata = createWpPointData(projectbzglpoint, projectbzgl.get());
|
|
|
+ resultList.add(projectbzglpointdata);
|
|
|
+ PointData projectzsglpointdata = createWpPointData(projectzsglpoint, projectzsgl.get());
|
|
|
+ resultList.add(projectzsglpointdata);
|
|
|
+ Double finalprojectZbzgl = projectbzgl.get();
|
|
|
+ wpbzgl.updateAndGet(v -> v + finalprojectZbzgl);
|
|
|
+ Double finalprojectZzsgl = projectzsgl.get();
|
|
|
+ wpzsgl.updateAndGet(v -> v + finalprojectZzsgl);
|
|
|
+ });
|
|
|
+ PointData wpbzglpointdata = createWpPointData(wpbzglpoint, wpbzgl.get());
|
|
|
+ resultList.add(wpbzglpointdata);
|
|
|
+ PointData wpzsglpointdata = createWpPointData(wpzsglpoint, wpzsgl.get());
|
|
|
+ resultList.add(wpzsglpointdata);
|
|
|
+ });
|
|
|
+ edosUtil.sendMultiPoint(resultList);
|
|
|
+ long end = System.currentTimeMillis();
|
|
|
+ log.info("用时:"+(end-begin));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 拟合功率曲线,存储到redis
|
|
|
+ */
|
|
|
+ public void fittingPower(){
|
|
|
+ init();
|
|
|
+ List<Windturbinepower> resultList = new ArrayList<>();
|
|
|
+ List<Windturbine> wtls = CacheContext.wtls;
|
|
|
+ Date date = new Date();
|
|
|
+ Calendar cal = Calendar.getInstance();
|
|
|
+ cal.setTime(date);
|
|
|
+ cal.add(Calendar.MONTH, -1);
|
|
|
+ Date begin = cal.getTime();
|
|
|
+
|
|
|
+ wtls.stream().forEach(wt->{
|
|
|
+ QueryWrapper<Windturbinepower> deleteqw = new QueryWrapper<>();
|
|
|
+ deleteqw.eq("windturbineid",wt.getId());
|
|
|
+ windturbinepowerService.remove(deleteqw);
|
|
|
+
|
|
|
+ Map<String, Windturbinetestingpointnew> windturbinetestingpointnewMap = wtpAimap.get(wt.getId());
|
|
|
+ Windturbinetestingpointnew speedPoint = windturbinetestingpointnewMap.get(Contant.AI022);
|
|
|
+ Windturbinetestingpointnew powerPoint = windturbinetestingpointnewMap.get(Contant.AI130);
|
|
|
+ Windturbinetestingpointnew fjztPoint = windturbinetestingpointnewMap.get(Contant.FJ5T);
|
|
|
+ List<PointVo> pointVoList = new ArrayList<>();
|
|
|
+ List<PointVo> tempList = new ArrayList<>();
|
|
|
+ try {
|
|
|
+ List<PointData> speedpoints = edosUtil.getHistoryDatasSnap(speedPoint, begin.getTime()/1000 , date.getTime()/1000 , null, 3600l);
|
|
|
+ List<PointData> powerpoints = edosUtil.getHistoryDatasSnap(powerPoint, begin.getTime()/1000 , date.getTime()/1000 , null, 3600l);
|
|
|
+ List<PointData> fjztpoints = edosUtil.getHistoryDatasSnap(fjztPoint, begin.getTime()/1000 , date.getTime()/1000 , null, 3600l);
|
|
|
+ for (int x = 0;x<speedpoints.size();x++){
|
|
|
+ if (fjztpoints.get(x).getPointValueInDouble()==1){
|
|
|
+ PointVo vo = new PointVo();
|
|
|
+ vo.setX(speedpoints.get(x).getPointValueInDouble());
|
|
|
+ vo.setY(powerpoints.get(x).getPointValueInDouble());
|
|
|
+ tempList.add(vo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<PointVo> collect = tempList.stream().filter(i -> i.getY() >= 0 && i.getY() <= (CacheContext.modelpower.get(wt.getId())*1.5) && i.getX()>=0 && i.getX()<=25).collect(Collectors.toList());
|
|
|
+ Collections.sort(collect, Comparator.comparing(PointVo::getY));
|
|
|
+ double[] speeds = collect.stream().map(i -> i.getX()).mapToDouble(Double::doubleValue).toArray();
|
|
|
+ double[] powers = collect.stream().map(i -> i.getY()).mapToDouble(Double::doubleValue).toArray();
|
|
|
+ pointVoList = LineBuild.buildLine(speeds, powers, speeds.length, 20, 0.01);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ pointVoList.stream().forEach(pointVo -> {
|
|
|
+ Windturbinepower windturbinepower = new Windturbinepower();
|
|
|
+ windturbinepower.setId(CommonUtils.getUUID());
|
|
|
+ windturbinepower.setWindturbineid(wt.getId());
|
|
|
+ windturbinepower.setWindpowerstationid(wt.getWindpowerstationid());
|
|
|
+ windturbinepower.setSpeed(pointVo.getX());
|
|
|
+ windturbinepower.setTheorypower(pointVo.getY());
|
|
|
+ resultList.add(windturbinepower);
|
|
|
+ });
|
|
|
+ });
|
|
|
+ windturbinepowerService.saveBatch(resultList);
|
|
|
+ Map<String,Map<Double,Double>> zzsglMap = new HashMap<>();
|
|
|
+ wtls.stream().forEach(wt->{
|
|
|
+ List<Windturbinepower> windturbinepowers = resultList.stream().filter(p -> p.getWindturbineid().equals(wt.getId())).collect(Collectors.toList());
|
|
|
+ Map<Double,Double> doubleMap = new HashMap<>();
|
|
|
+ windturbinepowers.stream().forEach(w->{
|
|
|
+ doubleMap.put(w.getSpeed(),w.getTheorypower());
|
|
|
+ });
|
|
|
+ zzsglMap.put(wt.getId(),doubleMap);
|
|
|
+ });
|
|
|
+ CacheContext.zzsglMap = zzsglMap;
|
|
|
+ redisService.set("ZZSGL", JSONObject.toJSONString(zzsglMap));
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private PointData createPointData(Windturbinetestingpointnew fjfdl, Double rfdl) {
|
|
|
+ PointData pointData = new PointData();
|
|
|
+ pointData.setEdnaId(fjfdl.getCode());
|
|
|
+ pointData.setPointName(fjfdl.getName());
|
|
|
+ pointData.setPointTime(currentDate.getTime());
|
|
|
+ pointData.setPointValueInDouble(rfdl);
|
|
|
+ pointData.setPointValue(String.valueOf(rfdl));
|
|
|
+ return pointData;
|
|
|
+ }
|
|
|
+
|
|
|
+ private PointData createWpPointData(Windpowerstationpointnew linepointnew, double linespeed) {
|
|
|
+ PointData pointData = new PointData();
|
|
|
+ pointData.setEdnaId(linepointnew.getCode());
|
|
|
+ pointData.setPointTime(currentDate.getTime());
|
|
|
+ pointData.setPointName(linepointnew.getName());
|
|
|
+ pointData.setPointValue(String.valueOf(linespeed));
|
|
|
+ pointData.setPointValueInDouble(linespeed);
|
|
|
+ return pointData;
|
|
|
+ }
|
|
|
+}
|