Bläddra i källkod

光伏功率拟合

wangb@gyee-china.com 1 år sedan
förälder
incheckning
d41ddedbff

+ 19 - 0
power-fitting-JN/src/main/java/com.gyee.power.fitting/common/alg/DBSCANPointALG.java

@@ -1,5 +1,6 @@
 package com.gyee.power.fitting.common.alg;
 
+import com.gyee.power.fitting.model.custom.PhotovoltaicInfo;
 import com.gyee.power.fitting.model.custom.PowerPointData;
 
 import java.util.ArrayList;
@@ -36,4 +37,22 @@ public class DBSCANPointALG {
         return map;
     }
 
+    public static  Map<String, List<PhotovoltaicInfo>> dbgfscan(List<PhotovoltaicInfo> points, double param){
+        Map<String, List<PhotovoltaicInfo>> map = new HashMap<>();
+
+        for (PhotovoltaicInfo item : points){
+            double x = item.getS() * param;
+            double y = item.getActualP() / param;
+
+            String key = Math.round(x) +  String.valueOf(Math.round(y));
+
+            if (!map.containsKey(key)){
+                map.put(key, new ArrayList<>());
+            }
+            map.get(key).add(item);
+        }
+
+        return map;
+    }
+
 }

+ 20 - 3
power-fitting-JN/src/main/java/com.gyee.power.fitting/controller/gf/NewPhotovoltaicController.java

@@ -13,6 +13,7 @@ import com.gyee.power.fitting.model.custom.PhotovoltaicInfo;
 import com.gyee.power.fitting.model.custom.TableTitle;
 import com.gyee.power.fitting.service.ProBasicEquipmentService;
 import com.gyee.power.fitting.service.impl.NewIvPvCurveFittingService;
+import com.gyee.power.fitting.service.impl.ScatterpointService;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.web.bind.annotation.*;
 
