|
@@ -1,5 +1,6 @@
|
|
package com.jiayue.biz.service.impl;
|
|
package com.jiayue.biz.service.impl;
|
|
|
|
|
|
|
|
+import cn.hutool.db.Entity;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.jiayue.biz.domain.*;
|
|
import com.jiayue.biz.domain.*;
|
|
import com.jiayue.biz.eunms.WindDirectionEnum;
|
|
import com.jiayue.biz.eunms.WindDirectionEnum;
|
|
@@ -33,12 +34,8 @@ public class DataAnalysisServiceImpl extends ServiceImpl<WindTowerDataParentTabl
|
|
private final WindTowerCalculationDataServiceImpl windTowerCalculationDataService;
|
|
private final WindTowerCalculationDataServiceImpl windTowerCalculationDataService;
|
|
private final EquipmentAttributeService equipmentAttributeService;
|
|
private final EquipmentAttributeService equipmentAttributeService;
|
|
|
|
|
|
-
|
|
|
|
- private final RealTimeDisplayService realTimeDisplayService;
|
|
|
|
-
|
|
|
|
|
|
+ private final ProphaseWeatherDataService prophaseWeatherDataService;
|
|
private final WindDirectionStatisticsDataServiceImpl windDirectionStatisticsDataService;
|
|
private final WindDirectionStatisticsDataServiceImpl windDirectionStatisticsDataService;
|
|
- private final WindTowerDataParentTableService windTowerDataParentTableService;
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -48,13 +45,253 @@ public class DataAnalysisServiceImpl extends ServiceImpl<WindTowerDataParentTabl
|
|
//将结束时间设置为昨天结束时间
|
|
//将结束时间设置为昨天结束时间
|
|
endDay = DateUtil.endOfDay(DateUtil.yesterday());
|
|
endDay = DateUtil.endOfDay(DateUtil.yesterday());
|
|
}
|
|
}
|
|
- Map<String, Object> map = new HashMap<>();
|
|
|
|
- SimpleDateFormat sdfTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
- long realityCount = 0;//数据实际条数
|
|
|
|
// 一年的计算数据
|
|
// 一年的计算数据
|
|
startDay = DateUtil.beginOfMonth(startDay);
|
|
startDay = DateUtil.beginOfMonth(startDay);
|
|
endDay = DateUtil.endOfMonth(endDay);
|
|
endDay = DateUtil.endOfMonth(endDay);
|
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
|
+ long realityCount = 0;//数据实际条数
|
|
|
|
+
|
|
|
|
+ List<WindTowerCalculationData> windTowerCalculationDatas = windTowerCalculationDataService.getByBetweenTimeAndEquipmentId(startDay, endDay, equipmentId);
|
|
|
|
+ // 一年的风向统计数据
|
|
|
|
+ List<WindDirectionStatisticsData> windDirectionStatisticsDataList = windDirectionStatisticsDataService.getByBetweenTimeAndEquipmentId(startDay, endDay, equipmentId);
|
|
|
|
+ //所有类型数据
|
|
|
|
+ List<EquipmentAttribute> equipmentAttributeList = equipmentAttributeService.list();
|
|
|
|
+ //测风塔信息
|
|
|
|
+ List<WindTowerInfo> windTowerInfos = windTowerInfoService.lambdaQuery().eq(WindTowerInfo::getEquipmentNo, equipmentId).list();
|
|
|
|
+ //计算完整性
|
|
|
|
+ List<Entity> entities = prophaseWeatherDataService.selectCount(equipmentId);
|
|
|
|
+
|
|
|
|
+ for (Entity entity : entities) {
|
|
|
|
+ // td engine 取出的时间需要截取字段
|
|
|
|
+ realityCount += (long) entity.get("count(*)");
|
|
|
|
+ }
|
|
|
|
+ //测风塔基本信息
|
|
|
|
+ Map<String, Object> windTowerInfo = this.getWindTowerInfo(windTowerInfos.get(0), startDay, endDay);
|
|
|
|
+ map.put("windTowerInfo", windTowerInfo);
|
|
|
|
+ //数据完整性
|
|
|
|
+ Map<String, Object> statusData = this.getStatusData(windTowerInfos.get(0), startDay, endDay, realityCount);
|
|
|
|
+ map.put("dataIntegrity", statusData);
|
|
|
|
+ //风速和风速密度各月日变化表格
|
|
|
|
+ Map<String, Object> monthWpdTable = getMonthWpdTable(windTowerCalculationDatas, equipmentAttributeList, windTowerInfos, startDay, endDay);
|
|
|
|
+ map.put("monthWpdTable", monthWpdTable);
|
|
|
|
+ //pdf威布尔
|
|
|
|
+ Map<String, Object> weibull = pdfWeibull(equipmentAttributeList, equipmentId, windTowerCalculationDatas, height);
|
|
|
|
+ map.put("weibull", weibull);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ return map;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public Map<String, Object> getStatusData(WindTowerInfo windTowerInfo, Date startDay, Date endDay, long realityCount) {
|
|
|
|
+ HashMap<String, Object> dataIntegrity = new HashMap<>();
|
|
|
|
+ dataIntegrity.put("time", DateUtil.format(windTowerInfo.getInstallationTime(), "yyyy年MM月dd日"));
|
|
|
|
+ dataIntegrity.put("startTime", DateUtil.format(startDay, "yyyy-MM-dd"));
|
|
|
|
+ long count = (endDay.getTime() + 1000 - startDay.getTime()) / (86400000);
|
|
|
|
+ long totalCount = count * 144;//时间范围内的总条数
|
|
|
|
+ BigDecimal divide = BigDecimal.valueOf(realityCount).divide(BigDecimal.valueOf(totalCount), 2, RoundingMode.HALF_UP);
|
|
|
|
+
|
|
|
|
+ dataIntegrity.put("integrityRate", divide);
|
|
|
|
+ dataIntegrity.put("totalNum", realityCount);
|
|
|
|
+ return dataIntegrity;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @param windTowerInfo 测风塔数据
|
|
|
|
+ * @param startDay 开始时间
|
|
|
|
+ * @param endDay 结束时间
|
|
|
|
+ * @return 基本信息
|
|
|
|
+ */
|
|
|
|
+ public Map<String, Object> getWindTowerInfo(WindTowerInfo windTowerInfo, Date startDay, Date endDay) {
|
|
|
|
+
|
|
|
|
+ HashMap<String, Object> hashMap = new HashMap<>();
|
|
|
|
+ hashMap.put("name", windTowerInfo.getName());
|
|
|
|
+ hashMap.put("equipmentNo", windTowerInfo.getEquipmentNo());
|
|
|
|
+ hashMap.put("installationTime", windTowerInfo.getInstallationTime());
|
|
|
|
+ hashMap.put("startTime", DateUtil.format(startDay, "yyyy-MM-dd"));
|
|
|
|
+ hashMap.put("endTime", DateUtil.format(endDay, "yyyy-MM-dd"));
|
|
|
|
+ hashMap.put("longitude", windTowerInfo.getLongitude());
|
|
|
|
+ hashMap.put("latitude", windTowerInfo.getLatitude());
|
|
|
|
+ hashMap.put("wsHeight", windTowerInfo.getHeights());
|
|
|
|
+ hashMap.put("wdHeight", windTowerInfo.getWdHeights());
|
|
|
|
+
|
|
|
|
+ return hashMap;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 风速和风速密度各月日变化表格
|
|
|
|
+ *
|
|
|
|
+ * @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威布尔
|
|
|
|
+ *
|
|
|
|
+ * @param height 层高
|
|
|
|
+ * @return weibull
|
|
|
|
+ */
|
|
|
|
+ public Map<String, Object> pdfWeibull(List<EquipmentAttribute> equipmentAttributeList, String equipmentId, List<WindTowerCalculationData> windTowerCalculationDataList, String height) {
|
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
|
+ List<BigDecimal> wsList = new ArrayList<>();
|
|
|
|
+ try {
|
|
|
|
+ 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) -> {
|
|
|
|
+
|
|
|
|
+ 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);
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
return map;
|
|
return map;
|
|
}
|
|
}
|
|
|
|
|