123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297 |
- 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<String, Map<String, Double>> 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<String, Map<String, Double>> resultmap = new HashMap<>();
- //查询风机
- List<ProBasicEquipment> wtls = CacheContext.wtls;
- //遍历所有风机ID
- for (ProBasicEquipment wt : wtls) {
- List<ProEconActivePowerData> yearList;
- List<ProEconActivePowerData> queryYear = new ArrayList<>();
- Map<String, ProBasicEquipmentPoint> wtpointmap = CacheContext.wtpAimap.get(wt.getId());
- ProBasicEquipmentPoint fspoint = wtpointmap.get(ContantXk.CJ_SSFS);
- List<PointData> fsls = edosUtil.getHistStat(fspoint.getNemCode(), yearbeginDate.getTime() / 1000, endDate.getTime() / 1000, null, 900L, StatData.AVG.getValue());
- ProBasicEquipmentPoint glpoint = wtpointmap.get(ContantXk.CJ_SSGL);
- List<PointData> 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<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));
- queryYear.add(po);
- }
- }
- yearList = calCoefficient(queryYear, wt);
- //****************************************月功率一致性统计********************************************************************/
- List<ProEconActivePowerData> monthList;
- List<ProEconActivePowerData> 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<ProEconActivePowerData> dayList;
- List<ProEconActivePowerData> 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<String, Double> tempmap = new HashMap<>();
- tempmap.put("year", resultYear);
- tempmap.put("month", resultMonth);
- tempmap.put("day", resultDay);
- resultmap.put(wt.getId(), tempmap);
- }
- return resultmap;
- }
- private List<ProEconActivePowerData> calCoefficient(List<ProEconActivePowerData> query, ProBasicEquipment wt) {
- Map<Double, List<ProEconActivePowerData>> apdataYearMap = query.stream().collect(Collectors.groupingBy(ProEconActivePowerData::getSpeed));
- Map<Double, Double> speedAndPowerYearMap = new HashMap<>();
- apdataYearMap.forEach((key, value) -> {
- DoubleSummaryStatistics summaryStatistics = value.stream().mapToDouble(ProEconActivePowerData::getPower).summaryStatistics();
- speedAndPowerYearMap.put(key, summaryStatistics.getAverage());
- });
- List<ProEconActivePowerData> 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<ProEconActivePowerData> dataList, Date currentDate, String windturbineId) {
- double result = 0.0;
- double count = 0.0;
- if (dataList != null && dataList.size() != 0) {
- List<ProEconWtPowerCurveFitting> 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;
- }
- }
|