package com.gyee.generation.service; import com.gyee.common.contant.ContantXk; import com.gyee.common.model.PointData; import com.gyee.generation.init.CacheContext; import com.gyee.generation.model.auto.ProBasicEquipment; import com.gyee.generation.model.auto.ProBasicEquipmentPoint; import com.gyee.generation.model.auto.ProEconActivePowerData; import com.gyee.generation.model.auto.ProEconWtPowerCurveFitting; import com.gyee.generation.model.vo.StatData; import com.gyee.generation.service.auto.IProEconWtPowerCurveFittingService; import com.gyee.generation.util.DateUtils; import com.gyee.generation.util.StringUtils; import com.gyee.generation.util.realtimesource.IEdosUtil; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.*; import java.util.stream.Collectors; @Service public class CoefficientService { // // private static final Logger logger = LoggerFactory.getLogger(CoefficientService.class); @Resource private IEdosUtil edosUtil; @Resource private IProEconWtPowerCurveFittingService proEconWtPowerCurveFittingService; public Map> coefficient(Date currentDate) throws Exception { //调度时间是第二天,currentDate 是第一天 currentDate = DateUtils.truncDay(currentDate); Calendar c = Calendar.getInstance(); c.setTime(currentDate); c.set(Calendar.DAY_OF_MONTH, 1); Date monthbeginDate = c.getTime(); c.set(Calendar.MONTH, 0); Date yearbeginDate = c.getTime(); c.setTime(currentDate); Date beginDate = c.getTime(); c.add(Calendar.DAY_OF_MONTH, 1); Date endDate = c.getTime(); Map> resultmap = new HashMap<>(); //查询风机 List wtls = CacheContext.wtls; //遍历所有风机ID for (ProBasicEquipment wt : wtls) { List yearList; List queryYear = new ArrayList<>(); Map wtpointmap = CacheContext.wtpAimap.get(wt.getId()); ProBasicEquipmentPoint fspoint = wtpointmap.get(ContantXk.CJ_SSFS); List fsls = edosUtil.getHistStat(fspoint.getNemCode(), yearbeginDate.getTime() / 1000, endDate.getTime() / 1000, null, 900L, StatData.AVG.getValue()); ProBasicEquipmentPoint glpoint = wtpointmap.get(ContantXk.CJ_SSGL); List glls = edosUtil.getHistStat(glpoint.getNemCode(), yearbeginDate.getTime() / 1000, endDate.getTime() / 1000, null, 900L, StatData.AVG.getValue()); if(!fsls.isEmpty() && !glls.isEmpty() && fsls.size()==glls.size()) { for(int i=0;i monthList; List queryMonth = new ArrayList<>(); fsls = edosUtil.getHistStat(fspoint.getNemCode(), monthbeginDate.getTime() / 1000, endDate.getTime() / 1000, null, 900L, StatData.AVG.getValue()); glls = edosUtil.getHistStat(glpoint.getNemCode(), monthbeginDate.getTime() / 1000, endDate.getTime() / 1000, null, 900L, StatData.AVG.getValue()); if (!fsls.isEmpty() && !glls.isEmpty() && fsls.size() == glls.size()) { for (int i = 0; i < fsls.size(); i++) { PointData fspd = fsls.get(i); PointData glpd = fsls.get(i); ProEconActivePowerData po = new ProEconActivePowerData(); po.setWindturbineId(wt.getId()); po.setModelId(wt.getModelId()); po.setWindpowerstationId(wt.getWindpowerstationId()); po.setFrequency(fsls.size()); po.setSpeed(StringUtils.round(fspd.getPointValueInDouble(), 2)); po.setPower(StringUtils.round(glpd.getPointValueInDouble(), 2)); queryMonth.add(po); } } monthList = calCoefficient(queryMonth, wt); //*****************************************日功率一致性统计********************************************************************/ List dayList; List queryDay = new ArrayList<>(); fsls = edosUtil.getHistStat(fspoint.getNemCode(), beginDate.getTime() / 1000, endDate.getTime() / 1000, null, 900L, StatData.AVG.getValue()); glls = edosUtil.getHistStat(glpoint.getNemCode(), beginDate.getTime() / 1000, endDate.getTime() / 1000, null, 900L, StatData.AVG.getValue()); if (!fsls.isEmpty() && !glls.isEmpty() && fsls.size() == glls.size()) { for (int i = 0; i < fsls.size(); i++) { PointData fspd = fsls.get(i); PointData glpd = fsls.get(i); ProEconActivePowerData po = new ProEconActivePowerData(); po.setWindturbineId(wt.getId()); po.setModelId(wt.getModelId()); po.setWindpowerstationId(wt.getWindpowerstationId()); po.setFrequency(fsls.size()); po.setSpeed(StringUtils.round(fspd.getPointValueInDouble(), 2)); po.setPower(StringUtils.round(glpd.getPointValueInDouble(), 2)); queryDay.add(po); } } dayList = calCoefficient(queryDay, wt); Double resultYear = coefficient(yearList, currentDate, wt.getId()); Double resultMonth = coefficient(monthList, currentDate, wt.getId()); Double resultDay = coefficient(dayList, currentDate, wt.getId()); Map tempmap = new HashMap<>(); tempmap.put("year", resultYear); tempmap.put("month", resultMonth); tempmap.put("day", resultDay); resultmap.put(wt.getId(), tempmap); } return resultmap; } private List calCoefficient(List query, ProBasicEquipment wt) { Map> apdataYearMap = query.stream().collect(Collectors.groupingBy(ProEconActivePowerData::getSpeed)); Map speedAndPowerYearMap = new HashMap<>(); apdataYearMap.forEach((key, value) -> { DoubleSummaryStatistics summaryStatistics = value.stream().mapToDouble(ProEconActivePowerData::getPower).summaryStatistics(); speedAndPowerYearMap.put(key, summaryStatistics.getAverage()); }); List yearList = new ArrayList<>(); speedAndPowerYearMap.forEach((key, value) -> { ProEconActivePowerData activepowerdata = new ProEconActivePowerData(); activepowerdata.setWindturbineId(wt.getId()); activepowerdata.setSpeed(key); activepowerdata.setPower(value); activepowerdata.setFrequency(1); activepowerdata.setModelId(wt.getModelId()); yearList.add(activepowerdata); }); return yearList; } //功率一致性系数 private Double coefficient(List dataList, Date currentDate, String windturbineId) { double result = 0.0; double count = 0.0; if (dataList != null && dataList.size() != 0) { List powerList; Calendar c = Calendar.getInstance(); c.setTime(currentDate); powerList = proEconWtPowerCurveFittingService.list().stream() .filter(i -> i.getWindturbineId().equals(windturbineId)).collect(Collectors.toList()); for (ProEconActivePowerData data : dataList) { Double p1 = data.getPower(); Double speed = data.getSpeed(); if (speed < 3 || speed > 25) { continue; } if (CacheContext.wtmap.containsKey(windturbineId)) { ProBasicEquipment wt = CacheContext.wtmap.get(windturbineId); if (wt.getWindpowerstationId().contains("GDC")) { speed /= 100; speed = StringUtils.round(speed, 2); speed *= 100; speed = StringUtils.round(speed, 2); } else { speed = StringUtils.round(speed, 2); } } if (CacheContext.modelpowermap.containsKey(data.getModelId())) { if (CacheContext.modelpowermap.get(data.getModelId()).size() > 0) { if (CacheContext.modelpowermap.get(data.getModelId()).containsKey(speed)) { Double p = CacheContext.modelpowermap.get(data.getModelId()).get(speed).getEnsurePower(); if (p != 0) { for (int i = 0; i < data.getFrequency(); i++) { result += Math.abs((p - p1) / p); count += 1; } } } } else { if (powerList.size() > 0) { Double finalSpeed = speed; OptionalDouble opd = powerList.stream().filter(i -> Objects.equals(i.getSpeed(), finalSpeed)).mapToDouble(ProEconWtPowerCurveFitting::getOptimalPower).findFirst(); double p; if (opd.isPresent()) { p = opd.getAsDouble(); if (p != 0) { for (int i = 0; i < data.getFrequency(); i++) { result += Math.abs((p - p1) / p); count += 1; } } } else { DoubleSummaryStatistics summaryStatistics = powerList.stream().mapToDouble(ProEconWtPowerCurveFitting::getSpeed).summaryStatistics(); double max = summaryStatistics.getMax(); if (speed > max) { summaryStatistics = powerList.stream().mapToDouble(ProEconWtPowerCurveFitting::getActualPower).summaryStatistics(); p = summaryStatistics.getMax(); if (p != 0.0) { for (int i = 0; i < data.getFrequency(); i++) { result += Math.abs((p - p1) / p); count += 1; } } } } } } } } if (count != 0) result = result / count * 100; else result = 100.0; } return result; } }