PowerCurveFittingByTimeService.java 90 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964
  1. package com.gyee.generation.service;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  4. import com.gyee.common.contant.ContantXk;
  5. import com.gyee.common.model.PointData;
  6. import com.gyee.generation.init.CacheContext;
  7. import com.gyee.generation.model.auto.*;
  8. import com.gyee.generation.model.vo.*;
  9. import com.gyee.generation.service.auto.*;
  10. import com.gyee.generation.util.DateUtils;
  11. import com.gyee.generation.util.DeviationRateUtil;
  12. import com.gyee.generation.util.StringUtils;
  13. import com.gyee.generation.util.realtimesource.IEdosUtil;
  14. import com.gyee.generation.util.realtimesource.math.LineUtil;
  15. import com.gyee.generation.util.redis.RedisService;
  16. import org.slf4j.Logger;
  17. import org.slf4j.LoggerFactory;
  18. import org.springframework.beans.factory.annotation.Value;
  19. import org.springframework.stereotype.Service;
  20. import javax.annotation.Resource;
  21. import java.util.*;
  22. import java.util.stream.Collectors;
  23. @Service
  24. public class PowerCurveFittingByTimeService {
  25. private static final Logger logger = LoggerFactory.getLogger(PowerCurveFittingByTimeService.class);
  26. @Resource
  27. private IEdosUtil edosUtil;
  28. @Value("${curvefitting.dimension}")
  29. private Integer dimension;
  30. @Value("${curvefitting.scale}")
  31. private Double scale;
  32. @Value("${initialcode}")
  33. private String initialcode;
  34. public Map<String, Double> windturbineCapacity;
  35. @Resource
  36. private RedisService redisService;
  37. @Resource
  38. private IProEconWtCurveFittingMonthService proEconWtCurveFittingMonthService;
  39. @Resource
  40. private IProEconWtCurveFittingYearService proEconWtCurveFittingYearService;
  41. @Resource
  42. private IProEconWtCurveFittingService proEconWtCurveFittingService;
  43. @Resource
  44. private IProEconCurveFittingMainService proEconCurveFittingMainService;
  45. @Resource
  46. private IProEconCurveFittingSubService proEconCurveFittingSubService;
  47. @Resource
  48. private IProEconCurveFittMonthMainService proEconCurveFittMonthMainService;
  49. @Resource
  50. private IProEconCurveFittMonthSubService proEconCurveFittMonthSubService;
  51. @Resource
  52. private IProEconWtPowerCurveFittingService proEconWtPowerCurveFittingService;
  53. @Resource
  54. private IProEconCurveFittYearSubService proEconCurveFittYearSubService;
  55. @Resource
  56. private IProEconCurveFittYearMainService proEconCurveFittYearMainService;
  57. public void cureFittingDay(Date recordDate,String wpId) throws Exception {
  58. //日期变为昨天
  59. Date end = DateUtils.addDays(DateUtils.truncate(recordDate), -1);
  60. Calendar c = Calendar.getInstance();
  61. c.setTime(end);
  62. Date begin = DateUtils.addDays(end, -6);
  63. List<ProBasicEquipment> wtls=new ArrayList<>();
  64. if(StringUtils.notEmp(wpId) && CacheContext.wpwtmap.containsKey(wpId))
  65. {
  66. wtls=CacheContext.wpwtmap.get(wpId);
  67. }else
  68. {
  69. wtls=CacheContext.wtls;
  70. }
  71. StringBuilder sb=new StringBuilder();
  72. for(ProBasicEquipment wt:wtls)
  73. {
  74. sb.append("'").append(wt.getId()).append("',");
  75. }
  76. String wtIds=sb.substring(0,sb.length()-1);
  77. proEconWtCurveFittingService.deleteProEconWtCurveFittingFByDay(DateUtils.truncate(recordDate),wtIds);
  78. proEconCurveFittingMainService.deleteProEconCurveFittingMainFByDay(DateUtils.truncate(recordDate),wtIds);
  79. proEconCurveFittingSubService.deleteProEconCurveFittingSubFByDay(DateUtils.truncate(recordDate),wtIds);
  80. Map<String, CureFittingVo> windMap = new HashMap<>();
  81. //初始化风机装机容量
  82. if (windturbineCapacity == null) {
  83. windturbineCapacity = new HashMap<>();
  84. Map<String, ProEconEquipmentmodel> modelMap = CacheContext.modelMap;
  85. for (ProBasicEquipment windturbine : CacheContext.wtls) {
  86. if (modelMap.containsKey(windturbine.getModelId())) {
  87. windturbineCapacity.put(windturbine.getId(), modelMap.get(windturbine.getModelId()).getPowerProduction());
  88. }
  89. }
  90. }
  91. for (ProBasicEquipment wt : wtls) {
  92. String windturbineId = wt.getId();
  93. if(wt.getWindpowerstationId().contains(WpType.GDC.id))
  94. {
  95. continue;
  96. }
  97. Map<String, ProBasicEquipmentPoint> windturbinetestingpointnewMap = CacheContext.wtpAimap.get(wt.getId());
  98. //设备有功功率
  99. String pointIdGL = null;
  100. //设备明细状态
  101. String pointIdZT = null;
  102. String pointIdFS = null;
  103. if (windturbinetestingpointnewMap.containsKey(ContantXk.CJ_SSFS)) {
  104. pointIdFS = windturbinetestingpointnewMap.get(ContantXk.CJ_SSFS).getNemCode();
  105. }
  106. if (windturbinetestingpointnewMap.containsKey(ContantXk.CJ_SSGL)) {
  107. pointIdGL = windturbinetestingpointnewMap.get(ContantXk.CJ_SSGL).getNemCode();
  108. }
  109. if (windturbinetestingpointnewMap.containsKey(ContantXk.MXZT)) {
  110. pointIdZT = windturbinetestingpointnewMap.get(ContantXk.MXZT).getNemCode();
  111. }
  112. CureFittingVo item = new CureFittingVo();
  113. item.setPointIdFS(pointIdFS);
  114. item.setPointIdZT(pointIdZT);
  115. item.setPointIdGL(pointIdGL);
  116. //获取标杆风机编号
  117. if (CacheContext.wtstandardmap.containsKey(wt.getId())) {
  118. item.setStandardId(CacheContext.wtstandardmap.get(wt.getId()));
  119. } else {
  120. item.setStandardId(wt.getId());
  121. }
  122. windMap.put(windturbineId, item);
  123. }
  124. for (String key : windMap.keySet()) {
  125. //初始化集合
  126. windMap.get(key).setYsjglPoints(new ArrayList<>());
  127. windMap.get(key).setYzyglPoints(new ArrayList<>());
  128. windMap.get(key).setRsjglPoints(new ArrayList<>());
  129. windMap.get(key).setRzyglPoints(new ArrayList<>());
  130. windMap.get(key).setNsjglPoints(new ArrayList<>());
  131. windMap.get(key).setNzyglPoints(new ArrayList<>());
  132. if (windMap.get(key).getPointIdGL() == null || windMap.get(key).getPointIdFS() == null || windMap.get(key).getPointIdZT() == null) {
  133. logger.info(key);
  134. continue;
  135. }
  136. //拟合日功率曲线
  137. curveFittingBuilder(begin, end, dimension, scale, windMap.get(key).getPointIdGL(), windMap.get(key).getPointIdFS(), windMap.get(key).getPointIdZT(), windMap.get(key).getRsjglPoints(), windMap.get(key).getRzyglPoints(), key);
  138. List<PointVo> vos = windMap.get(key).getRsjglPoints().stream().filter(it -> it.getX() >= 0 && it.getX() <= 25).sorted(Comparator.comparing(PointVo::getX)).collect(Collectors.toList());
  139. windMap.get(key).setRsjglPoints(vos);
  140. vos = windMap.get(key).getRzyglPoints().stream().filter(it -> it.getX() >= 0 && it.getX() <= 25).sorted(Comparator.comparing(PointVo::getX)).collect(Collectors.toList());
  141. windMap.get(key).setRzyglPoints(vos);
  142. }
  143. List<ProEconCurveFittingMain> mainls=new ArrayList<>();
  144. for (String key : windMap.keySet()) {
  145. Double modelpower = 1500.0;
  146. if (windturbineCapacity.containsKey(key)) {
  147. modelpower = windturbineCapacity.get(key);
  148. }
  149. //日的昨天
  150. List<PointVo> dayLastMonthPoints = new ArrayList<>();
  151. //日的去年同期
  152. List<PointVo> dayLastYearPoints = new ArrayList<>();
  153. //日标准功率
  154. List<PointVo> dayStandardPoints = new ArrayList<>();
  155. //保证功率
  156. List<PointVo> bzglpowerPoints = new ArrayList<>();
  157. if (CacheContext.wtstandardmap.containsKey(key)) {
  158. String standardId = CacheContext.wtstandardmap.get(key);
  159. if (StringUtils.notEmp(standardId)) {
  160. if (windMap.containsKey(key)) {
  161. dayStandardPoints = windMap.get(standardId).getRsjglPoints();
  162. }
  163. }
  164. }
  165. //*********************************************日曲线偏差上个日和上一年记录**********************************************************/
  166. Date d1 = DateUtils.addDays(recordDate, -1);
  167. Date d2 = DateUtils.addYears(recordDate, -1);
  168. QueryWrapper<ProEconWtCurveFitting> queryWrapper = new QueryWrapper<>();
  169. queryWrapper.eq("record_date",d1).eq("windturbine_id",key);
  170. List<ProEconWtCurveFitting> wcfls = proEconWtCurveFittingService.list(queryWrapper)
  171. .stream()
  172. // .filter(i -> i.getWindturbineId().equals(key) &&
  173. // i.getRecordDate().compareTo(d1) == 0)
  174. .sorted(Comparator.comparing(ProEconWtCurveFitting::getSpeed)).collect(Collectors.toList());
  175. dayBuildPoints(wcfls, dayLastMonthPoints);
  176. QueryWrapper<ProEconWtCurveFitting> queryWrapper2 = new QueryWrapper<>();
  177. queryWrapper2.eq("record_date",d2).eq("windturbine_id",key);
  178. wcfls = proEconWtCurveFittingService.list(queryWrapper2).stream()
  179. // .filter(i -> i.getWindturbineId().equals(key) &&
  180. // i.getRecordDate().compareTo(d2) == 0)
  181. .sorted(Comparator.comparing(ProEconWtCurveFitting::getSpeed)).collect(Collectors.toList());
  182. //与轶总的原始代码对比不一致,临时修改测试
  183. dayBuildPoints(wcfls, dayLastMonthPoints);
  184. //*********************************************日曲线偏差上个月和上一年记录**********************************************************/
  185. if (CacheContext.wtmap.containsKey(key)) {
  186. String modelid = CacheContext.wtmap.get(key).getModelId();
  187. if (StringUtils.notEmp(modelid)) {
  188. //获取模型功率曲线
  189. if (CacheContext.theoreticalPowerMap.containsKey(modelid)) {
  190. for (Double speed : CacheContext.theoreticalPowerMap.get(modelid).keySet()) {
  191. PointVo point = new PointVo();
  192. point.setX(speed);
  193. point.setY(CacheContext.theoreticalPowerMap.get(modelid).get(speed).getEnsurePower());
  194. bzglpowerPoints.add(point);
  195. }
  196. }
  197. }
  198. }
  199. //*********************************************当日曲线偏差记录**********************************************************/
  200. QueryWrapper<ProEconCurveFittingMain> queryWrapper3 = new QueryWrapper<>();
  201. queryWrapper3.eq("record_date",recordDate).eq("windturbine_id",key);
  202. Optional<ProEconCurveFittingMain> cfmdayo = proEconCurveFittingMainService.list(queryWrapper3).stream()
  203. // .filter(i -> i.getWindturbineId().equals(key)
  204. // && i.getRecordDate().compareTo(recordDate) == 0)
  205. .findFirst();
  206. ProEconCurveFittingMain cfmday;
  207. if (cfmdayo.isPresent()) {
  208. cfmday = cfmdayo.get();
  209. QueryWrapper<ProEconCurveFittingMain> wrapper = new QueryWrapper<>();
  210. wrapper.eq("id", cfmday.getId());
  211. proEconCurveFittingMainService.remove(wrapper);
  212. }
  213. cfmday = new ProEconCurveFittingMain();
  214. cfmday.setWindturbineId(key);
  215. cfmday.setRecordDate(DateUtils.truncate(recordDate));
  216. //日---实际/最优
  217. cfmday.setDeviationRate1(DeviationRateUtil.calculateDeviationRate(windMap.get(key).getRsjglPoints(), windMap.get(key).getRzyglPoints(), modelpower));
  218. //日---实际/保证
  219. cfmday.setDeviationRate2(DeviationRateUtil.calculateDeviationRate(windMap.get(key).getRsjglPoints(), bzglpowerPoints, modelpower));
  220. //日---最优/保证
  221. cfmday.setDeviationRate3(DeviationRateUtil.calculateDeviationRate(windMap.get(key).getRzyglPoints(), bzglpowerPoints, modelpower));
  222. //日---实际/上日实际
  223. cfmday.setMonthDeviationRate(DeviationRateUtil.calculateDeviationRate(windMap.get(key).getRsjglPoints(), dayLastMonthPoints, modelpower));
  224. //日---实际/同期实际
  225. cfmday.setYearDeviationRate(DeviationRateUtil.calculateDeviationRate(windMap.get(key).getRsjglPoints(), dayLastYearPoints, modelpower));
  226. //日---实际/标杆实际
  227. cfmday.setStandardDeviationRate(DeviationRateUtil.calculateDeviationRate(windMap.get(key).getRsjglPoints(), dayStandardPoints, modelpower));
  228. mainls.add(cfmday);
  229. //proEconCurveFittingMainService.save(cfmday);
  230. //*********************************************当日曲线偏差记录**********************************************************/
  231. List<ProEconCurveFittingSub> subls=new ArrayList<>();
  232. subls.add(pLCBuild(key, recordDate, windMap, modelpower, 3, bzglpowerPoints, dayLastMonthPoints, dayLastYearPoints, dayStandardPoints));
  233. subls.add(pLCBuild(key, recordDate, windMap, modelpower, 4, bzglpowerPoints, dayLastMonthPoints, dayLastYearPoints, dayStandardPoints));
  234. subls.add(pLCBuild(key, recordDate, windMap, modelpower, 5, bzglpowerPoints, dayLastMonthPoints, dayLastYearPoints, dayStandardPoints));
  235. subls.add(pLCBuild(key, recordDate, windMap, modelpower, 6, bzglpowerPoints, dayLastMonthPoints, dayLastYearPoints, dayStandardPoints));
  236. subls.add(pLCBuild(key, recordDate, windMap, modelpower, 7, bzglpowerPoints, dayLastMonthPoints, dayLastYearPoints, dayStandardPoints));
  237. subls.add(pLCBuild(key, recordDate, windMap, modelpower, 8, bzglpowerPoints, dayLastMonthPoints, dayLastYearPoints, dayStandardPoints));
  238. subls.add(pLCBuild(key, recordDate, windMap, modelpower, 9, bzglpowerPoints, dayLastMonthPoints, dayLastYearPoints, dayStandardPoints));
  239. subls.add(pLCBuild(key, recordDate, windMap, modelpower, 10, bzglpowerPoints, dayLastMonthPoints, dayLastYearPoints, dayStandardPoints));
  240. subls.add(pLCBuild(key, recordDate, windMap, modelpower, 11, bzglpowerPoints, dayLastMonthPoints, dayLastYearPoints, dayStandardPoints));
  241. subls.add(pLCBuild(key, recordDate, windMap, modelpower, 12, bzglpowerPoints, dayLastMonthPoints, dayLastYearPoints, dayStandardPoints));
  242. subls.add(pLCBuild(key, recordDate, windMap, modelpower, 13, bzglpowerPoints, dayLastMonthPoints, dayLastYearPoints, dayStandardPoints));
  243. List<ProEconCurveFittingSub> templs=new ArrayList<>();
  244. for(ProEconCurveFittingSub vo:subls)
  245. {
  246. templs.add(vo);
  247. if(templs.size()==1000)
  248. {
  249. proEconCurveFittingSubService.saveBatch(templs);
  250. templs=new ArrayList<>();
  251. }
  252. }
  253. if(!templs.isEmpty())
  254. {
  255. proEconCurveFittingSubService.saveBatch(templs);
  256. }
  257. // proEconCurveFittingSubService.saveBatch(subls);
  258. insertPoints(recordDate, windMap.get(key).getRsjglPoints(), windMap.get(key).getRzyglPoints(), key);
  259. logger.info(key);
  260. //
  261. // logger.info(String.format("{1}:更新sqlserver数据库记录数:{0}", z, new Date()));
  262. }
  263. List<ProEconCurveFittingMain> templs=new ArrayList<>();
  264. for(ProEconCurveFittingMain vo:mainls)
  265. {
  266. templs.add(vo);
  267. if(templs.size()==1000)
  268. {
  269. proEconCurveFittingMainService.saveBatch(templs);
  270. templs=new ArrayList<>();
  271. }
  272. }
  273. if(!templs.isEmpty())
  274. {
  275. proEconCurveFittingMainService.saveBatch(templs);
  276. }
  277. // proEconCurveFittingMainService.saveBatch(mainls);
  278. }
  279. public void cureFittingMonth(Date recordDate,String type,String wpId) throws Exception {
  280. //日期变为下一天
  281. Date end = DateUtils.addDays(DateUtils.truncate(recordDate), 1);
  282. Calendar c = Calendar.getInstance();
  283. c.setTime(recordDate);
  284. int day_year = c.get(Calendar.YEAR);
  285. int day_month = c.get(Calendar.MONTH) + 1;
  286. List<ProBasicEquipment> wtls=new ArrayList<>();
  287. if(StringUtils.notEmp(wpId) && CacheContext.wpwtmap.containsKey(wpId))
  288. {
  289. wtls=CacheContext.wpwtmap.get(wpId);
  290. }else
  291. {
  292. wtls=CacheContext.wtls;
  293. }
  294. StringBuilder sb=new StringBuilder();
  295. for(ProBasicEquipment wt:wtls)
  296. {
  297. sb.append("'").append(wt.getId()).append("',");
  298. }
  299. String wtIds=sb.substring(0,sb.length()-1);
  300. proEconWtCurveFittingMonthService.deleteProEconWtCurveFittingFByMonth(String.valueOf(day_year),String.valueOf(day_month),wtIds);
  301. proEconCurveFittMonthMainService.deleteProEconCurveFittMonthMainFByMonth(String.valueOf(day_year),String.valueOf(day_month), wtIds);
  302. proEconCurveFittMonthSubService.deleteProEconCurveFittMonthSubFByMonth(String.valueOf(day_year),String.valueOf(day_month),wtIds);
  303. c.set(Calendar.DAY_OF_MONTH, 1);
  304. Date begin = DateUtils.truncate(c.getTime());
  305. //上个月
  306. c.setTime(DateUtils.addMonths(begin, -1));
  307. int month_year = c.get(Calendar.YEAR);
  308. int month_month = c.get(Calendar.MONTH) + 1;
  309. //去年同期
  310. c.setTime(DateUtils.addYears(begin, -1));
  311. int year_year = c.get(Calendar.YEAR);
  312. int year_month = c.get(Calendar.MONTH) + 1;
  313. Map<String, CureFittingVo> windMap = new HashMap<>();
  314. if (windturbineCapacity == null) {
  315. windturbineCapacity = new HashMap<>();
  316. Map<String, ProEconEquipmentmodel> modelMap = CacheContext.modelMap;
  317. for (ProBasicEquipment windturbine : CacheContext.wtls) {
  318. if (modelMap.containsKey(windturbine.getModelId())) {
  319. windturbineCapacity.put(windturbine.getId(), modelMap.get(windturbine.getModelId()).getPowerProduction());
  320. }
  321. }
  322. }
  323. for (ProBasicEquipment wt : wtls) {
  324. String windturbineId = wt.getId();
  325. if(wt.getWindpowerstationId().contains(WpType.GDC.id) )
  326. {
  327. continue;
  328. }
  329. Map<String, ProBasicEquipmentPoint> windturbinetestingpointnewMap = CacheContext.wtpAimap.get(wt.getId());
  330. //设备有功功率
  331. String pointIdGL = windturbinetestingpointnewMap.get(ContantXk.CJ_SSGL).getNemCode();
  332. //设备明细状态
  333. String pointIdZT = windturbinetestingpointnewMap.get(ContantXk.MXZT).getNemCode();
  334. String pointIdFS;
  335. if (wt.getWindpowerstationId().contains(WpType.GDC.id)) { //测风塔70米风速
  336. if (windturbinetestingpointnewMap.containsKey(ContantXk.FCCFTFS70)) {
  337. ProBasicEquipmentPoint point = windturbinetestingpointnewMap.get(ContantXk.FCCFTFS70);
  338. if (StringUtils.notEmp(point.getNemCode()) && !point.getNemCode().equals(initialcode)) {
  339. pointIdFS = windturbinetestingpointnewMap.get(ContantXk.FCCFTFS70).getNemCode();
  340. } else {
  341. pointIdFS = windturbinetestingpointnewMap.get(ContantXk.CJ_SSFS).getNemCode();
  342. }
  343. } else {
  344. pointIdFS = windturbinetestingpointnewMap.get(ContantXk.CJ_SSFS).getNemCode();
  345. }
  346. } else { //设备风速
  347. pointIdFS = windturbinetestingpointnewMap.get(ContantXk.CJ_SSFS).getNemCode();
  348. }
  349. CureFittingVo item = new CureFittingVo();
  350. item.setPointIdFS(pointIdFS);
  351. item.setPointIdZT(pointIdZT);
  352. item.setPointIdGL(pointIdGL);
  353. //获取标杆风机编号
  354. if (CacheContext.wtstandardmap.containsKey(wt.getId())) {
  355. item.setStandardId(CacheContext.wtstandardmap.get(wt.getId()));
  356. } else {
  357. item.setStandardId(wt.getId());
  358. }
  359. windMap.put(windturbineId, item);
  360. }
  361. for (String key : windMap.keySet()) {
  362. //初始化集合
  363. windMap.get(key).setYsjglPoints(new ArrayList<>());
  364. windMap.get(key).setYzyglPoints(new ArrayList<>());
  365. windMap.get(key).setRsjglPoints(new ArrayList<>());
  366. windMap.get(key).setRzyglPoints(new ArrayList<>());
  367. windMap.get(key).setNsjglPoints(new ArrayList<>());
  368. windMap.get(key).setNzyglPoints(new ArrayList<>());
  369. if (windMap.get(key).getPointIdGL() == null || windMap.get(key).getPointIdFS() == null || windMap.get(key).getPointIdZT() == null) {
  370. logger.info(key);
  371. continue;
  372. }
  373. //拟合月功率曲线
  374. curveFittingBuilder(begin, end, dimension, scale, windMap.get(key).getPointIdGL(), windMap.get(key).getPointIdFS(), windMap.get(key).getPointIdZT(), windMap.get(key).getYsjglPoints(), windMap.get(key).getYzyglPoints(), key);
  375. List<PointVo> vos = windMap.get(key).getYsjglPoints().stream().filter(it -> it.getX() >= 0 && it.getX() <= 25).sorted(Comparator.comparing(PointVo::getX)).collect(Collectors.toList());
  376. windMap.get(key).setYsjglPoints(vos);
  377. vos = windMap.get(key).getYzyglPoints().stream().filter(it -> it.getX() >= 0 && it.getX() <= 25).sorted(Comparator.comparing(PointVo::getX)).collect(Collectors.toList());
  378. windMap.get(key).setYzyglPoints(vos);
  379. logger.info(key+"曲线拟合完成!");
  380. }
  381. logger.info("曲线拟合完成!");
  382. List<ProEconCurveFittMonthMain> mainls=new ArrayList<>();
  383. for (String key : windMap.keySet()) {
  384. Double modelpower = 1500.0;
  385. if (windturbineCapacity.containsKey(key)) {
  386. modelpower = windturbineCapacity.get(key);
  387. }
  388. //月的上月
  389. List<PointVo> monthLastMonthPoints = new ArrayList<>();
  390. //月的去年同期
  391. List<PointVo> monthLastYearPoints = new ArrayList<>();
  392. //月标准功率
  393. List<PointVo> monthStandardPoints = new ArrayList<>();
  394. //保证功率
  395. List<PointVo> bzglpowerPoints = new ArrayList<>();
  396. if (CacheContext.wtstandardmap.containsKey(key)) {
  397. String standardId = CacheContext.wtstandardmap.get(key);
  398. if (StringUtils.notEmp(standardId)) {
  399. if (windMap.containsKey(key)) {
  400. monthStandardPoints = windMap.get(standardId).getYsjglPoints();
  401. }
  402. }
  403. }
  404. String stringyear = String.valueOf(day_year);
  405. String stringmonth = String.valueOf(day_month);
  406. String stringyear2 = String.valueOf(month_year);
  407. String stringmonth2 = String.valueOf(month_month);
  408. String stringyear3 = String.valueOf(year_year);
  409. String stringmonth3 = String.valueOf(year_month);
  410. //*********************************************月曲线偏差上个月和上一年记录**********************************************************/
  411. QueryWrapper<ProEconWtCurveFittingMonth> queryWrapper = new QueryWrapper<>();
  412. queryWrapper.eq("year",stringyear2).eq("month",stringmonth2).eq("windturbine_id",key);
  413. List<ProEconWtCurveFittingMonth> wcfmls = proEconWtCurveFittingMonthService.list(queryWrapper).stream()
  414. // .filter(i -> i.getWindturbineId().equals(key) &&
  415. // i.getYear().equals(stringyear2) && i.getMonth().equals(stringmonth2))
  416. .sorted(Comparator.comparing(ProEconWtCurveFittingMonth::getSpeed)).collect(Collectors.toList());
  417. monthBuildPoints(wcfmls, monthLastMonthPoints);
  418. QueryWrapper<ProEconWtCurveFittingMonth> queryWrapper2 = new QueryWrapper<>();
  419. queryWrapper2.eq("year",stringyear3).eq("month",stringmonth3).eq("windturbine_id",key);
  420. wcfmls = proEconWtCurveFittingMonthService.list(queryWrapper2).stream()
  421. // .filter(i -> i.getWindturbineId().equals(key) &&
  422. // i.getYear().equals(stringyear3) && i.getMonth().equals(stringmonth3))
  423. .sorted(Comparator.comparing(ProEconWtCurveFittingMonth::getSpeed)).collect(Collectors.toList());
  424. monthBuildPoints(wcfmls, monthLastYearPoints);
  425. //*********************************************月曲线偏差上个月和上一年记录**********************************************************/
  426. if (CacheContext.wtmap.containsKey(key)) {
  427. String modelid = CacheContext.wtmap.get(key).getModelId();
  428. if (StringUtils.notEmp(modelid)) {
  429. //获取模型功率曲线
  430. if (CacheContext.theoreticalPowerMap.containsKey(modelid)) {
  431. for (Double speed : CacheContext.theoreticalPowerMap.get(modelid).keySet()) {
  432. PointVo point = new PointVo();
  433. point.setX(speed);
  434. point.setY(CacheContext.theoreticalPowerMap.get(modelid).get(speed).getEnsurePower());
  435. bzglpowerPoints.add(point);
  436. }
  437. }
  438. }
  439. }
  440. //*********************************************年曲线偏差记录**********************************************************/
  441. //*********************************************当月曲线偏差记录**********************************************************/
  442. QueryWrapper<ProEconCurveFittMonthMain> queryWrapper3 = new QueryWrapper<>();
  443. queryWrapper3.eq("year",stringyear).eq("month",stringmonth).eq("windturbine_id",key);
  444. Optional<ProEconCurveFittMonthMain> cfmmontho = proEconCurveFittMonthMainService.list(queryWrapper3).stream()
  445. // .filter(i -> i.getWindturbineId().equals(key)
  446. // && i.getYear().equals(stringyear) && i.getMonth().equals(stringmonth))
  447. .findFirst();
  448. ProEconCurveFittMonthMain cfmmonth;
  449. if (cfmmontho.isPresent()) {
  450. cfmmonth = cfmmontho.get();
  451. QueryWrapper<ProEconCurveFittMonthMain> wrapper = new QueryWrapper<>();
  452. wrapper.eq("id", cfmmonth.getId());
  453. proEconCurveFittMonthMainService.remove(wrapper);
  454. }
  455. cfmmonth = new ProEconCurveFittMonthMain();
  456. cfmmonth.setWindturbineId(key);
  457. cfmmonth.setYear(String.valueOf(day_year));
  458. cfmmonth.setMonth(String.valueOf(day_month));
  459. //月---实际/最优
  460. cfmmonth.setDeviationRate1(DeviationRateUtil.calculateDeviationRate(windMap.get(key).getYsjglPoints(), windMap.get(key).getYzyglPoints(), modelpower));
  461. //月---实际/保证
  462. cfmmonth.setDeviationRate2(DeviationRateUtil.calculateDeviationRate(windMap.get(key).getYsjglPoints(), bzglpowerPoints, modelpower));
  463. //月---最优/保证
  464. cfmmonth.setDeviationRate3(DeviationRateUtil.calculateDeviationRate(windMap.get(key).getYzyglPoints(), bzglpowerPoints, modelpower));
  465. //月---实际/上月实际
  466. cfmmonth.setMonthDeviationRate(DeviationRateUtil.calculateDeviationRate(windMap.get(key).getYsjglPoints(), monthLastMonthPoints, modelpower));
  467. //月---实际/同期实际
  468. cfmmonth.setYearDeviationRate(DeviationRateUtil.calculateDeviationRate(windMap.get(key).getYsjglPoints(), monthLastYearPoints, modelpower));
  469. //月---实际/标杆实际
  470. cfmmonth.setStandardDeviationRate(DeviationRateUtil.calculateDeviationRate(windMap.get(key).getYsjglPoints(), monthStandardPoints, modelpower));
  471. mainls.add(cfmmonth);
  472. // proEconCurveFittMonthMainService.save(cfmmonth);
  473. //*********************************************当月曲线偏差记录**********************************************************/
  474. List<ProEconCurveFittMonthSub> subls=new ArrayList<>();
  475. subls.add(pLCBuild(key, stringyear, stringmonth, windMap, modelpower, 3, bzglpowerPoints, monthLastMonthPoints, monthLastYearPoints, monthStandardPoints));
  476. subls.add(pLCBuild(key, stringyear, stringmonth, windMap, modelpower, 4, bzglpowerPoints, monthLastMonthPoints, monthLastYearPoints, monthStandardPoints));
  477. subls.add(pLCBuild(key, stringyear, stringmonth, windMap, modelpower, 5, bzglpowerPoints, monthLastMonthPoints, monthLastYearPoints, monthStandardPoints));
  478. subls.add(pLCBuild(key, stringyear, stringmonth, windMap, modelpower, 6, bzglpowerPoints, monthLastMonthPoints, monthLastYearPoints, monthStandardPoints));
  479. subls.add(pLCBuild(key, stringyear, stringmonth, windMap, modelpower, 7, bzglpowerPoints, monthLastMonthPoints, monthLastYearPoints, monthStandardPoints));
  480. subls.add(pLCBuild(key, stringyear, stringmonth, windMap, modelpower, 8, bzglpowerPoints, monthLastMonthPoints, monthLastYearPoints, monthStandardPoints));
  481. subls.add(pLCBuild(key, stringyear, stringmonth, windMap, modelpower, 9, bzglpowerPoints, monthLastMonthPoints, monthLastYearPoints, monthStandardPoints));
  482. subls.add(pLCBuild(key, stringyear, stringmonth, windMap, modelpower, 10, bzglpowerPoints, monthLastMonthPoints, monthLastYearPoints, monthStandardPoints));
  483. subls.add(pLCBuild(key, stringyear, stringmonth, windMap, modelpower, 11, bzglpowerPoints, monthLastMonthPoints, monthLastYearPoints, monthStandardPoints));
  484. subls.add(pLCBuild(key, stringyear, stringmonth, windMap, modelpower, 12, bzglpowerPoints, monthLastMonthPoints, monthLastYearPoints, monthStandardPoints));
  485. subls.add(pLCBuild(key, stringyear, stringmonth, windMap, modelpower, 13, bzglpowerPoints, monthLastMonthPoints, monthLastYearPoints, monthStandardPoints));
  486. List<ProEconCurveFittMonthSub> templs=new ArrayList<>();
  487. for(ProEconCurveFittMonthSub vo:subls)
  488. {
  489. templs.add(vo);
  490. if(templs.size()==1000)
  491. {
  492. proEconCurveFittMonthSubService.saveBatch(templs);
  493. templs=new ArrayList<>();
  494. }
  495. }
  496. if(!templs.isEmpty())
  497. {
  498. proEconCurveFittMonthSubService.saveBatch(templs);
  499. }
  500. // proEconCurveFittMonthSubService.saveBatch(subls);
  501. insertPoints(stringyear, stringmonth, windMap.get(key).getYsjglPoints(), windMap.get(key).getYzyglPoints(), key);
  502. if(type.equals("1"))
  503. {
  504. insertPoints2( windMap.get(key).getYsjglPoints(), windMap.get(key).getYzyglPoints(), key);
  505. }
  506. logger.info(key+"月曲线偏差率完成!");
  507. // logger.info(String.format("{1}:更新sqlserver数据库记录数:{0}", z, new Date()));
  508. }
  509. List<ProEconCurveFittMonthMain> templs=new ArrayList<>();
  510. for(ProEconCurveFittMonthMain vo:mainls)
  511. {
  512. templs.add(vo);
  513. if(templs.size()==1000)
  514. {
  515. proEconCurveFittMonthMainService.saveBatch(templs);
  516. templs=new ArrayList<>();
  517. }
  518. }
  519. if(!templs.isEmpty())
  520. {
  521. proEconCurveFittMonthMainService.saveBatch(templs);
  522. }
  523. // proEconCurveFittMonthMainService.saveBatch(mainls);
  524. logger.info("曲线保存完成!");
  525. }
  526. public void cureFittingYear(Date recordDate,String wpId) throws Exception {
  527. //日期变为昨天
  528. Date end = DateUtils.addDays(DateUtils.truncate(recordDate), 1);
  529. Calendar c = Calendar.getInstance();
  530. c.setTime(recordDate);
  531. int day_year = c.get(Calendar.YEAR);
  532. List<ProBasicEquipment> wtls=new ArrayList<>();
  533. if(StringUtils.notEmp(wpId) && CacheContext.wpwtmap.containsKey(wpId))
  534. {
  535. wtls=CacheContext.wpwtmap.get(wpId);
  536. }else
  537. {
  538. wtls=CacheContext.wtls;
  539. }
  540. StringBuilder sb=new StringBuilder();
  541. for(ProBasicEquipment wt:wtls)
  542. {
  543. sb.append("'").append(wt.getId()).append("',");
  544. }
  545. String wtIds=sb.substring(0,sb.length()-1);
  546. proEconWtCurveFittingYearService.deleteProEconWtCurveFittingFByYear(String.valueOf(day_year), wtIds);
  547. proEconCurveFittYearMainService.deleteProEconCurveFittYearMainFByYear(String.valueOf(day_year), wtIds);
  548. proEconCurveFittYearSubService.deleteProEconCurveFittYearSubFByYear(String.valueOf(day_year), wtIds);
  549. c.set(Calendar.DAY_OF_MONTH, 1);
  550. c.set(Calendar.MONTH, 0);
  551. Date begin = c.getTime();
  552. //去年同期
  553. c.setTime(DateUtils.addYears(begin, -1));
  554. int year_year = c.get(Calendar.YEAR);
  555. Map<String, CureFittingVo> windMap = new HashMap<>();
  556. if (windturbineCapacity == null) {
  557. windturbineCapacity = new HashMap<>();
  558. Map<String, ProEconEquipmentmodel> modelMap = CacheContext.modelMap;
  559. for (ProBasicEquipment windturbine : CacheContext.wtls) {
  560. if (modelMap.containsKey(windturbine.getModelId())) {
  561. windturbineCapacity.put(windturbine.getId(), modelMap.get(windturbine.getModelId()).getPowerProduction());
  562. }
  563. }
  564. }
  565. for (ProBasicEquipment wt : wtls) {
  566. String windturbineId = wt.getId();
  567. if(wt.getWindpowerstationId().contains(WpType.GDC.id))
  568. {
  569. continue;
  570. }
  571. Map<String, ProBasicEquipmentPoint> windturbinetestingpointnewMap = CacheContext.wtpAimap.get(wt.getId());
  572. //设备有功功率
  573. String pointIdGL = windturbinetestingpointnewMap.get(ContantXk.CJ_SSGL).getNemCode();
  574. //设备明细状态
  575. String pointIdZT = windturbinetestingpointnewMap.get(ContantXk.MXZT).getNemCode();
  576. String pointIdFS;
  577. if (wt.getWindpowerstationId().contains(WpType.GDC.id)) { //测风塔70米风速
  578. if (windturbinetestingpointnewMap.containsKey(ContantXk.FCCFTFS70)) {
  579. ProBasicEquipmentPoint point = windturbinetestingpointnewMap.get(ContantXk.FCCFTFS70);
  580. if (StringUtils.notEmp(point.getNemCode()) && !point.getNemCode().equals(initialcode)) {
  581. pointIdFS = windturbinetestingpointnewMap.get(ContantXk.FCCFTFS70).getNemCode();
  582. } else {
  583. pointIdFS = windturbinetestingpointnewMap.get(ContantXk.CJ_SSFS).getNemCode();
  584. }
  585. } else {
  586. pointIdFS = windturbinetestingpointnewMap.get(ContantXk.CJ_SSFS).getNemCode();
  587. }
  588. } else { //设备风速
  589. pointIdFS = windturbinetestingpointnewMap.get(ContantXk.CJ_SSFS).getNemCode();
  590. }
  591. CureFittingVo item = new CureFittingVo();
  592. item.setPointIdFS(pointIdFS);
  593. item.setPointIdZT(pointIdZT);
  594. item.setPointIdGL(pointIdGL);
  595. //获取标杆风机编号
  596. if (CacheContext.wtstandardmap.containsKey(wt.getId())) {
  597. item.setStandardId(CacheContext.wtstandardmap.get(wt.getId()));
  598. } else {
  599. item.setStandardId(wt.getId());
  600. }
  601. windMap.put(windturbineId, item);
  602. }
  603. for (String key : windMap.keySet()) {
  604. //初始化集合
  605. windMap.get(key).setYsjglPoints(new ArrayList<>());
  606. windMap.get(key).setYzyglPoints(new ArrayList<>());
  607. windMap.get(key).setRsjglPoints(new ArrayList<>());
  608. windMap.get(key).setRzyglPoints(new ArrayList<>());
  609. windMap.get(key).setNsjglPoints(new ArrayList<>());
  610. windMap.get(key).setNzyglPoints(new ArrayList<>());
  611. // if (windMap.get(key).getPointIdGL() == null || windMap.get(key).getPointIdFS() == null || windMap.get(key).getPointIdZT() == null) {
  612. // logger.info(key);
  613. // continue;
  614. // }
  615. //拟合年功率曲线
  616. // curveFittingBuilder(begin, end, dimension, scale, windMap.get(key).getPointIdGL(), windMap.get(key).getPointIdFS(), windMap.get(key).getPointIdZT(), windMap.get(key).getNsjglPoints(), windMap.get(key).getNzyglPoints(), key);
  617. QueryWrapper<ProEconWtPowerCurveFitting> queryWrapper = new QueryWrapper<>();
  618. queryWrapper.eq("windturbine_id",key);
  619. List<ProEconWtPowerCurveFitting> wtpowerls= proEconWtPowerCurveFittingService.list(queryWrapper)
  620. .stream()
  621. // .filter(i->i.getWindturbineId().equals(key))
  622. .sorted(Comparator.comparing(ProEconWtPowerCurveFitting::getSpeed)).collect(Collectors.toList());
  623. List<PointVo> zyglls=new ArrayList<>();
  624. List<PointVo> sjglls=new ArrayList<>();
  625. if(!wtpowerls.isEmpty())
  626. {
  627. for(ProEconWtPowerCurveFitting wtp:wtpowerls)
  628. {
  629. PointVo zyvo=new PointVo();
  630. zyvo.setX(wtp.getSpeed());
  631. zyvo.setY(wtp.getOptimalPower());
  632. zyglls.add(zyvo);
  633. PointVo sjvo=new PointVo();
  634. sjvo.setX(wtp.getSpeed());
  635. sjvo.setY(wtp.getActualPower());
  636. sjglls.add(sjvo);
  637. }
  638. }
  639. // List<PointVo> vos = windMap.get(key).getNsjglPoints().stream().filter(it -> it.getX() >= 0 && it.getX() <= 25).sorted(Comparator.comparing(PointVo::getX)).collect(Collectors.toList());
  640. // windMap.get(key).setNsjglPoints(vos);
  641. // vos = windMap.get(key).getNzyglPoints().stream().filter(it -> it.getX() >= 0 && it.getX() <= 25).sorted(Comparator.comparing(PointVo::getX)).collect(Collectors.toList());
  642. // windMap.get(key).setNzyglPoints(vos);
  643. windMap.get(key).setNsjglPoints(sjglls);
  644. windMap.get(key).setNzyglPoints(zyglls);
  645. }
  646. List<ProEconCurveFittYearMain> mainls=new ArrayList<>();
  647. for (String key : windMap.keySet()) {
  648. Double modelpower = 1500.0;
  649. if (windturbineCapacity.containsKey(key)) {
  650. modelpower = windturbineCapacity.get(key);
  651. }
  652. //年的上月
  653. List<PointVo> yearLastMonthPoints = new ArrayList<>();
  654. //年的去年同期
  655. List<PointVo> yearLastYearPoints;
  656. //年标准功率
  657. List<PointVo> yearStandardPoints = new ArrayList<>();
  658. //日的昨天
  659. //保证功率
  660. List<PointVo> bzglpowerPoints = new ArrayList<>();
  661. if (CacheContext.wtstandardmap.containsKey(key)) {
  662. String standardId = CacheContext.wtstandardmap.get(key);
  663. if (StringUtils.notEmp(standardId)) {
  664. if (windMap.containsKey(key)) {
  665. yearStandardPoints = windMap.get(standardId).getNsjglPoints();
  666. }
  667. }
  668. }
  669. String stringyear = String.valueOf(day_year);
  670. String stringyear3 = String.valueOf(year_year);
  671. // /*********************************************年曲线偏差上个月和上一年记录**********************************************************/
  672. QueryWrapper<ProEconWtCurveFittingYear> queryWrapper = new QueryWrapper<>();
  673. queryWrapper.eq("year",stringyear3).eq("windturbine_id",key);
  674. List<ProEconWtCurveFittingYear> wcfyls = proEconWtCurveFittingYearService.list(queryWrapper).stream()
  675. // .filter(i -> i.getWindturbineId().equals(key) &&
  676. // i.getYear().equals(stringyear3))
  677. .sorted(Comparator.comparing(ProEconWtCurveFittingYear::getSpeed)).collect(Collectors.toList());
  678. //与轶总的原始代码对比不一致,新增代码修改测试
  679. yearBuildPoints(wcfyls, yearLastMonthPoints);
  680. yearLastYearPoints = yearLastMonthPoints;
  681. //*********************************************年曲线偏差上个月和上一年记录**********************************************************/
  682. if (CacheContext.wtmap.containsKey(key)) {
  683. String modelid = CacheContext.wtmap.get(key).getModelId();
  684. if (StringUtils.notEmp(modelid)) {
  685. //获取模型功率曲线
  686. if (CacheContext.theoreticalPowerMap.containsKey(modelid)) {
  687. for (Double speed : CacheContext.theoreticalPowerMap.get(modelid).keySet()) {
  688. PointVo point = new PointVo();
  689. point.setX(speed);
  690. point.setY(CacheContext.theoreticalPowerMap.get(modelid).get(speed).getEnsurePower());
  691. bzglpowerPoints.add(point);
  692. }
  693. }
  694. }
  695. }
  696. //*********************************************年曲线偏差记录**********************************************************/
  697. //*********************************************当年曲线偏差记录**********************************************************/
  698. QueryWrapper<ProEconCurveFittYearMain> queryWrapper2 = new QueryWrapper<>();
  699. queryWrapper2.eq("year",stringyear).eq("windturbine_id",key);
  700. Optional<ProEconCurveFittYearMain> cfmyearo = proEconCurveFittYearMainService.list(queryWrapper2)
  701. .stream()
  702. // .filter(i -> i.getWindturbineId().equals(key)
  703. // && i.getYear().equals(stringyear))
  704. .findFirst();
  705. ProEconCurveFittYearMain cfmyear;
  706. if (cfmyearo.isPresent()) {
  707. cfmyear = cfmyearo.get();
  708. QueryWrapper<ProEconCurveFittMonthMain> wrapper = new QueryWrapper<>();
  709. wrapper.eq("id", cfmyear.getId());
  710. proEconCurveFittMonthMainService.remove(wrapper);
  711. }
  712. cfmyear = new ProEconCurveFittYearMain();
  713. cfmyear.setWindturbineId(key);
  714. cfmyear.setYear(String.valueOf(day_year));
  715. //年---实际/最优
  716. cfmyear.setDeviationRate1(DeviationRateUtil.calculateDeviationRate(windMap.get(key).getNsjglPoints(), windMap.get(key).getNzyglPoints(), modelpower));
  717. //年---实际/保证
  718. cfmyear.setDeviationRate2(DeviationRateUtil.calculateDeviationRate(windMap.get(key).getNsjglPoints(), bzglpowerPoints, modelpower));
  719. //年---最优/保证
  720. cfmyear.setDeviationRate3(DeviationRateUtil.calculateDeviationRate(windMap.get(key).getNzyglPoints(), bzglpowerPoints, modelpower));
  721. //年---实际/上月实际
  722. cfmyear.setMonthDeviationRate(DeviationRateUtil.calculateDeviationRate(windMap.get(key).getNsjglPoints(), yearLastMonthPoints, modelpower));
  723. //年---实际/同期实际
  724. cfmyear.setYearDeviationRate(DeviationRateUtil.calculateDeviationRate(windMap.get(key).getNsjglPoints(), yearLastYearPoints, modelpower));
  725. //年---实际/标杆实际
  726. cfmyear.setStandardDeviationRate(DeviationRateUtil.calculateDeviationRate(windMap.get(key).getNsjglPoints(), yearStandardPoints, modelpower));
  727. mainls.add(cfmyear);
  728. // proEconCurveFittYearMainService.save(cfmyear);
  729. //*********************************************当年曲线偏差记录**********************************************************/
  730. List<ProEconCurveFittYearSub> subls=new ArrayList<>();
  731. subls.add(pLCBuild(key, stringyear, windMap, modelpower, 3, bzglpowerPoints, yearLastMonthPoints, yearLastYearPoints, yearStandardPoints));
  732. subls.add(pLCBuild(key, stringyear, windMap, modelpower, 4, bzglpowerPoints, yearLastMonthPoints, yearLastYearPoints, yearStandardPoints));
  733. subls.add(pLCBuild(key, stringyear, windMap, modelpower, 5, bzglpowerPoints, yearLastMonthPoints, yearLastYearPoints, yearStandardPoints));
  734. subls.add(pLCBuild(key, stringyear, windMap, modelpower, 6, bzglpowerPoints, yearLastMonthPoints, yearLastYearPoints, yearStandardPoints));
  735. subls.add(pLCBuild(key, stringyear, windMap, modelpower, 7, bzglpowerPoints, yearLastMonthPoints, yearLastYearPoints, yearStandardPoints));
  736. subls.add(pLCBuild(key, stringyear, windMap, modelpower, 8, bzglpowerPoints, yearLastMonthPoints, yearLastYearPoints, yearStandardPoints));
  737. subls.add(pLCBuild(key, stringyear, windMap, modelpower, 9, bzglpowerPoints, yearLastMonthPoints, yearLastYearPoints, yearStandardPoints));
  738. subls.add(pLCBuild(key, stringyear, windMap, modelpower, 10, bzglpowerPoints, yearLastMonthPoints, yearLastYearPoints, yearStandardPoints));
  739. subls.add(pLCBuild(key, stringyear, windMap, modelpower, 11, bzglpowerPoints, yearLastMonthPoints, yearLastYearPoints, yearStandardPoints));
  740. subls.add(pLCBuild(key, stringyear, windMap, modelpower, 12, bzglpowerPoints, yearLastMonthPoints, yearLastYearPoints, yearStandardPoints));
  741. subls.add(pLCBuild(key, stringyear, windMap, modelpower, 13, bzglpowerPoints, yearLastMonthPoints, yearLastYearPoints, yearStandardPoints));
  742. List<ProEconCurveFittYearSub> templs=new ArrayList<>();
  743. for(ProEconCurveFittYearSub vo:subls)
  744. {
  745. templs.add(vo);
  746. if(templs.size()==1000)
  747. {
  748. proEconCurveFittYearSubService.saveBatch(templs);
  749. templs=new ArrayList<>();
  750. }
  751. }
  752. if(!templs.isEmpty())
  753. {
  754. proEconCurveFittYearSubService.saveBatch(templs);
  755. }
  756. // proEconCurveFittYearSubService.saveBatch(subls);
  757. insertPoints(stringyear, windMap.get(key).getNsjglPoints(), windMap.get(key).getNzyglPoints(), key);
  758. logger.info(key);
  759. //
  760. // logger.info(String.format("{1}:更新sqlserver数据库记录数:{0}", z, new Date()));
  761. }
  762. List<ProEconCurveFittYearMain> templs=new ArrayList<>();
  763. for(ProEconCurveFittYearMain vo:mainls)
  764. {
  765. templs.add(vo);
  766. if(templs.size()==1000)
  767. {
  768. proEconCurveFittYearMainService.saveBatch(templs);
  769. templs=new ArrayList<>();
  770. }
  771. }
  772. if(!templs.isEmpty())
  773. {
  774. proEconCurveFittYearMainService.saveBatch(templs);
  775. }
  776. // proEconCurveFittYearMainService.saveBatch(mainls);
  777. }
  778. public ProEconCurveFittingSub pLCBuild(String key, Date current, Map<String, CureFittingVo> windMap, Double modelpower, double speed,
  779. List<PointVo> bzglpowerPoints, List<PointVo> lastMonthPoints, List<PointVo> lastYearPoints, List<PointVo> lastStandardPoints
  780. ) {
  781. // String speedStr = String.valueOf(speed);
  782. //*********************************************当日曲线偏差子表记录**********************************************************/
  783. QueryWrapper<ProEconCurveFittingSub> queryWrapper2 = new QueryWrapper<>();
  784. queryWrapper2.eq("record_date",current).eq("speed",speed).eq("windturbine_id",key);
  785. Optional<ProEconCurveFittingSub> cfmso = proEconCurveFittingSubService.list(queryWrapper2)
  786. .stream()
  787. // .filter(i -> i.getWindturbineId().equals(key)
  788. // && i.getRecordDate().compareTo(current) == 0 && i.getSpeed().equals(speedStr))
  789. .findFirst();
  790. ProEconCurveFittingSub cfms;
  791. if (cfmso.isPresent()) {
  792. cfms = cfmso.get();
  793. QueryWrapper<ProEconCurveFittingSub> wrapper = new QueryWrapper<>();
  794. wrapper.eq("id", cfms.getId());
  795. proEconCurveFittingSubService.remove(wrapper);
  796. }
  797. cfms = new ProEconCurveFittingSub();
  798. cfms.setWindturbineId(key);
  799. cfms.setSpeed(speed);
  800. cfms.setRecordDate(DateUtils.truncate(current));
  801. cfms.setDeviationRate1(DeviationRateUtil.calculateDeviationRate(windMap.get(key).getRsjglPoints(), windMap.get(key).getRzyglPoints(), modelpower, speed));
  802. //日---实际/保证
  803. cfms.setDeviationRate2(DeviationRateUtil.calculateDeviationRate(windMap.get(key).getRsjglPoints(), bzglpowerPoints, modelpower, speed));
  804. //日---最优/保证
  805. cfms.setDeviationRate3(DeviationRateUtil.calculateDeviationRate(windMap.get(key).getRzyglPoints(), bzglpowerPoints, modelpower, speed));
  806. //日---实际/上日实际
  807. cfms.setMonthDeviationRate(DeviationRateUtil.calculateDeviationRate(windMap.get(key).getRsjglPoints(), lastMonthPoints, modelpower, speed));
  808. //日---实际/同期实际
  809. cfms.setYearDeviationRate(DeviationRateUtil.calculateDeviationRate(windMap.get(key).getRsjglPoints(), lastYearPoints, modelpower, speed));
  810. //日---实际/标杆实际
  811. cfms.setStandardDeviationRate(DeviationRateUtil.calculateDeviationRate(windMap.get(key).getRsjglPoints(), lastStandardPoints, modelpower, speed));
  812. return cfms;
  813. //proEconCurveFittingSubService.save(cfms);
  814. //*********************************************当日曲线偏差子表记录**********************************************************/
  815. }
  816. public ProEconCurveFittMonthSub pLCBuild(String key, String stringyear, String stringmonth, Map<String, CureFittingVo> windMap, Double modelpower, double speed,
  817. List<PointVo> bzglpowerPoints, List<PointVo> lastMonthPoints, List<PointVo> lastYearPoints, List<PointVo> lastStandardPoints
  818. ) {
  819. // String speedStr = String.valueOf(speed);
  820. //*********************************************当月曲线偏差子表记录**********************************************************/
  821. QueryWrapper<ProEconCurveFittMonthSub> queryWrapper2 = new QueryWrapper<>();
  822. queryWrapper2.eq("year",stringyear).eq("month",stringmonth).eq("speed",speed).eq("windturbine_id",key);
  823. Optional<ProEconCurveFittMonthSub> cfmsmontho = proEconCurveFittMonthSubService.list(queryWrapper2).stream()
  824. // .filter(i -> i.getWindturbineId().equals(key)
  825. // && i.getYear().equals(stringyear) && i.getMonth().equals(stringmonth) && i.getSpeed().equals(speedStr))
  826. .findFirst();
  827. ProEconCurveFittMonthSub cfmsmonth;
  828. if (cfmsmontho.isPresent()) {
  829. cfmsmonth = cfmsmontho.get();
  830. QueryWrapper<ProEconCurveFittMonthSub> wrapper = new QueryWrapper<>();
  831. wrapper.eq("id", cfmsmonth.getId());
  832. proEconCurveFittMonthSubService.remove(wrapper);
  833. }
  834. cfmsmonth = new ProEconCurveFittMonthSub();
  835. cfmsmonth.setWindturbineId(key);
  836. cfmsmonth.setYear(stringyear);
  837. cfmsmonth.setMonth(stringmonth);
  838. cfmsmonth.setSpeed(speed);
  839. //月---实际/最优
  840. cfmsmonth.setDeviationRate1(DeviationRateUtil.calculateDeviationRate(windMap.get(key).getYsjglPoints(), windMap.get(key).getYzyglPoints(), modelpower, speed));
  841. //月---实际/保证
  842. cfmsmonth.setDeviationRate2(DeviationRateUtil.calculateDeviationRate(windMap.get(key).getYsjglPoints(), bzglpowerPoints, modelpower, speed));
  843. //月---最优/保证
  844. cfmsmonth.setDeviationRate3(DeviationRateUtil.calculateDeviationRate(windMap.get(key).getYzyglPoints(), bzglpowerPoints, modelpower, speed));
  845. //月---实际/上月实际
  846. cfmsmonth.setMonthDeviationRate(DeviationRateUtil.calculateDeviationRate(windMap.get(key).getYsjglPoints(), lastMonthPoints, modelpower, speed));
  847. //月---实际/同期实际
  848. cfmsmonth.setYearDeviationRate(DeviationRateUtil.calculateDeviationRate(windMap.get(key).getYsjglPoints(), lastYearPoints, modelpower, speed));
  849. //月---实际/标杆实际
  850. cfmsmonth.setStandardDeviationRate(DeviationRateUtil.calculateDeviationRate(windMap.get(key).getYsjglPoints(), lastStandardPoints, modelpower, speed));
  851. // proEconCurveFittMonthSubService.save(cfmsmonth);
  852. return cfmsmonth;
  853. //*********************************************当月曲线偏差子表记录**********************************************************/
  854. }
  855. public ProEconCurveFittYearSub pLCBuild(String key, String stringyear, Map<String, CureFittingVo> windMap, Double modelpower, double speed,
  856. List<PointVo> bzglpowerPoints, List<PointVo> lastMonthPoints, List<PointVo> lastYearPoints, List<PointVo> lastStandardPoints
  857. ) {
  858. // String speedStr = String.valueOf(speed);
  859. //*********************************************当年曲线偏差子表记录**********************************************************/
  860. QueryWrapper<ProEconCurveFittYearSub> queryWrapper = new QueryWrapper<>();
  861. queryWrapper.eq("year",stringyear).eq("speed",speed).eq("windturbine_id",key);
  862. Optional<ProEconCurveFittYearSub> cfmsyearo = proEconCurveFittYearSubService.list(queryWrapper).stream()
  863. // .filter(i -> i.getWindturbineId().equals(key)
  864. // && i.getYear().equals(stringyear) && i.getSpeed().equals(speedStr))
  865. .findFirst();
  866. ProEconCurveFittYearSub cfmsyear;
  867. if (cfmsyearo.isPresent()) {
  868. cfmsyear = cfmsyearo.get();
  869. QueryWrapper<ProEconCurveFittYearSub> wrapper = new QueryWrapper<>();
  870. wrapper.eq("id", cfmsyear.getId());
  871. proEconCurveFittYearSubService.remove(wrapper);
  872. }
  873. cfmsyear = new ProEconCurveFittYearSub();
  874. cfmsyear.setWindturbineId(key);
  875. cfmsyear.setYear(stringyear);
  876. cfmsyear.setSpeed(speed);
  877. // proEconCurveFittYearSubService.save(cfmsyear);
  878. //年---实际/最优
  879. cfmsyear.setDeviationRate1(DeviationRateUtil.calculateDeviationRate(windMap.get(key).getNsjglPoints(), windMap.get(key).getNzyglPoints(), modelpower, speed));
  880. //年---实际/保证
  881. cfmsyear.setDeviationRate2(DeviationRateUtil.calculateDeviationRate(windMap.get(key).getNsjglPoints(), bzglpowerPoints, modelpower, speed));
  882. //年---最优/保证
  883. cfmsyear.setDeviationRate3(DeviationRateUtil.calculateDeviationRate(windMap.get(key).getNzyglPoints(), bzglpowerPoints, modelpower, speed));
  884. //年---实际/上月实际
  885. cfmsyear.setMonthDeviationRate(DeviationRateUtil.calculateDeviationRate(windMap.get(key).getNsjglPoints(), lastMonthPoints, modelpower, speed));
  886. //年---实际/同期实际
  887. cfmsyear.setYearDeviationRate(DeviationRateUtil.calculateDeviationRate(windMap.get(key).getNsjglPoints(), lastYearPoints, modelpower, speed));
  888. //年---实际/标杆实际
  889. cfmsyear.setStandardDeviationRate(DeviationRateUtil.calculateDeviationRate(windMap.get(key).getNsjglPoints(), lastStandardPoints, modelpower, speed));
  890. // proEconCurveFittYearSubService.save(cfmsyear);
  891. return cfmsyear;
  892. //*********************************************当年曲线偏差子表记录**********************************************************/
  893. }
  894. private void insertPoints(Date current, List<PointVo> sjglls, List<PointVo> zyglls, String windturbineId) {
  895. //*********************************************当日曲线偏差记录**********************************************************/
  896. // List<Long> wtcfidls = proEconWtCurveFittingService.list().stream().filter(i -> i.getWindturbineId().equals(windturbineId) &&
  897. // i.getRecordDate().compareTo(current) == 0).map(ProEconWtCurveFitting::getId).collect(Collectors.toList());
  898. //
  899. //
  900. // for (int i = 0; i < wtcfidls.size(); i++) {
  901. // proEconWtCurveFittingService.removeByIds(wtcfidls);
  902. // }
  903. List<ProEconWtCurveFitting> wtcfls=new ArrayList<>();
  904. if (sjglls.size() == zyglls.size()) {
  905. for (int i = 0; i < sjglls.size(); i++) {
  906. ProEconWtCurveFitting item = new ProEconWtCurveFitting();
  907. item.setWindturbineId(windturbineId);
  908. if (CacheContext.wtmap.containsKey(windturbineId)) {
  909. ProBasicEquipment wt = CacheContext.wtmap.get(windturbineId);
  910. if (wt.getWindpowerstationId().contains(WpType.GDC.id)) {
  911. continue;
  912. // item.SPEED = Double.Truncate(pointsF2[i].X);
  913. } else {
  914. // boolean l = String.valueOf(sjglls.get(i).getX()).contains(".");
  915. // if (l) {
  916. // continue;
  917. // }
  918. // item.setSpeed(sjglls.get(i).getX());
  919. item.setSpeed(StringUtils.round(sjglls.get(i).getX(),2));
  920. }
  921. // item.setActualPower(sjglls.get(i).getY());
  922. // item.setOptimalPower(zyglls.get(i).getY());
  923. item.setActualPower(StringUtils.round(sjglls.get(i).getY(),2));
  924. item.setOptimalPower(StringUtils.round(zyglls.get(i).getY(),2));
  925. item.setRecordDate(DateUtils.truncate(current));
  926. wtcfls.add(item);
  927. //proEconWtCurveFittingService.save(item);
  928. }
  929. }
  930. } else {
  931. logger.warn(String.format("下标不一致的风机编号:{0},实际功率:{1},最有功率:{2}", windturbineId, sjglls.size(), zyglls.size()));
  932. for (int i = 0; i < sjglls.size(); i++) {
  933. ProEconWtCurveFitting item = new ProEconWtCurveFitting();
  934. item.setWindturbineId(windturbineId);
  935. if (CacheContext.wtmap.containsKey(windturbineId)) {
  936. ProBasicEquipment wt = CacheContext.wtmap.get(windturbineId);
  937. if (wt.getWindpowerstationId().contains(WpType.GDC.id)) {
  938. continue;
  939. //item.SPEED = Double.Truncate(pointsF2[i].X);
  940. } else {
  941. boolean l = String.valueOf(sjglls.get(i).getX()).contains(".");
  942. if (l) {
  943. continue;
  944. }
  945. // item.setSpeed(sjglls.get(i).getX());
  946. item.setSpeed(StringUtils.round(sjglls.get(i).getX(),2));
  947. }
  948. int finalI = i;
  949. OptionalDouble op = zyglls.stream().filter(x -> Objects.equals(x.getX(), sjglls.get(finalI).getX())).mapToDouble(PointVo::getY).findFirst();
  950. if (op.isPresent()) {
  951. item.setOptimalPower(op.getAsDouble());
  952. } else {
  953. item.setOptimalPower(0.0);
  954. }
  955. // item.setActualPower(sjglls.get(i).getY());
  956. item.setActualPower(StringUtils.round(sjglls.get(i).getY(),2));
  957. item.setOptimalPower(StringUtils.round(zyglls.get(i).getY(),2));
  958. item.setRecordDate(current);
  959. wtcfls.add(item);
  960. //proEconWtCurveFittingService.save(item);
  961. }
  962. }
  963. //*********************************************当日曲线偏差记录**********************************************************/
  964. }
  965. List<ProEconWtCurveFitting> templs=new ArrayList<>();
  966. for(ProEconWtCurveFitting vo:wtcfls)
  967. {
  968. templs.add(vo);
  969. if(templs.size()==1000)
  970. {
  971. proEconWtCurveFittingService.saveBatch(templs);
  972. templs=new ArrayList<>();
  973. }
  974. }
  975. if(!templs.isEmpty())
  976. {
  977. proEconWtCurveFittingService.saveBatch(templs);
  978. }
  979. // proEconWtCurveFittingService.saveBatch(wtcfls);
  980. if(!wtcfls.isEmpty())
  981. {
  982. redisService.select(9);
  983. String s = JSONObject.toJSONString(wtcfls);
  984. redisService.set(CurveType.dayCurve.id+"_"+windturbineId, s);
  985. }
  986. }
  987. private void insertPoints(String year, String month, List<PointVo> sjglls, List<PointVo> zyglls, String windturbineId) {
  988. //*********************************************当月曲线偏差记录**********************************************************/
  989. // List<Long> wtcfmmonthidls = proEconWtCurveFittingMonthService.list().stream().filter(i -> i.getWindturbineId().equals(windturbineId) &&
  990. // i.getYear().equals(year) && i.getMonth().equals(month)).map(ProEconWtCurveFittingMonth::getId).collect(Collectors.toList());
  991. //
  992. //
  993. // for (int i = 0; i < wtcfmmonthidls.size(); i++) {
  994. // proEconWtCurveFittingMonthService.removeByIds(wtcfmmonthidls);
  995. // }
  996. List<ProEconWtCurveFittingMonth> wtcfls=new ArrayList<>();
  997. if (sjglls.size() == zyglls.size()) {
  998. for (int i = 0; i < sjglls.size(); i++) {
  999. ProEconWtCurveFittingMonth item = new ProEconWtCurveFittingMonth();
  1000. item.setWindturbineId(windturbineId);
  1001. if (CacheContext.wtmap.containsKey(windturbineId)) {
  1002. ProBasicEquipment wt = CacheContext.wtmap.get(windturbineId);
  1003. if (wt.getWindpowerstationId().contains(WpType.GDC.id)) {
  1004. continue;
  1005. // item.SPEED = Double.Truncate(pointsF1[i].X);
  1006. } else {
  1007. //item.setSpeed(sjglls.get(i).getX());
  1008. item.setSpeed(StringUtils.round(sjglls.get(i).getX(),2));
  1009. }
  1010. // item.setActualPower(sjglls.get(i).getY());
  1011. // item.setOptimalPower(zyglls.get(i).getY());
  1012. item.setActualPower(StringUtils.round(sjglls.get(i).getY(),2));
  1013. item.setOptimalPower(StringUtils.round(zyglls.get(i).getY(),2));
  1014. item.setYear(String.valueOf(year));
  1015. item.setMonth(String.valueOf(month));
  1016. wtcfls.add(item);
  1017. // proEconWtCurveFittingMonthService.save(item);
  1018. }
  1019. }
  1020. } else {
  1021. logger.warn(String.format("下标不一致的风机编号:{0},实际功率:{1},最有功率:{2}", windturbineId, sjglls.size(), zyglls.size()));
  1022. if(!sjglls.isEmpty() && !zyglls.isEmpty() && sjglls.size() == zyglls.size())
  1023. {
  1024. for (int i = 0; i < sjglls.size(); i++) {
  1025. ProEconWtCurveFittingMonth item = new ProEconWtCurveFittingMonth();
  1026. item.setWindturbineId(windturbineId);
  1027. if (CacheContext.wtmap.containsKey(windturbineId)) {
  1028. ProBasicEquipment wt = CacheContext.wtmap.get(windturbineId);
  1029. if (wt.getWindpowerstationId().contains(WpType.GDC.id)) {
  1030. continue;
  1031. //item.SPEED = Double.Truncate(pointsF1[i].X);
  1032. } else {
  1033. // item.setSpeed(sjglls.get(i).getX());
  1034. item.setSpeed(StringUtils.round(sjglls.get(i).getX(),2));
  1035. }
  1036. // item.setActualPower(sjglls.get(i).getY());
  1037. int finalI = i;
  1038. OptionalDouble op = zyglls.stream().filter(x -> Objects.equals(x.getX(), sjglls.get(finalI).getX())).mapToDouble(PointVo::getY).findFirst();
  1039. if (op.isPresent()) {
  1040. item.setOptimalPower(op.getAsDouble());
  1041. } else {
  1042. item.setOptimalPower(0.0);
  1043. }
  1044. item.setActualPower(StringUtils.round(sjglls.get(i).getY(),2));
  1045. item.setOptimalPower(StringUtils.round(zyglls.get(i).getY(),2));
  1046. item.setYear(String.valueOf(year));
  1047. item.setMonth(String.valueOf(month));
  1048. wtcfls.add(item);
  1049. //proEconWtCurveFittingMonthService.save(item);
  1050. }
  1051. }
  1052. }
  1053. }
  1054. //*********************************************当月曲线偏差记录**********************************************************/
  1055. List<ProEconWtCurveFittingMonth> templs=new ArrayList<>();
  1056. for(ProEconWtCurveFittingMonth vo:wtcfls)
  1057. {
  1058. templs.add(vo);
  1059. if(templs.size()==1000)
  1060. {
  1061. proEconWtCurveFittingMonthService.saveBatch(templs);
  1062. templs=new ArrayList<>();
  1063. }
  1064. }
  1065. if(!templs.isEmpty())
  1066. {
  1067. proEconWtCurveFittingMonthService.saveBatch(templs);
  1068. }
  1069. // proEconWtCurveFittingMonthService.saveBatch(wtcfls);
  1070. if(!wtcfls.isEmpty())
  1071. {
  1072. redisService.select(9);
  1073. String s = JSONObject.toJSONString(wtcfls);
  1074. redisService.set(CurveType.monthCurve.id+"_"+windturbineId, s);
  1075. }
  1076. }
  1077. private void insertPoints(String year, List<PointVo> sjglls, List<PointVo> zyglls, String windturbineId) {
  1078. //*********************************************当年曲线偏差记录**********************************************************/
  1079. // List<Long> wtcfmyearidls = proEconWtCurveFittingYearService.list().stream().filter(i -> i.getWindturbineId().equals(windturbineId) &&
  1080. // i.getYear().equals(year)).map(ProEconWtCurveFittingYear::getId).collect(Collectors.toList());
  1081. //
  1082. // for (int i = 0; i < wtcfmyearidls.size(); i++) {
  1083. // proEconWtCurveFittingYearService.removeByIds(wtcfmyearidls);
  1084. // }
  1085. List<ProEconWtCurveFittingYear> wtcfls=new ArrayList<>();
  1086. if (sjglls.size() == zyglls.size()) {
  1087. for (int i = 0; i < sjglls.size(); i++) {
  1088. ProEconWtCurveFittingYear item = new ProEconWtCurveFittingYear();
  1089. item.setWindturbineId(windturbineId);
  1090. if (CacheContext.wtmap.containsKey(windturbineId)) {
  1091. ProBasicEquipment wt = CacheContext.wtmap.get(windturbineId);
  1092. if (wt.getWindpowerstationId().contains(WpType.GDC.id)) {
  1093. continue;
  1094. // item.SPEED = Double.Truncate(pointsF1[i].X);
  1095. } else {
  1096. // item.setSpeed(sjglls.get(i).getX());
  1097. item.setSpeed(StringUtils.round(sjglls.get(i).getX(),2));
  1098. }
  1099. // item.setActualPower(sjglls.get(i).getY());
  1100. // item.setOptimalPower(zyglls.get(i).getY());
  1101. item.setActualPower(StringUtils.round(sjglls.get(i).getY(),2));
  1102. item.setOptimalPower(StringUtils.round(zyglls.get(i).getY(),2));
  1103. item.setYear(String.valueOf(year));
  1104. wtcfls.add(item);
  1105. // proEconWtCurveFittingYearService.save(item);
  1106. }
  1107. }
  1108. } else {
  1109. logger.warn(String.format("下标不一致的风机编号:{0},实际功率:{1},最有功率:{2}", windturbineId, sjglls.size(), zyglls.size()));
  1110. for (int i = 0; i < sjglls.size(); i++) {
  1111. ProEconWtCurveFittingYear item = new ProEconWtCurveFittingYear();
  1112. item.setWindturbineId(windturbineId);
  1113. if (CacheContext.wtmap.containsKey(windturbineId)) {
  1114. ProBasicEquipment wt = CacheContext.wtmap.get(windturbineId);
  1115. if (wt.getWindpowerstationId().contains(WpType.GDC.id)) {
  1116. continue;
  1117. //item.SPEED = Double.Truncate(pointsF1[i].X);
  1118. } else {
  1119. // item.setSpeed(sjglls.get(i).getX());
  1120. item.setSpeed(StringUtils.round(sjglls.get(i).getX(),2));
  1121. }
  1122. // item.setActualPower(sjglls.get(i).getY());
  1123. int finalI = i;
  1124. OptionalDouble op = zyglls.stream().filter(x -> Objects.equals(x.getX(), sjglls.get(finalI).getX())).mapToDouble(PointVo::getY).findFirst();
  1125. if (op.isPresent()) {
  1126. item.setOptimalPower(op.getAsDouble());
  1127. } else {
  1128. item.setOptimalPower(0.0);
  1129. }
  1130. item.setActualPower(StringUtils.round(sjglls.get(i).getY(),2));
  1131. item.setOptimalPower(StringUtils.round(zyglls.get(i).getY(),2));
  1132. item.setYear(String.valueOf(year));
  1133. wtcfls.add(item);
  1134. //proEconWtCurveFittingYearService.save(item);
  1135. }
  1136. }
  1137. }
  1138. //*********************************************当年曲线偏差记录**********************************************************/
  1139. List<ProEconWtCurveFittingYear> templs=new ArrayList<>();
  1140. for(ProEconWtCurveFittingYear vo:wtcfls)
  1141. {
  1142. templs.add(vo);
  1143. if(templs.size()==1000)
  1144. {
  1145. proEconWtCurveFittingYearService.saveBatch(templs);
  1146. templs=new ArrayList<>();
  1147. }
  1148. }
  1149. if(!templs.isEmpty())
  1150. {
  1151. proEconWtCurveFittingYearService.saveBatch(templs);
  1152. }
  1153. // proEconWtCurveFittingYearService.saveBatch(wtcfls);
  1154. if(!wtcfls.isEmpty())
  1155. {
  1156. redisService.select(9);
  1157. String s = JSONObject.toJSONString(wtcfls);
  1158. redisService.set(CurveType.yearCurve.id+"_"+windturbineId, s);
  1159. }
  1160. }
  1161. private void insertPoints2(List<PointVo> monthSjglls, List<PointVo> monthZyglls, String windturbineId) {
  1162. if(!monthSjglls.isEmpty() && !monthZyglls.isEmpty())
  1163. {
  1164. QueryWrapper<ProEconWtPowerCurveFitting> queryWrapper = new QueryWrapper<>();
  1165. if (com.gyee.common.model.StringUtils.isNotEmpty(windturbineId)){
  1166. queryWrapper.eq("windturbine_id",windturbineId);
  1167. }
  1168. List<ProEconWtPowerCurveFitting> ls= proEconWtPowerCurveFittingService.list(queryWrapper);
  1169. List<Long> wtpcfidls = ls.stream().map(ProEconWtPowerCurveFitting::getId).collect(Collectors.toList());
  1170. for (int i = 0; i < wtpcfidls.size(); i++) {
  1171. proEconWtPowerCurveFittingService.removeByIds(wtpcfidls);
  1172. }
  1173. // proEconWtPowerCurveFittingService.deleteProEconWtPowerCurveFitting();
  1174. List<ProEconWtPowerCurveFitting> wtcfls=new ArrayList<>();
  1175. if (monthSjglls.size() == monthZyglls.size()) {
  1176. for (int i = 0; i < monthSjglls.size(); i++) {
  1177. ProEconWtPowerCurveFitting item = new ProEconWtPowerCurveFitting();
  1178. item.setWindturbineId(windturbineId);
  1179. if (CacheContext.wtmap.containsKey(windturbineId)) {
  1180. ProBasicEquipment wt = CacheContext.wtmap.get(windturbineId);
  1181. if (wt.getWindpowerstationId().contains(WpType.GDC.id)) {
  1182. continue;
  1183. // item.SPEED = Double.Truncate(pointsF1[i].X);
  1184. } else {
  1185. //item.setSpeed(sjglls.get(i).getX());
  1186. item.setSpeed(StringUtils.round(monthSjglls.get(i).getX(),2));
  1187. }
  1188. // item.setActualPower(sjglls.get(i).getY());
  1189. // item.setOptimalPower(zyglls.get(i).getY());
  1190. item.setActualPower(StringUtils.round(monthSjglls.get(i).getY(),2));
  1191. item.setOptimalPower(StringUtils.round(monthSjglls.get(i).getY(),2));
  1192. wtcfls.add(item);
  1193. // proEconWtCurveFittingMonthService.save(item);
  1194. }
  1195. }
  1196. } else {
  1197. logger.warn(String.format("下标不一致的风机编号:{0},实际功率:{1},最有功率:{2}", windturbineId, monthSjglls.size(), monthZyglls.size()));
  1198. for (int i = 0; i < monthSjglls.size(); i++) {
  1199. ProEconWtPowerCurveFitting item = new ProEconWtPowerCurveFitting();
  1200. item.setWindturbineId(windturbineId);
  1201. if (CacheContext.wtmap.containsKey(windturbineId)) {
  1202. ProBasicEquipment wt = CacheContext.wtmap.get(windturbineId);
  1203. if (wt.getWindpowerstationId().contains(WpType.GDC.id)) {
  1204. continue;
  1205. //item.SPEED = Double.Truncate(pointsF1[i].X);
  1206. } else {
  1207. // item.setSpeed(sjglls.get(i).getX());
  1208. item.setSpeed(StringUtils.round(monthSjglls.get(i).getX(),2));
  1209. }
  1210. // item.setActualPower(sjglls.get(i).getY());
  1211. int finalI = i;
  1212. OptionalDouble op = monthZyglls.stream().filter(x -> Objects.equals(x.getX(), monthSjglls.get(finalI).getX())).mapToDouble(PointVo::getY).findFirst();
  1213. if (op.isPresent()) {
  1214. item.setOptimalPower(op.getAsDouble());
  1215. } else {
  1216. item.setOptimalPower(0.0);
  1217. }
  1218. item.setActualPower(StringUtils.round(monthSjglls.get(i).getY(),2));
  1219. item.setOptimalPower(StringUtils.round(monthSjglls.get(i).getY(),2));
  1220. wtcfls.add(item);
  1221. //proEconWtCurveFittingMonthService.save(item);
  1222. }
  1223. }
  1224. }
  1225. //*********************************************当月曲线偏差记录**********************************************************/
  1226. List<ProEconWtPowerCurveFitting> templs=new ArrayList<>();
  1227. for(ProEconWtPowerCurveFitting vo:wtcfls)
  1228. {
  1229. templs.add(vo);
  1230. if(templs.size()==1000)
  1231. {
  1232. proEconWtPowerCurveFittingService.saveBatch(templs);
  1233. templs=new ArrayList<>();
  1234. }
  1235. }
  1236. if(!templs.isEmpty())
  1237. {
  1238. proEconWtPowerCurveFittingService.saveBatch(templs);
  1239. }
  1240. }
  1241. // proEconWtPowerCurveFittingService.saveBatch(wtcfls);
  1242. }
  1243. private void yearBuildPoints(List<ProEconWtCurveFittingYear> data, List<PointVo> points) {
  1244. if (data != null) {
  1245. for (ProEconWtCurveFittingYear datum : data) {
  1246. PointVo point = new PointVo();
  1247. point.setX(datum.getSpeed());
  1248. point.setY(datum.getActualPower());
  1249. points.add(point);
  1250. }
  1251. }
  1252. }
  1253. private void monthBuildPoints(List<ProEconWtCurveFittingMonth> data, List<PointVo> points) {
  1254. if (data != null) {
  1255. for (ProEconWtCurveFittingMonth datum : data) {
  1256. PointVo point = new PointVo();
  1257. point.setX(datum.getSpeed());
  1258. point.setY(datum.getActualPower());
  1259. points.add(point);
  1260. }
  1261. }
  1262. }
  1263. private void dayBuildPoints(List<ProEconWtCurveFitting> data, List<PointVo> points) {
  1264. if (data != null) {
  1265. for (ProEconWtCurveFitting datum : data) {
  1266. PointVo point = new PointVo();
  1267. point.setX(datum.getSpeed());
  1268. point.setY(datum.getActualPower());
  1269. points.add(point);
  1270. }
  1271. }
  1272. }
  1273. // //曲线偏差率
  1274. // private double DeviationRateUtil.calculateDeviationRate(List<PointVo> points1, List<PointVo> points2, Double modelpower) {
  1275. // double result = -0;
  1276. // double pc = 0;
  1277. // if (points1 != null && points1.size() != 0 && points2 != null && points2.size() != 0) {
  1278. // double count = 0;
  1279. // double sum = 0;
  1280. // double max = modelpower;
  1281. // for (PointVo point : points1) {
  1282. // List<PointVo> item = points2.stream().filter(it -> Objects.equals(it.getX(), point.getX())).collect(Collectors.toList());
  1283. // if (item.size() > 0) {
  1284. // sum += Math.pow((point.getY() - item.get(0).getY()), 2);
  1285. // count++;
  1286. // pc += point.getY() - item.get(0).getY();
  1287. // }
  1288. // }
  1289. // sum = Math.sqrt(sum);
  1290. // count = Math.sqrt(count);
  1291. // max = max * count;
  1292. // if (max != 0) {
  1293. // result = sum / max * 100;
  1294. // }
  1295. //
  1296. // if (pc < 0) {
  1297. // result = 0 - result;
  1298. // }
  1299. // }
  1300. // return result;
  1301. // }
  1302. //
  1303. // //曲线偏差率2
  1304. // private double DeviationRateUtil.calculateDeviationRate(List<PointVo> points1, List<PointVo> points2, Double modelpower, double speed) {
  1305. // double minSpeed = speed;
  1306. // double maxSpeed = minSpeed + 1;
  1307. // double result = -0;
  1308. // double pc = 0;
  1309. // if (points1 != null && points1.size() != 0 && points2 != null && points2.size() != 0) {
  1310. // double count = 0;
  1311. // double sum = 0;
  1312. // double max = modelpower;
  1313. // for (PointVo point : points1) {
  1314. // List<PointVo> item = points2.stream().filter(it -> Objects.equals(it.getX(), point.getX())).collect(Collectors.toList());
  1315. // if (item.size() > 0 && item.get(0).getX() >= minSpeed && item.get(0).getX() < maxSpeed) {
  1316. // sum += Math.pow((point.getY() - item.get(0).getY()), 2);
  1317. // count++;
  1318. // pc += point.getY() - item.get(0).getY();
  1319. // }
  1320. // }
  1321. // sum = Math.sqrt(sum);
  1322. // count = Math.sqrt(count);
  1323. // max = max * count;
  1324. // if (max != 0) {
  1325. // result = sum / max * 100;
  1326. // }
  1327. //
  1328. // if (pc < 0) {
  1329. // result = 0 - result;
  1330. // }
  1331. // }
  1332. // return result;
  1333. // }
  1334. //todo-sl 添加数据筛选
  1335. private boolean filterData(PointData gl, PointData fs, List<PointData> ztls,List<PointData> qfztls,int i, double maxPower,double maxSpeed, String windturbineId) throws Exception {
  1336. if (StringUtils.notEmp(gl)) {
  1337. //判定功率是否超过最大值
  1338. if (gl.getPointValueInDouble() > maxPower || gl.getPointValueInDouble()<0) {
  1339. return false;
  1340. }
  1341. }
  1342. if (StringUtils.notEmp(fs)) {
  1343. //判定功率是否超过最大值
  1344. if (fs.getPointValueInDouble() > maxSpeed || fs.getPointValueInDouble()<0) {
  1345. return false;
  1346. }
  1347. }
  1348. //判定状态不为运行的进行过滤
  1349. if (ztls.get(i).getPointValueInDouble() != 2) {
  1350. return false;
  1351. }
  1352. if(i!=0)
  1353. {
  1354. if (ztls.get(i-1).getPointValueInDouble() != 2) {
  1355. return false;
  1356. }
  1357. }
  1358. //欠发
  1359. if (fs.getPointValueInDouble() == 0 && fs.getPointValueInDouble() >= 6 && fs.getPointValueInDouble() < 12.5 && qfztls.get(i).getPointValueInDouble() > 2) {
  1360. return false;
  1361. }else if (fs.getPointValueInDouble() >= 12.5 && qfztls.get(i).getPointValueInDouble() < 1) {
  1362. return false;
  1363. }
  1364. if (CacheContext.wtmap.containsKey(windturbineId)) {
  1365. String modelid = CacheContext.wtmap.get(windturbineId).getModelId();
  1366. if (StringUtils.notEmp(modelid)) {
  1367. //获取保证功率曲线中的风速和功率
  1368. if (CacheContext.theoreticalPowerMap.containsKey(modelid)) {
  1369. Map<Double,ProBasicModelPowerRd> theoreticalMap= CacheContext.theoreticalPowerMap.get(modelid);
  1370. double speed=StringUtils.round(fs.getPointValueInDouble(),2);
  1371. double power = theoreticalMap.get(speed).getEnsurePower(); //不同风速对应的保证功率
  1372. double k = gl.getPointValueInDouble() / power; //保证功率/实际功率 k:偏差百分比
  1373. if (gl.getPointValueInDouble() > 0) {
  1374. if (k < 0.95 && maxPower <= power) {
  1375. return false;
  1376. }
  1377. if (k < 0.9 && maxPower > power) {
  1378. return false;
  1379. }
  1380. if (k < 0.85 && speed < 6 && speed > 4) {
  1381. return false;
  1382. }
  1383. if (k < 0.9 && speed <= 4 && speed > 3.5) {
  1384. return false;
  1385. }
  1386. }
  1387. }
  1388. }
  1389. }
  1390. //
  1391. // //欠发状态大于2过滤掉
  1392. // if (qfztls.get(i).getPointValueInDouble() > 2) {
  1393. //
  1394. // return false;
  1395. // }
  1396. return true;
  1397. }
  1398. //功率曲线拟合
  1399. private void curveFittingBuilder(Date begin, Date end, int dimension, double scale, String pointIdGL, String pointIdFS, String pointIdZT, List<PointVo> sjglPoints, List<PointVo> zyglPoints, String windturbineId) throws Exception {
  1400. double maxPower = windturbineCapacity.get(windturbineId) ;
  1401. double maxSpeed = 25;
  1402. List<PointfVo> sjglnhpoints = new ArrayList<>();
  1403. Map<Double, PointfVo> zyglnhpoints = new HashMap<>();
  1404. Map<String, Map<String, ProBasicEquipmentPoint>> wtpAimap = CacheContext.wtpAimap;
  1405. Map<String, ProBasicEquipmentPoint> wtpointmap = wtpAimap.get(windturbineId);
  1406. String qfzt= wtpointmap.get(ContantXk.LSQFZT).getNemCode();
  1407. if (end.after(begin)) {
  1408. if (StringUtils.notEmp(pointIdGL) && StringUtils.notEmp(pointIdFS)) {
  1409. List<PointData> glpointstemp = edosUtil.getHistoryDatasSnap(pointIdGL, begin.getTime() / 1000, end.getTime() / 1000,null,60*10L);
  1410. List<PointData> fspointstemp = edosUtil.getHistoryDatasSnap(pointIdFS, begin.getTime() / 1000, end.getTime() / 1000,null,60*10L);
  1411. List<PointData> ztpointstemp = edosUtil.getHistoryDatasSnap(pointIdZT, begin.getTime() / 1000, end.getTime() / 1000,null,60*10L);
  1412. List<PointData> qfzttemp = edosUtil.getHistoryDatasSnap(qfzt, begin.getTime() / 1000, end.getTime() / 1000,null,60*10L);
  1413. List<PointData> glpoints = new ArrayList<>();
  1414. List<PointData> fspoints = new ArrayList<>();
  1415. List<PointData> ztpoints = new ArrayList<>();
  1416. if (!glpointstemp.isEmpty() && !fspointstemp.isEmpty() && !ztpointstemp.isEmpty() && glpointstemp.size() == fspointstemp.size() && fspointstemp.size() == ztpointstemp.size()) {
  1417. for (int i = 0; i < glpointstemp.size(); i++) {
  1418. if (filterData(glpointstemp.get(i), fspointstemp.get(i), ztpointstemp,qfzttemp,i, maxPower,maxSpeed, windturbineId)) {
  1419. glpoints.add(glpointstemp.get(i));
  1420. fspoints.add(fspointstemp.get(i));
  1421. ztpoints.add(ztpointstemp.get(i));
  1422. }
  1423. }
  1424. }
  1425. if (glpoints.size() != fspoints.size() || glpoints.size() != ztpoints.size()) {
  1426. for (int i = 0; i < fspoints.size(); i++) {
  1427. double x = fspoints.get(i).getPointValueInDouble();
  1428. double y = -1;
  1429. double z = -1;
  1430. int finalI1 = i;
  1431. List<PointData> yArray = glpoints.stream().filter(it -> it.getPointTime().compareTo(fspoints.get(finalI1).getPointTime()) == 0).collect(Collectors.toList());
  1432. if (yArray.size() > 0) {
  1433. y = yArray.get(0).getPointValueInDouble();
  1434. }
  1435. int finalI = i;
  1436. yArray = ztpoints.stream().filter(it -> it.getPointTime().compareTo(fspoints.get(finalI).getPointTime()) == 0).collect(Collectors.toList());
  1437. if (yArray.size() > 0) {
  1438. z = yArray.get(0).getPointValueInDouble();
  1439. }
  1440. Double x1 = StringUtils.round(x, 2);
  1441. Double y1 = y;
  1442. boolean b = true;
  1443. if (CacheContext.wtmap.containsKey(windturbineId)) {
  1444. ProBasicEquipment wt = CacheContext.wtmap.get(windturbineId);
  1445. if (wt.getWindpowerstationId().contains(WpType.GDC.id)) {
  1446. b = (x >= 0 && y > 0);
  1447. } else {
  1448. if (z == 2) {
  1449. b = (x >= 0 && x <= 30 && y >= 0 && y <= maxPower);
  1450. if (b) {
  1451. if (x > 3 && y <= 0) {
  1452. b = false;
  1453. }
  1454. if (x <= 3 && y > 0) {
  1455. b = false;
  1456. }
  1457. }
  1458. } else {
  1459. b = false;
  1460. }
  1461. }
  1462. }
  1463. if (b) {
  1464. sjglnhpoints.add(new PointfVo(x1, y1));
  1465. if (zyglnhpoints.containsKey(x1)) {
  1466. if (zyglnhpoints.get(x1).getY() < y1) {
  1467. zyglnhpoints.put(x1, new PointfVo(x1, y1));
  1468. }
  1469. } else {
  1470. zyglnhpoints.put(x1, new PointfVo(x1, y1));
  1471. }
  1472. }
  1473. }
  1474. } else {
  1475. for (int i = 0; i < fspoints.size(); i++) {
  1476. double x = fspoints.get(i).getPointValueInDouble();
  1477. double y = glpoints.get(i).getPointValueInDouble();
  1478. double z = ztpoints.get(i).getPointValueInDouble();
  1479. Double x1 = StringUtils.round(x, 2);
  1480. Double y1 = y;
  1481. boolean b = true;
  1482. if (CacheContext.wtmap.containsKey(windturbineId)) {
  1483. ProBasicEquipment wt = CacheContext.wtmap.get(windturbineId);
  1484. if (wt.getWindpowerstationId().contains(WpType.GDC.id)) {
  1485. b = (x >= 0 && y > 0);
  1486. } else {
  1487. if (z == 2) {
  1488. b = (x >= 0 && x <= 30 && y >= 0 && y <= maxPower);
  1489. if (b) {
  1490. if (x > 3 && y <= 0) {
  1491. b = false;
  1492. }
  1493. if (x <= 3 && y > 0) {
  1494. b = false;
  1495. }
  1496. }
  1497. } else {
  1498. b = false;
  1499. }
  1500. }
  1501. }
  1502. if (b) {
  1503. sjglnhpoints.add(new PointfVo(x1, y1));
  1504. if (zyglnhpoints.containsKey(x1)) {
  1505. if (zyglnhpoints.get(x1).getY() < y1) {
  1506. zyglnhpoints.put(x1, new PointfVo(x1, y1));
  1507. }
  1508. } else {
  1509. zyglnhpoints.put(x1, new PointfVo(x1, y1));
  1510. }
  1511. }
  1512. }
  1513. }
  1514. sjglnhpoints.add(new PointfVo(0.0, 0.0));
  1515. sjglnhpoints = sjglnhpoints.stream().filter(it -> it.getX() >= 3).sorted(Comparator.comparing(PointfVo::getX)).collect(Collectors.toList());
  1516. // if (sjglnhpoints.stream().min(Comparator.comparing(PointfVo::getX)).isPresent()) {
  1517. // double Xmax = sjglnhpoints.stream().max(Comparator.comparing(PointfVo::getX)).get().getX();
  1518. // double Ymax = sjglnhpoints.stream().max(Comparator.comparing(PointfVo::getX)).get().getY();
  1519. // System.out.println("");
  1520. // }
  1521. List<PointVo> temp = LineUtil.buildLine(sjglnhpoints.stream().mapToDouble(PointfVo::getX).toArray(), sjglnhpoints.stream().mapToDouble(PointfVo::getY).toArray(), sjglnhpoints.size(), dimension, scale);
  1522. sjglPoints.addAll(temp);
  1523. if (sjglPoints.size() != 0) {
  1524. buildMyPoints(sjglPoints, scale);
  1525. }
  1526. if (!zyglnhpoints.containsKey(0.0))
  1527. {
  1528. zyglnhpoints.put(0.0, new PointfVo(0.0, 0.0));
  1529. }
  1530. List<PointfVo> zygltemp = zyglnhpoints.values().stream().filter(it -> it.getX() >= 3).sorted(Comparator.comparing(PointfVo::getX)).collect(Collectors.toList());
  1531. if (zygltemp.size() != 0) {
  1532. temp = LineUtil.buildLine(zygltemp.stream().mapToDouble(PointfVo::getX).toArray(), zygltemp.stream().mapToDouble(PointfVo::getY).toArray(), zygltemp.size(), dimension, scale);
  1533. }
  1534. zyglPoints.addAll(temp);
  1535. if (zyglPoints.size() != 0) {
  1536. buildMyPoints(zyglPoints, scale);
  1537. }
  1538. }
  1539. }
  1540. }
  1541. private static void buildMyPoints(List<PointVo> sjglPoints, double scale) {
  1542. int coefficient = 1;
  1543. int dec = 0;
  1544. int smax = 25;
  1545. if (scale == 0.01) {
  1546. coefficient = 100;
  1547. dec = 2;
  1548. }
  1549. if (scale == 0.1) {
  1550. coefficient = 10;
  1551. dec = 1;
  1552. }
  1553. smax *= coefficient;
  1554. double min = 0.0;
  1555. double max = 0.0;
  1556. double maxval = 0.0;
  1557. if (sjglPoints.stream().min(Comparator.comparing(PointVo::getX)).isPresent()) {
  1558. min = sjglPoints.stream().min(Comparator.comparing(PointVo::getX)).get().getX() * coefficient;
  1559. }
  1560. if (sjglPoints.stream().max(Comparator.comparing(PointVo::getX)).isPresent()) {
  1561. max = sjglPoints.stream().max(Comparator.comparing(PointVo::getX)).get().getX() * coefficient;
  1562. }
  1563. if (sjglPoints.stream().max(Comparator.comparing(PointVo::getY)).isPresent()) {
  1564. maxval = sjglPoints.stream().max(Comparator.comparing(PointVo::getY)).get().getY();
  1565. }
  1566. for (double i = 0; i < min; i += 1) {
  1567. PointVo point = new PointVo();
  1568. point.setX(StringUtils.round(i / coefficient, dec));
  1569. point.setY(0.0);
  1570. sjglPoints.add(point);
  1571. }
  1572. for (double i = smax; i > max; i -= 1) {
  1573. PointVo point = new PointVo();
  1574. point.setX(StringUtils.round(i / coefficient, dec));
  1575. point.setY(maxval);
  1576. sjglPoints.add(point);
  1577. }
  1578. }
  1579. }