GoodnessOfFitService.java 13 KB

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