@@ -33,6 +34,9 @@ public class NewPhotovoltaicController {
     @Resource
     private ProBasicEquipmentService equipmentService;
 
+    @Resource
+    private ScatterpointService scatterpointService;
+
     @GetMapping("/filelist")
     private JSONObject getFileList(
             @RequestParam(value = "station", required = true) String station,
@@ -43,7 +47,7 @@ public class NewPhotovoltaicController {
         List<String> fileList = curveFittingService.getFileList(station, inverters, startdate,interval, enddate, false);
         if (fileList == null) {
             try {
-                curveFittingService.getDatas2File(station, startdate, enddate,interval);
+                curveFittingService.getDatas2File(station,startdate, enddate,interval);
                 curveFittingService.standardPointCalculate2();
             } catch (Exception e) {
                 return JsonResult.error(ResultCode.ERROR_FILE_NO);
@@ -164,6 +168,19 @@ public class NewPhotovoltaicController {
         return JsonResult.successData(ResultCode.SUCCESS, list);
     }
 
+    @GetMapping("/curve")
+    public JSONObject dataFittingCurve(@RequestParam("station") String station,
+                                       @RequestParam("inverters") List<String> inverters,
+                                       @RequestParam("startdate") long startdate,
+                                       @RequestParam("enddate") long enddate,
+                                       @RequestParam("interval") int interval,
+                                       @RequestParam("maxs") int maxs,
+                                       @RequestParam("mins") int mins,
+                                       @RequestParam("maxpower") int maxpower,
+                                       @RequestParam("minpower") int minpower){
+        Map<String, Object> result = scatterpointService.dataFittingCurve(station,inverters, startdate, enddate, interval,maxs,mins,maxpower,minpower);
+        return JsonResult.successData(ResultCode.SUCCESS, result);
+    }
     //文件删除
     @DeleteMapping("/delete/files")
     private JSONObject deleteFiles(@RequestBody JSONObject filename) {
@@ -206,7 +223,7 @@ public class NewPhotovoltaicController {
             @RequestParam(value = "enddate", required = true) long enddate) {
 
        int interval = 300;
-        Map<String, List<PhotovoltaicInfo>> datasInfos = curveFittingService.getDatas2File1(station, startdate, enddate, interval);
+        Map<String, List<PhotovoltaicInfo>> datasInfos = curveFittingService.getDatas2File1(station, inverters,startdate, enddate, interval);
         List<PhotovoltaicInfo> bzdList = curveFittingService.standardPointCalculate1(datasInfos);
 
         Map<String, List<PhotovoltaicInfo>> infos = curveFittingService.calculatAnalysis1(bzdList, datasInfos);
@@ -241,7 +258,7 @@ public class NewPhotovoltaicController {
                                         @RequestParam("maxpower") int maxpower,
                                         @RequestParam("minpower") int minpower) {
 
-        Map<String, List<PhotovoltaicInfo>> datasInfos = curveFittingService.getDatas2File1(station, startdate, enddate, interval);
+        Map<String, List<PhotovoltaicInfo>> datasInfos = curveFittingService.getDatas2File1(station,inverters, startdate, enddate, interval);
 
         List<PhotovoltaicInfo> infos = new ArrayList<>();
         //单台拟合

+ 3 - 0
power-fitting-JN/src/main/java/com.gyee.power.fitting/model/custom/PhotovoltaicInfo.java

@@ -55,6 +55,9 @@ public class PhotovoltaicInfo {
     @JsonProperty("cV")
     private double cV;
 
+    //是否过滤  0:不过滤 1:过滤
+    @Desc(des = "筛选", remark = "0")
+    private int filter = 0;
     /*public double getP() {
         if (I != 0 && V != 0) {
             return I * V;

+ 161 - 3
power-fitting-JN/src/main/java/com.gyee.power.fitting/service/impl/NewIvPvCurveFittingService.java

@@ -80,14 +80,14 @@ public class NewIvPvCurveFittingService {
         }
     }
 
-    public Map<String, List<PhotovoltaicInfo>> getDatas2File1(String stationid, long start, long end, int interval) {
+    public Map<String, List<PhotovoltaicInfo>> getDatas2File1(String stationid,List<String> inverters, long start, long end, int interval) {
 
         int daym = 24 * 60 * 60 * 1000;
         Map<String, List<PhotovoltaicInfo>> wj = new HashMap<>();
         //按天
         for (long i = start; i < end; i += daym) {
 
-            List<List<PhotovoltaicInfo>> datas = getDatas(stationid, i, i + daym, interval);
+            List<List<PhotovoltaicInfo>> datas = getDatasnotfile(stationid,inverters, i, i + daym, interval);
             for (List<PhotovoltaicInfo> data : datas) {
                 List<PhotovoltaicInfo> infos = wj.get(data.get(0).getInverter());
                 if (infos == null) {
@@ -629,6 +629,120 @@ public class NewIvPvCurveFittingService {
         return infosLit;
     }
 
+    /**
+     * 获取数据
+     *
+     * @return 逆变器,列表
+     */
+    public List<List<PhotovoltaicInfo>> getDatasnotfile(String stationid,List<String> inverters, long start, long end, int interval) {
+        //间隔
+        interval = 5 * 60; //5分钟-300
+
+        //获得测点
+        Map<String, String> zglpoints = getPoints1(stationid,inverters, "zgl");
+        Map<String, String> llglpoints = getPoints1(stationid,inverters, "llgl");
+        Map<String, String> adypoints = getPoints1(stationid,inverters, "ady");
+        Map<String, String> bdypoints = getPoints1(stationid, inverters,"bdy");
+        Map<String, String> cdypoints = getPoints1(stationid, inverters,"cdy");
+        Map<String, String> adlpoints = getPoints1(stationid,inverters, "adl");
+        Map<String, String> bdlpoints = getPoints1(stationid, inverters,"bdl");
+        Map<String, String> cdlpoints = getPoints1(stationid, inverters,"cdl");
+
+        List<ProBasicWeatherStation> weatherStations = weatherStationService.getBaseMapper().selectList(null);
+        List<ProBasicWeatherStation> collect = weatherStations.stream().filter(c -> stationid.equals(c.getWindpowerstationId())).collect(Collectors.toList());
+
+        String station = collect.get(0).getId();
+
+        ProBasicPowerstationPoint zfsPoint = InitialRunner.newzfsMap.get(stationid);
+        ProBasicPowerstationPoint zjwdPoint = InitialRunner.newzjwdMap.get(station);
+
+        //总辐射
+        //        List<TsDoubleData> zfsDatas = adpClient.getHistorySnap(zfsPoint.getNemCode(), start, end, interval);
+
+        List<TsDoubleData> zfsDatas = remoteService.adapterfd().getHistorySnap(zfsPoint.getNemCode(), start, end, interval);
+
+        //组件温度
+        //        List<TsDoubleData> zjwdDatas = adpClient.getHistorySnap(zjwdPoint.getNemCode(), start, end, interval);
+
+        List<TsDoubleData> zjwdDatas = remoteService.adaptergf().getHistorySnap(zjwdPoint.getNemCode(), start, end, interval);
+
+        List<List<PhotovoltaicInfo>> infosLit = new ArrayList<>();
+        //按逆变器
+        for (String wtid : zglpoints.keySet()) {
+
+            //总功率
+            //            List<TsDoubleData> zglDatas = adpClient.getHistorySnap(zglpoints.get(wtid), start, end, interval);
+            List<TsDoubleData> zglDatas = remoteService.adaptergf().getHistorySnap(zglpoints.get(wtid), start, end, interval);
+            List<TsDoubleData> llglDatas = remoteService.adapterfd().getHistorySnap(llglpoints.get(wtid), start, end, interval);
+
+            //电网A相电压
+            //            List<TsDoubleData> adyDatas = adpClient.getHistorySnap(adypoints.get(wtid), start, end, interval);
+            List<TsDoubleData> adyDatas = remoteService.adaptergf().getHistorySnap(adypoints.get(wtid), start, end, interval);
+            //电网A相电流
+            //            List<TsDoubleData> adlDatas = adpClient.getHistorySnap(adlpoints.get(wtid), start, end, interval);
+            List<TsDoubleData> adlDatas = remoteService.adaptergf().getHistorySnap(adlpoints.get(wtid), start, end, interval);
+
+            List<PhotovoltaicInfo> infos = new ArrayList<>();
+
+            List<TsDoubleData> bdyDatas = null, cdyDatas = null, bdlDatas = null, cdlDatas = null;
+            if ("HZJ_GDC".equals(stationid) || "AK_GDC".equals(stationid)) {
+                //电网B相电压
+                bdyDatas = adpClient.getHistorySnap(bdypoints.get(wtid), start, end, interval);
+                //电网C相电压
+                cdyDatas = adpClient.getHistorySnap(cdypoints.get(wtid), start, end, interval);
+                //电网B相电流
+                bdlDatas = adpClient.getHistorySnap(bdlpoints.get(wtid), start, end, interval);
+                //电网C相电流
+                cdlDatas = adpClient.getHistorySnap(cdlpoints.get(wtid), start, end, interval);
+            }
+
+            for (int j = 0; j < zfsDatas.size(); j++) {
+                PhotovoltaicInfo info = new PhotovoltaicInfo();
+                info.setStation(stationid);
+                info.setInverter(wtid);
+                long ts = zfsDatas.get(j).getTs();
+                info.setTime(ts);
+                info.setDatetime(DateUtils.date2StringL(new Date(ts)));
+
+                info.setT(double3Decimal(zjwdDatas.get(j).getDoubleValue()));
+                info.setS(double3Decimal(zfsDatas.get(j).getDoubleValue(), false));
+                if ("HZJ_GDC".equals(stationid) || "AK_GDC".equals(stationid)) {
+                    info.setAI(double3Decimal(adlDatas.get(j).getDoubleValue(), false));
+                    info.setBI(double3Decimal(bdlDatas.get(j).getDoubleValue(), false));
+                    info.setCI(double3Decimal(cdlDatas.get(j).getDoubleValue(), false));
+                    info.setAV(double3Decimal(adyDatas.get(j).getDoubleValue(), true));
+                    info.setBV(double3Decimal(bdyDatas.get(j).getDoubleValue(), true));
+                    info.setCV(double3Decimal(cdyDatas.get(j).getDoubleValue(), true));
+                } else {
+                    if (adlDatas.size() >= 1) {
+                        info.setI(double3Decimal(adlDatas.get(j).getDoubleValue(), false));
+                    } else {
+                        info.setI(0);
+                    }
+                    if (adyDatas.size() >= 1) {
+                        info.setV(double3Decimal(adyDatas.get(j).getDoubleValue(), true));
+                    } else {
+                        info.setV(0);
+                    }
+                }
+                if (zglDatas.size() >= 1) {
+                    info.setActualP(double3Decimal(zglDatas.get(j).getDoubleValue(), false));
+                } else {
+                    info.setActualP(0);
+                }
+                if (llglDatas.size() >= 1) {
+                    info.setIdeaP(double3Decimal(llglDatas.get(j).getDoubleValue(), false));
+                } else {
+                    info.setIdeaP(0);
+                }
+                infos.add(info);
+            }
+            infosLit.add(infos);
+        }
+
+        return infosLit;
+    }
+
     private double double3Decimal(double d) {
         BigDecimal bd = new BigDecimal(d);
         return bd.setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue();
@@ -686,6 +800,48 @@ public class NewIvPvCurveFittingService {
         return new HashMap<>();
     }
 
+    private Map<String, String> getPoints1(String stationid, List<String> inverters, String key) {
+
+        for (String wt : inverters) {
+            switch (key) {
+                case "zgl":
+                    //总功率
+                    return InitialRunner.newzglMap.get(stationid).stream().filter(c -> !c.getNemCode().equals("INTIAL") && c.getWindturbineId().equals(wt)).collect(Collectors.toMap(ProBasicEquipmentPoint::getWindturbineId, ProBasicEquipmentPoint::getNemCode));
+                case "llgl":
+                    //总功率
+                    return InitialRunner.newllglMap.get(stationid).stream().filter(c -> !c.getNemCode().equals("INTIAL")&& c.getWindturbineId().equals(wt)).collect(Collectors.toMap(ProBasicEquipmentPoint::getWindturbineId, ProBasicEquipmentPoint::getNemCode));
+
+                case "ady":
+                    List<ProBasicEquipmentPoint> adyPoints = null;
+                    if ("HZJ_GDC".equals(stationid)) {
+                        //电网A相电压
+                        adyPoints = proBasicEquipmentPointService.getPoints(stationid, null, "AIG005");
+                    } else {
+                        //电网A相电压
+                        adyPoints = proBasicEquipmentPointService.getPoints(stationid, null, "AIG005");
+                    }
+
+                    return adyPoints.stream().filter(c -> !c.getNemCode().equals("INTIAL")&& c.getWindturbineId().equals(wt)).collect(Collectors.toMap(ProBasicEquipmentPoint::getWindturbineId, ProBasicEquipmentPoint::getNemCode));
+                case "bdy":
+                    List<ProBasicEquipmentPoint> bdyPoints = proBasicEquipmentPointService.getPoints(stationid, null, "AIG008");
+                    return bdyPoints.stream().filter(c -> !c.getNemCode().equals("INTIAL")&& c.getWindturbineId().equals(wt)).collect(Collectors.toMap(ProBasicEquipmentPoint::getWindturbineId, ProBasicEquipmentPoint::getNemCode));
+                case "cdy":
+                    List<ProBasicEquipmentPoint> cdyPoints = proBasicEquipmentPointService.getPoints(stationid, null, "AIG011");
+                    return cdyPoints.stream().filter(c -> !c.getNemCode().equals("INTIAL")&& c.getWindturbineId().equals(wt)).collect(Collectors.toMap(ProBasicEquipmentPoint::getWindturbineId, ProBasicEquipmentPoint::getNemCode));
+                case "adl":
+                    List<ProBasicEquipmentPoint> adlPoints = proBasicEquipmentPointService.getPoints(stationid, null, "AIG004");
+                    return adlPoints.stream().filter(c -> !c.getNemCode().equals("INTIAL")&& c.getWindturbineId().equals(wt)).collect(Collectors.toMap(ProBasicEquipmentPoint::getWindturbineId, ProBasicEquipmentPoint::getNemCode));
+                case "bdl":
+                    List<ProBasicEquipmentPoint> bdlPoints = proBasicEquipmentPointService.getPoints(stationid, null, "AIG007");
+                    return bdlPoints.stream().filter(c -> !c.getNemCode().equals("INTIAL")&& c.getWindturbineId().equals(wt)).collect(Collectors.toMap(ProBasicEquipmentPoint::getWindturbineId, ProBasicEquipmentPoint::getNemCode));
+                case "cdl":
+                    List<ProBasicEquipmentPoint> cdlPoints = proBasicEquipmentPointService.getPoints(stationid, null, "AIG010");
+                    return cdlPoints.stream().filter(c -> !c.getNemCode().equals("INTIAL")&& c.getWindturbineId().equals(wt)).collect(Collectors.toMap(ProBasicEquipmentPoint::getWindturbineId, ProBasicEquipmentPoint::getNemCode));
+            }
+        }
+        return new HashMap<>();
+    }
+
     public int deleteFiles(List<String> fileList) {
         String fs = config.getFilePathPrepare() + "gf";
         List<PhotovoltaicInfo> infoList = new ArrayList<>();
@@ -748,7 +904,9 @@ public class NewIvPvCurveFittingService {
         if (!StringUtils.isEmpty(yk)) {
             String[] key = yk.split(",");
             for (String k : key) {
-                list.addAll(dataScangfService.getMapYY().get(k));
+                Map<String, List<PhotovoltaicInfo>> mapYY = dataScangfService.getMapYY();
+                List<PhotovoltaicInfo> photovoltaicInfos = mapYY.get(k);
+                list.addAll(photovoltaicInfos);
             }
         }
         if (!StringUtils.isEmpty(wk)) {

+ 143 - 0
power-fitting-JN/src/main/java/com.gyee.power.fitting/service/impl/ScatterpointService.java

@@ -0,0 +1,143 @@
+package com.gyee.power.fitting.service.impl;
+
+import com.gyee.power.fitting.common.alg.DBSCANPointALG;
+import com.gyee.power.fitting.common.result.JsonResult;
+import com.gyee.power.fitting.common.result.ResultCode;
+import com.gyee.power.fitting.common.spring.InitialRunner;
+import com.gyee.power.fitting.common.util.FileUtil;
+import com.gyee.power.fitting.model.ProBasicModelPower;
+import com.gyee.power.fitting.model.ProEconPowerFittingAnalySis;
+import com.gyee.power.fitting.model.custom.PhotovoltaicInfo;
+import com.gyee.power.fitting.model.custom.PointVo;
+import com.gyee.power.fitting.model.custom.PowerFittingData;
+import com.gyee.power.fitting.model.custom.PowerPointData;
+import com.gyee.power.fitting.service.custom.curve.DataScangfService;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.util.*;
+import java.util.stream.Collectors;
+
+
+@Service
+public class ScatterpointService {
+    @Resource
+    private NewIvPvCurveFittingService curveFittingService;
+
+    @Resource
+    private DataScangfService dataScangfService;
+    public Map<String, Object> dataFittingCurve(String stationid,List<String> inverters, long start, long end,int interval,int maxs,int mins,int maxpower,int minpower ){
+
+        Map<String, Object> map = new HashMap<>();
+//        ProEconPowerFittingAnalySis obj = proEconPowerFittingAnalySisService.selectItemById(id);
+        Map<String, List<PhotovoltaicInfo>> datasInfos = curveFittingService.getDatas2File1(stationid,inverters, start, end, interval);
+
+        List<PhotovoltaicInfo> infos = new ArrayList<>();
+        //单台拟合
+        if (inverters.size() == 1) {
+            infos = datasInfos.get(inverters.get(0));
+            //多台拟合
+        } else if (inverters.size() > 1) {
+            for (String inverter : inverters) {
+                infos.addAll(datasInfos.get(inverter));
+            }
+        } else {
+            return JsonResult.error(ResultCode.PARAM_NOT_COMPLETE);
+        }
+        //实际功率、风速、Cp值
+        List<Object> sjglList = new ArrayList<>();
+        List<Object> cpzList = new ArrayList<>();
+//        List<String> ls = FileUtil.readFile(obj.getPath(), true);
+//        for (int i = 1; i < datasInfos.size(); i++){
+//            PhotovoltaicInfo data = new PhotovoltaicInfo(ls.get(i).split(","));
+//            sjglList.add(new double[]{Double.valueOf(data.getS()), data.getActualP()});
+//            cpzList.add(new double[]{Double.valueOf(data.getS()), data.getActualP()});
+//        }
+//
+//        //保证功率
+//        List<ProBasicModelPower> modelPower = InitialRunner.modelPowerDetailNewMap.get(InitialRunner.wtNewMap.get(obj.getWindturbineId()).getModelId());
+//        List<Object> bzglList = modelPower.stream().sorted(Comparator.comparing(ProBasicModelPower::getSpeed)).map(m -> new double[]{m.getSpeed(), m.getEnsurePower()}).collect(Collectors.toList());
+//
+//        //散点
+//        String[] ids = obj.getProcessid().split(",");
+        List<PhotovoltaicInfo> yyd = new ArrayList<>(); //有用点
+        List<PhotovoltaicInfo> wyd = new ArrayList<>(); //无用点
+//        for (String pid : ids){
+//            ProEconPowerFittingAnalySis pf = proEconPowerFittingAnalySisService.selectItemById(pid);
+//            List<String> lp = FileUtil.readFile(pf.getPath(), true);
+//            for (int i = 1; i < lp.size(); i++){
+//                String[] split = lp.get(i).split(",");
+//                PhotovoltaicInfo pd = new PhotovoltaicInfo(split, true);
+//                if (pd.getS() < 0 || pd.getPower() < 0)
+//                    continue;
+//                pd.setInverter(pf.getWindturbineId());
+//                if (0 == pd.getFilter())
+//                    yyd.add(pd);   //没有过滤
+//                if (1 == pd.getFilter())
+//                    wyd.add(pd);   //已过滤
+//            }
+//        }
+
+//        yyd = infos.get(inverters.get(0));
+
+        yyd = infos.stream().filter(c -> c.getS() <= maxs && c.getS() >= mins && c.getActualP() <= maxpower && c.getActualP() >= minpower)
+                .collect(Collectors.toList());
+
+        wyd = infos.stream().filter(c -> !(c.getS() <= maxs && c.getS() >= mins && c.getActualP() <= maxpower && c.getActualP() >= minpower))
+                .collect(Collectors.toList());
+
+        List<double[]> yydnh = curveFittingService.oneFileFitting(yyd);
+
+        List<double[]> yy = new ArrayList<>();
+        for (PhotovoltaicInfo pi : yyd) {
+
+            double[] scatter = new double[3];
+
+            scatter[0] = pi.getS();
+            scatter[1] = pi.getActualP();
+            scatter[2] = pi.getT();
+
+            yy.add(scatter);
+        }
+
+        List<double[]> wy = new ArrayList<>();
+        for (PhotovoltaicInfo pi : wyd) {
+
+            double[] scatter = new double[3];
+
+            scatter[0] = pi.getS();
+            scatter[1] = pi.getActualP();
+            scatter[2] = pi.getT();
+
+            pi.setFilter(1);
+            wy.add(scatter);
+        }
+
+        Map<String, List<PhotovoltaicInfo>> dbgfscan = DBSCANPointALG.dbgfscan(yyd, 10);
+        dataScangfService.setMapYY(dbgfscan);
+        Map<String, List<PhotovoltaicInfo>> dbgfscan1 = DBSCANPointALG.dbgfscan(wyd, 10);
+        dataScangfService.setMapWY(dbgfscan1);
+
+        List<PointVo> listYY = new ArrayList<>();
+        List<PointVo> listWY = new ArrayList<>();
+
+        dataScangfService.getMapYY().forEach((k, v) -> {
+            // k: 前端画圈时的散点数据标记
+            listYY.add(new PointVo(v.get(0).getS(), v.get(0).getActualP(), v.get(0).getT(), k));
+        });
+        dataScangfService.getMapWY().forEach((k, v) -> {
+            // k: 前端画圈时的散点数据标记
+            listWY.add(new PointVo(v.get(0).getS(), v.get(0).getActualP(), v.get(0).getT(), k));
+        });
+
+//        map.put("sjgl", sjglList);    //实际功率
+//        map.put("llgl", bzglList);    //保证功率
+//        map.put("cpz", cpzList);      //Cp值
+//        map.put("obj", obj);     //对w象
+        map.put("yyd", listYY);  //有用散点
+        map.put("yydnh", yydnh);  //有用散点
+        map.put("wyd", listWY);  //无用散点
+
+        return map;
+    }
+}