PdfServiceImpl.java 95 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669
  1. package com.jiayue.biz.service.impl;
  2. import cn.hutool.core.convert.Convert;
  3. import cn.hutool.core.date.DateTime;
  4. import cn.hutool.db.Entity;
  5. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  6. import com.jiayue.biz.domain.*;
  7. import com.jiayue.biz.eunms.WindDirectionEnum;
  8. import com.jiayue.biz.mapper.WindTowerDataParentTableMapper;
  9. import com.jiayue.biz.service.*;
  10. import com.jiayue.biz.util.CalculationUtil;
  11. import com.jiayue.biz.util.DateMomentUtil;
  12. import com.jiayue.biz.util.DateTimeUtil;
  13. import com.jiayue.common.utils.DateUtil;
  14. import flanagan.analysis.ProbabilityPlot;
  15. import lombok.AllArgsConstructor;
  16. import org.apache.commons.lang3.time.DateUtils;
  17. import org.springframework.stereotype.Service;
  18. import java.math.BigDecimal;
  19. import java.math.RoundingMode;
  20. import java.sql.Timestamp;
  21. import java.text.SimpleDateFormat;
  22. import java.util.*;
  23. import java.util.stream.Collectors;
  24. import java.util.stream.Stream;
  25. import static com.jiayue.biz.eunms.TimeDimension.month;
  26. /**
  27. * 首页Service业务层处理
  28. *
  29. * @author L.ym
  30. * @date 2022-05-11
  31. */
  32. @Service
  33. @AllArgsConstructor
  34. public class PdfServiceImpl extends ServiceImpl<WindTowerDataParentTableMapper, WindTowerDataParentTable> implements PdfService {
  35. private final WindTowerInfoServiceImpl windTowerInfoService;
  36. private final WindTowerCalculationDataServiceImpl windTowerCalculationDataService;
  37. private final EquipmentAttributeService equipmentAttributeService;
  38. private final RealTimeDisplayService realTimeDisplayService;
  39. private final WindDirectionStatisticsDataServiceImpl windDirectionStatisticsDataService;
  40. private final ProphaseAnemometryDataService prophaseAnemometryDataService;
  41. private final ProphaseWeatherDataService prophaseWeatherDataService;
  42. @Override
  43. public Map<String, Object> generatePDF(String equipmentId, Date startDay, Date endDay) {
  44. //如果结束时间大于现在时间
  45. if (DateUtil.date().getTime() < endDay.getTime()) {
  46. //将结束时间设置为昨天结束时间
  47. endDay = DateUtil.endOfDay(DateUtil.yesterday());
  48. }
  49. Map<String, Object> map = new HashMap<>();
  50. // 一年的计算数据
  51. startDay = DateUtil.beginOfMonth(startDay);
  52. endDay = DateUtil.endOfMonth(endDay);
  53. List<WindTowerCalculationData> windTowerCalculationDatas = windTowerCalculationDataService.getByBetweenTimeAndEquipmentId(startDay, endDay, equipmentId);
  54. //实时数据查询
  55. List<ProphaseAnemometryData> prophaseAnemometryDataList = prophaseAnemometryDataService.selectWsAndWdForTime(equipmentId, new Timestamp(startDay.getTime()), new Timestamp(endDay.getTime()));
  56. // 一年的风向统计数据
  57. List<WindDirectionStatisticsData> windDirectionStatisticsDataList = windDirectionStatisticsDataService.getByBetweenTimeAndEquipmentId(startDay, endDay, equipmentId);
  58. //所有类型数据
  59. List<EquipmentAttribute> equipmentAttributeList = equipmentAttributeService.list();
  60. //所有测风塔信息
  61. List<WindTowerInfo> windTowerInfoList = windTowerInfoService.getAllWindTower();
  62. List<WindTowerInfo> windTowerInfos = windTowerInfoList.stream().filter(w -> w.getEquipmentNo().equals(equipmentId)).collect(Collectors.toList());
  63. //测风塔信息概要
  64. Map<String, Object> windTowerInfo = getWindTowerInfo(windTowerInfos, startDay, endDay);
  65. map.put("windTowerInfo", windTowerInfo);
  66. //环境数据
  67. Map<String, Object> statisticsData = statisticsWindTowerStatusData(windTowerCalculationDatas, equipmentAttributeList);
  68. map.put("statisticsData", statisticsData);
  69. //风速最大、最小、平均 数据
  70. ArrayList<Map<String, Object>> statisticsDataFen = statisticsWindTowerStatusDataFeng(windTowerCalculationDatas, equipmentAttributeList, windTowerInfos);
  71. map.put("statisticsDataFen", statisticsDataFen);
  72. //风速每月平均
  73. Map<String, Object> statisticsWindTowerStatusDataFenMonth = statisticsWindTowerStatusDataFenMonth(windTowerCalculationDatas, equipmentAttributeList, windTowerInfos, startDay, endDay);
  74. map.put("statisticsWindTowerStatusDataFenMonth", statisticsWindTowerStatusDataFenMonth);
  75. //风功率密度每月平均
  76. ArrayList<Map<String, Object>> statisticsWindTowerStatusDataFenWpd = statisticsWindTowerStatusDataWpd(windTowerCalculationDatas, equipmentAttributeList, windTowerInfos);
  77. map.put("statisticsWindTowerStatusDataFenWpd", statisticsWindTowerStatusDataFenWpd);
  78. //一年玫瑰图 以及风能玫瑰图
  79. ArrayList<Map<String, Object>> roseChart = roseCharts(windDirectionStatisticsDataList, equipmentAttributeList, windTowerInfos);
  80. map.put("roseChart", roseChart);
  81. //pdf威布尔
  82. ArrayList<Map<String, Object>> weibull = pdfWeibull(equipmentAttributeList, windTowerCalculationDatas, windTowerInfos);
  83. map.put("weibull", weibull);
  84. //15m/s湍流强度
  85. ArrayList<Map<String, Object>> statisticsWindTowerStatusDataFenTur = statisticsWindTowerStatusDataTur(windTowerCalculationDatas, equipmentAttributeList, windTowerInfos);
  86. map.put("statisticsWindTowerStatusDataFenTur", statisticsWindTowerStatusDataFenTur);
  87. //风切变
  88. Map<String, Object> statisticsWindTowerStatusDataShear = statisticsWindTowerStatusDataShear(prophaseAnemometryDataList, windTowerInfos);
  89. map.put("statisticsWindTowerStatusDataShear", statisticsWindTowerStatusDataShear);
  90. //
  91. // //风速和风功率密度时间曲线图 (时间序列)
  92. // Map<String, Object> wsAndWpd = getWsAndWpd(windTowerCalculationDatas, equipmentAttributeList, height, startDay, endDay);
  93. // map.put("wsAndWpd", wsAndWpd);
  94. // //风速和风速标准差时间曲线图
  95. // Map<String, Object> wsAndWsStaData = wsAndWsSta(windTowerCalculationDatas, equipmentAttributeList, height, startDay, endDay);
  96. // map.put("wsAndWsStaData", wsAndWsStaData);
  97. // //风速和风速密度日变化
  98. // Map<String, Object> windPowerDensityAndAverageWindSpeed = getWindPowerDensityAndAverageWindSpeed(windTowerCalculationDatas, equipmentAttributeList, windTowerInfos, height);
  99. // map.put("windPowerDensityAndAverageWindSpeed", windPowerDensityAndAverageWindSpeed);
  100. // //风速和风速密度各月日变化
  101. // List<Map<String, Object>> MonthWsAndWpd = getMonthWsAndWpd(windTowerCalculationDatas, equipmentAttributeList, height, startDay, endDay);
  102. // map.put("MonthWsAndWpd", MonthWsAndWpd);
  103. // //风速和风速密度年变化曲线
  104. // Map<String, Object> yearWsAndWpd = getYearWsAndWpd(windTowerCalculationDatas, equipmentAttributeList, height, startDay, endDay);
  105. // map.put("yearWsAndWpd", yearWsAndWpd);
  106. // //风速和风速密度各月日变化表格
  107. // Map<String, Object> monthWpdTable = getMonthWpdTable(windTowerCalculationDatas, equipmentAttributeList, windTowerInfos, startDay, endDay);
  108. // map.put("monthWpdTable", monthWpdTable);
  109. //
  110. // //各月玫瑰图
  111. // Map<String, Object> monthRoseCharts = getMonthRoseCharts(windDirectionStatisticsDataList, equipmentAttributeList, height);
  112. // map.put("monthRoseCharts", monthRoseCharts);
  113. //
  114. // //空气密度
  115. // Map<String, Object> airDensity = getAirDensity(windTowerCalculationDatas, equipmentAttributeList, startDay, endDay);
  116. // map.put("airDensity", airDensity);
  117. // //获取风切变指数(风向玫瑰图)
  118. // List<Map<String, Object>> windShearRose = getWindShearRose(windDirectionStatisticsDataList, equipmentAttributeList, height);
  119. // map.put("windShearRose", windShearRose);
  120. // //风切变日/年变化
  121. // Map<String, Object> windShear = getWindShear(windTowerCalculationDatas, equipmentAttributeList, height);
  122. // map.put("windShear", windShear);
  123. // //湍流曲线
  124. // List<List<BigDecimal>> turIntensityCharts = getTurIntensityCharts(windTowerCalculationDatas, equipmentAttributeList, height);
  125. // map.put("turIntensityCharts", turIntensityCharts);
  126. // //湍流日/年变化
  127. // Map<String, Object> turIntensity = getTurIntensity(windTowerCalculationDatas, equipmentAttributeList, height);
  128. // map.put("turIntensity", turIntensity);
  129. // //获取湍流(风向玫瑰图)
  130. // Map<String, Object> turIntensityRose = getTurIntensityRose(windDirectionStatisticsDataList, equipmentAttributeList, windTowerInfos.get(0), height);
  131. // map.put("turIntensityRose", turIntensityRose);
  132. return map;
  133. }
  134. /**
  135. * 测风塔信息概要
  136. *
  137. * @return
  138. */
  139. public Map<String, Object> getWindTowerInfo(List<WindTowerInfo> windTowerInfos, Date startDay, Date endDay) {
  140. Map<String, Object> map = new HashMap<>();
  141. Map<String, Long> dataTimeStartAndEnd = prophaseWeatherDataService.getDataTimeStartAndEnd(windTowerInfos.get(0).getEquipmentNo());
  142. List<Entity> count = prophaseWeatherDataService.selectCount(windTowerInfos.get(0).getEquipmentNo());
  143. long allCount = ((endDay.getTime() - startDay.getTime() + 1000) / 86400000l) * 144;
  144. BigDecimal percentage = BigDecimal.valueOf((Long) count.get(0).get("count(*)")).divide(BigDecimal.valueOf(allCount), 2, RoundingMode.HALF_UP);
  145. if (windTowerInfos.size() != 0) {
  146. map.put("windTowerInfo", windTowerInfos.get(0));
  147. map.put("startTime", DateUtil.format(new Date(dataTimeStartAndEnd.get("startTime")), "yyyy-MM-dd"));
  148. map.put("endTime", DateUtil.format(new Date(dataTimeStartAndEnd.get("endTime")), "yyyy-MM-dd"));
  149. map.put("count", count.get(0).get("count(*)"));
  150. map.put("allCount", allCount);
  151. map.put("percentage", percentage.multiply(new BigDecimal(100)));
  152. }
  153. return map;
  154. }
  155. /**
  156. * 环境数据
  157. *
  158. * @param windTowerCalculationDatas 统计数据
  159. * @param equipmentAttributeList 属性数据
  160. * @return
  161. */
  162. public Map<String, Object> statisticsWindTowerStatusData(List<WindTowerCalculationData> windTowerCalculationDatas, List<EquipmentAttribute> equipmentAttributeList) {
  163. Map<String, Object> map = new HashMap<>();
  164. try {
  165. // List<Map<String, Object>> dataList = new ArrayList<>();
  166. /*环境数据*/
  167. //从数据库属性表里查出环境数据的属性
  168. List<EquipmentAttribute> paMax = equipmentAttributeList.stream().filter(w -> w.getFieldName().equals("paMAX")).collect(Collectors.toList());
  169. List<EquipmentAttribute> paMin = equipmentAttributeList.stream().filter(w -> w.getFieldName().equals("paMIN")).collect(Collectors.toList());
  170. List<EquipmentAttribute> paAve = equipmentAttributeList.stream().filter(w -> w.getFieldName().equals("paAVE")).collect(Collectors.toList());
  171. List<EquipmentAttribute> rhMax = equipmentAttributeList.stream().filter(w -> w.getFieldName().equals("rhMAX")).collect(Collectors.toList());
  172. List<EquipmentAttribute> rhMin = equipmentAttributeList.stream().filter(w -> w.getFieldName().equals("rhMIN")).collect(Collectors.toList());
  173. List<EquipmentAttribute> rhAve = equipmentAttributeList.stream().filter(w -> w.getFieldName().equals("rhAVE")).collect(Collectors.toList());
  174. List<EquipmentAttribute> tMax = equipmentAttributeList.stream().filter(w -> w.getFieldName().equals("tMAX")).collect(Collectors.toList());
  175. List<EquipmentAttribute> tMin = equipmentAttributeList.stream().filter(w -> w.getFieldName().equals("tMIN")).collect(Collectors.toList());
  176. List<EquipmentAttribute> tAve = equipmentAttributeList.stream().filter(w -> w.getFieldName().equals("tAVE")).collect(Collectors.toList());
  177. List<EquipmentAttribute> airDensityAve = equipmentAttributeList.stream().filter(w -> w.getFieldName().equals("airDensityMonth")).collect(Collectors.toList());
  178. //通过属性过滤数据
  179. List<WindTowerCalculationData> paMaxData = windTowerCalculationDatas.stream().filter(w -> w.getEbId().equals(paMax.get(0).getId())).collect(Collectors.toList());
  180. List<WindTowerCalculationData> paMinData = windTowerCalculationDatas.stream().filter(w -> w.getEbId().equals(paMin.get(0).getId())).collect(Collectors.toList());
  181. List<WindTowerCalculationData> paAveData = windTowerCalculationDatas.stream().filter(w -> w.getEbId().equals(paAve.get(0).getId())).collect(Collectors.toList());
  182. List<WindTowerCalculationData> rhMaxData = windTowerCalculationDatas.stream().filter(w -> w.getEbId().equals(rhMax.get(0).getId())).collect(Collectors.toList());
  183. List<WindTowerCalculationData> rhMinData = windTowerCalculationDatas.stream().filter(w -> w.getEbId().equals(rhMin.get(0).getId())).collect(Collectors.toList());
  184. List<WindTowerCalculationData> rhAveData = windTowerCalculationDatas.stream().filter(w -> w.getEbId().equals(rhAve.get(0).getId())).collect(Collectors.toList());
  185. List<WindTowerCalculationData> tMaxData = windTowerCalculationDatas.stream().filter(w -> w.getEbId().equals(tMax.get(0).getId())).collect(Collectors.toList());
  186. List<WindTowerCalculationData> tMinData = windTowerCalculationDatas.stream().filter(w -> w.getEbId().equals(tMin.get(0).getId())).collect(Collectors.toList());
  187. List<WindTowerCalculationData> tAveData = windTowerCalculationDatas.stream().filter(w -> w.getEbId().equals(tAve.get(0).getId())).collect(Collectors.toList());
  188. List<WindTowerCalculationData> airDensityAveData = windTowerCalculationDatas.stream().filter(w -> w.getEbId().equals(airDensityAve.get(0).getId())).collect(Collectors.toList());
  189. //做平均值
  190. BigDecimal paMaxDataMax = paMaxData.stream().map(WindTowerCalculationData::getValue).max((x1, x2) -> x1.compareTo(x2)).get();
  191. BigDecimal paMinDataMin = paMinData.stream().map(WindTowerCalculationData::getValue).min((x1, x2) -> x1.compareTo(x2)).get();
  192. BigDecimal paAveDataAge = paAveData.stream().map(WindTowerCalculationData::getValue).reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(paAveData.size()), 2, RoundingMode.HALF_UP);
  193. BigDecimal rhMaxDataMax = rhMaxData.stream().map(WindTowerCalculationData::getValue).max((x1, x2) -> x1.compareTo(x2)).get();
  194. BigDecimal rhMinDataMin = rhMinData.stream().map(WindTowerCalculationData::getValue).min((x1, x2) -> x1.compareTo(x2)).get();
  195. BigDecimal rhAveDataAge = rhAveData.stream().map(WindTowerCalculationData::getValue).reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(rhAveData.size()), 2, RoundingMode.HALF_UP);
  196. BigDecimal tMaxDataMax = tMaxData.stream().map(WindTowerCalculationData::getValue).max((x1, x2) -> x1.compareTo(x2)).get();
  197. BigDecimal tMinDataMin = tMinData.stream().map(WindTowerCalculationData::getValue).min((x1, x2) -> x1.compareTo(x2)).get();
  198. BigDecimal tAveDataAge = tAveData.stream().map(WindTowerCalculationData::getValue).reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(tAveData.size()), 2, RoundingMode.HALF_UP);
  199. BigDecimal airDensityAveDataAge = airDensityAveData.stream().map(WindTowerCalculationData::getValue).reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(airDensityAveData.size()), 2, RoundingMode.HALF_UP);
  200. //放到list里
  201. List<Map<String, Object>> environmentData = new ArrayList<>();
  202. Map<String, Object> paMap = new HashMap<>();
  203. paMap.put("parameter", "气压(hpa)");
  204. paMap.put("min", paMinDataMin);
  205. paMap.put("max", paMaxDataMax);
  206. paMap.put("ave", paAveDataAge);
  207. Map<String, Object> rhMap = new HashMap<>();
  208. rhMap.put("parameter", "湿度(RH)");
  209. rhMap.put("min", rhMinDataMin.compareTo(new BigDecimal(0)) == 0 ? "--" : rhMinDataMin);
  210. rhMap.put("max", rhMaxDataMax.compareTo(new BigDecimal(0)) == 0 ? "--" : rhMaxDataMax);
  211. rhMap.put("ave", rhAveDataAge.compareTo(new BigDecimal(0)) == 0 ? "--" : rhAveDataAge);
  212. Map<String, Object> tMap = new HashMap<>();
  213. tMap.put("parameter", "气温(°C)");
  214. tMap.put("min", tMinDataMin);
  215. tMap.put("max", tMaxDataMax);
  216. tMap.put("ave", tAveDataAge);
  217. Map<String, Object> airDensityMap = new HashMap<>();
  218. airDensityMap.put("parameter", "空气密度(kg/m³)");
  219. airDensityMap.put("min", airDensityAveDataAge.multiply(BigDecimal.valueOf(0.8)));
  220. airDensityMap.put("max", airDensityAveDataAge.multiply(BigDecimal.valueOf(1.2)));
  221. airDensityMap.put("ave", airDensityAveDataAge);
  222. environmentData.add(paMap);
  223. environmentData.add(rhMap);
  224. environmentData.add(tMap);
  225. environmentData.add(airDensityMap);
  226. // map.put("dataList", dataList);
  227. map.put("environment", environmentData);
  228. } catch (Exception e) {
  229. e.printStackTrace();
  230. }
  231. return map;
  232. }
  233. /**
  234. * 风速最大、最小、平均 数据
  235. *
  236. * @param windTowerCalculationDatas 统计数据
  237. * @param equipmentAttributeList 属性数据
  238. * @return
  239. */
  240. public ArrayList<Map<String, Object>> statisticsWindTowerStatusDataFeng(List<WindTowerCalculationData> windTowerCalculationDatas, List<EquipmentAttribute> equipmentAttributeList, List<WindTowerInfo> windTowerInfos) {
  241. ArrayList<Map<String, Object>> heightAndWsList = new ArrayList<>();
  242. String[] heights = windTowerInfos.get(0).getHeights().split(",");
  243. for (String height : heights) {
  244. BigDecimal wsAve = BigDecimal.ZERO;
  245. BigDecimal wsMax = BigDecimal.ZERO;
  246. BigDecimal wsMin = BigDecimal.ZERO;
  247. Map<String, Object> map = new HashMap<>();
  248. List<EquipmentAttribute> equipmentAttributes = equipmentAttributeList.stream().filter(e -> e.getFieldName().equals(height + "awsDay")).collect(Collectors.toList());
  249. //通过属性过滤数据
  250. List<WindTowerCalculationData> wsDayList = windTowerCalculationDatas.stream().filter(w -> w.getEbId().equals(equipmentAttributes.get(0).getId())).collect(Collectors.toList());
  251. if (wsDayList.size() > 0) {
  252. wsAve = wsDayList.stream().map(WindTowerCalculationData::getValue).reduce(BigDecimal::add).get().divide(BigDecimal.valueOf(wsDayList.size()), 2, RoundingMode.HALF_UP);
  253. wsMin = wsDayList.stream().map(WindTowerCalculationData::getValue).min(BigDecimal::compareTo).get();
  254. wsMax = wsDayList.stream().map(WindTowerCalculationData::getValue).max((x1, x2) -> x1.compareTo(x2)).get();
  255. }
  256. map.put("wsAve", wsAve);
  257. map.put("wsMin", wsMin);
  258. map.put("wsMax", wsMax);
  259. map.put("height", height);
  260. heightAndWsList.add(map);
  261. }
  262. return heightAndWsList;
  263. }
  264. /**
  265. * 风速每月平均
  266. *
  267. * @param windTowerCalculationDatas 统计数据
  268. * @param equipmentAttributeList 属性数据
  269. * @return
  270. */
  271. public Map<String, Object> statisticsWindTowerStatusDataFenMonth(List<WindTowerCalculationData> windTowerCalculationDatas, List<EquipmentAttribute> equipmentAttributeList, List<WindTowerInfo> windTowerInfos, Date startDay, Date endDay) {
  272. Map<String, Object> objectMap = new HashMap<>();
  273. ArrayList<Map<String, Object>> heightAndWsList = new ArrayList<>();
  274. ArrayList<Map<String, Object>> timeList = new ArrayList<>();
  275. String[] heights = windTowerInfos.get(0).getHeights().split(",");
  276. int i = 0;
  277. for (String height : heights) {
  278. HashMap<String, Object> heightMap = new HashMap<>();
  279. List<EquipmentAttribute> equipmentAttributes = equipmentAttributeList.stream().filter(e -> e.getFieldName().equals(height + "awsDay")).collect(Collectors.toList());
  280. for (Long l = startDay.getTime(); l < endDay.getTime(); l = DateUtil.offsetMonth(new Date(l), 1).getTime()) {
  281. Date startTime = DateUtil.beginOfMonth(new Date(l));
  282. Date endTime = DateUtil.endOfMonth(startTime);
  283. BigDecimal wsAve = BigDecimal.ZERO;
  284. //通过属性过滤数据
  285. List<WindTowerCalculationData> wsDayList = windTowerCalculationDatas.stream().filter(w -> w.getTime().getTime() >= startTime.getTime() &&
  286. w.getTime().getTime() <= endTime.getTime() &&
  287. w.getEbId().equals(equipmentAttributes.get(0).getId())).collect(Collectors.toList());
  288. if (wsDayList.size() > 0) {
  289. wsAve = wsDayList.stream().map(WindTowerCalculationData::getValue).reduce(BigDecimal::add).get().divide(BigDecimal.valueOf(wsDayList.size()), 2, RoundingMode.HALF_UP);
  290. }
  291. heightMap.put(DateUtil.format(startTime, "yyyyMM"), wsAve);
  292. if (i == 0) {
  293. HashMap<String, Object> timeMap = new HashMap<>();
  294. timeMap.put("value",DateUtil.format(startTime, "yyyyMM"));
  295. timeMap.put("label",DateUtil.format(startTime, "yyyy.M"));
  296. timeList.add(timeMap);
  297. }
  298. }
  299. heightMap.put("height", height);
  300. heightAndWsList.add(heightMap);
  301. i++;
  302. }
  303. objectMap.put("timeTable", timeList);
  304. objectMap.put("mainData",heightAndWsList);
  305. return objectMap;
  306. }
  307. /**
  308. * 风功率密度最大、最小、平均 数据
  309. *
  310. * @param windTowerCalculationDatas 统计数据
  311. * @param equipmentAttributeList 属性数据
  312. * @return
  313. */
  314. public ArrayList<Map<String, Object>> statisticsWindTowerStatusDataWpd(List<WindTowerCalculationData> windTowerCalculationDatas, List<EquipmentAttribute> equipmentAttributeList, List<WindTowerInfo> windTowerInfos) {
  315. ArrayList<Map<String, Object>> heightAndWpdList = new ArrayList<>();
  316. String[] heights = windTowerInfos.get(0).getHeights().split(",");
  317. for (String height : heights) {
  318. BigDecimal wpdAve = BigDecimal.ZERO;
  319. BigDecimal wpdMax = BigDecimal.ZERO;
  320. BigDecimal wpdMin = BigDecimal.ZERO;
  321. Map<String, Object> map = new HashMap<>();
  322. List<EquipmentAttribute> equipmentAttributes = equipmentAttributeList.stream().filter(e -> e.getFieldName().equals(height + "wpdDay")).collect(Collectors.toList());
  323. //通过属性过滤数据
  324. List<WindTowerCalculationData> dayList = windTowerCalculationDatas.stream().filter(w -> w.getEbId().equals(equipmentAttributes.get(0).getId())).collect(Collectors.toList());
  325. if (dayList.size() > 0) {
  326. wpdAve = dayList.stream().map(WindTowerCalculationData::getValue).reduce(BigDecimal::add).get().divide(BigDecimal.valueOf(dayList.size()), 2, RoundingMode.HALF_UP);
  327. // wpdMax = dayList.stream().map(WindTowerCalculationData::getValue).min(BigDecimal::compareTo).get();
  328. // wpdMin = dayList.stream().map(WindTowerCalculationData::getValue).max((x1, x2) -> x1.compareTo(x2)).get();
  329. }
  330. map.put("wpdAve", wpdAve);
  331. // map.put("wpdMin", wpdMax);
  332. // map.put("wpdMax", wpdMin);
  333. map.put("height", height);
  334. heightAndWpdList.add(map);
  335. }
  336. return heightAndWpdList;
  337. }
  338. /**
  339. * 测风塔数据时间范围
  340. *
  341. * @return
  342. */
  343. public List<Map<String, Object>> getDataTime() {
  344. List<WindTowerInfo> windTowerInfoList = windTowerInfoService.getAllWindTower();
  345. ArrayList<Map<String, Object>> timeList = new ArrayList<>();
  346. for (WindTowerInfo windTowerInfo : windTowerInfoList) {
  347. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  348. HashMap<String, Object> hashMap = new HashMap<>();
  349. Map<String, Long> startAndEnd = prophaseWeatherDataService.getDataTimeStartAndEnd(windTowerInfo.getEquipmentNo());
  350. hashMap.put("time", sdf.format(new Date(startAndEnd.get("startTime"))) + " - " + sdf.format(new Date(startAndEnd.get("endTime"))));
  351. hashMap.put("eqId", windTowerInfo.getEquipmentNo());
  352. timeList.add(hashMap);
  353. }
  354. return timeList;
  355. }
  356. /**
  357. * 测风塔数据时间范围
  358. *
  359. * @return
  360. */
  361. public List<Map<String, Object>> getDataTimeForEveryTower() {
  362. List<WindTowerInfo> windTowerInfoList = windTowerInfoService.getAllWindTower();
  363. List<WindTowerInfo> collect = windTowerInfoList.stream().sorted(Comparator.comparing(WindTowerInfo::getEquipmentNo)).collect(Collectors.toList());
  364. ArrayList<Map<String, Object>> timeList = new ArrayList<>();
  365. for (WindTowerInfo windTowerInfo : collect) {
  366. try {
  367. HashMap<String, Object> hashMap = new HashMap<>();
  368. Map<String, Long> startAndEnd = prophaseWeatherDataService.getDataTimeStartAndEnd(windTowerInfo.getEquipmentNo());
  369. //获取去年数据截止的时间
  370. Date yearDay = DateTimeUtil.getYearDay(startAndEnd.get("endTime"));
  371. Date startTime;
  372. if (startAndEnd.get("startTime") < yearDay.getTime()) {
  373. startTime = DateUtil.offsetMonth(yearDay, 1);
  374. } else {
  375. startTime = new Date(startAndEnd.get("startTime"));
  376. }
  377. hashMap.put("startTime", startTime);
  378. hashMap.put("endTime", new Date(startAndEnd.get("endTime")));
  379. hashMap.put("eqId", windTowerInfo.getEquipmentNo());
  380. timeList.add(hashMap);
  381. }catch (Exception e){
  382. log.error("读取测风塔:{"+windTowerInfo.getName() +"} 开始结束时间错误:{"+e.getLocalizedMessage()+"}");
  383. }
  384. }
  385. return timeList;
  386. }
  387. /**
  388. * 风速和风功率密度时间曲线图
  389. *
  390. * @param
  391. * @return map
  392. */
  393. public Map<String, Object> getWsAndWpd(List<WindTowerCalculationData> windTowerCalculationDataList, List<EquipmentAttribute> equipmentAttributeList, String height, Date startDay, Date endDay) {
  394. Map<String, Object> map = new HashMap<>();
  395. try {
  396. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  397. // 根据设备属性表中的属性作用查询
  398. List<EquipmentAttribute> wsDayAttList = equipmentAttributeList.stream().filter(e -> "wsDay".equals(e.getAttributeFunction())).collect(Collectors.toList());
  399. List<EquipmentAttribute> wpdMonthAttList = equipmentAttributeList.stream().filter(e -> "WindPowerDensity".equals(e.getAttributeFunction())).collect(Collectors.toList());
  400. // 一年的计算数据
  401. String wsFieldName = height + "awsDay";
  402. String wpdFieldName = height + "wpdDay";
  403. // 过滤属性集合找对应的属性id
  404. List<EquipmentAttribute> wsDayAtt = wsDayAttList.stream().filter(w -> w.getFieldName().equals(wsFieldName)).collect(Collectors.toList());
  405. String wsEbId = wsDayAtt.get(0).getId();
  406. List<EquipmentAttribute> wpdMonthAtt = wpdMonthAttList.stream().filter(w -> w.getFieldName().equals(wpdFieldName)).collect(Collectors.toList());
  407. String wpdEbId = wpdMonthAtt.get(0).getId();
  408. // 过滤一周数据
  409. List<List<Object>> wsDataList = new ArrayList<>();
  410. List<List<Object>> wpdDataList = new ArrayList<>();
  411. for (Long l = startDay.getTime(); l <= endDay.getTime(); l += 86400000L) {
  412. Date finalL = DateTimeUtil.getDayStartTime(l);
  413. List<WindTowerCalculationData> wsList = windTowerCalculationDataList.stream().filter(w -> w.getEbId().equals(wsEbId) && w.getTime().equals(finalL)).collect(Collectors.toList());
  414. List<Object> list = new ArrayList<>();
  415. if (!wsList.isEmpty()) {
  416. list.add(sdf.format(wsList.get(0).getTime()));
  417. list.add(wsList.get(0).getValue());
  418. wsDataList.add(list);
  419. } else {
  420. list.add(sdf.format(new Date(l)));
  421. list.add(new BigDecimal(0));
  422. wsDataList.add(list);
  423. }
  424. List<WindTowerCalculationData> wpdList = windTowerCalculationDataList.stream().filter(w -> w.getEbId().equals(wpdEbId) && w.getTime().equals(finalL)).collect(Collectors.toList());
  425. List<Object> listWpd = new ArrayList<>();
  426. if (!wpdList.isEmpty()) {
  427. listWpd.add(sdf.format(wpdList.get(0).getTime()));
  428. listWpd.add(wpdList.get(0).getValue());
  429. wpdDataList.add(listWpd);
  430. } else {
  431. listWpd.add(sdf.format(new Date(l)));
  432. listWpd.add(new BigDecimal(0));
  433. wpdDataList.add(listWpd);
  434. }
  435. }
  436. map.put("ws", wsDataList);
  437. map.put("wpd", wpdDataList);
  438. } catch (Exception e) {
  439. e.printStackTrace();
  440. }
  441. return map;
  442. }
  443. /**
  444. * 风速和风速标准差时间曲线图
  445. *
  446. * @param windTowerCalculationDataList 统计数据
  447. * @param equipmentAttributeList 属性数据
  448. * @param height 层高
  449. * @return
  450. */
  451. public Map<String, Object> wsAndWsSta(List<WindTowerCalculationData> windTowerCalculationDataList, List<EquipmentAttribute> equipmentAttributeList, String height, Date startDay, Date endDay) {
  452. // long yesterday = new Date().getTime() - 1000 * 60 * 60 * 24;//昨天
  453. // Date startTime = DateTimeUtil.getDayStartTime(DateTimeUtil.getYearDay(yesterday).getTime());
  454. // Date endTime = DateTimeUtil.getDayLastTime(yesterday);
  455. // List<Long> dateTime = DateTimeUtil.getIntervalTimeByMonth(DateTimeUtil.beginOfMonth(startTime), DateTimeUtil.beginOfMonth(endTime));
  456. Map<String, Object> map = new HashMap<>();
  457. try {
  458. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  459. // 根据设备属性表中的属性作用查询
  460. String wsFieldName = height + "awsDay";
  461. // 过滤属性集合找对应的属性id
  462. List<EquipmentAttribute> wsDayAtt = equipmentAttributeList.stream().filter(w -> w.getFieldName().equals(wsFieldName)).collect(Collectors.toList());
  463. String wsEbId = wsDayAtt.get(0).getId();
  464. //取出heigth层高的平均风速标差属性
  465. String staEbId = equipmentAttributeList.stream().filter(e -> e.getFieldName().equals(height + "staDay")).collect(Collectors.toList()).get(0).getId();
  466. List<List<Object>> wsDataList = new ArrayList<>();
  467. List<List<Object>> wsStaDataList = new ArrayList<>();
  468. for (Long l = startDay.getTime(); l <= endDay.getTime(); l += 86400000L) {
  469. Date finalL = DateTimeUtil.getDayStartTime(l);
  470. List<WindTowerCalculationData> wsList = windTowerCalculationDataList.stream().filter(w -> w.getEbId().equals(wsEbId) && w.getTime().equals(finalL)).collect(Collectors.toList());
  471. List<Object> list = new ArrayList<>();
  472. if (!wsList.isEmpty()) {
  473. list.add(sdf.format(wsList.get(0).getTime()));
  474. list.add(wsList.get(0).getValue());
  475. wsDataList.add(list);
  476. } else {
  477. list.add(sdf.format(new Date(l)));
  478. list.add(new BigDecimal(0));
  479. wsDataList.add(list);
  480. }
  481. //计算风速标准差
  482. List<WindTowerCalculationData> wsStaList = windTowerCalculationDataList.stream().filter(w -> w.getEbId().equals(staEbId) && w.getTime().equals(finalL)).collect(Collectors.toList());
  483. //取出这个层高所有的数据
  484. list = new ArrayList<>();
  485. if (!wsStaList.isEmpty()) {
  486. list.add(sdf.format(wsStaList.get(0).getTime()));
  487. list.add(wsStaList.get(0).getValue());
  488. wsStaDataList.add(list);
  489. } else {
  490. list.add(sdf.format(new Date(l)));
  491. list.add(BigDecimal.ZERO);
  492. wsStaDataList.add(list);
  493. }
  494. }
  495. map.put("ws", wsDataList);
  496. map.put("wsSta", wsStaDataList);
  497. } catch (Exception e) {
  498. e.printStackTrace();
  499. }
  500. return map;
  501. }
  502. /**
  503. * 风速和风速密度日变化
  504. *
  505. * @param height
  506. * @return map
  507. */
  508. public Map<String, Object> getWindPowerDensityAndAverageWindSpeed(List<WindTowerCalculationData> windTowerCalculationDataList, List<EquipmentAttribute> equipmentAttributeList, List<WindTowerInfo> windTowerInfos, String height) {
  509. Map<String, Object> map = new HashMap<>();
  510. try {
  511. String wpdFieldName = height + "wpd";
  512. String awsFieldName = height + "aws";
  513. List<EquipmentAttribute> wpdFieldNameList = equipmentAttributeList.stream().filter(e -> wpdFieldName.equals(e.getFieldName())).collect(Collectors.toList());
  514. List<EquipmentAttribute> awsFieldNameList = equipmentAttributeList.stream().filter(e -> awsFieldName.equals(e.getFieldName())).collect(Collectors.toList());
  515. if (!wpdFieldNameList.isEmpty() && !awsFieldNameList.isEmpty()) {
  516. String wpdEbId = wpdFieldNameList.get(0).getId();
  517. String awsEbId = awsFieldNameList.get(0).getId();
  518. //平均风速集合
  519. List<WindTowerCalculationData> awsList;
  520. //风功率密度集合
  521. List<WindTowerCalculationData> wpdList;
  522. awsList = windTowerCalculationDataList.stream().filter(w -> awsEbId.equals(w.getEbId())).sorted(Comparator.comparing(WindTowerCalculationData::getTime)).collect(Collectors.toList());
  523. wpdList = windTowerCalculationDataList.stream().filter(w -> wpdEbId.equals(w.getEbId())).sorted(Comparator.comparing(WindTowerCalculationData::getTime)).collect(Collectors.toList());
  524. if (!awsList.isEmpty()) {
  525. map.put("AverageWindSpeed", CalculationUtil.getData24(awsList));
  526. }
  527. if (!wpdList.isEmpty()) {
  528. map.put("WindPowerDensity", CalculationUtil.getData24(wpdList));
  529. }
  530. }
  531. map.put("table", getWpdTable(windTowerCalculationDataList, equipmentAttributeList, windTowerInfos));
  532. } catch (Exception e) {
  533. e.printStackTrace();
  534. }
  535. return map;
  536. }
  537. /**
  538. * 风速和风速密度日变化表格
  539. *
  540. * @return map
  541. */
  542. public Map<String, Object> getWpdTable(List<WindTowerCalculationData> windTowerCalculationDataList, List<EquipmentAttribute> equipmentAttributeList, List<WindTowerInfo> windTowerInfos) {
  543. Map<String, Object> map = new HashMap<>();
  544. List<List<BigDecimal>> list = new ArrayList<>();
  545. try {
  546. String height;
  547. height = windTowerInfos.get(0).getHeights();
  548. if (height == null || height.equals("")) {
  549. height = "10,30,50,60,70,80,90,100,110,120,140,150";
  550. }
  551. String[] heightAll = height.split(",");
  552. List<String> tableHeader = new ArrayList<>();
  553. tableHeader.add("时间");
  554. for (String str : heightAll) {
  555. List<BigDecimal> wsDataList = new ArrayList<>();
  556. List<BigDecimal> wpdDataList = new ArrayList<>();
  557. tableHeader.add(str + "m风速(m/s)");
  558. tableHeader.add(str + "m风功率密度(w/㎡)");
  559. String wpdFieldName = str + "wpd";
  560. String awsFieldName = str + "aws";
  561. List<EquipmentAttribute> wpdFieldNameList = equipmentAttributeList.stream().filter(e -> wpdFieldName.equals(e.getFieldName())).collect(Collectors.toList());
  562. List<EquipmentAttribute> awsFieldNameList = equipmentAttributeList.stream().filter(e -> awsFieldName.equals(e.getFieldName())).collect(Collectors.toList());
  563. //选择时间段的平均风速
  564. BigDecimal avgWs = new BigDecimal(0);
  565. //选择时间段的风功率密度
  566. BigDecimal avgWpd = new BigDecimal(0);
  567. if (!wpdFieldNameList.isEmpty() && !awsFieldNameList.isEmpty()) {
  568. String wpdEbId = wpdFieldNameList.get(0).getId();
  569. String awsEbId = awsFieldNameList.get(0).getId();
  570. //平均风速集合
  571. List<WindTowerCalculationData> awsList;
  572. //风功率密度集合
  573. List<WindTowerCalculationData> wpdList;
  574. awsList = windTowerCalculationDataList.stream().filter(w -> awsEbId.equals(w.getEbId())).sorted(Comparator.comparing(WindTowerCalculationData::getTime)).collect(Collectors.toList());
  575. wpdList = windTowerCalculationDataList.stream().filter(w -> wpdEbId.equals(w.getEbId())).sorted(Comparator.comparing(WindTowerCalculationData::getTime)).collect(Collectors.toList());
  576. if (!awsList.isEmpty()) {
  577. BigDecimal wsSum = new BigDecimal(0);
  578. for (WindTowerCalculationData data : awsList) {
  579. wsSum = wsSum.add(data.getValue());
  580. }
  581. //如何总和不为0
  582. if (wsSum.compareTo(new BigDecimal(0)) != 0) {
  583. avgWs = wsSum.divide(new BigDecimal(awsList.size()), 2, RoundingMode.HALF_UP);
  584. }
  585. wsDataList = getData24(awsList);
  586. wsDataList.add(avgWs);
  587. }
  588. if (!wpdList.isEmpty()) {
  589. BigDecimal wpdSum = new BigDecimal(0);
  590. for (WindTowerCalculationData data : wpdList) {
  591. wpdSum = wpdSum.add(data.getValue());
  592. }
  593. //如何总和不为0
  594. if (wpdSum.compareTo(new BigDecimal(0)) != 0) {
  595. avgWpd = wpdSum.divide(new BigDecimal(wpdList.size()), 2, RoundingMode.HALF_UP);
  596. }
  597. wpdDataList = getData24(wpdList);
  598. wpdDataList.add(avgWpd);
  599. }
  600. }
  601. list.add(wsDataList);
  602. list.add(wpdDataList);
  603. }
  604. map.put("tableHeader", tableHeader);
  605. map.put("data", list);
  606. } catch (Exception e) {
  607. e.printStackTrace();
  608. }
  609. return map;
  610. }
  611. /**
  612. * 风速和风速密度各月日变化
  613. *
  614. * @param height
  615. * @return map
  616. */
  617. public List<Map<String, Object>> getMonthWsAndWpd(List<WindTowerCalculationData> windTowerCalculationDataList, List<EquipmentAttribute> equipmentAttributeList, String height, Date startDay, Date endDay) {
  618. List<Map<String, Object>> list = new ArrayList<>();
  619. try {
  620. SimpleDateFormat sdf = new SimpleDateFormat("M");
  621. String wpdFieldName = height + "wpd";
  622. String awsFieldName = height + "aws";
  623. List<EquipmentAttribute> wpdFieldNameList = equipmentAttributeList.stream().filter(e -> wpdFieldName.equals(e.getFieldName())).collect(Collectors.toList());
  624. List<EquipmentAttribute> awsFieldNameList = equipmentAttributeList.stream().filter(e -> awsFieldName.equals(e.getFieldName())).collect(Collectors.toList());
  625. List<String> nullList = new ArrayList<>();
  626. if (!wpdFieldNameList.isEmpty() && !awsFieldNameList.isEmpty()) {
  627. String wpdEbId = wpdFieldNameList.get(0).getId();
  628. String awsEbId = awsFieldNameList.get(0).getId();
  629. List<WindTowerCalculationData> awsAllList = windTowerCalculationDataList.stream().filter(w -> awsEbId.equals(w.getEbId())).sorted(Comparator.comparing(WindTowerCalculationData::getTime)).collect(Collectors.toList());
  630. List<WindTowerCalculationData> wpdAllList = windTowerCalculationDataList.stream().filter(w -> wpdEbId.equals(w.getEbId())).sorted(Comparator.comparing(WindTowerCalculationData::getTime)).collect(Collectors.toList());
  631. List<Long> intervalTimeByMonth = DateTimeUtil.getIntervalTimeByMonth(startDay, endDay);
  632. for (int i = 1; i <= 12; i++) {
  633. //平均风速集合
  634. List<WindTowerCalculationData> awsList = new ArrayList<>();
  635. //风功率密度集合
  636. List<WindTowerCalculationData> wpdList = new ArrayList<>();
  637. Map<String, Object> dataMap = new HashMap<>();
  638. for (Long l : intervalTimeByMonth) {
  639. //判断月份是否相等
  640. if (String.valueOf(i).equals(sdf.format(new Date(l)))) {
  641. Date monthStartTime = DateTimeUtil.beginOfMonth(new Date(l));
  642. Date monthendTime = DateTimeUtil.endOfMonth(new Date(l));
  643. awsList = awsAllList.stream().filter(w -> w.getTime().compareTo(monthStartTime) >= 0 && w.getTime().compareTo(monthendTime) < 0).collect(Collectors.toList());
  644. wpdList = wpdAllList.stream().filter(w -> w.getTime().compareTo(monthStartTime) >= 0 && w.getTime().compareTo(monthendTime) < 0).collect(Collectors.toList());
  645. }
  646. }
  647. if (!awsList.isEmpty()) {
  648. dataMap.put("ws", CalculationUtil.getData24(awsList));
  649. } else {
  650. dataMap.put("ws", nullList);
  651. }
  652. if (!wpdList.isEmpty()) {
  653. dataMap.put("wpd", CalculationUtil.getData24(wpdList));
  654. } else {
  655. dataMap.put("wpd", nullList);
  656. }
  657. dataMap.put("time", i + "月");
  658. list.add(dataMap);
  659. }
  660. }
  661. } catch (Exception e) {
  662. e.printStackTrace();
  663. }
  664. return list;
  665. }
  666. /**
  667. * 风速和风速密度年变化曲线
  668. *
  669. * @return map
  670. */
  671. public Map<String, Object> getYearWsAndWpd(List<WindTowerCalculationData> windTowerCalculationDataList, List<EquipmentAttribute> equipmentAttributeList, String height, Date startDay, Date endDay) {
  672. Map<String, Object> map = new HashMap<>();
  673. try {
  674. // Long yesterday = new Date().getTime() - 1000 * 60 * 60 * 24;//昨天
  675. // Date startTime = DateTimeUtil.getDayStartTime(DateTimeUtil.getYearDay(yesterday).getTime());//报告的开始时间 一年前的昨天的00:00:00
  676. // Date endTime = DateTimeUtil.getDayLastTime(yesterday);//报告的结束时间 昨天的23:59:59
  677. /*设备属性信息*/
  678. String wpdFieldName = height + "wpdMonth"; //wpdMonth awsDay
  679. String awsFieldName = height + "awsMonth";
  680. List<EquipmentAttribute> wpdFieldNameList = equipmentAttributeList.stream().filter(e -> wpdFieldName.equals(e.getFieldName())).collect(Collectors.toList());
  681. List<EquipmentAttribute> awsFieldNameList = equipmentAttributeList.stream().filter(e -> awsFieldName.equals(e.getFieldName())).collect(Collectors.toList());
  682. List<BigDecimal> wsDataList = new ArrayList<>();
  683. List<BigDecimal> wpdDataList = new ArrayList<>();
  684. List<String> timeList = new ArrayList<>();
  685. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
  686. if (!wpdFieldNameList.isEmpty() && !awsFieldNameList.isEmpty()) {
  687. String wpdEbId = wpdFieldNameList.get(0).getId();
  688. String awsEbId = awsFieldNameList.get(0).getId();
  689. //平均风速集合
  690. List<WindTowerCalculationData> awsAllList = new ArrayList<>();
  691. //风功率密度集合
  692. List<WindTowerCalculationData> wpdAllList = new ArrayList<>();
  693. awsAllList = windTowerCalculationDataList.stream().filter(w -> awsEbId.equals(w.getEbId())).sorted(Comparator.comparing(WindTowerCalculationData::getTime)).collect(Collectors.toList());
  694. wpdAllList = windTowerCalculationDataList.stream().filter(w -> wpdEbId.equals(w.getEbId())).sorted(Comparator.comparing(WindTowerCalculationData::getTime)).collect(Collectors.toList());
  695. List<Long> timeByMonth = DateTimeUtil.getIntervalTimeByMonth(startDay, endDay);
  696. for (Long aLong : timeByMonth) {
  697. BigDecimal avgWs = new BigDecimal(0);
  698. BigDecimal avgWpd = new BigDecimal(0);
  699. //过滤平均风速集合
  700. List<WindTowerCalculationData> awsList = new ArrayList<>();
  701. //过滤风功率密度集合
  702. List<WindTowerCalculationData> wpdList = new ArrayList<>();
  703. // awsList = awsAllList.stream().filter(w -> w.getTime().compareTo(monthStartTime) >= 0 && w.getTime().compareTo(monthendTime) < 0 && w.getValue() != null && w.getValue().compareTo(new BigDecimal(-99)) != 0).collect(Collectors.toList());
  704. awsList = awsAllList.stream().filter(w -> w.getTime().equals(new Date(aLong)) && w.getValue() != null && w.getValue().compareTo(new BigDecimal(-99)) != 0).collect(Collectors.toList());
  705. wpdList = wpdAllList.stream().filter(w -> w.getTime().equals(new Date(aLong)) && w.getValue() != null && w.getValue().compareTo(new BigDecimal(-99)) != 0).collect(Collectors.toList());
  706. if (!awsList.isEmpty()) {
  707. List<BigDecimal> valueList = awsList.stream().map(WindTowerCalculationData::getValue).collect(Collectors.toList());
  708. avgWs = valueList.stream().reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(valueList.size()), 2, RoundingMode.HALF_UP);
  709. }
  710. wsDataList.add(avgWs);
  711. if (!wpdList.isEmpty()) {
  712. List<BigDecimal> valueList = wpdList.stream().map(WindTowerCalculationData::getValue).collect(Collectors.toList());
  713. avgWpd = valueList.stream().reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(valueList.size()), 2, RoundingMode.HALF_UP);
  714. }
  715. wpdDataList.add(avgWpd);
  716. timeList.add(sdf.format(aLong));
  717. }
  718. }
  719. map.put("wsList", wsDataList);
  720. map.put("wpdList", wpdDataList);
  721. map.put("time", timeList);
  722. } catch (Exception e) {
  723. e.printStackTrace();
  724. }
  725. return map;
  726. }
  727. /**
  728. * 风速和风速密度各月日变化表格
  729. *
  730. * @return map
  731. */
  732. public Map<String, Object> getMonthWpdTable(List<WindTowerCalculationData> windTowerCalculationDataList, List<EquipmentAttribute> equipmentAttributeList, List<WindTowerInfo> windTowerInfos, Date startDay, Date endDay) {
  733. Map<String, Object> map = new HashMap<>();
  734. List<List<BigDecimal>> list = new ArrayList<>();
  735. List<String> timeList = new ArrayList<>();
  736. try {
  737. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
  738. List<Long> timeByMonth = DateTimeUtil.getIntervalTimeByMonth(startDay, endDay);
  739. for (Long aLong : timeByMonth) {
  740. Date monthStartTime = DateTimeUtil.getDayStartTime(aLong);
  741. timeList.add(sdf.format(monthStartTime));
  742. }
  743. timeList.add("平均");
  744. //获取风速层高
  745. String height;
  746. height = windTowerInfos.get(0).getHeights();
  747. if (height == null || height.equals("")) {
  748. height = "10,30,50,60,70,80,90,100,110,120,140,150";
  749. }
  750. String[] heightAll = height.split(",");
  751. List<String> tableHeader = new ArrayList<>();
  752. tableHeader.add("月份");
  753. for (String str : heightAll) {
  754. List<BigDecimal> wsDataList = new ArrayList<>();
  755. List<BigDecimal> wpdDataList = new ArrayList<>();
  756. tableHeader.add(str + "m风速(m/s)");
  757. tableHeader.add(str + "m风功率密度(w/㎡)");
  758. String wpdFieldName = str + "wpdMonth"; //wpdMonth awsDay
  759. String awsFieldName = str + "awsMonth";
  760. List<EquipmentAttribute> wpdFieldNameList = equipmentAttributeList.stream().filter(e -> wpdFieldName.equals(e.getFieldName())).collect(Collectors.toList());
  761. List<EquipmentAttribute> awsFieldNameList = equipmentAttributeList.stream().filter(e -> awsFieldName.equals(e.getFieldName())).collect(Collectors.toList());
  762. BigDecimal sumAveWs = new BigDecimal(0);
  763. BigDecimal sumAveWpd = new BigDecimal(0);
  764. if (!wpdFieldNameList.isEmpty() && !awsFieldNameList.isEmpty()) {
  765. String wpdEbId = wpdFieldNameList.get(0).getId();
  766. String awsEbId = awsFieldNameList.get(0).getId();
  767. //平均风速集合
  768. List<WindTowerCalculationData> awsAllList;
  769. //风功率密度集合
  770. List<WindTowerCalculationData> wpdAllList;
  771. awsAllList = windTowerCalculationDataList.stream().filter(w -> awsEbId.equals(w.getEbId())).sorted(Comparator.comparing(WindTowerCalculationData::getTime)).collect(Collectors.toList());
  772. wpdAllList = windTowerCalculationDataList.stream().filter(w -> wpdEbId.equals(w.getEbId())).sorted(Comparator.comparing(WindTowerCalculationData::getTime)).collect(Collectors.toList());
  773. for (Long aLong : timeByMonth) {
  774. BigDecimal avgWs = new BigDecimal(0);
  775. BigDecimal avgWpd = new BigDecimal(0);
  776. //过滤平均风速集合
  777. List<WindTowerCalculationData> awsList;
  778. //过滤风功率密度集合
  779. List<WindTowerCalculationData> wpdList;
  780. awsList = awsAllList.stream().filter(w -> w.getTime().equals(new Date(aLong))).collect(Collectors.toList());
  781. wpdList = wpdAllList.stream().filter(w -> w.getTime().equals(new Date(aLong))).collect(Collectors.toList());
  782. if (!awsList.isEmpty()) {
  783. List<BigDecimal> valueList = awsList.stream().map(WindTowerCalculationData::getValue).collect(Collectors.toList());
  784. avgWs = valueList.stream().reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(valueList.size()), 2, RoundingMode.HALF_UP);
  785. }
  786. wsDataList.add(avgWs);
  787. if (!wpdList.isEmpty()) {
  788. List<BigDecimal> valueList = wpdList.stream().map(WindTowerCalculationData::getValue).collect(Collectors.toList());
  789. avgWpd = valueList.stream().reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(valueList.size()), 2, RoundingMode.HALF_UP);
  790. }
  791. wpdDataList.add(avgWpd);
  792. }
  793. int wsListCount = wsDataList.stream().filter(w -> w.compareTo(new BigDecimal(0)) != 0).collect(Collectors.toList()).size();
  794. int wpdListCount = wpdDataList.stream().filter(w -> w.compareTo(new BigDecimal(0)) != 0).collect(Collectors.toList()).size();
  795. if (wsListCount != 0) {
  796. sumAveWs = wsDataList.stream().reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(wsListCount), 2, RoundingMode.HALF_UP);
  797. }
  798. if (wpdListCount != 0) {
  799. sumAveWpd = wpdDataList.stream().reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(wpdListCount), 2, RoundingMode.HALF_UP);
  800. }
  801. wsDataList.add(sumAveWs);
  802. wpdDataList.add(sumAveWpd);
  803. }
  804. list.add(wsDataList);
  805. list.add(wpdDataList);
  806. }
  807. map.put("tableHeader", tableHeader);
  808. map.put("data", list);
  809. map.put("month", timeList);
  810. } catch (Exception e) {
  811. e.printStackTrace();
  812. }
  813. return map;
  814. }
  815. /**
  816. * pdf威布尔
  817. *
  818. * @return weibull
  819. */
  820. public ArrayList<Map<String, Object>> pdfWeibull(List<EquipmentAttribute> equipmentAttributeList, List<WindTowerCalculationData> windTowerCalculationDataList, List<WindTowerInfo> windTowerInfos) {
  821. ArrayList<Map<String, Object>> weibullDataList = new ArrayList<>();
  822. try {
  823. String[] heightWs = windTowerInfos.get(0).getHeights().split(",");
  824. for (String height : heightWs) {
  825. Map<String, Object> map = new HashMap<>();
  826. List<BigDecimal> wsList = new ArrayList<>();
  827. double e = 2.71828183;
  828. // 风速集合
  829. String ebId = equipmentAttributeList.stream().filter(w -> w.getFieldName().equals(height + "aws")).collect(Collectors.toList()).get(0).getId();
  830. List<WindTowerCalculationData> calculationDataList = windTowerCalculationDataList.stream().filter(w -> w.getEbId().equals(ebId)).collect(Collectors.toList());
  831. for (WindTowerCalculationData w : calculationDataList) {
  832. wsList.add(w.getValue());
  833. }
  834. TreeMap<BigDecimal, List<BigDecimal>> wsMap = new TreeMap<>();
  835. if (!wsList.isEmpty()) {
  836. ArrayList<Object> arrayWsList = new ArrayList<>(wsList);
  837. //把风速集合传入,计算A、K
  838. ProbabilityPlot probabilityPlot = new ProbabilityPlot(arrayWsList);
  839. probabilityPlot.suppressDisplay();
  840. double K = probabilityPlot.weibullTwoParGamma();
  841. double A = probabilityPlot.weibullTwoParSigma();
  842. //
  843. //
  844. // map.put("K", BigDecimal.valueOf(K).setScale(2, RoundingMode.HALF_UP).doubleValue());
  845. // map.put("A", BigDecimal.valueOf(A).setScale(2, RoundingMode.HALF_UP).doubleValue());
  846. // BigDecimal wsAve = wsList.stream().reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(wsList.size()), 2, RoundingMode.HALF_UP);
  847. // map.put("wsAve", wsAve);
  848. /*根据风速过滤出风速区间集合*/
  849. for (BigDecimal ws : wsList) {
  850. // 风速区间
  851. BigDecimal speedLevel = BigDecimal.valueOf(Math.ceil(ws.subtract(BigDecimal.valueOf(0.5)).doubleValue()));
  852. if (wsMap.containsKey(speedLevel)) {
  853. wsMap.get(speedLevel).add(ws);
  854. } else {
  855. wsMap.put(speedLevel, new ArrayList<>());
  856. wsMap.get(speedLevel.setScale(1, RoundingMode.HALF_UP)).add(ws);
  857. }
  858. }
  859. /*风速频率*/
  860. List<List<BigDecimal>> wsFreList = new ArrayList<>();
  861. /*威布尔*/
  862. List<List<BigDecimal>> weibullList = new ArrayList<>();
  863. wsMap.forEach((key, val) -> {
  864. Map<String, Object> freMap = new HashMap<>();
  865. List<BigDecimal> list = new ArrayList<>();
  866. List<BigDecimal> tempList = new ArrayList<>();
  867. BigDecimal wsFrequency = new BigDecimal(val.size()).divide(new BigDecimal(wsList.size()), 4, RoundingMode.HALF_UP).multiply(new BigDecimal(100));
  868. list.add(key.setScale(0, RoundingMode.HALF_UP));
  869. list.add(wsFrequency);
  870. wsFreList.add(list);
  871. /*区间威布尔累加求和求平均值*/
  872. BigDecimal aveWs = val.stream().reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(val.size()), 2, RoundingMode.HALF_UP);
  873. BigDecimal weibull = CalculationUtil.getBigDecimal(e, aveWs.doubleValue(), K, A);
  874. tempList.add(key.setScale(0, RoundingMode.HALF_UP));
  875. tempList.add(weibull);
  876. weibullList.add(tempList);
  877. });
  878. map.put("wsFrequency", wsFreList);
  879. map.put("weibull", weibullList);
  880. map.put("height", height);
  881. }
  882. weibullDataList.add(map);
  883. }
  884. } catch (Exception e) {
  885. e.printStackTrace();
  886. }
  887. return weibullDataList;
  888. }
  889. /**
  890. * 湍流(15m/s湍流)最大、最小、平均 数据
  891. *
  892. * @param windTowerCalculationDatas 统计数据
  893. * @param equipmentAttributeList 属性数据
  894. * @return
  895. */
  896. public ArrayList<Map<String, Object>> statisticsWindTowerStatusDataTur(List<WindTowerCalculationData> windTowerCalculationDatas, List<EquipmentAttribute> equipmentAttributeList, List<WindTowerInfo> windTowerInfos) {
  897. ArrayList<Map<String, Object>> heightAndTurList = new ArrayList<>();
  898. String[] heights = windTowerInfos.get(0).getHeights().split(",");
  899. for (String height : heights) {
  900. BigDecimal turAve = BigDecimal.ZERO;
  901. BigDecimal turForFifteen = BigDecimal.ZERO;
  902. Map<String, Object> map = new HashMap<>();
  903. List<EquipmentAttribute> equipmentAttributes = equipmentAttributeList.stream().filter(e -> e.getFieldName().equals(height + "turbulenceDay")).collect(Collectors.toList());
  904. List<EquipmentAttribute> equipmentAttribute = equipmentAttributeList.stream().filter(e -> e.getFieldName().equals(height + "turForWsByFifteenDay")).collect(Collectors.toList());
  905. //通过属性过滤数据
  906. List<WindTowerCalculationData> dayList = windTowerCalculationDatas.stream().filter(w -> w.getEbId().equals(equipmentAttributes.get(0).getId())).collect(Collectors.toList());
  907. List<WindTowerCalculationData> turDayList = windTowerCalculationDatas.stream().filter(w -> w.getEbId().equals(equipmentAttribute.get(0).getId())).collect(Collectors.toList());
  908. if (dayList.size() > 0) {
  909. turAve = dayList.stream().map(WindTowerCalculationData::getValue).reduce(BigDecimal::add).get().divide(BigDecimal.valueOf(dayList.size()), 2, RoundingMode.HALF_UP);
  910. }
  911. if (turDayList.size() > 0) {
  912. turForFifteen = turDayList.stream().map(WindTowerCalculationData::getValue).reduce(BigDecimal::add).get().divide(BigDecimal.valueOf(turDayList.size()), 2, RoundingMode.HALF_UP);
  913. }
  914. map.put("turAve", turAve);
  915. map.put("turForFifteen", turForFifteen);
  916. map.put("height", height);
  917. heightAndTurList.add(map);
  918. }
  919. return heightAndTurList;
  920. }
  921. /**
  922. * 风切变
  923. *
  924. * @return
  925. */
  926. public Map<String, Object> statisticsWindTowerStatusDataShear(List<ProphaseAnemometryData> prophaseAnemometryData, List<WindTowerInfo> windTowerInfos) {
  927. Map<String, Object> map = new HashMap<>();
  928. ArrayList<Object> wsShearTableData = new ArrayList<>();
  929. // HashMap<String, Object> heightMap = new HashMap<>();
  930. String[] heights = windTowerInfos.get(0).getHeights().split(",");
  931. for (int i = heights.length - 1 ; i > 0; i--) {
  932. String mixHeight = heights[i];
  933. HashMap<Object, Object> mainData = new HashMap<>();
  934. if (mixHeight.contains("A")) {
  935. continue;
  936. }
  937. List<BigDecimal> minHeightForWsList = prophaseAnemometryData.stream().filter(p -> p.getLayerHeight().equals(mixHeight)).map(p -> {
  938. return CalculationUtil.getBigDecimal(null == p.getWsAve()?0: p.getWsAve());
  939. }).collect(Collectors.toList());
  940. BigDecimal wsAveForMin = CalculationUtil.getAvgWind(minHeightForWsList);
  941. //筛选高层高
  942. List<String> heightList = new ArrayList<>(Arrays.asList(heights)).stream().filter(s -> Integer.valueOf(CalculationUtil.getNumberFromString(mixHeight)) < Integer.valueOf(CalculationUtil.getNumberFromString(s))).collect(Collectors.toList());
  943. for (String maxHeight : heightList) {
  944. if (maxHeight.contains("A")) {
  945. continue;
  946. }
  947. List<BigDecimal> maxHeightForWsList = prophaseAnemometryData.stream().filter(p -> p.getLayerHeight().equals(maxHeight)).map(p -> {
  948. return CalculationUtil.getBigDecimal(null == p.getWsAve()?0: p.getWsAve());
  949. }).collect(Collectors.toList());
  950. BigDecimal wsAveMax = CalculationUtil.getAvgWind(maxHeightForWsList);
  951. double z = new BigDecimal(CalculationUtil.getNumberFromString(maxHeight)).divide(new BigDecimal(CalculationUtil.getNumberFromString(mixHeight)), 8, RoundingMode.HALF_UP).doubleValue();
  952. double z1 = Math.log10(z);
  953. if (wsAveForMin.compareTo(BigDecimal.ZERO) > 0 && wsAveMax.compareTo(BigDecimal.ZERO) > 0 && z1 != 0) {
  954. BigDecimal shear = Convert.toBigDecimal(Math.log10(Convert.toDouble(wsAveMax.divide(wsAveForMin, 8, RoundingMode.HALF_UP))))
  955. .divide(BigDecimal.valueOf(z1), 2, RoundingMode.HALF_UP);
  956. mainData.put(maxHeight, shear);
  957. }
  958. }
  959. mainData.put("height", mixHeight);
  960. wsShearTableData.add(mainData);
  961. }
  962. // heightMap.put("headerData", Arrays.asList(heights));
  963. // wsShearTableData.add(heightMap);
  964. map.put("mainData",wsShearTableData);
  965. map.put("headerData",Arrays.asList(heights));
  966. return map;
  967. }
  968. /**
  969. * 一年玫瑰图
  970. *
  971. * @param
  972. * @return
  973. * @throws Exception
  974. */
  975. public ArrayList<Map<String, Object>> roseCharts(List<WindDirectionStatisticsData> windDirectionStatisticsData, List<EquipmentAttribute> equipmentAttributeList, List<WindTowerInfo> windTowerInfos) {
  976. ArrayList<Map<String, Object>> wdList = new ArrayList<>();
  977. try {
  978. String[] heightWd = windTowerInfos.get(0).getWdHeights().split(",");
  979. for (String height : heightWd) {
  980. Map<String, Object> map = new HashMap<>();
  981. // 若层高包含A按照去掉A的层高计算
  982. if (height.contains("A")) {
  983. height = height.substring(0, height.length() - 1);
  984. }
  985. map.put("height", height);
  986. map.put("wd", getwd(windDirectionStatisticsData, equipmentAttributeList, height));
  987. map.put("power", getPower(windDirectionStatisticsData, equipmentAttributeList, height));
  988. wdList.add(map);
  989. }
  990. } catch (Exception e) {
  991. e.printStackTrace();
  992. }
  993. return wdList;
  994. }
  995. /**
  996. * 各月玫瑰图
  997. *
  998. * @param height 层高
  999. * @return
  1000. * @throws Exception
  1001. */
  1002. public Map<String, Object> getMonthRoseCharts(List<WindDirectionStatisticsData> windDirectionStatisticsData, List<EquipmentAttribute> equipmentAttributeList, String height) {
  1003. Map<String, Object> map = new HashMap<>();
  1004. List<Map<String, Object>> wdList = new ArrayList<>();
  1005. List<Map<String, Object>> powerList = new ArrayList<>();
  1006. SimpleDateFormat monthSdf = new SimpleDateFormat("M");
  1007. try {
  1008. // 若层高包含A按照去掉A的层高计算
  1009. if (height.contains("A")) {
  1010. height = height.substring(0, height.length() - 1);
  1011. }
  1012. for (int i = 1; i <= 12; i++) {
  1013. Map<String, Object> wdMap = new HashMap<>();
  1014. Map<String, Object> powerMap = new HashMap<>();
  1015. // Date monthStartTime = DateTimeUtil.getDayStartTime(DateTimeUtil.mouthOneDay(i).getTime());
  1016. // Date monthendTime = DateTimeUtil.getDayLastTime(DateTimeUtil.mouthLastDay(i).getTime());
  1017. //过滤时间区间集合
  1018. List<WindDirectionStatisticsData> filterList = new ArrayList<>();
  1019. // filterList = windDirectionStatisticsData.stream().filter(w -> w.getTime().compareTo(monthStartTime) >= 0 && w.getTime().compareTo(monthendTime) < 0).collect(Collectors.toList());
  1020. int finalI = i;
  1021. filterList = windDirectionStatisticsData.stream().filter(w -> monthSdf.format(w.getTime()).equals(String.valueOf(finalI))).collect(Collectors.toList());
  1022. wdMap.put("time", i + "月");
  1023. powerMap.put("time", i + "月");
  1024. //如果月份数据为空就放null
  1025. if (!filterList.isEmpty()) {
  1026. List<Map<String, Object>> getwd = getwd(filterList, equipmentAttributeList, height);
  1027. wdMap.put("data", getwd);
  1028. powerMap.put("data", getPower(filterList, equipmentAttributeList, height));
  1029. } else {
  1030. wdMap.put("data", null);
  1031. powerMap.put("data", null);
  1032. }
  1033. wdList.add(wdMap);
  1034. powerList.add(powerMap);
  1035. }
  1036. map.put("wd", wdList);
  1037. map.put("power", powerList);
  1038. } catch (Exception e) {
  1039. e.printStackTrace();
  1040. }
  1041. return map;
  1042. }
  1043. /*风向玫瑰图数据*/
  1044. public List<Map<String, Object>> getwd(List<WindDirectionStatisticsData> windDirectionStatisticsData, List<EquipmentAttribute> equipmentAttributeList, String height) {
  1045. List<Map<String, Object>> list = new ArrayList<>();
  1046. String wdFieldName = height + "monthWdRose";
  1047. // 过滤获取ebId
  1048. List<EquipmentAttribute> wdEquipmentAttribute = equipmentAttributeList.stream().filter(e -> wdFieldName.equals(e.getFieldName())).collect(Collectors.toList());
  1049. // 获取风向统计数据
  1050. List<WindDirectionStatisticsData> wdList = windDirectionStatisticsData.stream().filter(e -> e.getEbId().equals(wdEquipmentAttribute.get(0).getId())).collect(Collectors.toList());
  1051. /*玫瑰图风向枚举*/
  1052. for (WindDirectionEnum value : WindDirectionEnum.values()) {
  1053. Map<String, Object> wdMap = new HashMap<>();
  1054. // 根据风向过滤统计表
  1055. List<WindDirectionStatisticsData> filterWdList = wdList.stream().filter(e -> e.getDirection().equals(value.name())).collect(Collectors.toList());
  1056. // 提取过滤的value值
  1057. // List<BigDecimal> filterwdValueList = filterWdList.stream().map(WindDirectionStatisticsData::getValue).filter(w -> w != null).collect(Collectors.toList());
  1058. // 累加保留两位小数
  1059. BigDecimal proportionWd = BigDecimal.ZERO;
  1060. if (!filterWdList.isEmpty()) {
  1061. proportionWd = BigDecimal.valueOf(filterWdList.size()).multiply(new BigDecimal(100)).divide(BigDecimal.valueOf(wdList.size()), 2, RoundingMode.HALF_UP);
  1062. }
  1063. wdMap.put(value.name(), proportionWd);
  1064. list.add(wdMap);
  1065. }
  1066. return list;
  1067. }
  1068. /*风能玫瑰图数据*/
  1069. public List<Map<String, Object>> getPower(List<WindDirectionStatisticsData> windDirectionStatisticsData, List<EquipmentAttribute> equipmentAttributeList, String height) {
  1070. List<Map<String, Object>> list = new ArrayList<>();
  1071. String powerFieldName = height + "monthPowerRose";
  1072. // 过滤获取ebId
  1073. List<EquipmentAttribute> powerEquipmentAttribute = equipmentAttributeList.stream().filter(e -> powerFieldName.equals(e.getFieldName())).collect(Collectors.toList());
  1074. // 获取风向统计数据
  1075. List<WindDirectionStatisticsData> powerList = windDirectionStatisticsData.stream().filter(e -> e.getEbId().equals(powerEquipmentAttribute.get(0).getId())).collect(Collectors.toList());
  1076. BigDecimal sumPower = powerList.stream().map(WindDirectionStatisticsData::getValue).reduce(BigDecimal::add).get();
  1077. /*玫瑰图风向枚举*/
  1078. for (WindDirectionEnum value : WindDirectionEnum.values()) {
  1079. Map<String, Object> powerMap = new HashMap<>();
  1080. // 根据风向过滤统计表
  1081. List<WindDirectionStatisticsData> filterPowerList = powerList.stream().filter(e -> e.getDirection().equals(value.name())).collect(Collectors.toList());
  1082. BigDecimal sumPowerForWd = BigDecimal.ZERO;
  1083. if (filterPowerList.size() > 0) {
  1084. sumPowerForWd = filterPowerList.stream().filter(w -> w.getValue() != null).map(WindDirectionStatisticsData::getValue).reduce(BigDecimal::add).get();
  1085. }
  1086. // 累加保留两位小数
  1087. BigDecimal proportionPower = BigDecimal.ZERO;
  1088. if (sumPower.compareTo(BigDecimal.ZERO) > 0) {
  1089. proportionPower = sumPowerForWd.multiply(new BigDecimal(100)).divide(sumPower, 2, RoundingMode.HALF_UP);
  1090. }
  1091. powerMap.put(value.name(), proportionPower);
  1092. list.add(powerMap);
  1093. }
  1094. return list;
  1095. }
  1096. /**
  1097. * 空气密度
  1098. *
  1099. * @return
  1100. * @throws Exception
  1101. */
  1102. public Map<String, Object> getAirDensity(List<WindTowerCalculationData> windTowerCalculationDatas, List<EquipmentAttribute> equipmentAttributeList, Date startDay, Date endDay) {
  1103. Map<String, Object> map = new HashMap<>();
  1104. List<String> timeList = new ArrayList<>();
  1105. List<String> monthTimeList = new ArrayList<>();
  1106. List<BigDecimal> tList = new ArrayList<>();
  1107. List<BigDecimal> paList = new ArrayList<>();
  1108. try {
  1109. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
  1110. SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
  1111. List<EquipmentAttribute> tAVE = equipmentAttributeList.stream().filter(e -> "tDay".equals(e.getFieldName())).collect(Collectors.toList());
  1112. List<EquipmentAttribute> paAVE = equipmentAttributeList.stream().filter(e -> "paDay".equals(e.getFieldName())).collect(Collectors.toList());
  1113. List<EquipmentAttribute> airDensityMonth = equipmentAttributeList.stream().filter(e -> "airDensityMonth".equals(e.getFieldName())).collect(Collectors.toList());
  1114. List<EquipmentAttribute> airDensityDayForYear = equipmentAttributeList.stream().filter(e -> "airDensityDayForYear".equals(e.getFieldName())).collect(Collectors.toList());
  1115. List<WindTowerCalculationData> tAVEData = windTowerCalculationDatas.stream().filter(w -> w.getEbId().equals(tAVE.get(0).getId())).sorted(Comparator.comparing(WindTowerCalculationData::getTime)).collect(Collectors.toList());
  1116. List<WindTowerCalculationData> paAVEData = windTowerCalculationDatas.stream().filter(w -> w.getEbId().equals(paAVE.get(0).getId())).sorted(Comparator.comparing(WindTowerCalculationData::getTime)).collect(Collectors.toList());
  1117. List<WindTowerCalculationData> airDensityMonthData = windTowerCalculationDatas.stream().filter(w -> w.getEbId().equals(airDensityMonth.get(0).getId())).sorted(Comparator.comparing(WindTowerCalculationData::getTime)).collect(Collectors.toList());
  1118. List<WindTowerCalculationData> airDensityDayForYearData = windTowerCalculationDatas.stream().filter(w -> w.getEbId().equals(airDensityDayForYear.get(0).getId())).sorted(Comparator.comparing(WindTowerCalculationData::getTime)).collect(Collectors.toList());
  1119. /*温度气压曲线*/
  1120. //补点做法
  1121. for (Long l = startDay.getTime(); l <= endDay.getTime(); l += 86400000L) {
  1122. Date finalL = DateUtil.beginOfDay(new Date(l));
  1123. String dates = sdf1.format(finalL);
  1124. List<WindTowerCalculationData> collect = tAVEData.stream().filter(t -> sdf1.format(t.getTime()).equals(dates)).collect(Collectors.toList());
  1125. if (!collect.isEmpty()) {
  1126. tList.add(collect.get(0).getValue());
  1127. } else {
  1128. tList.add(null);
  1129. }
  1130. List<WindTowerCalculationData> collect1 = paAVEData.stream().filter(p -> sdf1.format(p.getTime()).equals(dates)).collect(Collectors.toList());
  1131. if (!collect1.isEmpty()) {
  1132. paList.add(collect1.get(0).getValue());
  1133. } else {
  1134. paList.add(null);
  1135. }
  1136. timeList.add(sdf.format(finalL));
  1137. }
  1138. map.put("time", timeList);
  1139. map.put("t", tList);
  1140. map.put("pa", paList);
  1141. // //月平均温度
  1142. // for (WindTowerCalculationData w : tAVEData) {
  1143. // timeList.add(sdf.format(w.getTime()));
  1144. // tList.add(w.getValue());
  1145. // }
  1146. // //月平均气压
  1147. // for (WindTowerCalculationData w : paAVEData) {
  1148. // paList.add(w.getValue());
  1149. // }
  1150. // map.put("time", timeList);
  1151. // map.put("t", tList);
  1152. // map.put("pa", paList);
  1153. /*空气密度日变化*/
  1154. List<BigDecimal> airDensityList = new ArrayList<>();
  1155. if (!airDensityDayForYearData.isEmpty()) {
  1156. airDensityList = CalculationUtil.getData24(airDensityDayForYearData);
  1157. }
  1158. List<BigDecimal> airDensityCollect = airDensityList.stream().filter(w -> w.compareTo(new BigDecimal(0)) != 0).collect(Collectors.toList());
  1159. BigDecimal ave24AirDensity = BigDecimal.ZERO;
  1160. if (!airDensityCollect.isEmpty()) {
  1161. ave24AirDensity = airDensityCollect.stream().reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(24), 3, RoundingMode.HALF_UP);
  1162. }
  1163. map.put("dayAirDensity", airDensityList);
  1164. map.put("aveDayAirDensity", ave24AirDensity);
  1165. /*空气年变化*/
  1166. List<BigDecimal> monthList = new ArrayList<>();
  1167. SimpleDateFormat sdfMonth = new SimpleDateFormat("M");
  1168. for (int i = 1; i <= 12; i++) {
  1169. // Date monthStartTime = DateTimeUtil.getDayStartTime(DateTimeUtil.mouthOneDay(i).getTime());
  1170. //过滤时间区间集合
  1171. List<WindTowerCalculationData> filterList = new ArrayList<>();
  1172. BigDecimal value = new BigDecimal(0);
  1173. int finalI = i;
  1174. filterList = airDensityMonthData.stream().filter(w -> sdfMonth.format(w.getTime()).equals(String.valueOf(finalI))).collect(Collectors.toList());
  1175. if (!filterList.isEmpty()) {
  1176. value = filterList.get(0).getValue();
  1177. }
  1178. monthList.add(value);
  1179. monthTimeList.add(i + "月");
  1180. }
  1181. // for (WindTowerCalculationData w : airDensityMonthData) {
  1182. // monthTimeList.add(sdf.format(w.getTime()));
  1183. // monthList.add(w.getValue());
  1184. // }
  1185. List<BigDecimal> collect = monthList.stream().filter(w -> w.compareTo(new BigDecimal(0)) != 0).collect(Collectors.toList());
  1186. BigDecimal yearAveAirDensity = new BigDecimal(0);
  1187. if (!collect.isEmpty()) {
  1188. yearAveAirDensity = collect.stream().reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(collect.size()), 3, RoundingMode.HALF_UP);
  1189. }
  1190. map.put("monthTime", monthTimeList);
  1191. map.put("yearAirDensity", monthList);
  1192. map.put("yearAveAirDensity", yearAveAirDensity);
  1193. } catch (Exception e) {
  1194. e.printStackTrace();
  1195. }
  1196. return map;
  1197. }
  1198. /**
  1199. * 获取风切变指数(风向玫瑰图)
  1200. *
  1201. * @param height
  1202. */
  1203. public List<Map<String, Object>> getWindShearRose(List<WindDirectionStatisticsData> windDirectionStatisticsData, List<EquipmentAttribute> equipmentAttributeList, String height) {
  1204. List<Map<String, Object>> list = new ArrayList<>();
  1205. try {
  1206. // 若层高包含A按照去掉A的层高计算
  1207. if (height.contains("A")) {
  1208. height = height.substring(0, height.length() - 1);
  1209. }
  1210. String shearFieldName = height + "monthShearRose";
  1211. // 过滤获取ebId
  1212. List<EquipmentAttribute> shearEquipmentAttribute = equipmentAttributeList.stream().filter(e -> shearFieldName.equals(e.getFieldName())).collect(Collectors.toList());
  1213. // 获取风向统计数据
  1214. List<WindDirectionStatisticsData> shearList = windDirectionStatisticsData.stream().filter(e -> e.getEbId().equals(shearEquipmentAttribute.get(0).getId())).collect(Collectors.toList());
  1215. for (WindDirectionEnum value : WindDirectionEnum.values()) {
  1216. Map<String, Object> map = new HashMap<>();
  1217. // 根据风向过滤统计表
  1218. List<WindDirectionStatisticsData> filterShearList = shearList.stream().filter(e -> e.getDirection().equals(value.name())).collect(Collectors.toList());
  1219. // 提取过滤的value值
  1220. List<BigDecimal> filterShearValueList = filterShearList.stream().map(WindDirectionStatisticsData::getValue).filter(w -> w != null).collect(Collectors.toList());
  1221. // 累加保留两位小数
  1222. BigDecimal sumShear = null;
  1223. if (!filterShearValueList.isEmpty()) {
  1224. sumShear = filterShearValueList.stream().reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, RoundingMode.HALF_UP);
  1225. }
  1226. map.put(value.name(), sumShear);
  1227. list.add(map);
  1228. }
  1229. } catch (Exception e) {
  1230. e.printStackTrace();
  1231. }
  1232. return list;
  1233. }
  1234. /**
  1235. * 风切变日/年变化
  1236. *
  1237. * @return
  1238. * @throws Exception
  1239. */
  1240. public Map<String, Object> getWindShear(List<WindTowerCalculationData> windTowerCalculationDataLists, List<EquipmentAttribute> equipmentAttributeList, String height) {
  1241. Map<String, Object> map = new HashMap<>();
  1242. try {
  1243. List<BigDecimal> dayResults = new ArrayList<>();//日变化
  1244. List<BigDecimal> yearResults = new ArrayList<>();//年变化
  1245. List<String> monthTimeList = new ArrayList<>();
  1246. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH");
  1247. SimpleDateFormat sdf = new SimpleDateFormat("M");
  1248. String shearFieldName = "windShear";
  1249. List<EquipmentAttribute> shearFieldNameList = equipmentAttributeList.stream().filter(e -> shearFieldName.equals(e.getFieldName())).collect(Collectors.toList());
  1250. if (!shearFieldNameList.isEmpty()) {
  1251. String ebId = shearFieldNameList.get(0).getId(); //属性id
  1252. //查询风切变 月平均数据 根据时间,层高,设备id 并根据时间升序排列
  1253. List<WindTowerCalculationData> windTowerCalculationDataList = windTowerCalculationDataLists.stream().filter(w -> ebId.equals(w.getEbId())).sorted(Comparator.comparing(WindTowerCalculationData::getTime)).collect(Collectors.toList());
  1254. if (!windTowerCalculationDataList.isEmpty()) {
  1255. /*日变化*/
  1256. long startTime1 = DateMomentUtil.getDayStartTime(DateUtils.addDays(new Date(), -1).getTime());
  1257. long endTime1 = startTime1 + 86399000L;
  1258. for (long time = startTime1; time <= endTime1; time += 3600000L) {
  1259. Long finalTime = time;
  1260. String format = simpleDateFormat.format(finalTime);
  1261. List<BigDecimal> collect = windTowerCalculationDataList.stream().filter(s -> simpleDateFormat.format(s.getTime())
  1262. .equals(format) && s.getValue() != null && s.getValue().compareTo(new BigDecimal(-99)) != 0)
  1263. .map(WindTowerCalculationData::getValue).collect(Collectors.toList());
  1264. BigDecimal ave = new BigDecimal(0);
  1265. if (!collect.isEmpty()) {
  1266. ave = collect.stream().reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(collect.size()), 3, RoundingMode.HALF_UP);
  1267. }
  1268. dayResults.add(ave);
  1269. }
  1270. BigDecimal dayAve = new BigDecimal(0);
  1271. if (!dayResults.isEmpty()) {
  1272. dayAve = dayResults.stream().reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(24), 3, RoundingMode.HALF_UP);
  1273. }
  1274. map.put("dayShear", dayResults);
  1275. map.put("aveDayShear", dayAve);
  1276. /*年变化*/
  1277. for (int i = 1; i <= 12; i++) {
  1278. //过滤时间区间集合
  1279. List<WindTowerCalculationData> filterList = new ArrayList<>();
  1280. BigDecimal yearShear = new BigDecimal(0);
  1281. int finalI = i;
  1282. filterList = windTowerCalculationDataList.stream().filter(w -> sdf.format(w.getTime()).equals(String.valueOf(finalI))).collect(Collectors.toList());
  1283. if (!filterList.isEmpty()) {
  1284. List<BigDecimal> collect = filterList.stream().map(WindTowerCalculationData::getValue).collect(Collectors.toList());
  1285. yearShear = collect.stream().reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(collect.size()), 3, RoundingMode.HALF_UP);
  1286. }
  1287. yearResults.add(yearShear);
  1288. monthTimeList.add(i + "月");
  1289. }
  1290. BigDecimal aveYearShear = new BigDecimal(0);
  1291. List<BigDecimal> collect = yearResults.stream().filter(w -> w.compareTo(new BigDecimal(0)) != 0).collect(Collectors.toList());
  1292. if (!collect.isEmpty()) {
  1293. aveYearShear = collect.stream().reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(collect.size()), 3, RoundingMode.HALF_UP);
  1294. }
  1295. map.put("monthTime", monthTimeList);
  1296. map.put("yearShear", yearResults);
  1297. map.put("aveYearShear", aveYearShear);
  1298. }
  1299. }
  1300. } catch (Exception e) {
  1301. e.printStackTrace();
  1302. }
  1303. return map;
  1304. }
  1305. /**
  1306. * 湍流曲线
  1307. *
  1308. * @param height 层高
  1309. * @return
  1310. * @throws Exception
  1311. */
  1312. public List<List<BigDecimal>> getTurIntensityCharts(List<WindTowerCalculationData> windTowerCalculationDataList, List<EquipmentAttribute> equipmentAttributeList, String height) {
  1313. List<List<BigDecimal>> list = new ArrayList<>();
  1314. try {
  1315. BigDecimal ws;//风速值
  1316. BigDecimal sta;//风速标准差
  1317. BigDecimal turInsity = new BigDecimal(0);//湍流值
  1318. String wsFieldName = height + "awsDay";
  1319. List<EquipmentAttribute> wsDayAttList = equipmentAttributeList.stream().filter(e -> "wsDay".equals(e.getAttributeFunction())).collect(Collectors.toList());
  1320. // 过滤属性集合找对应的属性id
  1321. List<EquipmentAttribute> wsDayAtt = wsDayAttList.stream().filter(w -> w.getFieldName().equals(wsFieldName)).collect(Collectors.toList());
  1322. String wsEbId = wsDayAtt.get(0).getId();
  1323. //height层高的平均风速
  1324. List<WindTowerCalculationData> wsList = windTowerCalculationDataList.stream().filter(w -> w.getEbId().equals(wsEbId)).collect(Collectors.toList());
  1325. //取出heigth层高的平均风速标差属性
  1326. List<EquipmentAttribute> equipmentAttributeList1 = equipmentAttributeList.stream().filter(e -> e.getFieldName().equals(height + "staDay")).collect(Collectors.toList());
  1327. //取出这个层高所有的数据
  1328. List<WindTowerCalculationData> staList = windTowerCalculationDataList.stream().filter(w -> w.getEbId().equals(equipmentAttributeList1.get(0).getId())).sorted(Comparator.comparing(WindTowerCalculationData::getTime)).collect(Collectors.toList());
  1329. /*风速段-----方差数组*/
  1330. Map<BigDecimal, List<BigDecimal>> turbulenceMap = new HashMap<>();
  1331. BigDecimal speedLevel;
  1332. for (int i = 0; i < wsList.size(); i++) {
  1333. try {
  1334. ws = wsList.get(i).getValue();
  1335. if (i >= staList.size()) {
  1336. break;
  1337. } else {
  1338. sta = staList.get(i).getValue();
  1339. }
  1340. turInsity = sta.divide(ws, 2, RoundingMode.HALF_UP);
  1341. //风速段
  1342. speedLevel = BigDecimal.valueOf(Math.ceil(ws.subtract(BigDecimal.valueOf(0.5)).doubleValue()));
  1343. if (turbulenceMap.containsKey((speedLevel))) {
  1344. turbulenceMap.get(speedLevel).add(turInsity);
  1345. } else {
  1346. turbulenceMap.put(speedLevel, new ArrayList<>());
  1347. turbulenceMap.get(speedLevel.setScale(1, RoundingMode.HALF_UP)).add(turInsity);
  1348. }
  1349. } catch (IndexOutOfBoundsException e) {
  1350. log.error("PDF 湍流曲线计算异常:" + e);
  1351. }
  1352. }
  1353. //利用treeMap排序
  1354. HashMap<BigDecimal, List<BigDecimal>> turbulenceTreeMap = new HashMap<>(turbulenceMap);
  1355. turbulenceTreeMap.forEach((key, val) -> {
  1356. List<BigDecimal> tempList = new ArrayList<>();
  1357. BigDecimal turbulence = val.stream().reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(val.size()), 3, RoundingMode.HALF_UP);
  1358. tempList.add(key.setScale(0, RoundingMode.HALF_UP));
  1359. tempList.add(turbulence);
  1360. list.add(tempList);
  1361. });
  1362. } catch (Exception e) {
  1363. e.printStackTrace();
  1364. }
  1365. return list;
  1366. }
  1367. /**
  1368. * 湍流日/年变化
  1369. *
  1370. * @return
  1371. * @throws Exception
  1372. */
  1373. public Map<String, Object> getTurIntensity(List<WindTowerCalculationData> windTowerCalculationDataList, List<EquipmentAttribute> equipmentAttributeList, String height) {
  1374. Map<String, Object> map = new HashMap<>();
  1375. try {
  1376. List<BigDecimal> dayResults = new ArrayList<>();//日变化
  1377. List<BigDecimal> yearResults = new ArrayList<>();//年变化
  1378. List<String> monthTimeList = new ArrayList<>();
  1379. SimpleDateFormat sdf = new SimpleDateFormat("M");
  1380. String wsFieldName = height + "turbulenceMonth";
  1381. String turFieldName = height + "turDayForMonth";
  1382. //height层高月平均湍流属性
  1383. List<EquipmentAttribute> turbulenceMonth = equipmentAttributeList.stream().filter(e -> wsFieldName.equals(e.getFieldName())).collect(Collectors.toList());
  1384. //height层高 月逐时湍流属性
  1385. List<EquipmentAttribute> turbulenceHourForMonth = equipmentAttributeList.stream().filter(e -> turFieldName.equals(e.getFieldName())).collect(Collectors.toList());
  1386. //height层高的月平均湍流集合
  1387. List<WindTowerCalculationData> turbulenceList = windTowerCalculationDataList.stream().filter(w -> w.getEbId().equals(turbulenceMonth.get(0).getId())).sorted(Comparator.comparing(WindTowerCalculationData::getTime)).collect(Collectors.toList());
  1388. //height层高的月逐时湍流集合
  1389. List<WindTowerCalculationData> turbulenceHourForMonthList = windTowerCalculationDataList.stream().filter(w -> w.getEbId().equals(turbulenceHourForMonth.get(0).getId())).sorted(Comparator.comparing(WindTowerCalculationData::getTime)).collect(Collectors.toList());
  1390. /*日变化*/
  1391. if (!turbulenceHourForMonthList.isEmpty()) {
  1392. dayResults = CalculationUtil.getData24(turbulenceHourForMonthList);
  1393. }
  1394. BigDecimal aveDayTurInsity = new BigDecimal(0);
  1395. aveDayTurInsity = dayResults.stream().reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(24), 2, RoundingMode.HALF_UP);
  1396. map.put("dayTurInsity", dayResults);
  1397. map.put("aveDayTurInsity", aveDayTurInsity);
  1398. /*年变化*/
  1399. // for (WindTowerCalculationData w : turbulenceList) {
  1400. // yearResults.add(w.getValue());
  1401. // monthTimeList.add(sdf.format(w.getTime()));
  1402. // }
  1403. for (int i = 1; i <= 12; i++) {
  1404. // Date monthStartTime = DateTimeUtil.getDayStartTime(DateTimeUtil.mouthOneDay(i).getTime());
  1405. //过滤时间区间集合
  1406. List<WindTowerCalculationData> filterList = new ArrayList<>();
  1407. BigDecimal value = new BigDecimal(0);
  1408. int finalI = i;
  1409. filterList = turbulenceList.stream().filter(w -> sdf.format(w.getTime()).equals(String.valueOf(finalI))).collect(Collectors.toList());
  1410. if (!filterList.isEmpty()) {
  1411. value = filterList.get(0).getValue();
  1412. }
  1413. yearResults.add(value);
  1414. monthTimeList.add(i + "月");
  1415. }
  1416. BigDecimal aveYearTurInsity = new BigDecimal(0);
  1417. //过滤为0的数据
  1418. List<BigDecimal> collect = yearResults.stream().filter(w -> w.compareTo(new BigDecimal(0)) != 0).collect(Collectors.toList());
  1419. if (collect.size() > 0) {
  1420. aveYearTurInsity = collect.stream().reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(collect.size()), 2, RoundingMode.HALF_UP);
  1421. }
  1422. map.put("yearTurInsity", yearResults);
  1423. map.put("aveYearTurInsity", aveYearTurInsity);
  1424. map.put("monthTime", monthTimeList);
  1425. } catch (Exception e) {
  1426. e.printStackTrace();
  1427. }
  1428. return map;
  1429. }
  1430. /**
  1431. * 获取湍流(风向玫瑰图)
  1432. *
  1433. * @param height
  1434. */
  1435. public Map<String, Object> getTurIntensityRose(List<WindDirectionStatisticsData> windDirectionStatisticsData, List<EquipmentAttribute> equipmentAttributeList, WindTowerInfo windTowerInfo, String height) {
  1436. Map<String, Object> map = new HashMap<>();
  1437. try {
  1438. // 若层高包含A按照去掉A的层高计算
  1439. if (height.contains("A")) {
  1440. height = height.substring(0, height.length() - 1);
  1441. }
  1442. List<Map<String, Object>> list = new ArrayList<>();
  1443. String turFieldName = height + "monthTurRose";
  1444. // 过滤获取ebId
  1445. List<EquipmentAttribute> turEquipmentAttribute = equipmentAttributeList.stream().filter(e -> turFieldName.equals(e.getFieldName())).collect(Collectors.toList());
  1446. // 获取风向统计数据
  1447. List<WindDirectionStatisticsData> turList = windDirectionStatisticsData.stream().filter(e -> e.getEbId().equals(turEquipmentAttribute.get(0).getId())).collect(Collectors.toList());
  1448. for (WindDirectionEnum value : WindDirectionEnum.values()) {
  1449. Map<String, Object> roseMap = new HashMap<>();
  1450. // 根据风向过滤统计表
  1451. List<WindDirectionStatisticsData> filterTurList = turList.stream().filter(e -> e.getDirection().equals(value.name())).collect(Collectors.toList());
  1452. // 提取过滤的value值
  1453. List<BigDecimal> filterTurValueList = filterTurList.stream().map(WindDirectionStatisticsData::getValue).filter(w -> w != null).collect(Collectors.toList());
  1454. // 累加保留两位小数
  1455. BigDecimal sumtur = null;
  1456. if (!filterTurValueList.isEmpty()) {
  1457. sumtur = filterTurValueList.stream().reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, RoundingMode.HALF_UP);
  1458. }
  1459. roseMap.put(value.name(), sumtur);
  1460. list.add(roseMap);
  1461. }
  1462. List<Map<String, Object>> aveTurbulenceIntensity;
  1463. aveTurbulenceIntensity = getAveTurbulenceIntensity(windDirectionStatisticsData, equipmentAttributeList, windTowerInfo);
  1464. map.put("turIntensity", list);
  1465. map.put("aveTurIntensity", aveTurbulenceIntensity);
  1466. } catch (Exception e) {
  1467. e.printStackTrace();
  1468. }
  1469. return map;
  1470. }
  1471. /**
  1472. * 获取所有层高的平均湍流(风向玫瑰图)
  1473. */
  1474. public List<Map<String, Object>> getAveTurbulenceIntensity(List<WindDirectionStatisticsData> windDirectionStatisticsData, List<EquipmentAttribute> equipmentAttributeList, WindTowerInfo windTowerInfo) {
  1475. String heights;
  1476. heights = windTowerInfo.getWdHeights();
  1477. if (heights == null || heights.equals("")) {
  1478. heights = "10,30,50,60,70,80,90,100,110,120,140,150";
  1479. }
  1480. String[] heightAll = heights.split(",");
  1481. BigDecimal zero = new BigDecimal(0);
  1482. List<Map<String, Object>> list = new ArrayList<>();
  1483. for (WindDirectionEnum value : WindDirectionEnum.values()) {
  1484. Map<String, Object> map = new HashMap<>();
  1485. List<BigDecimal> dataList = new ArrayList<>();
  1486. // 累加保留两位小数
  1487. BigDecimal sumtur = zero;
  1488. BigDecimal sumCount = zero;
  1489. BigDecimal aveTur = zero;
  1490. for (String height : heightAll) {
  1491. String turFieldName = height + "monthTurRose";
  1492. // 过滤获取ebId
  1493. List<EquipmentAttribute> turEquipmentAttribute = equipmentAttributeList.stream().filter(e -> turFieldName.equals(e.getFieldName())).collect(Collectors.toList());
  1494. // 获取风向统计数据
  1495. List<WindDirectionStatisticsData> turList = windDirectionStatisticsData.stream().filter(e -> e.getEbId().equals(turEquipmentAttribute.get(0).getId()) && e.getDirection().equals(value.name())).collect(Collectors.toList());
  1496. // 提取过滤的value值
  1497. List<BigDecimal> filterTurValueList = turList.stream().map(WindDirectionStatisticsData::getValue).filter(w -> w != null).collect(Collectors.toList());
  1498. if (!filterTurValueList.isEmpty()) {
  1499. sumtur = sumtur.add(filterTurValueList.stream().reduce(BigDecimal.ZERO, BigDecimal::add));
  1500. sumCount = sumCount.add(BigDecimal.valueOf(filterTurValueList.size()));
  1501. }
  1502. }
  1503. if (sumCount.compareTo(zero) != 0 && sumtur.compareTo(zero) != 0) {
  1504. aveTur = sumtur.divide(sumCount, 2, RoundingMode.HALF_UP);
  1505. }
  1506. map.put(value.name(), aveTur);
  1507. list.add(map);
  1508. }
  1509. return list;
  1510. }
  1511. /**
  1512. * 封装逐小时数据集合
  1513. *
  1514. * @param awsList 数据
  1515. * @return
  1516. */
  1517. public List<BigDecimal> getData24(List<WindTowerCalculationData> awsList) {
  1518. long hour = 3600000L;
  1519. Date systemDate = new Date();
  1520. List<BigDecimal> results = new ArrayList<>();
  1521. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH");
  1522. //获取昨日开始和结束时间
  1523. long startTime = DateMomentUtil.getDayStartTime(DateUtils.addDays(systemDate, -1).getTime());
  1524. long endTime = startTime + 86399000;
  1525. for (long time = startTime; time <= endTime; time += hour) {
  1526. Long finalTime = time;
  1527. String format = simpleDateFormat.format(finalTime);
  1528. List<BigDecimal> collect = awsList.stream().filter(s -> simpleDateFormat.format(s.getTime())
  1529. .equals(format) && s.getValue().compareTo(new BigDecimal(-99)) != 0)
  1530. .map(WindTowerCalculationData::getValue).collect(Collectors.toList());
  1531. BigDecimal avg = collect.stream().reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(collect.size()), 2, RoundingMode.HALF_UP);
  1532. results.add(avg);
  1533. }
  1534. return results;
  1535. }
  1536. }