package com.gyee.generation.service; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; 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.ProEconWtCurveFittingMonth; import com.gyee.generation.model.vo.FitClassVo; import com.gyee.generation.model.vo.StatData; import com.gyee.generation.service.auto.IProEconWtCurveFittingMonthService; 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.*; @Service public class GoodnessOfFitService { // private static final Logger logger = LoggerFactory.getLogger(GoodnessOfFitService.class); @Resource private IEdosUtil edosUtil; @Resource private IProEconWtCurveFittingMonthService proEconWtCurveFittingMonthService; public Map> goodnessOfFit(String wtId,Date nowDate) throws Exception { Date startDate = DateUtils.addDays(nowDate,-1); Date endDate =new Date(); Calendar c= Calendar.getInstance(); c.setTime(startDate); String year =String.valueOf(c.get(Calendar.YEAR)); String month = String.valueOf(c.get(Calendar.MONTH)+1); c.setTime(nowDate); c.set(Calendar.DAY_OF_MONTH,1); Date startDateM = c.getTime(); c.set(Calendar.MONTH,0); Date startDateY = c.getTime(); Map> resultmap =new HashMap<>(); Map theMapY = new HashMap<>(); Map theMapM = new HashMap<>(); Map theMapD = new HashMap<>(); List theList = new ArrayList<>(); List powerList; QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.eq("year",year).eq("month",month).eq("windturbine_id",wtId); powerList = proEconWtCurveFittingMonthService.list(queryWrapper); // .stream().filter(i->i.getMonth().equals(month) // && i.getWindturbineId().equals(wtId) // && i.getYear().equals(year)).collect(Collectors.toList()); ProBasicEquipment wt=CacheContext.wtmap.get(wtId); // for (ProBasicEquipment wt : CacheContext.wtls) // // { List fitsD= new ArrayList<>(); List fitsM= new ArrayList<>(); List fitsY= new ArrayList<>(); //月数据筛选日分钟间隔 Map wtpointmap= CacheContext.wtpAimap.get(wt.getId()); ProBasicEquipmentPoint fspoint=wtpointmap.get(ContantXk.CJ_SSFS); List fsls=edosUtil.getHistStat(fspoint.getNemCode(),startDate.getTime()/1000,endDate.getTime()/1000,null, 900L, StatData.AVG.getValue()); ProBasicEquipmentPoint glpoint=wtpointmap.get(ContantXk.CJ_SSGL); List glls=edosUtil.getHistStat(glpoint.getNemCode(),startDate.getTime()/1000,endDate.getTime()/1000,null,900L, StatData.AVG.getValue()); if(!fsls.isEmpty() && !glls.isEmpty() && fsls.size()==glls.size()) { for(int i=0;i{ if(resultmap.containsKey(key)) { Map tempmap=resultmap.get(key); tempmap.put("day",value.getPower() > 1 ? 1 : value.getPower()); resultmap.put(key,tempmap); }else { Map tempmap=new HashMap<>(); tempmap.put("day",value.getPower() > 1 ? 1 : value.getPower()); resultmap.put(key,tempmap); } }); theMapM.forEach((key,value)->{ if(resultmap.containsKey(key)) { Map tempmap=resultmap.get(key); tempmap.put("month",value.getPower() > 1 ? 1 : value.getPower()); resultmap.put(key,tempmap); }else { Map tempmap=new HashMap<>(); tempmap.put("month",value.getPower() > 1 ? 1 : value.getPower()); resultmap.put(key,tempmap); } }); theMapY.forEach((key,value)->{ if(resultmap.containsKey(key)) { Map tempmap=resultmap.get(key); tempmap.put("year",value.getPower() > 1 ? 1 : value.getPower()); resultmap.put(key,tempmap); }else { Map tempmap=new HashMap<>(); tempmap.put("year",value.getPower() > 1 ? 1 : value.getPower()); resultmap.put(key,tempmap); } }); // } // // for (FitClassVo item : theList) // { // Double rnew = 0.0; // Double speed = 0.0; // // if (item.getEpower() != 0) // { // rnew = (Double)Math.sqrt((double)(item.getPower() / item.getEpower())); // } // if (item.getNumber() != 0) // { // speed = item.getSpeed() / item.getNumber(); // } // item.setSpeed(speed); // item.setPower(rnew); // // } return resultmap; } private void buildList(Map theMap, List theList, String windpowerstationId, List fitsY, List powerList) { for (FitClassVo item : fitsY) { Double speed; if (windpowerstationId.contains("GDC")) { speed = item.getSpeed(); speed /= 100; speed = StringUtils.round(speed, 1); speed *= 100; //speed = speed; } else { speed = StringUtils.round(item.getSpeed(), 1); } String windturbineId = item.getWindturbineId(); if (CacheContext.theoreticalPowerMap.containsKey(item.getModelId())) { if (CacheContext.theoreticalPowerMap.get(item.getModelId()).size() > 0) { if (CacheContext.theoreticalPowerMap.get(item.getModelId()).containsKey(speed)) { Double epower = CacheContext.theoreticalPowerMap.get(item.getModelId()).get(speed).getEnsurePower(); buildtheMap(theMap, theList, windpowerstationId, item, speed, epower); } } else { if (powerList != null && powerList.size()>0) { Double finalSpeed = speed; OptionalDouble tempp=powerList.stream() .filter(i-> Objects.equals(i.getSpeed(), finalSpeed) && i.getWindturbineId().equals(windturbineId)) .mapToDouble(ProEconWtCurveFittingMonth::getOptimalPower).findFirst(); double p; if (tempp.isPresent()) { Double epower = tempp.getAsDouble(); buildtheMap(theMap, theList, windpowerstationId, item, speed, epower); } else { DoubleSummaryStatistics summaryStatistics=powerList.stream().filter(i->i.getWindturbineId().equals(windturbineId)) .mapToDouble(ProEconWtCurveFittingMonth::getSpeed).summaryStatistics(); double max = summaryStatistics.getMax(); if (speed > max) { summaryStatistics=powerList.stream().filter(i->i.getWindturbineId().equals(windturbineId)).mapToDouble(ProEconWtCurveFittingMonth::getActualPower).summaryStatistics(); p = summaryStatistics.getMax(); Double epower = p; buildtheMap(theMap, theList, windpowerstationId, item, speed, epower); } } } } } } } private static void buildtheMap(Map theMap, List theList, String windpowerstationId, FitClassVo item, Double speed, Double epower) { Double value1 = item.getPower() - epower; value1 *= value1; Double value2 = item.getPower(); value2 *= value2; if (theMap.containsKey(item.getWindturbineId())) { FitClassVo vo= theMap.get(item.getWindturbineId()); int number=vo.getNumber(); vo.setSpeed(item.getSpeed()+speed); vo.setPower(item.getPower()+value1); vo.setEpower(item.getEpower()+value2); number=number+1; vo.setNumber(number); theMap.put(item.getWindturbineId(),vo); } else { FitClassVo fit = new FitClassVo(); fit.setWindturbineId(item.getWindturbineId()); fit.setWindpowerstationId(windpowerstationId); fit.setModelId(item.getModelId()); fit.setSpeed(speed); fit.setPower(value1); fit.setEpower(value2); fit.setNumber(1); theList.add(fit); theMap.put(item.getWindturbineId(), fit); } } }