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 list = new ArrayList<>(); //初始化列表 EasyExcel.read("D:/工作簿2.xlsx") //文件路径 .sheet("Sheet1") //表单名 .registerReadListener(new AnalysisEventListener>() { //监听器,以行的形式读取Excel //一行一行读取Excel,在这里处理读取到的数据 @Override public void invoke(Map 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 wrap = new QueryWrapper<>(); wrap.eq("STATIONID", "HZJ_GDC"); List 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 rawValues = adpClient.getRawValuesByKey(hzj_gdc.getCode(), start, end); rawValues=rawValues.stream().filter(rw->rw.getDoubleValue()!=0.0).collect(Collectors.toList()); List 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 WDvalues = adpClient.getValuesByKey("HZJGGL.NX_GD_HZJG_YC_P1_L1_001_QXZ006", tsstart, tsend, 5 * 60); //获取光伏逆变器支路电流电压测点 QueryWrapper wrapper = new QueryWrapper<>(); //wrapper.eq("electric", "电压").lt("rownum",19).orderByAsc("windturbineid"); wrapper.eq("electric", "电压"); //电压测点 List DYlist = photovoltaicivService.list(wrapper); wrapper.clear(); //wrapper.eq("electric", "电流").lt("rownum",19).orderByAsc("windturbineid"); wrapper.eq("electric", "电流"); //电流测点 List 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> DYMapMap = new HashMap<>(); //逆变器+支路号,时间,电流值 Map> DLMapMap = new HashMap<>(); //逆变器+支路号,光照强度,功率 Map> GLMapMap = new HashMap<>(); Map PointsMap = new HashMap<>(); for (Photovoltaiciv ptvtc : DYlist) { //电压值 List DYrawValues = adpClient.getValuesByKey(ptvtc.getId(), tsstart, tsend, 5*60); Map collect = DYrawValues.stream().collect(Collectors.toMap(TsDoubleData::getTs, TsDoubleData::getDoubleValue)); DYMapMap.put(ptvtc.getWindturbineid()+ptvtc.getBranchnum(), collect); } for (Photovoltaiciv ptvtc : DLlist) { //电流值 List DLrawValues = adpClient.getValuesByKey(ptvtc.getId(), tsstart, tsend, 5*60); Map 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 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> 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> 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> 电流MapMap = new HashMap<>(); Map> 电压MapMap = new HashMap<>(); Map> 功率MapMap = new HashMap<>(); List> 电流ListList = new ArrayList<>(); List> 电压ListList = new ArrayList<>(); List> 功率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 rawValuesByKey = adpClient.getRawValuesByKey(code, start, end); List rawValuesByKey = adpClient.getValuesByKey(code, start, end, 60); //Map 电压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 valuesByKey = adpClient.getValuesByKey(code, start, end, 60); //Map 电流Map = valuesByKey.stream().collect(Collectors.toMap(TsDoubleData::getTs, TsDoubleData::getDoubleValue)); //电流MapMap.put(j - 18, 电流Map); 电流ListList.add(valuesByKey); } /*电压MapMap.forEach((i,pdata)->{ Map 功率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 dyData = 电压ListList.get(i); List dlData = 电流ListList.get(i); List 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() + ","); } } }