GoodnessOfFitService.java 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. package com.gyee.generation.service;
  2. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  3. import com.gyee.common.contant.ContantXk;
  4. import com.gyee.common.model.PointData;
  5. import com.gyee.generation.init.CacheContext;
  6. import com.gyee.generation.model.auto.ProBasicEquipment;
  7. import com.gyee.generation.model.auto.ProBasicEquipmentPoint;
  8. import com.gyee.generation.model.auto.ProEconWtCurveFittingMonth;
  9. import com.gyee.generation.model.vo.FitClassVo;
  10. import com.gyee.generation.model.vo.StatData;
  11. import com.gyee.generation.service.auto.IProEconWtCurveFittingMonthService;
  12. import com.gyee.generation.util.DateUtils;
  13. import com.gyee.generation.util.StringUtils;
  14. import com.gyee.generation.util.realtimesource.IEdosUtil;
  15. import org.springframework.stereotype.Service;
  16. import javax.annotation.Resource;
  17. import java.util.*;
  18. @Service
  19. public class GoodnessOfFitService {
  20. // private static final Logger logger = LoggerFactory.getLogger(GoodnessOfFitService.class);
  21. @Resource
  22. private IEdosUtil edosUtil;
  23. @Resource
  24. private IProEconWtCurveFittingMonthService proEconWtCurveFittingMonthService;
  25. public Map<String,Map<String,Double>> goodnessOfFit(String wtId,Date nowDate) throws Exception {
  26. Date startDate = DateUtils.addDays(nowDate,-1);
  27. Date endDate =new Date();
  28. Calendar c= Calendar.getInstance();
  29. c.setTime(startDate);
  30. String year =String.valueOf(c.get(Calendar.YEAR));
  31. String month = String.valueOf(c.get(Calendar.MONTH)+1);
  32. c.setTime(nowDate);
  33. c.set(Calendar.DAY_OF_MONTH,1);
  34. Date startDateM = c.getTime();
  35. c.set(Calendar.MONTH,0);
  36. Date startDateY = c.getTime();
  37. Map<String,Map<String,Double>> resultmap =new HashMap<>();
  38. Map<String, FitClassVo> theMapY = new HashMap<>();
  39. Map<String, FitClassVo> theMapM = new HashMap<>();
  40. Map<String, FitClassVo> theMapD = new HashMap<>();
  41. List<FitClassVo> theList = new ArrayList<>();
  42. List<ProEconWtCurveFittingMonth> powerList;
  43. QueryWrapper<ProEconWtCurveFittingMonth> queryWrapper = new QueryWrapper<>();
  44. queryWrapper.eq("year",year).eq("month",month).eq("windturbine_id",wtId);
  45. powerList = proEconWtCurveFittingMonthService.list(queryWrapper);
  46. // .stream().filter(i->i.getMonth().equals(month)
  47. // && i.getWindturbineId().equals(wtId)
  48. // && i.getYear().equals(year)).collect(Collectors.toList());
  49. ProBasicEquipment wt=CacheContext.wtmap.get(wtId);
  50. // for (ProBasicEquipment wt : CacheContext.wtls)
  51. //
  52. // {
  53. List<FitClassVo> fitsD= new ArrayList<>();
  54. List<FitClassVo> fitsM= new ArrayList<>();
  55. List<FitClassVo> fitsY= new ArrayList<>();
  56. //月数据筛选日分钟间隔
  57. Map<String, ProBasicEquipmentPoint> wtpointmap= CacheContext.wtpAimap.get(wt.getId());
  58. ProBasicEquipmentPoint fspoint=wtpointmap.get(ContantXk.CJ_SSFS);
  59. List<PointData> fsls=edosUtil.getHistStat(fspoint.getNemCode(),startDate.getTime()/1000,endDate.getTime()/1000,null, 900L, StatData.AVG.getValue());
  60. ProBasicEquipmentPoint glpoint=wtpointmap.get(ContantXk.CJ_SSGL);
  61. List<PointData> glls=edosUtil.getHistStat(glpoint.getNemCode(),startDate.getTime()/1000,endDate.getTime()/1000,null,900L, StatData.AVG.getValue());
  62. if(!fsls.isEmpty() && !glls.isEmpty() && fsls.size()==glls.size())
  63. {
  64. for(int i=0;i<fsls.size();i++)
  65. {
  66. PointData fspd=fsls.get(i);
  67. PointData glpd=glls.get(i);
  68. FitClassVo po=new FitClassVo();
  69. po.setWindturbineId(wt.getId());
  70. po.setModelId(wt.getModelId());
  71. po.setWindpowerstationId(wt.getWindpowerstationId());
  72. po.setSpeed(StringUtils.round(fspd.getPointValueInDouble(),2));
  73. po.setPower(StringUtils.round(glpd.getPointValueInDouble(),2));
  74. fitsD.add(po);
  75. }
  76. }
  77. //月数据筛选15分钟间隔
  78. fsls=edosUtil.getHistStat(fspoint.getNemCode(),startDateM.getTime()/1000,endDate.getTime()/1000,null,900L, StatData.AVG.getValue());
  79. glls=edosUtil.getHistStat(glpoint.getNemCode(),startDateM.getTime()/1000,endDate.getTime()/1000,null,900L, StatData.AVG.getValue());
  80. if(!fsls.isEmpty() && !glls.isEmpty() && fsls.size()==glls.size())
  81. {
  82. for(int i=0;i<fsls.size();i++)
  83. {
  84. PointData fspd=fsls.get(i);
  85. PointData glpd=glls.get(i);
  86. FitClassVo po=new FitClassVo();
  87. po.setWindturbineId(wt.getId());
  88. po.setModelId(wt.getModelId());
  89. po.setWindpowerstationId(wt.getWindpowerstationId());
  90. po.setSpeed(StringUtils.round(fspd.getPointValueInDouble(),2));
  91. po.setPower(StringUtils.round(glpd.getPointValueInDouble(),2));
  92. fitsM.add(po);
  93. }
  94. }
  95. //年数据筛选15分钟间隔
  96. fsls=edosUtil.getHistStat(fspoint.getNemCode(),startDateY.getTime()/1000,endDate.getTime()/1000,null,900L, StatData.AVG.getValue());
  97. glls=edosUtil.getHistStat(glpoint.getNemCode(),startDateY.getTime()/1000,endDate.getTime()/1000,null,900L, StatData.AVG.getValue());
  98. if(!fsls.isEmpty() && !glls.isEmpty() && fsls.size()==glls.size())
  99. {
  100. for(int i=0;i<fsls.size();i++)
  101. {
  102. PointData fspd=fsls.get(i);
  103. PointData glpd=glls.get(i);
  104. FitClassVo po=new FitClassVo();
  105. po.setWindturbineId(wt.getId());
  106. po.setModelId(wt.getModelId());
  107. po.setWindpowerstationId(wt.getWindpowerstationId());
  108. po.setSpeed(StringUtils.round(fspd.getPointValueInDouble(),2));
  109. po.setPower(StringUtils.round(glpd.getPointValueInDouble(),2));
  110. fitsY.add(po);
  111. }
  112. }
  113. buildList(theMapY, theList, wt.getWindpowerstationId(), fitsY, powerList);
  114. buildList(theMapM, theList, wt.getWindpowerstationId(), fitsM, powerList);
  115. buildList(theMapD, theList, wt.getWindpowerstationId(), fitsD, powerList);
  116. theMapD.forEach((key,value)->{
  117. if(resultmap.containsKey(key))
  118. {
  119. Map<String,Double> tempmap=resultmap.get(key);
  120. tempmap.put("day",value.getPower() > 1 ? 1 : value.getPower());
  121. resultmap.put(key,tempmap);
  122. }else
  123. {
  124. Map<String,Double> tempmap=new HashMap<>();
  125. tempmap.put("day",value.getPower() > 1 ? 1 : value.getPower());
  126. resultmap.put(key,tempmap);
  127. }
  128. });
  129. theMapM.forEach((key,value)->{
  130. if(resultmap.containsKey(key))
  131. {
  132. Map<String,Double> tempmap=resultmap.get(key);
  133. tempmap.put("month",value.getPower() > 1 ? 1 : value.getPower());
  134. resultmap.put(key,tempmap);
  135. }else
  136. {
  137. Map<String,Double> tempmap=new HashMap<>();
  138. tempmap.put("month",value.getPower() > 1 ? 1 : value.getPower());
  139. resultmap.put(key,tempmap);
  140. }
  141. });
  142. theMapY.forEach((key,value)->{
  143. if(resultmap.containsKey(key))
  144. {
  145. Map<String,Double> tempmap=resultmap.get(key);
  146. tempmap.put("year",value.getPower() > 1 ? 1 : value.getPower());
  147. resultmap.put(key,tempmap);
  148. }else
  149. {
  150. Map<String,Double> tempmap=new HashMap<>();
  151. tempmap.put("year",value.getPower() > 1 ? 1 : value.getPower());
  152. resultmap.put(key,tempmap);
  153. }
  154. });
  155. // }
  156. //
  157. // for (FitClassVo item : theList)
  158. // {
  159. // Double rnew = 0.0;
  160. // Double speed = 0.0;
  161. //
  162. // if (item.getEpower() != 0)
  163. // {
  164. // rnew = (Double)Math.sqrt((double)(item.getPower() / item.getEpower()));
  165. // }
  166. // if (item.getNumber() != 0)
  167. // {
  168. // speed = item.getSpeed() / item.getNumber();
  169. // }
  170. // item.setSpeed(speed);
  171. // item.setPower(rnew);
  172. //
  173. // }
  174. return resultmap;
  175. }
  176. private void buildList(Map<String, FitClassVo> theMap, List<FitClassVo> theList, String windpowerstationId, List<FitClassVo> fitsY, List<ProEconWtCurveFittingMonth> powerList)
  177. {
  178. for (FitClassVo item : fitsY)
  179. {
  180. Double speed;
  181. if (windpowerstationId.contains("GDC"))
  182. {
  183. speed = item.getSpeed();
  184. speed /= 100;
  185. speed = StringUtils.round(speed, 1);
  186. speed *= 100;
  187. //speed = speed;
  188. }
  189. else
  190. {
  191. speed = StringUtils.round(item.getSpeed(), 1);
  192. }
  193. String windturbineId = item.getWindturbineId();
  194. if (CacheContext.theoreticalPowerMap.containsKey(item.getModelId()))
  195. {
  196. if (CacheContext.theoreticalPowerMap.get(item.getModelId()).size() > 0)
  197. {
  198. if (CacheContext.theoreticalPowerMap.get(item.getModelId()).containsKey(speed))
  199. {
  200. Double epower = CacheContext.theoreticalPowerMap.get(item.getModelId()).get(speed).getEnsurePower();
  201. buildtheMap(theMap, theList, windpowerstationId, item, speed, epower);
  202. }
  203. }
  204. else
  205. {
  206. if (powerList != null && powerList.size()>0)
  207. {
  208. Double finalSpeed = speed;
  209. OptionalDouble tempp=powerList.stream()
  210. .filter(i-> Objects.equals(i.getSpeed(), finalSpeed) && i.getWindturbineId().equals(windturbineId))
  211. .mapToDouble(ProEconWtCurveFittingMonth::getOptimalPower).findFirst();
  212. double p;
  213. if (tempp.isPresent())
  214. {
  215. Double epower = tempp.getAsDouble();
  216. buildtheMap(theMap, theList, windpowerstationId, item, speed, epower);
  217. }
  218. else
  219. {
  220. DoubleSummaryStatistics summaryStatistics=powerList.stream().filter(i->i.getWindturbineId().equals(windturbineId))
  221. .mapToDouble(ProEconWtCurveFittingMonth::getSpeed).summaryStatistics();
  222. double max = summaryStatistics.getMax();
  223. if (speed > max)
  224. {
  225. summaryStatistics=powerList.stream().filter(i->i.getWindturbineId().equals(windturbineId)).mapToDouble(ProEconWtCurveFittingMonth::getActualPower).summaryStatistics();
  226. p = summaryStatistics.getMax();
  227. Double epower = p;
  228. buildtheMap(theMap, theList, windpowerstationId, item, speed, epower);
  229. }
  230. }
  231. }
  232. }
  233. }
  234. }
  235. }
  236. private static void buildtheMap(Map<String, FitClassVo> theMap, List<FitClassVo> theList, String windpowerstationId, FitClassVo item, Double speed, Double epower)
  237. {
  238. Double value1 = item.getPower() - epower;
  239. value1 *= value1;
  240. Double value2 = item.getPower();
  241. value2 *= value2;
  242. if (theMap.containsKey(item.getWindturbineId()))
  243. {
  244. FitClassVo vo= theMap.get(item.getWindturbineId());
  245. int number=vo.getNumber();
  246. vo.setSpeed(item.getSpeed()+speed);
  247. vo.setPower(item.getPower()+value1);
  248. vo.setEpower(item.getEpower()+value2);
  249. number=number+1;
  250. vo.setNumber(number);
  251. theMap.put(item.getWindturbineId(),vo);
  252. }
  253. else
  254. {
  255. FitClassVo fit = new FitClassVo();
  256. fit.setWindturbineId(item.getWindturbineId());
  257. fit.setWindpowerstationId(windpowerstationId);
  258. fit.setModelId(item.getModelId());
  259. fit.setSpeed(speed);
  260. fit.setPower(value1);
  261. fit.setEpower(value2);
  262. fit.setNumber(1);
  263. theList.add(fit);
  264. theMap.put(item.getWindturbineId(), fit);
  265. }
  266. }
  267. }