|
@@ -0,0 +1,271 @@
|
|
|
+
|
|
|
+import com.alibaba.excel.EasyExcel;
|
|
|
+import com.alibaba.excel.context.AnalysisContext;
|
|
|
+import com.alibaba.excel.event.AnalysisEventListener;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.gyee.power.fitting.PowerBootApplication;
|
|
|
+import com.gyee.power.fitting.common.alg.PolynomialCurveFitting;
|
|
|
+import com.gyee.power.fitting.common.feign.IAdapterService;
|
|
|
+import com.gyee.power.fitting.common.util.DateUtils;
|
|
|
+import com.gyee.power.fitting.model.Photovoltaiccapacity;
|
|
|
+import com.gyee.power.fitting.model.Photovoltaiciv;
|
|
|
+import com.gyee.power.fitting.model.Windpowerstationtestingpoint2;
|
|
|
+import com.gyee.power.fitting.model.custom.TsDoubleData;
|
|
|
+import com.gyee.power.fitting.service.IPhotovoltaiccapacityService;
|
|
|
+import com.gyee.power.fitting.service.IPhotovoltaicivService;
|
|
|
+import com.gyee.power.fitting.service.IWindpowerstationtestingpoint2Service;
|
|
|
+import com.gyee.power.fitting.service.Windturbinetestingpointai2Service;
|
|
|
+import org.apache.commons.math3.fitting.WeightedObservedPoint;
|
|
|
+import org.apache.commons.math3.fitting.WeightedObservedPoints;
|
|
|
+import org.junit.jupiter.api.Test;
|
|
|
+import org.springframework.boot.test.context.SpringBootTest;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.io.File;
|
|
|
+import java.io.FileOutputStream;
|
|
|
+import java.io.PrintWriter;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 光伏经济运行
|
|
|
+ */
|
|
|
+@SpringBootTest(classes = PowerBootApplication.class,webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
|
|
+public class PhotovoltaicEconomicOperationTest {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private Windturbinetestingpointai2Service windturbinetestingpointai2Service;
|
|
|
+ @Resource
|
|
|
+ private IAdapterService adpClient;
|
|
|
+ @Resource
|
|
|
+ private IPhotovoltaicivService photovoltaicivService;
|
|
|
+ @Resource
|
|
|
+ private IWindpowerstationtestingpoint2Service windpowerstationtestingpoint2Service;
|
|
|
+ @Resource
|
|
|
+ private IPhotovoltaiccapacityService photovoltaiccapacityService;
|
|
|
+
|
|
|
+ @Test()
|
|
|
+ public void test() throws Exception {
|
|
|
+ PolynomialCurveFitting pncf = new PolynomialCurveFitting();
|
|
|
+ //HZJGGL.NX_GD_HZJG_YC_P1_L1_001_QXZ006
|
|
|
+ List<String> list = new ArrayList<>(); //初始化列表
|
|
|
+
|
|
|
+ EasyExcel.read("D:/工作簿2.xlsx") //文件路径
|
|
|
+ .sheet("Sheet1") //表单名
|
|
|
+ .registerReadListener(new AnalysisEventListener<Map<Integer,String>>() { //监听器,以行的形式读取Excel
|
|
|
+
|
|
|
+ //一行一行读取Excel,在这里处理读取到的数据
|
|
|
+ @Override
|
|
|
+ public void invoke(Map<Integer, String> integerStringMap, AnalysisContext analysisContext) {
|
|
|
+ // TODO Auto-generated method stub
|
|
|
+ list.add(integerStringMap.get(0)); //将读取到的每一行为一组存入列表中
|
|
|
+ }
|
|
|
+
|
|
|
+ //数据读取完毕后运行下面
|
|
|
+ @Override
|
|
|
+ public void doAfterAllAnalysed(AnalysisContext context) {
|
|
|
+ System.out.println("数据读取完毕");
|
|
|
+ }
|
|
|
+ }).headRowNumber(0).doRead();
|
|
|
+ /*QueryWrapper<Photovoltaiccapacity> wrap = new QueryWrapper<>();
|
|
|
+ wrap.eq("STATIONID", "HZJ_GDC");
|
|
|
+ List<Photovoltaiccapacity> list = photovoltaiccapacityService.list(wrap);*/
|
|
|
+ WeightedObservedPoints points = new WeightedObservedPoints();
|
|
|
+ //获取场站光照测点
|
|
|
+ Windpowerstationtestingpoint2 hzj_gdc = windpowerstationtestingpoint2Service.getStationIllumination("HZJ_GDC");
|
|
|
+ long start = DateUtils.string2DateL("2022-12-10 00:00:00").getTime();
|
|
|
+ long end = DateUtils.string2DateL("2022-12-10 23:59:59").getTime();
|
|
|
+ //获取场站光照值
|
|
|
+ List<TsDoubleData> rawValues = adpClient.getRawValuesByKey(hzj_gdc.getCode(), start, end);
|
|
|
+ rawValues=rawValues.stream().filter(rw->rw.getDoubleValue()!=0.0).collect(Collectors.toList());
|
|
|
+ List<TsDoubleData> rawValues2=rawValues.stream().sorted(Comparator.comparing(TsDoubleData::getDoubleValue)).collect(Collectors.toList());
|
|
|
+
|
|
|
+ long tsstart = rawValues.get(0).getTs();
|
|
|
+ long tsend = rawValues.get(rawValues.size() - 1).getTs() + 5*60*1000;
|
|
|
+
|
|
|
+ double[] index = {0.751897050683247, 0.0131420628997927};
|
|
|
+ pncf.printResultAll(rawValues2,index,2);
|
|
|
+ String s1 = pncf.printResultY(rawValues2, index);
|
|
|
+
|
|
|
+
|
|
|
+ List<TsDoubleData> WDvalues = adpClient.getValuesByKey("HZJGGL.NX_GD_HZJG_YC_P1_L1_001_QXZ006", tsstart, tsend, 5 * 60);
|
|
|
+
|
|
|
+ //获取光伏逆变器支路电流电压测点
|
|
|
+ QueryWrapper<Photovoltaiciv> wrapper = new QueryWrapper<>();
|
|
|
+ //wrapper.eq("electric", "电压").lt("rownum",19).orderByAsc("windturbineid");
|
|
|
+ wrapper.eq("electric", "电压");
|
|
|
+ //电压测点
|
|
|
+ List<Photovoltaiciv> DYlist = photovoltaicivService.list(wrapper);
|
|
|
+ wrapper.clear();
|
|
|
+ //wrapper.eq("electric", "电流").lt("rownum",19).orderByAsc("windturbineid");
|
|
|
+ wrapper.eq("electric", "电流");
|
|
|
+ //电流测点
|
|
|
+ List<Photovoltaiciv> DLlist = photovoltaicivService.list(wrapper);
|
|
|
+
|
|
|
+ DYlist=DYlist.stream().filter(dl->!list.contains(dl.getWindturbineid()+dl.getBranchnum())).collect(Collectors.toList());
|
|
|
+ DLlist=DLlist.stream().filter(dl->!list.contains(dl.getWindturbineid()+dl.getBranchnum())).collect(Collectors.toList());
|
|
|
+
|
|
|
+ //逆变器+支路号,时间,电压值
|
|
|
+ Map<String, Map<Long, Double>> DYMapMap = new HashMap<>();
|
|
|
+ //逆变器+支路号,时间,电流值
|
|
|
+ Map<String, Map<Long, Double>> DLMapMap = new HashMap<>();
|
|
|
+ //逆变器+支路号,光照强度,功率
|
|
|
+ Map<String, Map<Double, Double>> GLMapMap = new HashMap<>();
|
|
|
+ Map<String, WeightedObservedPoints> PointsMap = new HashMap<>();
|
|
|
+
|
|
|
+ for (Photovoltaiciv ptvtc : DYlist) {
|
|
|
+ //电压值
|
|
|
+ List<TsDoubleData> DYrawValues = adpClient.getValuesByKey(ptvtc.getId(), tsstart, tsend, 5*60);
|
|
|
+ Map<Long, Double> collect = DYrawValues.stream().collect(Collectors.toMap(TsDoubleData::getTs, TsDoubleData::getDoubleValue));
|
|
|
+ DYMapMap.put(ptvtc.getWindturbineid()+ptvtc.getBranchnum(), collect);
|
|
|
+ }
|
|
|
+
|
|
|
+ for (Photovoltaiciv ptvtc : DLlist) {
|
|
|
+ //电流值
|
|
|
+ List<TsDoubleData> DLrawValues = adpClient.getValuesByKey(ptvtc.getId(), tsstart, tsend, 5*60);
|
|
|
+ Map<Long, Double> collect = DLrawValues.stream().collect(Collectors.toMap(TsDoubleData::getTs, TsDoubleData::getDoubleValue));
|
|
|
+ DLMapMap.put(ptvtc.getWindturbineid()+ptvtc.getBranchnum(), collect);
|
|
|
+ }
|
|
|
+ for (Photovoltaiciv ptvtc : DYlist) {
|
|
|
+ //逆变器+支路号
|
|
|
+ String nbqzl = ptvtc.getWindturbineid() + ptvtc.getBranchnum();
|
|
|
+ Map<Double, Double> GLMap = new LinkedHashMap<>();
|
|
|
+ WeightedObservedPoints pointsOne = new WeightedObservedPoints();
|
|
|
+ for (TsDoubleData rv : rawValues2) {
|
|
|
+ double v = DYMapMap.get(nbqzl).get(rv.getTs()) * 0.001 * DLMapMap.get(nbqzl).get(rv.getTs());
|
|
|
+ /*if((rv.getDoubleValue()<318.0&&v>7.3)||(rv.getDoubleValue()<190.0&&v>4.3)){
|
|
|
+ System.out.println(nbqzl+","+DYMapMap.get(nbqzl).get(rv.getTs())+","+DLMapMap.get(nbqzl).get(rv.getTs())+","+rv.getTs());
|
|
|
+ }*/
|
|
|
+ GLMap.put(rv.getDoubleValue(), v);
|
|
|
+ points.add(rv.getDoubleValue(), v);
|
|
|
+ pointsOne.add(rv.getDoubleValue(), v);
|
|
|
+ }
|
|
|
+ PointsMap.put(nbqzl, pointsOne);
|
|
|
+ GLMapMap.put(nbqzl, GLMap);
|
|
|
+ }
|
|
|
+ /*for (WeightedObservedPoint point : points.toList()) {
|
|
|
+ System.out.print("[");
|
|
|
+ System.out.printf("%.2f", point.getX());
|
|
|
+ System.out.print(",");
|
|
|
+ System.out.printf("%.2f", point.getY());
|
|
|
+ System.out.println("],\n");
|
|
|
+ }*/
|
|
|
+
|
|
|
+ /*File files = new File("D:/光伏光照强度-功率.txt");
|
|
|
+
|
|
|
+ FileOutputStream fos = new FileOutputStream(files);
|
|
|
+ // 逐行写入
|
|
|
+ PrintWriter pw = new PrintWriter(fos);
|
|
|
+ for (WeightedObservedPoint point : points.toList()) {
|
|
|
+ String s = "[" + String.format("%.2f", point.getX()) + "," + String.format("%.2f", point.getY()) + "],";
|
|
|
+ pw.println(s);
|
|
|
+ }
|
|
|
+ pw.close();*/
|
|
|
+
|
|
|
+ File files = new File("D:/光伏光照强度-功率.txt");
|
|
|
+
|
|
|
+ FileOutputStream fos = new FileOutputStream(files);
|
|
|
+ // 逐行写入
|
|
|
+ PrintWriter pw = new PrintWriter(fos);
|
|
|
+ //文件写入光照强度
|
|
|
+ for (TsDoubleData rawValue : rawValues2) {
|
|
|
+ pw.print(String.format("%.2f", rawValue.getDoubleValue()) + ",");
|
|
|
+ }
|
|
|
+ pw.println();
|
|
|
+ //文件写入各支路功率
|
|
|
+ for (Map.Entry<String, Map<Double, Double>> sme : GLMapMap.entrySet()) {
|
|
|
+ pw.println(sme.getKey());
|
|
|
+ for (Double value : sme.getValue().values()) {
|
|
|
+ String s = String.format("%.2f", value) + ",";
|
|
|
+ pw.print(s);
|
|
|
+ }
|
|
|
+ pw.println();
|
|
|
+ }
|
|
|
+ pw.close();
|
|
|
+
|
|
|
+
|
|
|
+ //double[] run = pncf.run(points);
|
|
|
+ double[] hzj01_22416s = pncf.run(PointsMap.get("HZJ01_22416"));
|
|
|
+ double[] hzj01_1893s = pncf.run(PointsMap.get("HZJ01_1893"));
|
|
|
+
|
|
|
+ /*//计算最差的和最好的
|
|
|
+ for (Map.Entry<String, Map<Double, Double>> sme : GLMapMap.entrySet()) {
|
|
|
+ double v = pncf.calcLow(sme.getValue(), run);
|
|
|
+ System.out.println(sme.getKey()+","+v);
|
|
|
+ }*/
|
|
|
+
|
|
|
+ pncf.printResultAll(rawValues2,index,2);
|
|
|
+ pncf.printResultAll(rawValues2,hzj01_22416s,2);
|
|
|
+ pncf.printResultAll(rawValues2,hzj01_1893s,2);
|
|
|
+ }
|
|
|
+
|
|
|
+ void test2(){
|
|
|
+ String faultCode = windturbinetestingpointai2Service.getFaultCodes().get(0).getId();
|
|
|
+ Calendar instance = Calendar.getInstance();
|
|
|
+ instance.add(Calendar.DATE, -2);
|
|
|
+ long start = DateUtils.getZero(instance).getTimeInMillis();
|
|
|
+ long end = DateUtils.getNight(instance).getTimeInMillis();
|
|
|
+
|
|
|
+ Map<Integer, Map<Long, Double>> 电流MapMap = new HashMap<>();
|
|
|
+ Map<Integer, Map<Long, Double>> 电压MapMap = new HashMap<>();
|
|
|
+ Map<Integer, Map<Long, Double>> 功率MapMap = new HashMap<>();
|
|
|
+ List<List<TsDoubleData>> 电流ListList = new ArrayList<>();
|
|
|
+ List<List<TsDoubleData>> 电压ListList = new ArrayList<>();
|
|
|
+ List<List<Double>> 功率ListList = new ArrayList<>();
|
|
|
+ for (int i = 1; i < 19; i++) {
|
|
|
+ String s = String.valueOf(i);
|
|
|
+ String code = faultCode.substring(0, faultCode.length() - s.length()) + s;
|
|
|
+ //List<TsDoubleData> rawValuesByKey = adpClient.getRawValuesByKey(code, start, end);
|
|
|
+ List<TsDoubleData> rawValuesByKey = adpClient.getValuesByKey(code, start, end, 60);
|
|
|
+ //Map<Long, Double> 电压Map = rawValuesByKey.stream().collect(Collectors.toMap(TsDoubleData::getTs, TsDoubleData::getDoubleValue));
|
|
|
+ //电压MapMap.put(i, 电压Map);
|
|
|
+ 电压ListList.add(rawValuesByKey);
|
|
|
+ }
|
|
|
+ for (int j = 19; j < 37; j++) {
|
|
|
+ String s = String.valueOf(j);
|
|
|
+ String code = faultCode.substring(0, faultCode.length() - s.length()) + s;
|
|
|
+ List<TsDoubleData> valuesByKey = adpClient.getValuesByKey(code, start, end, 60);
|
|
|
+ //Map<Long, Double> 电流Map = valuesByKey.stream().collect(Collectors.toMap(TsDoubleData::getTs, TsDoubleData::getDoubleValue));
|
|
|
+ //电流MapMap.put(j - 18, 电流Map);
|
|
|
+ 电流ListList.add(valuesByKey);
|
|
|
+ }
|
|
|
+ /*电压MapMap.forEach((i,pdata)->{
|
|
|
+ Map<Long, Double> 功率Map = new HashMap<>();
|
|
|
+ pdata.forEach((ts,data)->{
|
|
|
+ //电流值
|
|
|
+ Double aDouble = 电流MapMap.get(i).get(ts);
|
|
|
+ 功率Map.put(ts, data * 0.001 * aDouble);
|
|
|
+ });
|
|
|
+ 功率MapMap.put(i, 功率Map);
|
|
|
+ });
|
|
|
+ 功率MapMap.forEach((i,pdata)->{
|
|
|
+ System.out.println(i);
|
|
|
+ pdata.forEach((ts,data)->{
|
|
|
+ System.out.print(ts+",");
|
|
|
+ });
|
|
|
+ pdata.forEach((ts,data)->{
|
|
|
+ System.out.print(data+",");
|
|
|
+ });
|
|
|
+ });*/
|
|
|
+ for (int i = 0; i < 电压ListList.size(); i++) {
|
|
|
+ List<TsDoubleData> dyData = 电压ListList.get(i);
|
|
|
+ List<TsDoubleData> dlData = 电流ListList.get(i);
|
|
|
+ List<Double> glData = new ArrayList<>();
|
|
|
+ System.out.println("\n\n\n" + i);
|
|
|
+ for (int j = 0; j < dyData.size(); j++) {
|
|
|
+ double v = dyData.get(j).getDoubleValue() * 0.001 * dlData.get(j).getDoubleValue();
|
|
|
+ glData.add(v);
|
|
|
+ }
|
|
|
+ for (Double glDatum : glData) {
|
|
|
+ System.out.printf("%.2f", glDatum);
|
|
|
+ System.out.print(",");
|
|
|
+ }
|
|
|
+ 功率ListList.add(glData);
|
|
|
+ }
|
|
|
+ System.out.println("\n\n\n");
|
|
|
+ for (TsDoubleData dyDatum : 电压ListList.get(0)) {
|
|
|
+ System.out.print(dyDatum.getTs() + ",");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|