1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669 |
- package com.jiayue.biz.service.impl;
- import cn.hutool.core.convert.Convert;
- import cn.hutool.core.date.DateTime;
- import cn.hutool.db.Entity;
- import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
- import com.jiayue.biz.domain.*;
- import com.jiayue.biz.eunms.WindDirectionEnum;
- import com.jiayue.biz.mapper.WindTowerDataParentTableMapper;
- import com.jiayue.biz.service.*;
- import com.jiayue.biz.util.CalculationUtil;
- import com.jiayue.biz.util.DateMomentUtil;
- import com.jiayue.biz.util.DateTimeUtil;
- import com.jiayue.common.utils.DateUtil;
- import flanagan.analysis.ProbabilityPlot;
- import lombok.AllArgsConstructor;
- import org.apache.commons.lang3.time.DateUtils;
- import org.springframework.stereotype.Service;
- import java.math.BigDecimal;
- import java.math.RoundingMode;
- import java.sql.Timestamp;
- import java.text.SimpleDateFormat;
- import java.util.*;
- import java.util.stream.Collectors;
- import java.util.stream.Stream;
- import static com.jiayue.biz.eunms.TimeDimension.month;
- /**
- * 首页Service业务层处理
- *
- * @author L.ym
- * @date 2022-05-11
- */
- @Service
- @AllArgsConstructor
- public class PdfServiceImpl extends ServiceImpl<WindTowerDataParentTableMapper, WindTowerDataParentTable> implements PdfService {
- private final WindTowerInfoServiceImpl windTowerInfoService;
- private final WindTowerCalculationDataServiceImpl windTowerCalculationDataService;
- private final EquipmentAttributeService equipmentAttributeService;
- private final RealTimeDisplayService realTimeDisplayService;
- private final WindDirectionStatisticsDataServiceImpl windDirectionStatisticsDataService;
- private final ProphaseAnemometryDataService prophaseAnemometryDataService;
- private final ProphaseWeatherDataService prophaseWeatherDataService;
- @Override
- public Map<String, Object> generatePDF(String equipmentId, Date startDay, Date endDay) {
- //如果结束时间大于现在时间
- if (DateUtil.date().getTime() < endDay.getTime()) {
- //将结束时间设置为昨天结束时间
- endDay = DateUtil.endOfDay(DateUtil.yesterday());
- }
- Map<String, Object> map = new HashMap<>();
- // 一年的计算数据
- startDay = DateUtil.beginOfMonth(startDay);
- endDay = DateUtil.endOfMonth(endDay);
- List<WindTowerCalculationData> windTowerCalculationDatas = windTowerCalculationDataService.getByBetweenTimeAndEquipmentId(startDay, endDay, equipmentId);
- //实时数据查询
- List<ProphaseAnemometryData> prophaseAnemometryDataList = prophaseAnemometryDataService.selectWsAndWdForTime(equipmentId, new Timestamp(startDay.getTime()), new Timestamp(endDay.getTime()));
- // 一年的风向统计数据
- List<WindDirectionStatisticsData> windDirectionStatisticsDataList = windDirectionStatisticsDataService.getByBetweenTimeAndEquipmentId(startDay, endDay, equipmentId);
- //所有类型数据
- List<EquipmentAttribute> equipmentAttributeList = equipmentAttributeService.list();
- //所有测风塔信息
- List<WindTowerInfo> windTowerInfoList = windTowerInfoService.getAllWindTower();
- List<WindTowerInfo> windTowerInfos = windTowerInfoList.stream().filter(w -> w.getEquipmentNo().equals(equipmentId)).collect(Collectors.toList());
- //测风塔信息概要
- Map<String, Object> windTowerInfo = getWindTowerInfo(windTowerInfos, startDay, endDay);
- map.put("windTowerInfo", windTowerInfo);
- //环境数据
- Map<String, Object> statisticsData = statisticsWindTowerStatusData(windTowerCalculationDatas, equipmentAttributeList);
- map.put("statisticsData", statisticsData);
- //风速最大、最小、平均 数据
- ArrayList<Map<String, Object>> statisticsDataFen = statisticsWindTowerStatusDataFeng(windTowerCalculationDatas, equipmentAttributeList, windTowerInfos);
- map.put("statisticsDataFen", statisticsDataFen);
- //风速每月平均
- Map<String, Object> statisticsWindTowerStatusDataFenMonth = statisticsWindTowerStatusDataFenMonth(windTowerCalculationDatas, equipmentAttributeList, windTowerInfos, startDay, endDay);
- map.put("statisticsWindTowerStatusDataFenMonth", statisticsWindTowerStatusDataFenMonth);
- //风功率密度每月平均
- ArrayList<Map<String, Object>> statisticsWindTowerStatusDataFenWpd = statisticsWindTowerStatusDataWpd(windTowerCalculationDatas, equipmentAttributeList, windTowerInfos);
- map.put("statisticsWindTowerStatusDataFenWpd", statisticsWindTowerStatusDataFenWpd);
- //一年玫瑰图 以及风能玫瑰图
- ArrayList<Map<String, Object>> roseChart = roseCharts(windDirectionStatisticsDataList, equipmentAttributeList, windTowerInfos);
- map.put("roseChart", roseChart);
- //pdf威布尔
- ArrayList<Map<String, Object>> weibull = pdfWeibull(equipmentAttributeList, windTowerCalculationDatas, windTowerInfos);
- map.put("weibull", weibull);
- //15m/s湍流强度
- ArrayList<Map<String, Object>> statisticsWindTowerStatusDataFenTur = statisticsWindTowerStatusDataTur(windTowerCalculationDatas, equipmentAttributeList, windTowerInfos);
- map.put("statisticsWindTowerStatusDataFenTur", statisticsWindTowerStatusDataFenTur);
- //风切变
- Map<String, Object> statisticsWindTowerStatusDataShear = statisticsWindTowerStatusDataShear(prophaseAnemometryDataList, windTowerInfos);
- map.put("statisticsWindTowerStatusDataShear", statisticsWindTowerStatusDataShear);
- //
- // //风速和风功率密度时间曲线图 (时间序列)
- // Map<String, Object> wsAndWpd = getWsAndWpd(windTowerCalculationDatas, equipmentAttributeList, height, startDay, endDay);
- // map.put("wsAndWpd", wsAndWpd);
- // //风速和风速标准差时间曲线图
- // Map<String, Object> wsAndWsStaData = wsAndWsSta(windTowerCalculationDatas, equipmentAttributeList, height, startDay, endDay);
- // map.put("wsAndWsStaData", wsAndWsStaData);
- // //风速和风速密度日变化
- // Map<String, Object> windPowerDensityAndAverageWindSpeed = getWindPowerDensityAndAverageWindSpeed(windTowerCalculationDatas, equipmentAttributeList, windTowerInfos, height);
- // map.put("windPowerDensityAndAverageWindSpeed", windPowerDensityAndAverageWindSpeed);
- // //风速和风速密度各月日变化
- // List<Map<String, Object>> MonthWsAndWpd = getMonthWsAndWpd(windTowerCalculationDatas, equipmentAttributeList, height, startDay, endDay);
- // map.put("MonthWsAndWpd", MonthWsAndWpd);
- // //风速和风速密度年变化曲线
- // Map<String, Object> yearWsAndWpd = getYearWsAndWpd(windTowerCalculationDatas, equipmentAttributeList, height, startDay, endDay);
- // map.put("yearWsAndWpd", yearWsAndWpd);
- // //风速和风速密度各月日变化表格
- // Map<String, Object> monthWpdTable = getMonthWpdTable(windTowerCalculationDatas, equipmentAttributeList, windTowerInfos, startDay, endDay);
- // map.put("monthWpdTable", monthWpdTable);
- //
- // //各月玫瑰图
- // Map<String, Object> monthRoseCharts = getMonthRoseCharts(windDirectionStatisticsDataList, equipmentAttributeList, height);
- // map.put("monthRoseCharts", monthRoseCharts);
- //
- // //空气密度
- // Map<String, Object> airDensity = getAirDensity(windTowerCalculationDatas, equipmentAttributeList, startDay, endDay);
- // map.put("airDensity", airDensity);
- // //获取风切变指数(风向玫瑰图)
- // List<Map<String, Object>> windShearRose = getWindShearRose(windDirectionStatisticsDataList, equipmentAttributeList, height);
- // map.put("windShearRose", windShearRose);
- // //风切变日/年变化
- // Map<String, Object> windShear = getWindShear(windTowerCalculationDatas, equipmentAttributeList, height);
- // map.put("windShear", windShear);
- // //湍流曲线
- // List<List<BigDecimal>> turIntensityCharts = getTurIntensityCharts(windTowerCalculationDatas, equipmentAttributeList, height);
- // map.put("turIntensityCharts", turIntensityCharts);
- // //湍流日/年变化
- // Map<String, Object> turIntensity = getTurIntensity(windTowerCalculationDatas, equipmentAttributeList, height);
- // map.put("turIntensity", turIntensity);
- // //获取湍流(风向玫瑰图)
- // Map<String, Object> turIntensityRose = getTurIntensityRose(windDirectionStatisticsDataList, equipmentAttributeList, windTowerInfos.get(0), height);
- // map.put("turIntensityRose", turIntensityRose);
- return map;
- }
- /**
- * 测风塔信息概要
- *
- * @return
- */
- public Map<String, Object> getWindTowerInfo(List<WindTowerInfo> windTowerInfos, Date startDay, Date endDay) {
- Map<String, Object> map = new HashMap<>();
- Map<String, Long> dataTimeStartAndEnd = prophaseWeatherDataService.getDataTimeStartAndEnd(windTowerInfos.get(0).getEquipmentNo());
- List<Entity> count = prophaseWeatherDataService.selectCount(windTowerInfos.get(0).getEquipmentNo());
- long allCount = ((endDay.getTime() - startDay.getTime() + 1000) / 86400000l) * 144;
- BigDecimal percentage = BigDecimal.valueOf((Long) count.get(0).get("count(*)")).divide(BigDecimal.valueOf(allCount), 2, RoundingMode.HALF_UP);
- if (windTowerInfos.size() != 0) {
- map.put("windTowerInfo", windTowerInfos.get(0));
- map.put("startTime", DateUtil.format(new Date(dataTimeStartAndEnd.get("startTime")), "yyyy-MM-dd"));
- map.put("endTime", DateUtil.format(new Date(dataTimeStartAndEnd.get("endTime")), "yyyy-MM-dd"));
- map.put("count", count.get(0).get("count(*)"));
- map.put("allCount", allCount);
- map.put("percentage", percentage.multiply(new BigDecimal(100)));
- }
- return map;
- }
- /**
- * 环境数据
- *
- * @param windTowerCalculationDatas 统计数据
- * @param equipmentAttributeList 属性数据
- * @return
- */
- public Map<String, Object> statisticsWindTowerStatusData(List<WindTowerCalculationData> windTowerCalculationDatas, List<EquipmentAttribute> equipmentAttributeList) {
- Map<String, Object> map = new HashMap<>();
- try {
- // List<Map<String, Object>> dataList = new ArrayList<>();
- /*环境数据*/
- //从数据库属性表里查出环境数据的属性
- List<EquipmentAttribute> paMax = equipmentAttributeList.stream().filter(w -> w.getFieldName().equals("paMAX")).collect(Collectors.toList());
- List<EquipmentAttribute> paMin = equipmentAttributeList.stream().filter(w -> w.getFieldName().equals("paMIN")).collect(Collectors.toList());
- List<EquipmentAttribute> paAve = equipmentAttributeList.stream().filter(w -> w.getFieldName().equals("paAVE")).collect(Collectors.toList());
- List<EquipmentAttribute> rhMax = equipmentAttributeList.stream().filter(w -> w.getFieldName().equals("rhMAX")).collect(Collectors.toList());
- List<EquipmentAttribute> rhMin = equipmentAttributeList.stream().filter(w -> w.getFieldName().equals("rhMIN")).collect(Collectors.toList());
- List<EquipmentAttribute> rhAve = equipmentAttributeList.stream().filter(w -> w.getFieldName().equals("rhAVE")).collect(Collectors.toList());
- List<EquipmentAttribute> tMax = equipmentAttributeList.stream().filter(w -> w.getFieldName().equals("tMAX")).collect(Collectors.toList());
- List<EquipmentAttribute> tMin = equipmentAttributeList.stream().filter(w -> w.getFieldName().equals("tMIN")).collect(Collectors.toList());
- List<EquipmentAttribute> tAve = equipmentAttributeList.stream().filter(w -> w.getFieldName().equals("tAVE")).collect(Collectors.toList());
- List<EquipmentAttribute> airDensityAve = equipmentAttributeList.stream().filter(w -> w.getFieldName().equals("airDensityMonth")).collect(Collectors.toList());
- //通过属性过滤数据
- List<WindTowerCalculationData> paMaxData = windTowerCalculationDatas.stream().filter(w -> w.getEbId().equals(paMax.get(0).getId())).collect(Collectors.toList());
- List<WindTowerCalculationData> paMinData = windTowerCalculationDatas.stream().filter(w -> w.getEbId().equals(paMin.get(0).getId())).collect(Collectors.toList());
- List<WindTowerCalculationData> paAveData = windTowerCalculationDatas.stream().filter(w -> w.getEbId().equals(paAve.get(0).getId())).collect(Collectors.toList());
- List<WindTowerCalculationData> rhMaxData = windTowerCalculationDatas.stream().filter(w -> w.getEbId().equals(rhMax.get(0).getId())).collect(Collectors.toList());
- List<WindTowerCalculationData> rhMinData = windTowerCalculationDatas.stream().filter(w -> w.getEbId().equals(rhMin.get(0).getId())).collect(Collectors.toList());
- List<WindTowerCalculationData> rhAveData = windTowerCalculationDatas.stream().filter(w -> w.getEbId().equals(rhAve.get(0).getId())).collect(Collectors.toList());
- List<WindTowerCalculationData> tMaxData = windTowerCalculationDatas.stream().filter(w -> w.getEbId().equals(tMax.get(0).getId())).collect(Collectors.toList());
- List<WindTowerCalculationData> tMinData = windTowerCalculationDatas.stream().filter(w -> w.getEbId().equals(tMin.get(0).getId())).collect(Collectors.toList());
- List<WindTowerCalculationData> tAveData = windTowerCalculationDatas.stream().filter(w -> w.getEbId().equals(tAve.get(0).getId())).collect(Collectors.toList());
- List<WindTowerCalculationData> airDensityAveData = windTowerCalculationDatas.stream().filter(w -> w.getEbId().equals(airDensityAve.get(0).getId())).collect(Collectors.toList());
- //做平均值
- BigDecimal paMaxDataMax = paMaxData.stream().map(WindTowerCalculationData::getValue).max((x1, x2) -> x1.compareTo(x2)).get();
- BigDecimal paMinDataMin = paMinData.stream().map(WindTowerCalculationData::getValue).min((x1, x2) -> x1.compareTo(x2)).get();
- BigDecimal paAveDataAge = paAveData.stream().map(WindTowerCalculationData::getValue).reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(paAveData.size()), 2, RoundingMode.HALF_UP);
- BigDecimal rhMaxDataMax = rhMaxData.stream().map(WindTowerCalculationData::getValue).max((x1, x2) -> x1.compareTo(x2)).get();
- BigDecimal rhMinDataMin = rhMinData.stream().map(WindTowerCalculationData::getValue).min((x1, x2) -> x1.compareTo(x2)).get();
- BigDecimal rhAveDataAge = rhAveData.stream().map(WindTowerCalculationData::getValue).reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(rhAveData.size()), 2, RoundingMode.HALF_UP);
- BigDecimal tMaxDataMax = tMaxData.stream().map(WindTowerCalculationData::getValue).max((x1, x2) -> x1.compareTo(x2)).get();
- BigDecimal tMinDataMin = tMinData.stream().map(WindTowerCalculationData::getValue).min((x1, x2) -> x1.compareTo(x2)).get();
- BigDecimal tAveDataAge = tAveData.stream().map(WindTowerCalculationData::getValue).reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(tAveData.size()), 2, RoundingMode.HALF_UP);
- BigDecimal airDensityAveDataAge = airDensityAveData.stream().map(WindTowerCalculationData::getValue).reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(airDensityAveData.size()), 2, RoundingMode.HALF_UP);
- //放到list里
- List<Map<String, Object>> environmentData = new ArrayList<>();
- Map<String, Object> paMap = new HashMap<>();
- paMap.put("parameter", "气压(hpa)");
- paMap.put("min", paMinDataMin);
- paMap.put("max", paMaxDataMax);
- paMap.put("ave", paAveDataAge);
- Map<String, Object> rhMap = new HashMap<>();
- rhMap.put("parameter", "湿度(RH)");
- rhMap.put("min", rhMinDataMin.compareTo(new BigDecimal(0)) == 0 ? "--" : rhMinDataMin);
- rhMap.put("max", rhMaxDataMax.compareTo(new BigDecimal(0)) == 0 ? "--" : rhMaxDataMax);
- rhMap.put("ave", rhAveDataAge.compareTo(new BigDecimal(0)) == 0 ? "--" : rhAveDataAge);
- Map<String, Object> tMap = new HashMap<>();
- tMap.put("parameter", "气温(°C)");
- tMap.put("min", tMinDataMin);
- tMap.put("max", tMaxDataMax);
- tMap.put("ave", tAveDataAge);
- Map<String, Object> airDensityMap = new HashMap<>();
- airDensityMap.put("parameter", "空气密度(kg/m³)");
- airDensityMap.put("min", airDensityAveDataAge.multiply(BigDecimal.valueOf(0.8)));
- airDensityMap.put("max", airDensityAveDataAge.multiply(BigDecimal.valueOf(1.2)));
- airDensityMap.put("ave", airDensityAveDataAge);
- environmentData.add(paMap);
- environmentData.add(rhMap);
- environmentData.add(tMap);
- environmentData.add(airDensityMap);
- // map.put("dataList", dataList);
- map.put("environment", environmentData);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return map;
- }
- /**
- * 风速最大、最小、平均 数据
- *
- * @param windTowerCalculationDatas 统计数据
- * @param equipmentAttributeList 属性数据
- * @return
- */
- public ArrayList<Map<String, Object>> statisticsWindTowerStatusDataFeng(List<WindTowerCalculationData> windTowerCalculationDatas, List<EquipmentAttribute> equipmentAttributeList, List<WindTowerInfo> windTowerInfos) {
- ArrayList<Map<String, Object>> heightAndWsList = new ArrayList<>();
- String[] heights = windTowerInfos.get(0).getHeights().split(",");
- for (String height : heights) {
- BigDecimal wsAve = BigDecimal.ZERO;
- BigDecimal wsMax = BigDecimal.ZERO;
- BigDecimal wsMin = BigDecimal.ZERO;
- Map<String, Object> map = new HashMap<>();
- List<EquipmentAttribute> equipmentAttributes = equipmentAttributeList.stream().filter(e -> e.getFieldName().equals(height + "awsDay")).collect(Collectors.toList());
- //通过属性过滤数据
- List<WindTowerCalculationData> wsDayList = windTowerCalculationDatas.stream().filter(w -> w.getEbId().equals(equipmentAttributes.get(0).getId())).collect(Collectors.toList());
- if (wsDayList.size() > 0) {
- wsAve = wsDayList.stream().map(WindTowerCalculationData::getValue).reduce(BigDecimal::add).get().divide(BigDecimal.valueOf(wsDayList.size()), 2, RoundingMode.HALF_UP);
- wsMin = wsDayList.stream().map(WindTowerCalculationData::getValue).min(BigDecimal::compareTo).get();
- wsMax = wsDayList.stream().map(WindTowerCalculationData::getValue).max((x1, x2) -> x1.compareTo(x2)).get();
- }
- map.put("wsAve", wsAve);
- map.put("wsMin", wsMin);
- map.put("wsMax", wsMax);
- map.put("height", height);
- heightAndWsList.add(map);
- }
- return heightAndWsList;
- }
- /**
- * 风速每月平均
- *
- * @param windTowerCalculationDatas 统计数据
- * @param equipmentAttributeList 属性数据
- * @return
- */
- public Map<String, Object> statisticsWindTowerStatusDataFenMonth(List<WindTowerCalculationData> windTowerCalculationDatas, List<EquipmentAttribute> equipmentAttributeList, List<WindTowerInfo> windTowerInfos, Date startDay, Date endDay) {
- Map<String, Object> objectMap = new HashMap<>();
- ArrayList<Map<String, Object>> heightAndWsList = new ArrayList<>();
- ArrayList<Map<String, Object>> timeList = new ArrayList<>();
- String[] heights = windTowerInfos.get(0).getHeights().split(",");
- int i = 0;
- for (String height : heights) {
- HashMap<String, Object> heightMap = new HashMap<>();
- List<EquipmentAttribute> equipmentAttributes = equipmentAttributeList.stream().filter(e -> e.getFieldName().equals(height + "awsDay")).collect(Collectors.toList());
- for (Long l = startDay.getTime(); l < endDay.getTime(); l = DateUtil.offsetMonth(new Date(l), 1).getTime()) {
- Date startTime = DateUtil.beginOfMonth(new Date(l));
- Date endTime = DateUtil.endOfMonth(startTime);
- BigDecimal wsAve = BigDecimal.ZERO;
- //通过属性过滤数据
- List<WindTowerCalculationData> wsDayList = windTowerCalculationDatas.stream().filter(w -> w.getTime().getTime() >= startTime.getTime() &&
- w.getTime().getTime() <= endTime.getTime() &&
- w.getEbId().equals(equipmentAttributes.get(0).getId())).collect(Collectors.toList());
- if (wsDayList.size() > 0) {
- wsAve = wsDayList.stream().map(WindTowerCalculationData::getValue).reduce(BigDecimal::add).get().divide(BigDecimal.valueOf(wsDayList.size()), 2, RoundingMode.HALF_UP);
- }
- heightMap.put(DateUtil.format(startTime, "yyyyMM"), wsAve);
- if (i == 0) {
- HashMap<String, Object> timeMap = new HashMap<>();
- timeMap.put("value",DateUtil.format(startTime, "yyyyMM"));
- timeMap.put("label",DateUtil.format(startTime, "yyyy.M"));
- timeList.add(timeMap);
- }
- }
- heightMap.put("height", height);
- heightAndWsList.add(heightMap);
- i++;
- }
- objectMap.put("timeTable", timeList);
- objectMap.put("mainData",heightAndWsList);
- return objectMap;
- }
- /**
- * 风功率密度最大、最小、平均 数据
- *
- * @param windTowerCalculationDatas 统计数据
- * @param equipmentAttributeList 属性数据
- * @return
- */
- public ArrayList<Map<String, Object>> statisticsWindTowerStatusDataWpd(List<WindTowerCalculationData> windTowerCalculationDatas, List<EquipmentAttribute> equipmentAttributeList, List<WindTowerInfo> windTowerInfos) {
- ArrayList<Map<String, Object>> heightAndWpdList = new ArrayList<>();
- String[] heights = windTowerInfos.get(0).getHeights().split(",");
- for (String height : heights) {
- BigDecimal wpdAve = BigDecimal.ZERO;
- BigDecimal wpdMax = BigDecimal.ZERO;
- BigDecimal wpdMin = BigDecimal.ZERO;
- Map<String, Object> map = new HashMap<>();
- List<EquipmentAttribute> equipmentAttributes = equipmentAttributeList.stream().filter(e -> e.getFieldName().equals(height + "wpdDay")).collect(Collectors.toList());
- //通过属性过滤数据
- List<WindTowerCalculationData> dayList = windTowerCalculationDatas.stream().filter(w -> w.getEbId().equals(equipmentAttributes.get(0).getId())).collect(Collectors.toList());
- if (dayList.size() > 0) {
- wpdAve = dayList.stream().map(WindTowerCalculationData::getValue).reduce(BigDecimal::add).get().divide(BigDecimal.valueOf(dayList.size()), 2, RoundingMode.HALF_UP);
- // wpdMax = dayList.stream().map(WindTowerCalculationData::getValue).min(BigDecimal::compareTo).get();
- // wpdMin = dayList.stream().map(WindTowerCalculationData::getValue).max((x1, x2) -> x1.compareTo(x2)).get();
- }
- map.put("wpdAve", wpdAve);
- // map.put("wpdMin", wpdMax);
- // map.put("wpdMax", wpdMin);
- map.put("height", height);
- heightAndWpdList.add(map);
- }
- return heightAndWpdList;
- }
- /**
- * 测风塔数据时间范围
- *
- * @return
- */
- public List<Map<String, Object>> getDataTime() {
- List<WindTowerInfo> windTowerInfoList = windTowerInfoService.getAllWindTower();
- ArrayList<Map<String, Object>> timeList = new ArrayList<>();
- for (WindTowerInfo windTowerInfo : windTowerInfoList) {
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
- HashMap<String, Object> hashMap = new HashMap<>();
- Map<String, Long> startAndEnd = prophaseWeatherDataService.getDataTimeStartAndEnd(windTowerInfo.getEquipmentNo());
- hashMap.put("time", sdf.format(new Date(startAndEnd.get("startTime"))) + " - " + sdf.format(new Date(startAndEnd.get("endTime"))));
- hashMap.put("eqId", windTowerInfo.getEquipmentNo());
- timeList.add(hashMap);
- }
- return timeList;
- }
- /**
- * 测风塔数据时间范围
- *
- * @return
- */
- public List<Map<String, Object>> getDataTimeForEveryTower() {
- List<WindTowerInfo> windTowerInfoList = windTowerInfoService.getAllWindTower();
- List<WindTowerInfo> collect = windTowerInfoList.stream().sorted(Comparator.comparing(WindTowerInfo::getEquipmentNo)).collect(Collectors.toList());
- ArrayList<Map<String, Object>> timeList = new ArrayList<>();
- for (WindTowerInfo windTowerInfo : collect) {
- try {
- HashMap<String, Object> hashMap = new HashMap<>();
- Map<String, Long> startAndEnd = prophaseWeatherDataService.getDataTimeStartAndEnd(windTowerInfo.getEquipmentNo());
- //获取去年数据截止的时间
- Date yearDay = DateTimeUtil.getYearDay(startAndEnd.get("endTime"));
- Date startTime;
- if (startAndEnd.get("startTime") < yearDay.getTime()) {
- startTime = DateUtil.offsetMonth(yearDay, 1);
- } else {
- startTime = new Date(startAndEnd.get("startTime"));
- }
- hashMap.put("startTime", startTime);
- hashMap.put("endTime", new Date(startAndEnd.get("endTime")));
- hashMap.put("eqId", windTowerInfo.getEquipmentNo());
- timeList.add(hashMap);
- }catch (Exception e){
- log.error("读取测风塔:{"+windTowerInfo.getName() +"} 开始结束时间错误:{"+e.getLocalizedMessage()+"}");
- }
- }
- return timeList;
- }
- /**
- * 风速和风功率密度时间曲线图
- *
- * @param
- * @return map
- */
- public Map<String, Object> getWsAndWpd(List<WindTowerCalculationData> windTowerCalculationDataList, List<EquipmentAttribute> equipmentAttributeList, String height, Date startDay, Date endDay) {
- Map<String, Object> map = new HashMap<>();
- try {
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
- // 根据设备属性表中的属性作用查询
- List<EquipmentAttribute> wsDayAttList = equipmentAttributeList.stream().filter(e -> "wsDay".equals(e.getAttributeFunction())).collect(Collectors.toList());
- List<EquipmentAttribute> wpdMonthAttList = equipmentAttributeList.stream().filter(e -> "WindPowerDensity".equals(e.getAttributeFunction())).collect(Collectors.toList());
- // 一年的计算数据
- String wsFieldName = height + "awsDay";
- String wpdFieldName = height + "wpdDay";
- // 过滤属性集合找对应的属性id
- List<EquipmentAttribute> wsDayAtt = wsDayAttList.stream().filter(w -> w.getFieldName().equals(wsFieldName)).collect(Collectors.toList());
- String wsEbId = wsDayAtt.get(0).getId();
- List<EquipmentAttribute> wpdMonthAtt = wpdMonthAttList.stream().filter(w -> w.getFieldName().equals(wpdFieldName)).collect(Collectors.toList());
- String wpdEbId = wpdMonthAtt.get(0).getId();
- // 过滤一周数据
- List<List<Object>> wsDataList = new ArrayList<>();
- List<List<Object>> wpdDataList = new ArrayList<>();
- for (Long l = startDay.getTime(); l <= endDay.getTime(); l += 86400000L) {
- Date finalL = DateTimeUtil.getDayStartTime(l);
- List<WindTowerCalculationData> wsList = windTowerCalculationDataList.stream().filter(w -> w.getEbId().equals(wsEbId) && w.getTime().equals(finalL)).collect(Collectors.toList());
- List<Object> list = new ArrayList<>();
- if (!wsList.isEmpty()) {
- list.add(sdf.format(wsList.get(0).getTime()));
- list.add(wsList.get(0).getValue());
- wsDataList.add(list);
- } else {
- list.add(sdf.format(new Date(l)));
- list.add(new BigDecimal(0));
- wsDataList.add(list);
- }
- List<WindTowerCalculationData> wpdList = windTowerCalculationDataList.stream().filter(w -> w.getEbId().equals(wpdEbId) && w.getTime().equals(finalL)).collect(Collectors.toList());
- List<Object> listWpd = new ArrayList<>();
- if (!wpdList.isEmpty()) {
- listWpd.add(sdf.format(wpdList.get(0).getTime()));
- listWpd.add(wpdList.get(0).getValue());
- wpdDataList.add(listWpd);
- } else {
- listWpd.add(sdf.format(new Date(l)));
- listWpd.add(new BigDecimal(0));
- wpdDataList.add(listWpd);
- }
- }
- map.put("ws", wsDataList);
- map.put("wpd", wpdDataList);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return map;
- }
- /**
- * 风速和风速标准差时间曲线图
- *
- * @param windTowerCalculationDataList 统计数据
- * @param equipmentAttributeList 属性数据
- * @param height 层高
- * @return
- */
- public Map<String, Object> wsAndWsSta(List<WindTowerCalculationData> windTowerCalculationDataList, List<EquipmentAttribute> equipmentAttributeList, String height, Date startDay, Date endDay) {
- // long yesterday = new Date().getTime() - 1000 * 60 * 60 * 24;//昨天
- // Date startTime = DateTimeUtil.getDayStartTime(DateTimeUtil.getYearDay(yesterday).getTime());
- // Date endTime = DateTimeUtil.getDayLastTime(yesterday);
- // List<Long> dateTime = DateTimeUtil.getIntervalTimeByMonth(DateTimeUtil.beginOfMonth(startTime), DateTimeUtil.beginOfMonth(endTime));
- Map<String, Object> map = new HashMap<>();
- try {
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
- // 根据设备属性表中的属性作用查询
- String wsFieldName = height + "awsDay";
- // 过滤属性集合找对应的属性id
- List<EquipmentAttribute> wsDayAtt = equipmentAttributeList.stream().filter(w -> w.getFieldName().equals(wsFieldName)).collect(Collectors.toList());
- String wsEbId = wsDayAtt.get(0).getId();
- //取出heigth层高的平均风速标差属性
- String staEbId = equipmentAttributeList.stream().filter(e -> e.getFieldName().equals(height + "staDay")).collect(Collectors.toList()).get(0).getId();
- List<List<Object>> wsDataList = new ArrayList<>();
- List<List<Object>> wsStaDataList = new ArrayList<>();
- for (Long l = startDay.getTime(); l <= endDay.getTime(); l += 86400000L) {
- Date finalL = DateTimeUtil.getDayStartTime(l);
- List<WindTowerCalculationData> wsList = windTowerCalculationDataList.stream().filter(w -> w.getEbId().equals(wsEbId) && w.getTime().equals(finalL)).collect(Collectors.toList());
- List<Object> list = new ArrayList<>();
- if (!wsList.isEmpty()) {
- list.add(sdf.format(wsList.get(0).getTime()));
- list.add(wsList.get(0).getValue());
- wsDataList.add(list);
- } else {
- list.add(sdf.format(new Date(l)));
- list.add(new BigDecimal(0));
- wsDataList.add(list);
- }
- //计算风速标准差
- List<WindTowerCalculationData> wsStaList = windTowerCalculationDataList.stream().filter(w -> w.getEbId().equals(staEbId) && w.getTime().equals(finalL)).collect(Collectors.toList());
- //取出这个层高所有的数据
- list = new ArrayList<>();
- if (!wsStaList.isEmpty()) {
- list.add(sdf.format(wsStaList.get(0).getTime()));
- list.add(wsStaList.get(0).getValue());
- wsStaDataList.add(list);
- } else {
- list.add(sdf.format(new Date(l)));
- list.add(BigDecimal.ZERO);
- wsStaDataList.add(list);
- }
- }
- map.put("ws", wsDataList);
- map.put("wsSta", wsStaDataList);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return map;
- }
- /**
- * 风速和风速密度日变化
- *
- * @param height
- * @return map
- */
- public Map<String, Object> getWindPowerDensityAndAverageWindSpeed(List<WindTowerCalculationData> windTowerCalculationDataList, List<EquipmentAttribute> equipmentAttributeList, List<WindTowerInfo> windTowerInfos, String height) {
- Map<String, Object> map = new HashMap<>();
- try {
- String wpdFieldName = height + "wpd";
- String awsFieldName = height + "aws";
- List<EquipmentAttribute> wpdFieldNameList = equipmentAttributeList.stream().filter(e -> wpdFieldName.equals(e.getFieldName())).collect(Collectors.toList());
- List<EquipmentAttribute> awsFieldNameList = equipmentAttributeList.stream().filter(e -> awsFieldName.equals(e.getFieldName())).collect(Collectors.toList());
- if (!wpdFieldNameList.isEmpty() && !awsFieldNameList.isEmpty()) {
- String wpdEbId = wpdFieldNameList.get(0).getId();
- String awsEbId = awsFieldNameList.get(0).getId();
- //平均风速集合
- List<WindTowerCalculationData> awsList;
- //风功率密度集合
- List<WindTowerCalculationData> wpdList;
- awsList = windTowerCalculationDataList.stream().filter(w -> awsEbId.equals(w.getEbId())).sorted(Comparator.comparing(WindTowerCalculationData::getTime)).collect(Collectors.toList());
- wpdList = windTowerCalculationDataList.stream().filter(w -> wpdEbId.equals(w.getEbId())).sorted(Comparator.comparing(WindTowerCalculationData::getTime)).collect(Collectors.toList());
- if (!awsList.isEmpty()) {
- map.put("AverageWindSpeed", CalculationUtil.getData24(awsList));
- }
- if (!wpdList.isEmpty()) {
- map.put("WindPowerDensity", CalculationUtil.getData24(wpdList));
- }
- }
- map.put("table", getWpdTable(windTowerCalculationDataList, equipmentAttributeList, windTowerInfos));
- } catch (Exception e) {
- e.printStackTrace();
- }
- return map;
- }
- /**
- * 风速和风速密度日变化表格
- *
- * @return map
- */
- public Map<String, Object> getWpdTable(List<WindTowerCalculationData> windTowerCalculationDataList, List<EquipmentAttribute> equipmentAttributeList, List<WindTowerInfo> windTowerInfos) {
- Map<String, Object> map = new HashMap<>();
- List<List<BigDecimal>> list = new ArrayList<>();
- try {
- String height;
- height = windTowerInfos.get(0).getHeights();
- if (height == null || height.equals("")) {
- height = "10,30,50,60,70,80,90,100,110,120,140,150";
- }
- String[] heightAll = height.split(",");
- List<String> tableHeader = new ArrayList<>();
- tableHeader.add("时间");
- for (String str : heightAll) {
- List<BigDecimal> wsDataList = new ArrayList<>();
- List<BigDecimal> wpdDataList = new ArrayList<>();
- tableHeader.add(str + "m风速(m/s)");
- tableHeader.add(str + "m风功率密度(w/㎡)");
- String wpdFieldName = str + "wpd";
- String awsFieldName = str + "aws";
- List<EquipmentAttribute> wpdFieldNameList = equipmentAttributeList.stream().filter(e -> wpdFieldName.equals(e.getFieldName())).collect(Collectors.toList());
- List<EquipmentAttribute> awsFieldNameList = equipmentAttributeList.stream().filter(e -> awsFieldName.equals(e.getFieldName())).collect(Collectors.toList());
- //选择时间段的平均风速
- BigDecimal avgWs = new BigDecimal(0);
- //选择时间段的风功率密度
- BigDecimal avgWpd = new BigDecimal(0);
- if (!wpdFieldNameList.isEmpty() && !awsFieldNameList.isEmpty()) {
- String wpdEbId = wpdFieldNameList.get(0).getId();
- String awsEbId = awsFieldNameList.get(0).getId();
- //平均风速集合
- List<WindTowerCalculationData> awsList;
- //风功率密度集合
- List<WindTowerCalculationData> wpdList;
- awsList = windTowerCalculationDataList.stream().filter(w -> awsEbId.equals(w.getEbId())).sorted(Comparator.comparing(WindTowerCalculationData::getTime)).collect(Collectors.toList());
- wpdList = windTowerCalculationDataList.stream().filter(w -> wpdEbId.equals(w.getEbId())).sorted(Comparator.comparing(WindTowerCalculationData::getTime)).collect(Collectors.toList());
- if (!awsList.isEmpty()) {
- BigDecimal wsSum = new BigDecimal(0);
- for (WindTowerCalculationData data : awsList) {
- wsSum = wsSum.add(data.getValue());
- }
- //如何总和不为0
- if (wsSum.compareTo(new BigDecimal(0)) != 0) {
- avgWs = wsSum.divide(new BigDecimal(awsList.size()), 2, RoundingMode.HALF_UP);
- }
- wsDataList = getData24(awsList);
- wsDataList.add(avgWs);
- }
- if (!wpdList.isEmpty()) {
- BigDecimal wpdSum = new BigDecimal(0);
- for (WindTowerCalculationData data : wpdList) {
- wpdSum = wpdSum.add(data.getValue());
- }
- //如何总和不为0
- if (wpdSum.compareTo(new BigDecimal(0)) != 0) {
- avgWpd = wpdSum.divide(new BigDecimal(wpdList.size()), 2, RoundingMode.HALF_UP);
- }
- wpdDataList = getData24(wpdList);
- wpdDataList.add(avgWpd);
- }
- }
- list.add(wsDataList);
- list.add(wpdDataList);
- }
- map.put("tableHeader", tableHeader);
- map.put("data", list);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return map;
- }
- /**
- * 风速和风速密度各月日变化
- *
- * @param height
- * @return map
- */
- public List<Map<String, Object>> getMonthWsAndWpd(List<WindTowerCalculationData> windTowerCalculationDataList, List<EquipmentAttribute> equipmentAttributeList, String height, Date startDay, Date endDay) {
- List<Map<String, Object>> list = new ArrayList<>();
- try {
- SimpleDateFormat sdf = new SimpleDateFormat("M");
- String wpdFieldName = height + "wpd";
- String awsFieldName = height + "aws";
- List<EquipmentAttribute> wpdFieldNameList = equipmentAttributeList.stream().filter(e -> wpdFieldName.equals(e.getFieldName())).collect(Collectors.toList());
- List<EquipmentAttribute> awsFieldNameList = equipmentAttributeList.stream().filter(e -> awsFieldName.equals(e.getFieldName())).collect(Collectors.toList());
- List<String> nullList = new ArrayList<>();
- if (!wpdFieldNameList.isEmpty() && !awsFieldNameList.isEmpty()) {
- String wpdEbId = wpdFieldNameList.get(0).getId();
- String awsEbId = awsFieldNameList.get(0).getId();
- List<WindTowerCalculationData> awsAllList = windTowerCalculationDataList.stream().filter(w -> awsEbId.equals(w.getEbId())).sorted(Comparator.comparing(WindTowerCalculationData::getTime)).collect(Collectors.toList());
- List<WindTowerCalculationData> wpdAllList = windTowerCalculationDataList.stream().filter(w -> wpdEbId.equals(w.getEbId())).sorted(Comparator.comparing(WindTowerCalculationData::getTime)).collect(Collectors.toList());
- List<Long> intervalTimeByMonth = DateTimeUtil.getIntervalTimeByMonth(startDay, endDay);
- for (int i = 1; i <= 12; i++) {
- //平均风速集合
- List<WindTowerCalculationData> awsList = new ArrayList<>();
- //风功率密度集合
- List<WindTowerCalculationData> wpdList = new ArrayList<>();
- Map<String, Object> dataMap = new HashMap<>();
- for (Long l : intervalTimeByMonth) {
- //判断月份是否相等
- if (String.valueOf(i).equals(sdf.format(new Date(l)))) {
- Date monthStartTime = DateTimeUtil.beginOfMonth(new Date(l));
- Date monthendTime = DateTimeUtil.endOfMonth(new Date(l));
- awsList = awsAllList.stream().filter(w -> w.getTime().compareTo(monthStartTime) >= 0 && w.getTime().compareTo(monthendTime) < 0).collect(Collectors.toList());
- wpdList = wpdAllList.stream().filter(w -> w.getTime().compareTo(monthStartTime) >= 0 && w.getTime().compareTo(monthendTime) < 0).collect(Collectors.toList());
- }
- }
- if (!awsList.isEmpty()) {
- dataMap.put("ws", CalculationUtil.getData24(awsList));
- } else {
- dataMap.put("ws", nullList);
- }
- if (!wpdList.isEmpty()) {
- dataMap.put("wpd", CalculationUtil.getData24(wpdList));
- } else {
- dataMap.put("wpd", nullList);
- }
- dataMap.put("time", i + "月");
- list.add(dataMap);
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return list;
- }
- /**
- * 风速和风速密度年变化曲线
- *
- * @return map
- */
- public Map<String, Object> getYearWsAndWpd(List<WindTowerCalculationData> windTowerCalculationDataList, List<EquipmentAttribute> equipmentAttributeList, String height, Date startDay, Date endDay) {
- Map<String, Object> map = new HashMap<>();
- try {
- // Long yesterday = new Date().getTime() - 1000 * 60 * 60 * 24;//昨天
- // Date startTime = DateTimeUtil.getDayStartTime(DateTimeUtil.getYearDay(yesterday).getTime());//报告的开始时间 一年前的昨天的00:00:00
- // Date endTime = DateTimeUtil.getDayLastTime(yesterday);//报告的结束时间 昨天的23:59:59
- /*设备属性信息*/
- String wpdFieldName = height + "wpdMonth"; //wpdMonth awsDay
- String awsFieldName = height + "awsMonth";
- List<EquipmentAttribute> wpdFieldNameList = equipmentAttributeList.stream().filter(e -> wpdFieldName.equals(e.getFieldName())).collect(Collectors.toList());
- List<EquipmentAttribute> awsFieldNameList = equipmentAttributeList.stream().filter(e -> awsFieldName.equals(e.getFieldName())).collect(Collectors.toList());
- List<BigDecimal> wsDataList = new ArrayList<>();
- List<BigDecimal> wpdDataList = new ArrayList<>();
- List<String> timeList = new ArrayList<>();
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
- if (!wpdFieldNameList.isEmpty() && !awsFieldNameList.isEmpty()) {
- String wpdEbId = wpdFieldNameList.get(0).getId();
- String awsEbId = awsFieldNameList.get(0).getId();
- //平均风速集合
- List<WindTowerCalculationData> awsAllList = new ArrayList<>();
- //风功率密度集合
- List<WindTowerCalculationData> wpdAllList = new ArrayList<>();
- awsAllList = windTowerCalculationDataList.stream().filter(w -> awsEbId.equals(w.getEbId())).sorted(Comparator.comparing(WindTowerCalculationData::getTime)).collect(Collectors.toList());
- wpdAllList = windTowerCalculationDataList.stream().filter(w -> wpdEbId.equals(w.getEbId())).sorted(Comparator.comparing(WindTowerCalculationData::getTime)).collect(Collectors.toList());
- List<Long> timeByMonth = DateTimeUtil.getIntervalTimeByMonth(startDay, endDay);
- for (Long aLong : timeByMonth) {
- BigDecimal avgWs = new BigDecimal(0);
- BigDecimal avgWpd = new BigDecimal(0);
- //过滤平均风速集合
- List<WindTowerCalculationData> awsList = new ArrayList<>();
- //过滤风功率密度集合
- List<WindTowerCalculationData> wpdList = new ArrayList<>();
- // 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());
- awsList = awsAllList.stream().filter(w -> w.getTime().equals(new Date(aLong)) && w.getValue() != null && w.getValue().compareTo(new BigDecimal(-99)) != 0).collect(Collectors.toList());
- wpdList = wpdAllList.stream().filter(w -> w.getTime().equals(new Date(aLong)) && w.getValue() != null && w.getValue().compareTo(new BigDecimal(-99)) != 0).collect(Collectors.toList());
- if (!awsList.isEmpty()) {
- List<BigDecimal> valueList = awsList.stream().map(WindTowerCalculationData::getValue).collect(Collectors.toList());
- avgWs = valueList.stream().reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(valueList.size()), 2, RoundingMode.HALF_UP);
- }
- wsDataList.add(avgWs);
- if (!wpdList.isEmpty()) {
- List<BigDecimal> valueList = wpdList.stream().map(WindTowerCalculationData::getValue).collect(Collectors.toList());
- avgWpd = valueList.stream().reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(valueList.size()), 2, RoundingMode.HALF_UP);
- }
- wpdDataList.add(avgWpd);
- timeList.add(sdf.format(aLong));
- }
- }
- map.put("wsList", wsDataList);
- map.put("wpdList", wpdDataList);
- map.put("time", timeList);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return map;
- }
- /**
- * 风速和风速密度各月日变化表格
- *
- * @return map
- */
- public Map<String, Object> getMonthWpdTable(List<WindTowerCalculationData> windTowerCalculationDataList, List<EquipmentAttribute> equipmentAttributeList, List<WindTowerInfo> windTowerInfos, Date startDay, Date endDay) {
- Map<String, Object> map = new HashMap<>();
- List<List<BigDecimal>> list = new ArrayList<>();
- List<String> timeList = new ArrayList<>();
- try {
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
- List<Long> timeByMonth = DateTimeUtil.getIntervalTimeByMonth(startDay, endDay);
- for (Long aLong : timeByMonth) {
- Date monthStartTime = DateTimeUtil.getDayStartTime(aLong);
- timeList.add(sdf.format(monthStartTime));
- }
- timeList.add("平均");
- //获取风速层高
- String height;
- height = windTowerInfos.get(0).getHeights();
- if (height == null || height.equals("")) {
- height = "10,30,50,60,70,80,90,100,110,120,140,150";
- }
- String[] heightAll = height.split(",");
- List<String> tableHeader = new ArrayList<>();
- tableHeader.add("月份");
- for (String str : heightAll) {
- List<BigDecimal> wsDataList = new ArrayList<>();
- List<BigDecimal> wpdDataList = new ArrayList<>();
- tableHeader.add(str + "m风速(m/s)");
- tableHeader.add(str + "m风功率密度(w/㎡)");
- String wpdFieldName = str + "wpdMonth"; //wpdMonth awsDay
- String awsFieldName = str + "awsMonth";
- List<EquipmentAttribute> wpdFieldNameList = equipmentAttributeList.stream().filter(e -> wpdFieldName.equals(e.getFieldName())).collect(Collectors.toList());
- List<EquipmentAttribute> awsFieldNameList = equipmentAttributeList.stream().filter(e -> awsFieldName.equals(e.getFieldName())).collect(Collectors.toList());
- BigDecimal sumAveWs = new BigDecimal(0);
- BigDecimal sumAveWpd = new BigDecimal(0);
- if (!wpdFieldNameList.isEmpty() && !awsFieldNameList.isEmpty()) {
- String wpdEbId = wpdFieldNameList.get(0).getId();
- String awsEbId = awsFieldNameList.get(0).getId();
- //平均风速集合
- List<WindTowerCalculationData> awsAllList;
- //风功率密度集合
- List<WindTowerCalculationData> wpdAllList;
- awsAllList = windTowerCalculationDataList.stream().filter(w -> awsEbId.equals(w.getEbId())).sorted(Comparator.comparing(WindTowerCalculationData::getTime)).collect(Collectors.toList());
- wpdAllList = windTowerCalculationDataList.stream().filter(w -> wpdEbId.equals(w.getEbId())).sorted(Comparator.comparing(WindTowerCalculationData::getTime)).collect(Collectors.toList());
- for (Long aLong : timeByMonth) {
- BigDecimal avgWs = new BigDecimal(0);
- BigDecimal avgWpd = new BigDecimal(0);
- //过滤平均风速集合
- List<WindTowerCalculationData> awsList;
- //过滤风功率密度集合
- List<WindTowerCalculationData> wpdList;
- awsList = awsAllList.stream().filter(w -> w.getTime().equals(new Date(aLong))).collect(Collectors.toList());
- wpdList = wpdAllList.stream().filter(w -> w.getTime().equals(new Date(aLong))).collect(Collectors.toList());
- if (!awsList.isEmpty()) {
- List<BigDecimal> valueList = awsList.stream().map(WindTowerCalculationData::getValue).collect(Collectors.toList());
- avgWs = valueList.stream().reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(valueList.size()), 2, RoundingMode.HALF_UP);
- }
- wsDataList.add(avgWs);
- if (!wpdList.isEmpty()) {
- List<BigDecimal> valueList = wpdList.stream().map(WindTowerCalculationData::getValue).collect(Collectors.toList());
- avgWpd = valueList.stream().reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(valueList.size()), 2, RoundingMode.HALF_UP);
- }
- wpdDataList.add(avgWpd);
- }
- int wsListCount = wsDataList.stream().filter(w -> w.compareTo(new BigDecimal(0)) != 0).collect(Collectors.toList()).size();
- int wpdListCount = wpdDataList.stream().filter(w -> w.compareTo(new BigDecimal(0)) != 0).collect(Collectors.toList()).size();
- if (wsListCount != 0) {
- sumAveWs = wsDataList.stream().reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(wsListCount), 2, RoundingMode.HALF_UP);
- }
- if (wpdListCount != 0) {
- sumAveWpd = wpdDataList.stream().reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(wpdListCount), 2, RoundingMode.HALF_UP);
- }
- wsDataList.add(sumAveWs);
- wpdDataList.add(sumAveWpd);
- }
- list.add(wsDataList);
- list.add(wpdDataList);
- }
- map.put("tableHeader", tableHeader);
- map.put("data", list);
- map.put("month", timeList);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return map;
- }
- /**
- * pdf威布尔
- *
- * @return weibull
- */
- public ArrayList<Map<String, Object>> pdfWeibull(List<EquipmentAttribute> equipmentAttributeList, List<WindTowerCalculationData> windTowerCalculationDataList, List<WindTowerInfo> windTowerInfos) {
- ArrayList<Map<String, Object>> weibullDataList = new ArrayList<>();
- try {
- String[] heightWs = windTowerInfos.get(0).getHeights().split(",");
- for (String height : heightWs) {
- Map<String, Object> map = new HashMap<>();
- List<BigDecimal> wsList = new ArrayList<>();
- double e = 2.71828183;
- // 风速集合
- String ebId = equipmentAttributeList.stream().filter(w -> w.getFieldName().equals(height + "aws")).collect(Collectors.toList()).get(0).getId();
- List<WindTowerCalculationData> calculationDataList = windTowerCalculationDataList.stream().filter(w -> w.getEbId().equals(ebId)).collect(Collectors.toList());
- for (WindTowerCalculationData w : calculationDataList) {
- wsList.add(w.getValue());
- }
- TreeMap<BigDecimal, List<BigDecimal>> wsMap = new TreeMap<>();
- if (!wsList.isEmpty()) {
- ArrayList<Object> arrayWsList = new ArrayList<>(wsList);
- //把风速集合传入,计算A、K
- ProbabilityPlot probabilityPlot = new ProbabilityPlot(arrayWsList);
- probabilityPlot.suppressDisplay();
- double K = probabilityPlot.weibullTwoParGamma();
- double A = probabilityPlot.weibullTwoParSigma();
- //
- //
- // map.put("K", BigDecimal.valueOf(K).setScale(2, RoundingMode.HALF_UP).doubleValue());
- // map.put("A", BigDecimal.valueOf(A).setScale(2, RoundingMode.HALF_UP).doubleValue());
- // BigDecimal wsAve = wsList.stream().reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(wsList.size()), 2, RoundingMode.HALF_UP);
- // map.put("wsAve", wsAve);
- /*根据风速过滤出风速区间集合*/
- for (BigDecimal ws : wsList) {
- // 风速区间
- BigDecimal speedLevel = BigDecimal.valueOf(Math.ceil(ws.subtract(BigDecimal.valueOf(0.5)).doubleValue()));
- if (wsMap.containsKey(speedLevel)) {
- wsMap.get(speedLevel).add(ws);
- } else {
- wsMap.put(speedLevel, new ArrayList<>());
- wsMap.get(speedLevel.setScale(1, RoundingMode.HALF_UP)).add(ws);
- }
- }
- /*风速频率*/
- List<List<BigDecimal>> wsFreList = new ArrayList<>();
- /*威布尔*/
- List<List<BigDecimal>> weibullList = new ArrayList<>();
- wsMap.forEach((key, val) -> {
- Map<String, Object> freMap = new HashMap<>();
- List<BigDecimal> list = new ArrayList<>();
- List<BigDecimal> tempList = new ArrayList<>();
- BigDecimal wsFrequency = new BigDecimal(val.size()).divide(new BigDecimal(wsList.size()), 4, RoundingMode.HALF_UP).multiply(new BigDecimal(100));
- list.add(key.setScale(0, RoundingMode.HALF_UP));
- list.add(wsFrequency);
- wsFreList.add(list);
- /*区间威布尔累加求和求平均值*/
- BigDecimal aveWs = val.stream().reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(val.size()), 2, RoundingMode.HALF_UP);
- BigDecimal weibull = CalculationUtil.getBigDecimal(e, aveWs.doubleValue(), K, A);
- tempList.add(key.setScale(0, RoundingMode.HALF_UP));
- tempList.add(weibull);
- weibullList.add(tempList);
- });
- map.put("wsFrequency", wsFreList);
- map.put("weibull", weibullList);
- map.put("height", height);
- }
- weibullDataList.add(map);
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return weibullDataList;
- }
- /**
- * 湍流(15m/s湍流)最大、最小、平均 数据
- *
- * @param windTowerCalculationDatas 统计数据
- * @param equipmentAttributeList 属性数据
- * @return
- */
- public ArrayList<Map<String, Object>> statisticsWindTowerStatusDataTur(List<WindTowerCalculationData> windTowerCalculationDatas, List<EquipmentAttribute> equipmentAttributeList, List<WindTowerInfo> windTowerInfos) {
- ArrayList<Map<String, Object>> heightAndTurList = new ArrayList<>();
- String[] heights = windTowerInfos.get(0).getHeights().split(",");
- for (String height : heights) {
- BigDecimal turAve = BigDecimal.ZERO;
- BigDecimal turForFifteen = BigDecimal.ZERO;
- Map<String, Object> map = new HashMap<>();
- List<EquipmentAttribute> equipmentAttributes = equipmentAttributeList.stream().filter(e -> e.getFieldName().equals(height + "turbulenceDay")).collect(Collectors.toList());
- List<EquipmentAttribute> equipmentAttribute = equipmentAttributeList.stream().filter(e -> e.getFieldName().equals(height + "turForWsByFifteenDay")).collect(Collectors.toList());
- //通过属性过滤数据
- List<WindTowerCalculationData> dayList = windTowerCalculationDatas.stream().filter(w -> w.getEbId().equals(equipmentAttributes.get(0).getId())).collect(Collectors.toList());
- List<WindTowerCalculationData> turDayList = windTowerCalculationDatas.stream().filter(w -> w.getEbId().equals(equipmentAttribute.get(0).getId())).collect(Collectors.toList());
- if (dayList.size() > 0) {
- turAve = dayList.stream().map(WindTowerCalculationData::getValue).reduce(BigDecimal::add).get().divide(BigDecimal.valueOf(dayList.size()), 2, RoundingMode.HALF_UP);
- }
- if (turDayList.size() > 0) {
- turForFifteen = turDayList.stream().map(WindTowerCalculationData::getValue).reduce(BigDecimal::add).get().divide(BigDecimal.valueOf(turDayList.size()), 2, RoundingMode.HALF_UP);
- }
- map.put("turAve", turAve);
- map.put("turForFifteen", turForFifteen);
- map.put("height", height);
- heightAndTurList.add(map);
- }
- return heightAndTurList;
- }
- /**
- * 风切变
- *
- * @return
- */
- public Map<String, Object> statisticsWindTowerStatusDataShear(List<ProphaseAnemometryData> prophaseAnemometryData, List<WindTowerInfo> windTowerInfos) {
- Map<String, Object> map = new HashMap<>();
- ArrayList<Object> wsShearTableData = new ArrayList<>();
- // HashMap<String, Object> heightMap = new HashMap<>();
- String[] heights = windTowerInfos.get(0).getHeights().split(",");
- for (int i = heights.length - 1 ; i > 0; i--) {
- String mixHeight = heights[i];
- HashMap<Object, Object> mainData = new HashMap<>();
- if (mixHeight.contains("A")) {
- continue;
- }
- List<BigDecimal> minHeightForWsList = prophaseAnemometryData.stream().filter(p -> p.getLayerHeight().equals(mixHeight)).map(p -> {
- return CalculationUtil.getBigDecimal(null == p.getWsAve()?0: p.getWsAve());
- }).collect(Collectors.toList());
- BigDecimal wsAveForMin = CalculationUtil.getAvgWind(minHeightForWsList);
- //筛选高层高
- List<String> heightList = new ArrayList<>(Arrays.asList(heights)).stream().filter(s -> Integer.valueOf(CalculationUtil.getNumberFromString(mixHeight)) < Integer.valueOf(CalculationUtil.getNumberFromString(s))).collect(Collectors.toList());
- for (String maxHeight : heightList) {
- if (maxHeight.contains("A")) {
- continue;
- }
- List<BigDecimal> maxHeightForWsList = prophaseAnemometryData.stream().filter(p -> p.getLayerHeight().equals(maxHeight)).map(p -> {
- return CalculationUtil.getBigDecimal(null == p.getWsAve()?0: p.getWsAve());
- }).collect(Collectors.toList());
- BigDecimal wsAveMax = CalculationUtil.getAvgWind(maxHeightForWsList);
- double z = new BigDecimal(CalculationUtil.getNumberFromString(maxHeight)).divide(new BigDecimal(CalculationUtil.getNumberFromString(mixHeight)), 8, RoundingMode.HALF_UP).doubleValue();
- double z1 = Math.log10(z);
- if (wsAveForMin.compareTo(BigDecimal.ZERO) > 0 && wsAveMax.compareTo(BigDecimal.ZERO) > 0 && z1 != 0) {
- BigDecimal shear = Convert.toBigDecimal(Math.log10(Convert.toDouble(wsAveMax.divide(wsAveForMin, 8, RoundingMode.HALF_UP))))
- .divide(BigDecimal.valueOf(z1), 2, RoundingMode.HALF_UP);
- mainData.put(maxHeight, shear);
- }
- }
- mainData.put("height", mixHeight);
- wsShearTableData.add(mainData);
- }
- // heightMap.put("headerData", Arrays.asList(heights));
- // wsShearTableData.add(heightMap);
- map.put("mainData",wsShearTableData);
- map.put("headerData",Arrays.asList(heights));
- return map;
- }
- /**
- * 一年玫瑰图
- *
- * @param
- * @return
- * @throws Exception
- */
- public ArrayList<Map<String, Object>> roseCharts(List<WindDirectionStatisticsData> windDirectionStatisticsData, List<EquipmentAttribute> equipmentAttributeList, List<WindTowerInfo> windTowerInfos) {
- ArrayList<Map<String, Object>> wdList = new ArrayList<>();
- try {
- String[] heightWd = windTowerInfos.get(0).getWdHeights().split(",");
- for (String height : heightWd) {
- Map<String, Object> map = new HashMap<>();
- // 若层高包含A按照去掉A的层高计算
- if (height.contains("A")) {
- height = height.substring(0, height.length() - 1);
- }
- map.put("height", height);
- map.put("wd", getwd(windDirectionStatisticsData, equipmentAttributeList, height));
- map.put("power", getPower(windDirectionStatisticsData, equipmentAttributeList, height));
- wdList.add(map);
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return wdList;
- }
- /**
- * 各月玫瑰图
- *
- * @param height 层高
- * @return
- * @throws Exception
- */
- public Map<String, Object> getMonthRoseCharts(List<WindDirectionStatisticsData> windDirectionStatisticsData, List<EquipmentAttribute> equipmentAttributeList, String height) {
- Map<String, Object> map = new HashMap<>();
- List<Map<String, Object>> wdList = new ArrayList<>();
- List<Map<String, Object>> powerList = new ArrayList<>();
- SimpleDateFormat monthSdf = new SimpleDateFormat("M");
- try {
- // 若层高包含A按照去掉A的层高计算
- if (height.contains("A")) {
- height = height.substring(0, height.length() - 1);
- }
- for (int i = 1; i <= 12; i++) {
- Map<String, Object> wdMap = new HashMap<>();
- Map<String, Object> powerMap = new HashMap<>();
- // Date monthStartTime = DateTimeUtil.getDayStartTime(DateTimeUtil.mouthOneDay(i).getTime());
- // Date monthendTime = DateTimeUtil.getDayLastTime(DateTimeUtil.mouthLastDay(i).getTime());
- //过滤时间区间集合
- List<WindDirectionStatisticsData> filterList = new ArrayList<>();
- // filterList = windDirectionStatisticsData.stream().filter(w -> w.getTime().compareTo(monthStartTime) >= 0 && w.getTime().compareTo(monthendTime) < 0).collect(Collectors.toList());
- int finalI = i;
- filterList = windDirectionStatisticsData.stream().filter(w -> monthSdf.format(w.getTime()).equals(String.valueOf(finalI))).collect(Collectors.toList());
- wdMap.put("time", i + "月");
- powerMap.put("time", i + "月");
- //如果月份数据为空就放null
- if (!filterList.isEmpty()) {
- List<Map<String, Object>> getwd = getwd(filterList, equipmentAttributeList, height);
- wdMap.put("data", getwd);
- powerMap.put("data", getPower(filterList, equipmentAttributeList, height));
- } else {
- wdMap.put("data", null);
- powerMap.put("data", null);
- }
- wdList.add(wdMap);
- powerList.add(powerMap);
- }
- map.put("wd", wdList);
- map.put("power", powerList);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return map;
- }
- /*风向玫瑰图数据*/
- public List<Map<String, Object>> getwd(List<WindDirectionStatisticsData> windDirectionStatisticsData, List<EquipmentAttribute> equipmentAttributeList, String height) {
- List<Map<String, Object>> list = new ArrayList<>();
- String wdFieldName = height + "monthWdRose";
- // 过滤获取ebId
- List<EquipmentAttribute> wdEquipmentAttribute = equipmentAttributeList.stream().filter(e -> wdFieldName.equals(e.getFieldName())).collect(Collectors.toList());
- // 获取风向统计数据
- List<WindDirectionStatisticsData> wdList = windDirectionStatisticsData.stream().filter(e -> e.getEbId().equals(wdEquipmentAttribute.get(0).getId())).collect(Collectors.toList());
- /*玫瑰图风向枚举*/
- for (WindDirectionEnum value : WindDirectionEnum.values()) {
- Map<String, Object> wdMap = new HashMap<>();
- // 根据风向过滤统计表
- List<WindDirectionStatisticsData> filterWdList = wdList.stream().filter(e -> e.getDirection().equals(value.name())).collect(Collectors.toList());
- // 提取过滤的value值
- // List<BigDecimal> filterwdValueList = filterWdList.stream().map(WindDirectionStatisticsData::getValue).filter(w -> w != null).collect(Collectors.toList());
- // 累加保留两位小数
- BigDecimal proportionWd = BigDecimal.ZERO;
- if (!filterWdList.isEmpty()) {
- proportionWd = BigDecimal.valueOf(filterWdList.size()).multiply(new BigDecimal(100)).divide(BigDecimal.valueOf(wdList.size()), 2, RoundingMode.HALF_UP);
- }
- wdMap.put(value.name(), proportionWd);
- list.add(wdMap);
- }
- return list;
- }
- /*风能玫瑰图数据*/
- public List<Map<String, Object>> getPower(List<WindDirectionStatisticsData> windDirectionStatisticsData, List<EquipmentAttribute> equipmentAttributeList, String height) {
- List<Map<String, Object>> list = new ArrayList<>();
- String powerFieldName = height + "monthPowerRose";
- // 过滤获取ebId
- List<EquipmentAttribute> powerEquipmentAttribute = equipmentAttributeList.stream().filter(e -> powerFieldName.equals(e.getFieldName())).collect(Collectors.toList());
- // 获取风向统计数据
- List<WindDirectionStatisticsData> powerList = windDirectionStatisticsData.stream().filter(e -> e.getEbId().equals(powerEquipmentAttribute.get(0).getId())).collect(Collectors.toList());
- BigDecimal sumPower = powerList.stream().map(WindDirectionStatisticsData::getValue).reduce(BigDecimal::add).get();
- /*玫瑰图风向枚举*/
- for (WindDirectionEnum value : WindDirectionEnum.values()) {
- Map<String, Object> powerMap = new HashMap<>();
- // 根据风向过滤统计表
- List<WindDirectionStatisticsData> filterPowerList = powerList.stream().filter(e -> e.getDirection().equals(value.name())).collect(Collectors.toList());
- BigDecimal sumPowerForWd = BigDecimal.ZERO;
- if (filterPowerList.size() > 0) {
- sumPowerForWd = filterPowerList.stream().filter(w -> w.getValue() != null).map(WindDirectionStatisticsData::getValue).reduce(BigDecimal::add).get();
- }
- // 累加保留两位小数
- BigDecimal proportionPower = BigDecimal.ZERO;
- if (sumPower.compareTo(BigDecimal.ZERO) > 0) {
- proportionPower = sumPowerForWd.multiply(new BigDecimal(100)).divide(sumPower, 2, RoundingMode.HALF_UP);
- }
- powerMap.put(value.name(), proportionPower);
- list.add(powerMap);
- }
- return list;
- }
- /**
- * 空气密度
- *
- * @return
- * @throws Exception
- */
- public Map<String, Object> getAirDensity(List<WindTowerCalculationData> windTowerCalculationDatas, List<EquipmentAttribute> equipmentAttributeList, Date startDay, Date endDay) {
- Map<String, Object> map = new HashMap<>();
- List<String> timeList = new ArrayList<>();
- List<String> monthTimeList = new ArrayList<>();
- List<BigDecimal> tList = new ArrayList<>();
- List<BigDecimal> paList = new ArrayList<>();
- try {
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
- SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
- List<EquipmentAttribute> tAVE = equipmentAttributeList.stream().filter(e -> "tDay".equals(e.getFieldName())).collect(Collectors.toList());
- List<EquipmentAttribute> paAVE = equipmentAttributeList.stream().filter(e -> "paDay".equals(e.getFieldName())).collect(Collectors.toList());
- List<EquipmentAttribute> airDensityMonth = equipmentAttributeList.stream().filter(e -> "airDensityMonth".equals(e.getFieldName())).collect(Collectors.toList());
- List<EquipmentAttribute> airDensityDayForYear = equipmentAttributeList.stream().filter(e -> "airDensityDayForYear".equals(e.getFieldName())).collect(Collectors.toList());
- List<WindTowerCalculationData> tAVEData = windTowerCalculationDatas.stream().filter(w -> w.getEbId().equals(tAVE.get(0).getId())).sorted(Comparator.comparing(WindTowerCalculationData::getTime)).collect(Collectors.toList());
- List<WindTowerCalculationData> paAVEData = windTowerCalculationDatas.stream().filter(w -> w.getEbId().equals(paAVE.get(0).getId())).sorted(Comparator.comparing(WindTowerCalculationData::getTime)).collect(Collectors.toList());
- List<WindTowerCalculationData> airDensityMonthData = windTowerCalculationDatas.stream().filter(w -> w.getEbId().equals(airDensityMonth.get(0).getId())).sorted(Comparator.comparing(WindTowerCalculationData::getTime)).collect(Collectors.toList());
- List<WindTowerCalculationData> airDensityDayForYearData = windTowerCalculationDatas.stream().filter(w -> w.getEbId().equals(airDensityDayForYear.get(0).getId())).sorted(Comparator.comparing(WindTowerCalculationData::getTime)).collect(Collectors.toList());
- /*温度气压曲线*/
- //补点做法
- for (Long l = startDay.getTime(); l <= endDay.getTime(); l += 86400000L) {
- Date finalL = DateUtil.beginOfDay(new Date(l));
- String dates = sdf1.format(finalL);
- List<WindTowerCalculationData> collect = tAVEData.stream().filter(t -> sdf1.format(t.getTime()).equals(dates)).collect(Collectors.toList());
- if (!collect.isEmpty()) {
- tList.add(collect.get(0).getValue());
- } else {
- tList.add(null);
- }
- List<WindTowerCalculationData> collect1 = paAVEData.stream().filter(p -> sdf1.format(p.getTime()).equals(dates)).collect(Collectors.toList());
- if (!collect1.isEmpty()) {
- paList.add(collect1.get(0).getValue());
- } else {
- paList.add(null);
- }
- timeList.add(sdf.format(finalL));
- }
- map.put("time", timeList);
- map.put("t", tList);
- map.put("pa", paList);
- // //月平均温度
- // for (WindTowerCalculationData w : tAVEData) {
- // timeList.add(sdf.format(w.getTime()));
- // tList.add(w.getValue());
- // }
- // //月平均气压
- // for (WindTowerCalculationData w : paAVEData) {
- // paList.add(w.getValue());
- // }
- // map.put("time", timeList);
- // map.put("t", tList);
- // map.put("pa", paList);
- /*空气密度日变化*/
- List<BigDecimal> airDensityList = new ArrayList<>();
- if (!airDensityDayForYearData.isEmpty()) {
- airDensityList = CalculationUtil.getData24(airDensityDayForYearData);
- }
- List<BigDecimal> airDensityCollect = airDensityList.stream().filter(w -> w.compareTo(new BigDecimal(0)) != 0).collect(Collectors.toList());
- BigDecimal ave24AirDensity = BigDecimal.ZERO;
- if (!airDensityCollect.isEmpty()) {
- ave24AirDensity = airDensityCollect.stream().reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(24), 3, RoundingMode.HALF_UP);
- }
- map.put("dayAirDensity", airDensityList);
- map.put("aveDayAirDensity", ave24AirDensity);
- /*空气年变化*/
- List<BigDecimal> monthList = new ArrayList<>();
- SimpleDateFormat sdfMonth = new SimpleDateFormat("M");
- for (int i = 1; i <= 12; i++) {
- // Date monthStartTime = DateTimeUtil.getDayStartTime(DateTimeUtil.mouthOneDay(i).getTime());
- //过滤时间区间集合
- List<WindTowerCalculationData> filterList = new ArrayList<>();
- BigDecimal value = new BigDecimal(0);
- int finalI = i;
- filterList = airDensityMonthData.stream().filter(w -> sdfMonth.format(w.getTime()).equals(String.valueOf(finalI))).collect(Collectors.toList());
- if (!filterList.isEmpty()) {
- value = filterList.get(0).getValue();
- }
- monthList.add(value);
- monthTimeList.add(i + "月");
- }
- // for (WindTowerCalculationData w : airDensityMonthData) {
- // monthTimeList.add(sdf.format(w.getTime()));
- // monthList.add(w.getValue());
- // }
- List<BigDecimal> collect = monthList.stream().filter(w -> w.compareTo(new BigDecimal(0)) != 0).collect(Collectors.toList());
- BigDecimal yearAveAirDensity = new BigDecimal(0);
- if (!collect.isEmpty()) {
- yearAveAirDensity = collect.stream().reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(collect.size()), 3, RoundingMode.HALF_UP);
- }
- map.put("monthTime", monthTimeList);
- map.put("yearAirDensity", monthList);
- map.put("yearAveAirDensity", yearAveAirDensity);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return map;
- }
- /**
- * 获取风切变指数(风向玫瑰图)
- *
- * @param height
- */
- public List<Map<String, Object>> getWindShearRose(List<WindDirectionStatisticsData> windDirectionStatisticsData, List<EquipmentAttribute> equipmentAttributeList, String height) {
- List<Map<String, Object>> list = new ArrayList<>();
- try {
- // 若层高包含A按照去掉A的层高计算
- if (height.contains("A")) {
- height = height.substring(0, height.length() - 1);
- }
- String shearFieldName = height + "monthShearRose";
- // 过滤获取ebId
- List<EquipmentAttribute> shearEquipmentAttribute = equipmentAttributeList.stream().filter(e -> shearFieldName.equals(e.getFieldName())).collect(Collectors.toList());
- // 获取风向统计数据
- List<WindDirectionStatisticsData> shearList = windDirectionStatisticsData.stream().filter(e -> e.getEbId().equals(shearEquipmentAttribute.get(0).getId())).collect(Collectors.toList());
- for (WindDirectionEnum value : WindDirectionEnum.values()) {
- Map<String, Object> map = new HashMap<>();
- // 根据风向过滤统计表
- List<WindDirectionStatisticsData> filterShearList = shearList.stream().filter(e -> e.getDirection().equals(value.name())).collect(Collectors.toList());
- // 提取过滤的value值
- List<BigDecimal> filterShearValueList = filterShearList.stream().map(WindDirectionStatisticsData::getValue).filter(w -> w != null).collect(Collectors.toList());
- // 累加保留两位小数
- BigDecimal sumShear = null;
- if (!filterShearValueList.isEmpty()) {
- sumShear = filterShearValueList.stream().reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, RoundingMode.HALF_UP);
- }
- map.put(value.name(), sumShear);
- list.add(map);
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return list;
- }
- /**
- * 风切变日/年变化
- *
- * @return
- * @throws Exception
- */
- public Map<String, Object> getWindShear(List<WindTowerCalculationData> windTowerCalculationDataLists, List<EquipmentAttribute> equipmentAttributeList, String height) {
- Map<String, Object> map = new HashMap<>();
- try {
- List<BigDecimal> dayResults = new ArrayList<>();//日变化
- List<BigDecimal> yearResults = new ArrayList<>();//年变化
- List<String> monthTimeList = new ArrayList<>();
- SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH");
- SimpleDateFormat sdf = new SimpleDateFormat("M");
- String shearFieldName = "windShear";
- List<EquipmentAttribute> shearFieldNameList = equipmentAttributeList.stream().filter(e -> shearFieldName.equals(e.getFieldName())).collect(Collectors.toList());
- if (!shearFieldNameList.isEmpty()) {
- String ebId = shearFieldNameList.get(0).getId(); //属性id
- //查询风切变 月平均数据 根据时间,层高,设备id 并根据时间升序排列
- List<WindTowerCalculationData> windTowerCalculationDataList = windTowerCalculationDataLists.stream().filter(w -> ebId.equals(w.getEbId())).sorted(Comparator.comparing(WindTowerCalculationData::getTime)).collect(Collectors.toList());
- if (!windTowerCalculationDataList.isEmpty()) {
- /*日变化*/
- long startTime1 = DateMomentUtil.getDayStartTime(DateUtils.addDays(new Date(), -1).getTime());
- long endTime1 = startTime1 + 86399000L;
- for (long time = startTime1; time <= endTime1; time += 3600000L) {
- Long finalTime = time;
- String format = simpleDateFormat.format(finalTime);
- List<BigDecimal> collect = windTowerCalculationDataList.stream().filter(s -> simpleDateFormat.format(s.getTime())
- .equals(format) && s.getValue() != null && s.getValue().compareTo(new BigDecimal(-99)) != 0)
- .map(WindTowerCalculationData::getValue).collect(Collectors.toList());
- BigDecimal ave = new BigDecimal(0);
- if (!collect.isEmpty()) {
- ave = collect.stream().reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(collect.size()), 3, RoundingMode.HALF_UP);
- }
- dayResults.add(ave);
- }
- BigDecimal dayAve = new BigDecimal(0);
- if (!dayResults.isEmpty()) {
- dayAve = dayResults.stream().reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(24), 3, RoundingMode.HALF_UP);
- }
- map.put("dayShear", dayResults);
- map.put("aveDayShear", dayAve);
- /*年变化*/
- for (int i = 1; i <= 12; i++) {
- //过滤时间区间集合
- List<WindTowerCalculationData> filterList = new ArrayList<>();
- BigDecimal yearShear = new BigDecimal(0);
- int finalI = i;
- filterList = windTowerCalculationDataList.stream().filter(w -> sdf.format(w.getTime()).equals(String.valueOf(finalI))).collect(Collectors.toList());
- if (!filterList.isEmpty()) {
- List<BigDecimal> collect = filterList.stream().map(WindTowerCalculationData::getValue).collect(Collectors.toList());
- yearShear = collect.stream().reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(collect.size()), 3, RoundingMode.HALF_UP);
- }
- yearResults.add(yearShear);
- monthTimeList.add(i + "月");
- }
- BigDecimal aveYearShear = new BigDecimal(0);
- List<BigDecimal> collect = yearResults.stream().filter(w -> w.compareTo(new BigDecimal(0)) != 0).collect(Collectors.toList());
- if (!collect.isEmpty()) {
- aveYearShear = collect.stream().reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(collect.size()), 3, RoundingMode.HALF_UP);
- }
- map.put("monthTime", monthTimeList);
- map.put("yearShear", yearResults);
- map.put("aveYearShear", aveYearShear);
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return map;
- }
- /**
- * 湍流曲线
- *
- * @param height 层高
- * @return
- * @throws Exception
- */
- public List<List<BigDecimal>> getTurIntensityCharts(List<WindTowerCalculationData> windTowerCalculationDataList, List<EquipmentAttribute> equipmentAttributeList, String height) {
- List<List<BigDecimal>> list = new ArrayList<>();
- try {
- BigDecimal ws;//风速值
- BigDecimal sta;//风速标准差
- BigDecimal turInsity = new BigDecimal(0);//湍流值
- String wsFieldName = height + "awsDay";
- List<EquipmentAttribute> wsDayAttList = equipmentAttributeList.stream().filter(e -> "wsDay".equals(e.getAttributeFunction())).collect(Collectors.toList());
- // 过滤属性集合找对应的属性id
- List<EquipmentAttribute> wsDayAtt = wsDayAttList.stream().filter(w -> w.getFieldName().equals(wsFieldName)).collect(Collectors.toList());
- String wsEbId = wsDayAtt.get(0).getId();
- //height层高的平均风速
- List<WindTowerCalculationData> wsList = windTowerCalculationDataList.stream().filter(w -> w.getEbId().equals(wsEbId)).collect(Collectors.toList());
- //取出heigth层高的平均风速标差属性
- List<EquipmentAttribute> equipmentAttributeList1 = equipmentAttributeList.stream().filter(e -> e.getFieldName().equals(height + "staDay")).collect(Collectors.toList());
- //取出这个层高所有的数据
- List<WindTowerCalculationData> staList = windTowerCalculationDataList.stream().filter(w -> w.getEbId().equals(equipmentAttributeList1.get(0).getId())).sorted(Comparator.comparing(WindTowerCalculationData::getTime)).collect(Collectors.toList());
- /*风速段-----方差数组*/
- Map<BigDecimal, List<BigDecimal>> turbulenceMap = new HashMap<>();
- BigDecimal speedLevel;
- for (int i = 0; i < wsList.size(); i++) {
- try {
- ws = wsList.get(i).getValue();
- if (i >= staList.size()) {
- break;
- } else {
- sta = staList.get(i).getValue();
- }
- turInsity = sta.divide(ws, 2, RoundingMode.HALF_UP);
- //风速段
- speedLevel = BigDecimal.valueOf(Math.ceil(ws.subtract(BigDecimal.valueOf(0.5)).doubleValue()));
- if (turbulenceMap.containsKey((speedLevel))) {
- turbulenceMap.get(speedLevel).add(turInsity);
- } else {
- turbulenceMap.put(speedLevel, new ArrayList<>());
- turbulenceMap.get(speedLevel.setScale(1, RoundingMode.HALF_UP)).add(turInsity);
- }
- } catch (IndexOutOfBoundsException e) {
- log.error("PDF 湍流曲线计算异常:" + e);
- }
- }
- //利用treeMap排序
- HashMap<BigDecimal, List<BigDecimal>> turbulenceTreeMap = new HashMap<>(turbulenceMap);
- turbulenceTreeMap.forEach((key, val) -> {
- List<BigDecimal> tempList = new ArrayList<>();
- BigDecimal turbulence = val.stream().reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(val.size()), 3, RoundingMode.HALF_UP);
- tempList.add(key.setScale(0, RoundingMode.HALF_UP));
- tempList.add(turbulence);
- list.add(tempList);
- });
- } catch (Exception e) {
- e.printStackTrace();
- }
- return list;
- }
- /**
- * 湍流日/年变化
- *
- * @return
- * @throws Exception
- */
- public Map<String, Object> getTurIntensity(List<WindTowerCalculationData> windTowerCalculationDataList, List<EquipmentAttribute> equipmentAttributeList, String height) {
- Map<String, Object> map = new HashMap<>();
- try {
- List<BigDecimal> dayResults = new ArrayList<>();//日变化
- List<BigDecimal> yearResults = new ArrayList<>();//年变化
- List<String> monthTimeList = new ArrayList<>();
- SimpleDateFormat sdf = new SimpleDateFormat("M");
- String wsFieldName = height + "turbulenceMonth";
- String turFieldName = height + "turDayForMonth";
- //height层高月平均湍流属性
- List<EquipmentAttribute> turbulenceMonth = equipmentAttributeList.stream().filter(e -> wsFieldName.equals(e.getFieldName())).collect(Collectors.toList());
- //height层高 月逐时湍流属性
- List<EquipmentAttribute> turbulenceHourForMonth = equipmentAttributeList.stream().filter(e -> turFieldName.equals(e.getFieldName())).collect(Collectors.toList());
- //height层高的月平均湍流集合
- List<WindTowerCalculationData> turbulenceList = windTowerCalculationDataList.stream().filter(w -> w.getEbId().equals(turbulenceMonth.get(0).getId())).sorted(Comparator.comparing(WindTowerCalculationData::getTime)).collect(Collectors.toList());
- //height层高的月逐时湍流集合
- List<WindTowerCalculationData> turbulenceHourForMonthList = windTowerCalculationDataList.stream().filter(w -> w.getEbId().equals(turbulenceHourForMonth.get(0).getId())).sorted(Comparator.comparing(WindTowerCalculationData::getTime)).collect(Collectors.toList());
- /*日变化*/
- if (!turbulenceHourForMonthList.isEmpty()) {
- dayResults = CalculationUtil.getData24(turbulenceHourForMonthList);
- }
- BigDecimal aveDayTurInsity = new BigDecimal(0);
- aveDayTurInsity = dayResults.stream().reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(24), 2, RoundingMode.HALF_UP);
- map.put("dayTurInsity", dayResults);
- map.put("aveDayTurInsity", aveDayTurInsity);
- /*年变化*/
- // for (WindTowerCalculationData w : turbulenceList) {
- // yearResults.add(w.getValue());
- // monthTimeList.add(sdf.format(w.getTime()));
- // }
- for (int i = 1; i <= 12; i++) {
- // Date monthStartTime = DateTimeUtil.getDayStartTime(DateTimeUtil.mouthOneDay(i).getTime());
- //过滤时间区间集合
- List<WindTowerCalculationData> filterList = new ArrayList<>();
- BigDecimal value = new BigDecimal(0);
- int finalI = i;
- filterList = turbulenceList.stream().filter(w -> sdf.format(w.getTime()).equals(String.valueOf(finalI))).collect(Collectors.toList());
- if (!filterList.isEmpty()) {
- value = filterList.get(0).getValue();
- }
- yearResults.add(value);
- monthTimeList.add(i + "月");
- }
- BigDecimal aveYearTurInsity = new BigDecimal(0);
- //过滤为0的数据
- List<BigDecimal> collect = yearResults.stream().filter(w -> w.compareTo(new BigDecimal(0)) != 0).collect(Collectors.toList());
- if (collect.size() > 0) {
- aveYearTurInsity = collect.stream().reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(collect.size()), 2, RoundingMode.HALF_UP);
- }
- map.put("yearTurInsity", yearResults);
- map.put("aveYearTurInsity", aveYearTurInsity);
- map.put("monthTime", monthTimeList);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return map;
- }
- /**
- * 获取湍流(风向玫瑰图)
- *
- * @param height
- */
- public Map<String, Object> getTurIntensityRose(List<WindDirectionStatisticsData> windDirectionStatisticsData, List<EquipmentAttribute> equipmentAttributeList, WindTowerInfo windTowerInfo, String height) {
- Map<String, Object> map = new HashMap<>();
- try {
- // 若层高包含A按照去掉A的层高计算
- if (height.contains("A")) {
- height = height.substring(0, height.length() - 1);
- }
- List<Map<String, Object>> list = new ArrayList<>();
- String turFieldName = height + "monthTurRose";
- // 过滤获取ebId
- List<EquipmentAttribute> turEquipmentAttribute = equipmentAttributeList.stream().filter(e -> turFieldName.equals(e.getFieldName())).collect(Collectors.toList());
- // 获取风向统计数据
- List<WindDirectionStatisticsData> turList = windDirectionStatisticsData.stream().filter(e -> e.getEbId().equals(turEquipmentAttribute.get(0).getId())).collect(Collectors.toList());
- for (WindDirectionEnum value : WindDirectionEnum.values()) {
- Map<String, Object> roseMap = new HashMap<>();
- // 根据风向过滤统计表
- List<WindDirectionStatisticsData> filterTurList = turList.stream().filter(e -> e.getDirection().equals(value.name())).collect(Collectors.toList());
- // 提取过滤的value值
- List<BigDecimal> filterTurValueList = filterTurList.stream().map(WindDirectionStatisticsData::getValue).filter(w -> w != null).collect(Collectors.toList());
- // 累加保留两位小数
- BigDecimal sumtur = null;
- if (!filterTurValueList.isEmpty()) {
- sumtur = filterTurValueList.stream().reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, RoundingMode.HALF_UP);
- }
- roseMap.put(value.name(), sumtur);
- list.add(roseMap);
- }
- List<Map<String, Object>> aveTurbulenceIntensity;
- aveTurbulenceIntensity = getAveTurbulenceIntensity(windDirectionStatisticsData, equipmentAttributeList, windTowerInfo);
- map.put("turIntensity", list);
- map.put("aveTurIntensity", aveTurbulenceIntensity);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return map;
- }
- /**
- * 获取所有层高的平均湍流(风向玫瑰图)
- */
- public List<Map<String, Object>> getAveTurbulenceIntensity(List<WindDirectionStatisticsData> windDirectionStatisticsData, List<EquipmentAttribute> equipmentAttributeList, WindTowerInfo windTowerInfo) {
- String heights;
- heights = windTowerInfo.getWdHeights();
- if (heights == null || heights.equals("")) {
- heights = "10,30,50,60,70,80,90,100,110,120,140,150";
- }
- String[] heightAll = heights.split(",");
- BigDecimal zero = new BigDecimal(0);
- List<Map<String, Object>> list = new ArrayList<>();
- for (WindDirectionEnum value : WindDirectionEnum.values()) {
- Map<String, Object> map = new HashMap<>();
- List<BigDecimal> dataList = new ArrayList<>();
- // 累加保留两位小数
- BigDecimal sumtur = zero;
- BigDecimal sumCount = zero;
- BigDecimal aveTur = zero;
- for (String height : heightAll) {
- String turFieldName = height + "monthTurRose";
- // 过滤获取ebId
- List<EquipmentAttribute> turEquipmentAttribute = equipmentAttributeList.stream().filter(e -> turFieldName.equals(e.getFieldName())).collect(Collectors.toList());
- // 获取风向统计数据
- List<WindDirectionStatisticsData> turList = windDirectionStatisticsData.stream().filter(e -> e.getEbId().equals(turEquipmentAttribute.get(0).getId()) && e.getDirection().equals(value.name())).collect(Collectors.toList());
- // 提取过滤的value值
- List<BigDecimal> filterTurValueList = turList.stream().map(WindDirectionStatisticsData::getValue).filter(w -> w != null).collect(Collectors.toList());
- if (!filterTurValueList.isEmpty()) {
- sumtur = sumtur.add(filterTurValueList.stream().reduce(BigDecimal.ZERO, BigDecimal::add));
- sumCount = sumCount.add(BigDecimal.valueOf(filterTurValueList.size()));
- }
- }
- if (sumCount.compareTo(zero) != 0 && sumtur.compareTo(zero) != 0) {
- aveTur = sumtur.divide(sumCount, 2, RoundingMode.HALF_UP);
- }
- map.put(value.name(), aveTur);
- list.add(map);
- }
- return list;
- }
- /**
- * 封装逐小时数据集合
- *
- * @param awsList 数据
- * @return
- */
- public List<BigDecimal> getData24(List<WindTowerCalculationData> awsList) {
- long hour = 3600000L;
- Date systemDate = new Date();
- List<BigDecimal> results = new ArrayList<>();
- SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH");
- //获取昨日开始和结束时间
- long startTime = DateMomentUtil.getDayStartTime(DateUtils.addDays(systemDate, -1).getTime());
- long endTime = startTime + 86399000;
- for (long time = startTime; time <= endTime; time += hour) {
- Long finalTime = time;
- String format = simpleDateFormat.format(finalTime);
- List<BigDecimal> collect = awsList.stream().filter(s -> simpleDateFormat.format(s.getTime())
- .equals(format) && s.getValue().compareTo(new BigDecimal(-99)) != 0)
- .map(WindTowerCalculationData::getValue).collect(Collectors.toList());
- BigDecimal avg = collect.stream().reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(collect.size()), 2, RoundingMode.HALF_UP);
- results.add(avg);
- }
- return results;
- }
- }
|