GoodnessOfFitService.java 13 KB

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