Commit 77aea05f authored by yangyang's avatar yangyang

风机 & 光伏 - 按时刻生成设备、子阵、场站和片区数据

parent 857c2ad7
package com.yeejoin.amos.boot.module.jxiop.biz.service.impl;
import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yeejoin.amos.boot.module.jxiop.biz.entity.IdxBizFanWeight;
import com.yeejoin.amos.boot.module.jxiop.biz.mapper2.IdxBizFanHealthLevelMapper;
import com.yeejoin.amos.boot.module.jxiop.biz.mapper2.IdxBizFanWeightMapper;
import com.yeejoin.amos.boot.module.jxiop.biz.mapper2.IdxBizPvHealthIndexMapper;
import com.yeejoin.amos.boot.module.jxiop.biz.mapper2.IdxBizPvHealthLevelMapper;
import com.yeejoin.amos.boot.module.jxiop.biz.tdMapper2.FanHealthIndexMapper;
import com.yeejoin.amos.boot.module.jxiop.biz.tdMapper2.PvHealthIndexMapper;
import com.yeejoin.amos.boot.module.jxiop.biz.tdengine.FanHealthIndex;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.apache.logging.log4j.util.Strings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
* TODO(一句话描述该类的功能)
* <p>
* ProjectName: amos-boot-zx-biz
* PackageName: com.yeejoin.amos.boot.module.jxiop.biz.service.impl
*
* @author yangyang
* @version v1.0
* @date 2024/7/23 19:05
*/
@Component
@Slf4j
public class FanHealthIndexServiceImpl {
@Autowired
private FanHealthIndexMapper fanHealthIndexMapper;
@Autowired
private IdxBizPvHealthIndexMapper idxFanHealthIndexMapper;
@Autowired
private PvHealthIndexMapper pvHealthIndexMapper;
@Autowired
private IdxBizFanHealthLevelMapper idxBizFanHealthLevelMapper;
@Autowired
private IdxBizPvHealthLevelMapper idxBizPvHealthLevelMapper;
@Autowired
private IdxBizFanWeightMapper idxBizFanWeightMapper;
/**
* 子系统加权平均
* 加权平均数 = (w1 * x1 + w2 * x2 + … + wn * xn) / (w1 + w2 + … + wn)
* w1, w2, …, wn 是各个数据点的权重;
* x1, x2, …, xn 是各个数据点的数值;
* n 是数据点的总数。
*
* @param startTime startTime
* @param tableName tableName
* @param analysisObjectType analysisObjectType
* @return {@link List< FanHealthIndex>}
* @throws
* @author yangyang
* @date 2024/7/23 21:02
*/
public List<FanHealthIndex> getInfoListByGroupByZxtFan(String startTime, String tableName, String analysisObjectType) {
List<FanHealthIndex> fanHealthIndicesZxt = fanHealthIndexMapper.getInfoList(startTime, tableName, analysisObjectType);
QueryWrapper<IdxBizFanWeight> idxBizFanWeightQueryWrapper = new QueryWrapper<>();
idxBizFanWeightQueryWrapper.ne("type", "5");
List<IdxBizFanWeight> idxBizFanWeights = idxBizFanWeightMapper.selectList(idxBizFanWeightQueryWrapper);
Map<String, Float> weightMap = idxBizFanWeights.stream().collect(Collectors.toMap(o -> o.getArae() + o.getStation() + o.getEquipmentName() + o.getSubarray() + o.getOrgCode() + o.getPointName(), IdxBizFanWeight::getValue));
// 开始计算加权平均
Map<String, List<FanHealthIndex>> fanHealthIndicesZxtMap = fanHealthIndicesZxt.stream().collect(Collectors.groupingBy(o -> o.getArea() + o.getStation() + o.getEquipmentName() + o.getSubSystem() + o.getOrgCode() + o.getPointName()));
List<FanHealthIndex> fanHealthIndicesZxtNews = new ArrayList<>();
fanHealthIndicesZxtMap.forEach((k, v) -> {
FanHealthIndex fanHealthIndex = new FanHealthIndex();
fanHealthIndex.setGatewayId(v.get(0).getGatewayId());
fanHealthIndex.setStation(v.get(0).getStation());
fanHealthIndex.setAnalysisObjType("子系统");
fanHealthIndex.setArea(v.get(0).getArea());
fanHealthIndex.setSubSystem(v.get(0).getSubSystem());
fanHealthIndex.setEquipmentName(v.get(0).getEquipmentName());
fanHealthIndex.setNumber(v.get(0).getNumber());
fanHealthIndex.setOrgCode(v.get(0).getOrgCode());
// 例如 子系统 = (测点1 * 测点1权重 + 测点2 * 测点2权重 + .... 测点n权重) / (测点1权重 + 测点2权重 + .... 测点n权重)
// 但是测点是没有权重的,所以子系统无法计算加权平均
// 设备 = (子系统1 * 子系统1权重 + 子系统2 * 子系统2权重 + .... 子系统n权重) / (子系统1权重 + 子系统2权重 + .... 子系统n权重)
// 但如果没有配置子系统的权重,如何计算?
Double totalHealthIndex = v.stream().mapToDouble(o -> weightMap.get(o.getArea() + o.getStation() + o.getEquipmentName() + o.getSubSystem() + o.getPointName()).doubleValue() * o.getHealthIndex()).sum();
Double totalAnomaly = v.stream().mapToDouble(o -> weightMap.get(o.getArea() + o.getStation() + o.getEquipmentName() + o.getSubSystem() + o.getPointName()).doubleValue() * o.getAnomaly()).sum();
Double totalWeight = v.stream().mapToDouble(o -> weightMap.get(o.getArea() + o.getStation() + o.getEquipmentName() + o.getSubSystem() + o.getPointName()).doubleValue()).sum();
fanHealthIndex.setAnomaly(totalAnomaly / totalWeight);
fanHealthIndex.setHealthIndex(totalHealthIndex / totalWeight);
fanHealthIndicesZxtNews.add(fanHealthIndex);
});
return fanHealthIndicesZxtNews;
}
/**
* 设备加权平均
* 加权平均数 = (w1 * x1 + w2 * x2 + … + wn * xn) / (w1 + w2 + … + wn)
* w1, w2, …, wn 是各个数据点的权重;
* x1, x2, …, xn 是各个数据点的数值;
* n 是数据点的总数。
*
* @param startTime startTime
* @param tableName tableName
* @param analysisObjectType analysisObjectType
* @return {@link List< FanHealthIndex>}
* @throws
* @author yangyang
* @date 2024/7/23 21:02
*/
public List<FanHealthIndex> getInfoListByGroupBySbFan(String startTime, String tableName, String analysisObjectType) {
List<FanHealthIndex> fanHealthIndicesZxt = fanHealthIndexMapper.getInfoList(startTime, tableName, analysisObjectType);
QueryWrapper<IdxBizFanWeight> idxBizFanWeightQueryWrapper = new QueryWrapper<>();
idxBizFanWeightQueryWrapper.ne("type", "5");
List<IdxBizFanWeight> idxBizFanWeights = idxBizFanWeightMapper.selectList(idxBizFanWeightQueryWrapper);
Map<String, Float> weightMap = idxBizFanWeights.stream().collect(Collectors.toMap(o -> o.getArae() + o.getStation() + o.getEquipmentName() + o.getSubarray(), IdxBizFanWeight::getValue));
// 开始计算加权平均
Map<String, List<FanHealthIndex>> fanHealthIndicesZxtMap = fanHealthIndicesZxt.stream().collect(Collectors.groupingBy(o -> o.getGatewayId() + o.getStation() + o.getAnalysisObjType() + o.getArea() + o.getNumber() + o.getEquipmentName() + o.getOrgCode()));
List<FanHealthIndex> fanHealthIndicesZxtNews = new ArrayList<>();
fanHealthIndicesZxtMap.forEach((k, v) -> {
FanHealthIndex fanHealthIndex = new FanHealthIndex();
fanHealthIndex.setGatewayId(v.get(0).getGatewayId());
fanHealthIndex.setStation(v.get(0).getStation());
fanHealthIndex.setAnalysisObjType("设备");
fanHealthIndex.setArea(v.get(0).getArea());
fanHealthIndex.setNumber(v.get(0).getNumber());
fanHealthIndex.setEquipmentName(v.get(0).getEquipmentName());
fanHealthIndex.setOrgCode(v.get(0).getOrgCode());
// 例如 子系统 = (测点1 * 测点1权重 + 测点2 * 测点2权重 + .... 测点n权重) / (测点1权重 + 测点2权重 + .... 测点n权重)
// 但是测点是没有权重的,所以子系统无法计算加权平均
// 设备 = (子系统1 * 子系统1权重 + 子系统2 * 子系统2权重 + .... 子系统n权重) / (子系统1权重 + 子系统2权重 + .... 子系统n权重)
// 但如果没有配置子系统的权重,如何计算?
Double totalHealthIndex = v.stream().mapToDouble(o -> weightMap.get(o.getArea() + o.getStation() + o.getEquipmentName() + o.getSubSystem()).doubleValue() * o.getHealthIndex()).sum();
Double totalAnomaly = v.stream().mapToDouble(o -> weightMap.get(o.getArea() + o.getStation() + o.getEquipmentName() + o.getSubSystem()).doubleValue() * o.getAnomaly()).sum();
Double totalWeight = v.stream().mapToDouble(o -> weightMap.get(o.getArea() + o.getStation() + o.getEquipmentName() + o.getSubSystem()).doubleValue()).sum();
fanHealthIndex.setAnomaly(totalAnomaly / totalWeight);
fanHealthIndex.setHealthIndex(totalHealthIndex / totalWeight);
fanHealthIndicesZxtNews.add(fanHealthIndex);
});
return fanHealthIndicesZxtNews;
}
/**
* 场站加权平均
* 加权平均数 = (w1 * x1 + w2 * x2 + … + wn * xn) / (w1 + w2 + … + wn)
* w1, w2, …, wn 是各个数据点的权重;
* x1, x2, …, xn 是各个数据点的数值;
* n 是数据点的总数。
*
* @param startTime startTime
* @param tableName tableName
* @param analysisObjectType analysisObjectType
* @return {@link List< FanHealthIndex>}
* @throws
* @author yangyang
* @date 2024/7/23 21:02
*/
public List<FanHealthIndex> getInfoListByGroupByCzFan(String startTime, String tableName, String analysisObjectType) {
List<FanHealthIndex> fanHealthIndicesZxt = fanHealthIndexMapper.getInfoList(startTime, tableName, analysisObjectType);
QueryWrapper<IdxBizFanWeight> idxBizFanWeightQueryWrapper = new QueryWrapper<>();
idxBizFanWeightQueryWrapper.ne("type", "5");
List<IdxBizFanWeight> idxBizFanWeights = idxBizFanWeightMapper.selectList(idxBizFanWeightQueryWrapper);
Map<String, Float> weightMap = idxBizFanWeights.stream().collect(Collectors.toMap(o -> o.getArae() + o.getStation() + o.getEquipmentName(), IdxBizFanWeight::getValue));
// 开始计算加权平均
Map<String, List<FanHealthIndex>> fanHealthIndicesZxtMap = fanHealthIndicesZxt.stream().collect(Collectors.groupingBy(o -> o.getGatewayId() + o.getStation() + o.getAnalysisObjType() + o.getArea() + o.getOrgCode()));
List<FanHealthIndex> fanHealthIndicesZxtNews = new ArrayList<>();
fanHealthIndicesZxtMap.forEach((k, v) -> {
FanHealthIndex fanHealthIndex = new FanHealthIndex();
fanHealthIndex.setGatewayId(v.get(0).getGatewayId());
fanHealthIndex.setStation(v.get(0).getStation());
fanHealthIndex.setAnalysisObjType("场站");
fanHealthIndex.setArea(v.get(0).getArea());
fanHealthIndex.setOrgCode(v.get(0).getOrgCode());
// 例如 子系统 = (测点1 * 测点1权重 + 测点2 * 测点2权重 + .... 测点n权重) / (测点1权重 + 测点2权重 + .... 测点n权重)
// 但是测点是没有权重的,所以子系统无法计算加权平均
// 设备 = (子系统1 * 子系统1权重 + 子系统2 * 子系统2权重 + .... 子系统n权重) / (子系统1权重 + 子系统2权重 + .... 子系统n权重)
// 但如果没有配置子系统的权重,如何计算?
Double totalHealthIndex = v.stream().mapToDouble(o -> weightMap.get(o.getArea() + o.getStation() + o.getEquipmentName()).doubleValue() * o.getHealthIndex()).sum();
Double totalAnomaly = v.stream().mapToDouble(o -> weightMap.get(o.getArea() + o.getStation() + o.getEquipmentName()).doubleValue() * o.getAnomaly()).sum();
Double totalWeight = v.stream().mapToDouble(o -> weightMap.get(o.getArea() + o.getStation() + o.getEquipmentName()).doubleValue()).sum();
fanHealthIndex.setAnomaly(totalAnomaly / totalWeight);
fanHealthIndex.setHealthIndex(totalHealthIndex / totalWeight);
fanHealthIndicesZxtNews.add(fanHealthIndex);
});
return fanHealthIndicesZxtNews;
}
/**
* 区域加权平均
* 加权平均数 = (w1 * x1 + w2 * x2 + … + wn * xn) / (w1 + w2 + … + wn)
* w1, w2, …, wn 是各个数据点的权重;
* x1, x2, …, xn 是各个数据点的数值;
* n 是数据点的总数。
*
* @param startTime startTime
* @param tableName tableName
* @param analysisObjectType analysisObjectType
* @return {@link List< FanHealthIndex>}
* @throws
* @author yangyang
* @date 2024/7/23 21:02
*/
public List<FanHealthIndex> getInfoListByGroupByQyFan(String startTime, String tableName, String analysisObjectType) {
List<FanHealthIndex> fanHealthIndicesZxt = fanHealthIndexMapper.getInfoList(startTime, tableName, analysisObjectType);
QueryWrapper<IdxBizFanWeight> idxBizFanWeightQueryWrapper = new QueryWrapper<>();
idxBizFanWeightQueryWrapper.ne("type", "5");
List<IdxBizFanWeight> idxBizFanWeights = idxBizFanWeightMapper.selectList(idxBizFanWeightQueryWrapper);
Map<String, Float> weightMap = idxBizFanWeights.stream().collect(Collectors.toMap(o -> o.getArae() + o.getStation(), IdxBizFanWeight::getValue));
// 开始计算加权平均
Map<String, List<FanHealthIndex>> fanHealthIndicesZxtMap = fanHealthIndicesZxt.stream().collect(Collectors.groupingBy(o -> o.getAnalysisObjType() + o.getArea() + o.getOrgCode()));
List<FanHealthIndex> fanHealthIndicesZxtNews = new ArrayList<>();
fanHealthIndicesZxtMap.forEach((k, v) -> {
FanHealthIndex fanHealthIndex = new FanHealthIndex();
fanHealthIndex.setAnalysisObjType("片区");
fanHealthIndex.setArea(v.get(0).getArea());
fanHealthIndex.setOrgCode(v.get(0).getOrgCode());
// 例如 子系统 = (测点1 * 测点1权重 + 测点2 * 测点2权重 + .... 测点n权重) / (测点1权重 + 测点2权重 + .... 测点n权重)
// 但是测点是没有权重的,所以子系统无法计算加权平均
// 设备 = (子系统1 * 子系统1权重 + 子系统2 * 子系统2权重 + .... 子系统n权重) / (子系统1权重 + 子系统2权重 + .... 子系统n权重)
// 但如果没有配置子系统的权重,如何计算?
Double totalHealthIndex = v.stream().mapToDouble(o -> weightMap.get(o.getArea() + o.getStation()).doubleValue() * o.getHealthIndex()).sum();
Double totalAnomaly = v.stream().mapToDouble(o -> weightMap.get(o.getArea() + o.getStation()).doubleValue() * o.getAnomaly()).sum();
Double totalWeight = v.stream().mapToDouble(o -> weightMap.get(o.getArea() + o.getStation()).doubleValue()).sum();
fanHealthIndex.setAnomaly(totalAnomaly / totalWeight);
fanHealthIndex.setHealthIndex(totalHealthIndex / totalWeight);
fanHealthIndicesZxtNews.add(fanHealthIndex);
});
return fanHealthIndicesZxtNews;
}
/**
* 全域【所有 / 全国】加权平均
* 加权平均数 = (w1 * x1 + w2 * x2 + … + wn * xn) / (w1 + w2 + … + wn)
* w1, w2, …, wn 是各个数据点的权重;
* x1, x2, …, xn 是各个数据点的数值;
* n 是数据点的总数。
*
* @param startTime startTime
* @param tableName tableName
* @param analysisObjectType analysisObjectType
* @return {@link List< FanHealthIndex>}
* @throws
* @author yangyang
* @date 2024/7/23 21:02
*/
public List<FanHealthIndex> getInfoListByGroupByQgFan(String startTime, String tableName, String analysisObjectType) {
List<FanHealthIndex> fanHealthIndicesZxt = fanHealthIndexMapper.getInfoList(startTime, tableName, analysisObjectType);
QueryWrapper<IdxBizFanWeight> idxBizFanWeightQueryWrapper = new QueryWrapper<>();
idxBizFanWeightQueryWrapper.ne("type", "5");
List<IdxBizFanWeight> idxBizFanWeights = idxBizFanWeightMapper.selectList(idxBizFanWeightQueryWrapper);
Map<String, Float> weightMap = idxBizFanWeights.stream().collect(Collectors.toMap(o -> o.getArae(), IdxBizFanWeight::getValue));
// 开始计算加权平均
Map<String, List<FanHealthIndex>> fanHealthIndicesZxtMap = fanHealthIndicesZxt.stream().collect(Collectors.groupingBy(o -> o.getAnalysisObjType() + o.getOrgCode()));
List<FanHealthIndex> fanHealthIndicesZxtNews = new ArrayList<>();
fanHealthIndicesZxtMap.forEach((k, v) -> {
FanHealthIndex fanHealthIndex = new FanHealthIndex();
fanHealthIndex.setAnalysisObjType("全域");
fanHealthIndex.setOrgCode(v.get(0).getOrgCode());
// 例如 子系统 = (测点1 * 测点1权重 + 测点2 * 测点2权重 + .... 测点n权重) / (测点1权重 + 测点2权重 + .... 测点n权重)
// 但是测点是没有权重的,所以子系统无法计算加权平均
// 设备 = (子系统1 * 子系统1权重 + 子系统2 * 子系统2权重 + .... 子系统n权重) / (子系统1权重 + 子系统2权重 + .... 子系统n权重)
// 但如果没有配置子系统的权重,如何计算?
Double totalHealthIndex = v.stream().mapToDouble(o -> weightMap.get(o.getArea()).doubleValue() * o.getHealthIndex()).sum();
Double totalAnomaly = v.stream().mapToDouble(o -> weightMap.get(o.getArea()).doubleValue() * o.getAnomaly()).sum();
Double totalWeight = v.stream().mapToDouble(o -> weightMap.get(o.getArea()).doubleValue()).sum();
fanHealthIndex.setAnomaly(totalAnomaly / totalWeight);
fanHealthIndex.setHealthIndex(totalHealthIndex / totalWeight);
fanHealthIndicesZxtNews.add(fanHealthIndex);
});
return fanHealthIndicesZxtNews;
}
}
package com.yeejoin.amos.boot.module.jxiop.biz.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yeejoin.amos.boot.module.jxiop.biz.entity.IdxBizFanWeight;
import com.yeejoin.amos.boot.module.jxiop.biz.entity.IdxBizPvHealthIndex;
import com.yeejoin.amos.boot.module.jxiop.biz.entity.IdxBizPvWeight;
import com.yeejoin.amos.boot.module.jxiop.biz.mapper2.IdxBizFanHealthLevelMapper;
import com.yeejoin.amos.boot.module.jxiop.biz.mapper2.IdxBizFanWeightMapper;
import com.yeejoin.amos.boot.module.jxiop.biz.mapper2.IdxBizPvHealthIndexMapper;
import com.yeejoin.amos.boot.module.jxiop.biz.mapper2.IdxBizPvHealthLevelMapper;
import com.yeejoin.amos.boot.module.jxiop.biz.mapper2.IdxBizPvWeightMapper;
import com.yeejoin.amos.boot.module.jxiop.biz.tdMapper2.FanHealthIndexMapper;
import com.yeejoin.amos.boot.module.jxiop.biz.tdMapper2.PvHealthIndexMapper;
import com.yeejoin.amos.boot.module.jxiop.biz.tdengine.FanHealthIndex;
import com.yeejoin.amos.boot.module.jxiop.biz.tdengine.PvHealthIndex;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* 光伏 - 按时刻生成设备、子阵、场站和片区数据
* <p>
* ProjectName: amos-boot-zx-biz
* PackageName: com.yeejoin.amos.boot.module.jxiop.biz.service.impl
*
* @author yangyang
* @version v1.0
* @date 2024/7/23 21:08
*/
@Component
@Slf4j
public class PvHealthIndexServiceImpl {
@Autowired
private FanHealthIndexMapper fanHealthIndexMapper;
@Autowired
private IdxBizPvHealthIndexMapper idxFanHealthIndexMapper;
@Autowired
private PvHealthIndexMapper pvHealthIndexMapper;
@Autowired
private IdxBizFanHealthLevelMapper idxBizFanHealthLevelMapper;
@Autowired
private IdxBizPvHealthLevelMapper idxBizPvHealthLevelMapper;
@Autowired
private IdxBizPvWeightMapper idxBizPvWeightMapper;
/**
* 设备加权平均
* 加权平均数 = (w1 * x1 + w2 * x2 + … + wn * xn) / (w1 + w2 + … + wn)
* w1, w2, …, wn 是各个数据点的权重;
* x1, x2, …, xn 是各个数据点的数值;
* n 是数据点的总数。
*
* @param startTime startTime
* @param tableName tableName
* @param analysisObjectType analysisObjectType
* @return {@link List< FanHealthIndex>}
* @throws
* @author yangyang
* @date 2024/7/23 21:02
*/
public List<PvHealthIndex> getInfoListByGroupBySbPv(String startTime,
String tableName,
String analysisObjectType) {
List<PvHealthIndex> pvHealthIndices = pvHealthIndexMapper.getInfoList(startTime, tableName, analysisObjectType);
QueryWrapper<IdxBizPvWeight> queryWrapper = new QueryWrapper<>();
queryWrapper.ne("type", "5");
List<IdxBizPvWeight> idxBizFanWeights = idxBizPvWeightMapper.selectList(queryWrapper);
Map<String, Float> weightMap = idxBizFanWeights.stream().collect(Collectors.toMap(o -> o.getArae() + o.getStation() + o.getEquipmentName() + o.getSubarray() + o.getPointName(), IdxBizPvWeight::getValue));
// 开始计算加权平均
Map<String, List<PvHealthIndex>> healthIndicesMap = pvHealthIndices.stream().collect(Collectors.groupingBy(o -> o.getGatewayId() + o.getStation() + o.getAnalysisObjType() + o.getArea() + o.getSubarray() + o.getOrgCode() + o.getEquipmentName()));
List<PvHealthIndex> pvHealthIndexList = new ArrayList<>();
healthIndicesMap.forEach((k, v) -> {
PvHealthIndex pvHealthIndex = new PvHealthIndex();
pvHealthIndex.setGatewayId(v.get(0).getGatewayId());
pvHealthIndex.setStation(v.get(0).getStation());
pvHealthIndex.setAnalysisObjType("设备");
pvHealthIndex.setArea(v.get(0).getArea());
pvHealthIndex.setSubarray(v.get(0).getSubarray());
pvHealthIndex.setEquipmentName(v.get(0).getEquipmentName());
pvHealthIndex.setOrgCode(v.get(0).getOrgCode());
// 例如 子系统 = (测点1 * 测点1权重 + 测点2 * 测点2权重 + .... 测点n权重) / (测点1权重 + 测点2权重 + .... 测点n权重)
// 但是测点是没有权重的,所以子系统无法计算加权平均
// 设备 = (子系统1 * 子系统1权重 + 子系统2 * 子系统2权重 + .... 子系统n权重) / (子系统1权重 + 子系统2权重 + .... 子系统n权重)
// 但如果没有配置子系统的权重,如何计算?
Double totalHealthIndex = v.stream().mapToDouble(o -> weightMap.get(o.getArea() + o.getStation() + o.getEquipmentName() + o.getSubarray() + o.getPointName()).doubleValue() * o.getHealthIndex()).sum();
Double totalAnomaly = v.stream().mapToDouble(o -> weightMap.get(o.getArea() + o.getStation() + o.getEquipmentName() + o.getSubarray() + o.getPointName()).doubleValue() * o.getAnomaly()).sum();
Double totalWeight = v.stream().mapToDouble(o -> weightMap.get(o.getArea() + o.getStation() + o.getEquipmentName() + o.getSubarray() + o.getPointName()).doubleValue()).sum();
pvHealthIndex.setAnomaly(totalAnomaly / totalWeight);
pvHealthIndex.setHealthIndex(totalHealthIndex / totalWeight);
pvHealthIndexList.add(pvHealthIndex);
});
return pvHealthIndexList;
}
/**
* 子阵加权平均
* 加权平均数 = (w1 * x1 + w2 * x2 + … + wn * xn) / (w1 + w2 + … + wn)
* w1, w2, …, wn 是各个数据点的权重;
* x1, x2, …, xn 是各个数据点的数值;
* n 是数据点的总数。
*
* @param startTime startTime
* @param tableName tableName
* @param analysisObjectType analysisObjectType
* @return {@link List< FanHealthIndex>}
* @throws
* @author yangyang
* @date 2024/7/23 21:02
*/
public List<PvHealthIndex> getInfoListByGroupByZzPv(String startTime,
String tableName,
String analysisObjectType) {
List<PvHealthIndex> pvHealthIndices = pvHealthIndexMapper.getInfoList(startTime, tableName, analysisObjectType);
QueryWrapper<IdxBizPvWeight> queryWrapper = new QueryWrapper<>();
queryWrapper.ne("type", "5");
List<IdxBizPvWeight> idxBizFanWeights = idxBizPvWeightMapper.selectList(queryWrapper);
Map<String, Float> weightMap = idxBizFanWeights.stream().collect(Collectors.toMap(o -> o.getArae() + o.getStation() + o.getEquipmentName() + o.getSubarray(), IdxBizPvWeight::getValue));
// 开始计算加权平均
Map<String, List<PvHealthIndex>> healthIndicesMap = pvHealthIndices.stream().collect(Collectors.groupingBy(o -> o.getGatewayId() + o.getStation() + o.getAnalysisObjType() + o.getArea() + o.getSubarray() + o.getOrgCode()));
List<PvHealthIndex> pvHealthIndexList = new ArrayList<>();
healthIndicesMap.forEach((k, v) -> {
PvHealthIndex pvHealthIndex = new PvHealthIndex();
pvHealthIndex.setGatewayId(v.get(0).getGatewayId());
pvHealthIndex.setStation(v.get(0).getStation());
pvHealthIndex.setAnalysisObjType("子阵");
pvHealthIndex.setArea(v.get(0).getArea());
pvHealthIndex.setSubarray(v.get(0).getSubarray());
pvHealthIndex.setOrgCode(v.get(0).getOrgCode());
// 例如 子系统 = (测点1 * 测点1权重 + 测点2 * 测点2权重 + .... 测点n权重) / (测点1权重 + 测点2权重 + .... 测点n权重)
// 但是测点是没有权重的,所以子系统无法计算加权平均
// 设备 = (子系统1 * 子系统1权重 + 子系统2 * 子系统2权重 + .... 子系统n权重) / (子系统1权重 + 子系统2权重 + .... 子系统n权重)
// 但如果没有配置子系统的权重,如何计算?
Double totalHealthIndex = v.stream().mapToDouble(o -> weightMap.get(o.getArea() + o.getStation() + o.getEquipmentName() + o.getSubarray()).doubleValue() * o.getHealthIndex()).sum();
Double totalAnomaly = v.stream().mapToDouble(o -> weightMap.get(o.getArea() + o.getStation() + o.getEquipmentName() + o.getSubarray()).doubleValue() * o.getAnomaly()).sum();
Double totalWeight = v.stream().mapToDouble(o -> weightMap.get(o.getArea() + o.getStation() + o.getEquipmentName() + o.getSubarray()).doubleValue()).sum();
pvHealthIndex.setAnomaly(totalAnomaly / totalWeight);
pvHealthIndex.setHealthIndex(totalHealthIndex / totalWeight);
pvHealthIndexList.add(pvHealthIndex);
});
return pvHealthIndexList;
}
/**
* 场站加权平均
* 加权平均数 = (w1 * x1 + w2 * x2 + … + wn * xn) / (w1 + w2 + … + wn)
* w1, w2, …, wn 是各个数据点的权重;
* x1, x2, …, xn 是各个数据点的数值;
* n 是数据点的总数。
*
* @param startTime startTime
* @param tableName tableName
* @param analysisObjectType analysisObjectType
* @return {@link List< FanHealthIndex>}
* @throws
* @author yangyang
* @date 2024/7/23 21:02
*/
public List<PvHealthIndex> getInfoListByGroupByCzPv(String startTime,
String tableName,
String analysisObjectType) {
List<PvHealthIndex> pvHealthIndices = pvHealthIndexMapper.getInfoList(startTime, tableName, analysisObjectType);
QueryWrapper<IdxBizPvWeight> queryWrapper = new QueryWrapper<>();
queryWrapper.ne("type", "5");
List<IdxBizPvWeight> idxBizFanWeights = idxBizPvWeightMapper.selectList(queryWrapper);
Map<String, Float> weightMap = idxBizFanWeights.stream().collect(Collectors.toMap(o -> o.getArae() + o.getStation() + o.getEquipmentName(), IdxBizPvWeight::getValue));
// 开始计算加权平均
Map<String, List<PvHealthIndex>> healthIndicesMap = pvHealthIndices.stream().collect(Collectors.groupingBy(o -> o.getGatewayId() + o.getStation() + o.getAnalysisObjType() + o.getArea() + o.getOrgCode()));
List<PvHealthIndex> pvHealthIndexList = new ArrayList<>();
healthIndicesMap.forEach((k, v) -> {
PvHealthIndex pvHealthIndex = new PvHealthIndex();
pvHealthIndex.setGatewayId(v.get(0).getGatewayId());
pvHealthIndex.setStation(v.get(0).getStation());
pvHealthIndex.setAnalysisObjType("场站");
pvHealthIndex.setArea(v.get(0).getArea());
pvHealthIndex.setOrgCode(v.get(0).getOrgCode());
// 例如 子系统 = (测点1 * 测点1权重 + 测点2 * 测点2权重 + .... 测点n权重) / (测点1权重 + 测点2权重 + .... 测点n权重)
// 但是测点是没有权重的,所以子系统无法计算加权平均
// 设备 = (子系统1 * 子系统1权重 + 子系统2 * 子系统2权重 + .... 子系统n权重) / (子系统1权重 + 子系统2权重 + .... 子系统n权重)
// 但如果没有配置子系统的权重,如何计算?
Double totalHealthIndex = v.stream().mapToDouble(o -> weightMap.get(o.getArea() + o.getStation() + o.getEquipmentName()).doubleValue() * o.getHealthIndex()).sum();
Double totalAnomaly = v.stream().mapToDouble(o -> weightMap.get(o.getArea() + o.getStation() + o.getEquipmentName()).doubleValue() * o.getAnomaly()).sum();
Double totalWeight = v.stream().mapToDouble(o -> weightMap.get(o.getArea() + o.getStation() + o.getEquipmentName()).doubleValue()).sum();
pvHealthIndex.setAnomaly(totalAnomaly / totalWeight);
pvHealthIndex.setHealthIndex(totalHealthIndex / totalWeight);
pvHealthIndexList.add(pvHealthIndex);
});
return pvHealthIndexList;
}
/**
* 片区加权平均
* 加权平均数 = (w1 * x1 + w2 * x2 + … + wn * xn) / (w1 + w2 + … + wn)
* w1, w2, …, wn 是各个数据点的权重;
* x1, x2, …, xn 是各个数据点的数值;
* n 是数据点的总数。
*
* @param startTime startTime
* @param tableName tableName
* @param analysisObjectType analysisObjectType
* @return {@link List< FanHealthIndex>}
* @throws
* @author yangyang
* @date 2024/7/23 21:02
*/
public List<PvHealthIndex> getInfoListByGroupByQyPv(String startTime,
String tableName,
String analysisObjectType) {
List<PvHealthIndex> pvHealthIndices = pvHealthIndexMapper.getInfoList(startTime, tableName, analysisObjectType);
QueryWrapper<IdxBizPvWeight> queryWrapper = new QueryWrapper<>();
queryWrapper.ne("type", "5");
List<IdxBizPvWeight> idxBizFanWeights = idxBizPvWeightMapper.selectList(queryWrapper);
Map<String, Float> weightMap = idxBizFanWeights.stream().collect(Collectors.toMap(o -> o.getArae() + o.getStation(), IdxBizPvWeight::getValue));
// 开始计算加权平均
Map<String, List<PvHealthIndex>> healthIndicesMap = pvHealthIndices.stream().collect(Collectors.groupingBy(o -> o.getAnalysisObjType() + o.getArea() + o.getOrgCode()));
List<PvHealthIndex> pvHealthIndexList = new ArrayList<>();
healthIndicesMap.forEach((k, v) -> {
PvHealthIndex pvHealthIndex = new PvHealthIndex();
pvHealthIndex.setAnalysisObjType("片区");
pvHealthIndex.setArea(v.get(0).getArea());
pvHealthIndex.setOrgCode(v.get(0).getOrgCode());
// 例如 子系统 = (测点1 * 测点1权重 + 测点2 * 测点2权重 + .... 测点n权重) / (测点1权重 + 测点2权重 + .... 测点n权重)
// 但是测点是没有权重的,所以子系统无法计算加权平均
// 设备 = (子系统1 * 子系统1权重 + 子系统2 * 子系统2权重 + .... 子系统n权重) / (子系统1权重 + 子系统2权重 + .... 子系统n权重)
// 但如果没有配置子系统的权重,如何计算?
Double totalHealthIndex = v.stream().mapToDouble(o -> weightMap.get(o.getArea() + o.getStation()).doubleValue() * o.getHealthIndex()).sum();
Double totalAnomaly = v.stream().mapToDouble(o -> weightMap.get(o.getArea() + o.getStation()).doubleValue() * o.getAnomaly()).sum();
Double totalWeight = v.stream().mapToDouble(o -> weightMap.get(o.getArea() + o.getStation()).doubleValue()).sum();
pvHealthIndex.setAnomaly(totalAnomaly / totalWeight);
pvHealthIndex.setHealthIndex(totalHealthIndex / totalWeight);
pvHealthIndexList.add(pvHealthIndex);
});
return pvHealthIndexList;
}
/**
* 全域【所有 / 全国】加权平均
* 加权平均数 = (w1 * x1 + w2 * x2 + … + wn * xn) / (w1 + w2 + … + wn)
* w1, w2, …, wn 是各个数据点的权重;
* x1, x2, …, xn 是各个数据点的数值;
* n 是数据点的总数。
*
* @param startTime startTime
* @param tableName tableName
* @param analysisObjectType analysisObjectType
* @return {@link List< FanHealthIndex>}
* @throws
* @author yangyang
* @date 2024/7/23 21:02
*/
public List<PvHealthIndex> getInfoListByGroupByQgPv(String startTime,
String tableName,
String analysisObjectType) {
List<PvHealthIndex> pvHealthIndices = pvHealthIndexMapper.getInfoList(startTime, tableName, analysisObjectType);
QueryWrapper<IdxBizPvWeight> queryWrapper = new QueryWrapper<>();
queryWrapper.ne("type", "5");
List<IdxBizPvWeight> idxBizFanWeights = idxBizPvWeightMapper.selectList(queryWrapper);
Map<String, Float> weightMap = idxBizFanWeights.stream().collect(Collectors.toMap(o -> o.getArae(), IdxBizPvWeight::getValue));
// 开始计算加权平均
Map<String, List<PvHealthIndex>> healthIndicesMap = pvHealthIndices.stream().collect(Collectors.groupingBy(o -> o.getAnalysisObjType() + o.getOrgCode()));
List<PvHealthIndex> pvHealthIndexList = new ArrayList<>();
healthIndicesMap.forEach((k, v) -> {
PvHealthIndex pvHealthIndex = new PvHealthIndex();
pvHealthIndex.setAnalysisObjType("全域");
pvHealthIndex.setOrgCode(v.get(0).getOrgCode());
// 例如 子系统 = (测点1 * 测点1权重 + 测点2 * 测点2权重 + .... 测点n权重) / (测点1权重 + 测点2权重 + .... 测点n权重)
// 但是测点是没有权重的,所以子系统无法计算加权平均
// 设备 = (子系统1 * 子系统1权重 + 子系统2 * 子系统2权重 + .... 子系统n权重) / (子系统1权重 + 子系统2权重 + .... 子系统n权重)
// 但如果没有配置子系统的权重,如何计算?
Double totalHealthIndex = v.stream().mapToDouble(o -> weightMap.get(o.getArea()).doubleValue() * o.getHealthIndex()).sum();
Double totalAnomaly = v.stream().mapToDouble(o -> weightMap.get(o.getArea()).doubleValue() * o.getAnomaly()).sum();
Double totalWeight = v.stream().mapToDouble(o -> weightMap.get(o.getArea()).doubleValue()).sum();
pvHealthIndex.setAnomaly(totalAnomaly / totalWeight);
pvHealthIndex.setHealthIndex(totalHealthIndex / totalWeight);
pvHealthIndexList.add(pvHealthIndex);
});
return pvHealthIndexList;
}
}
......@@ -83,6 +83,41 @@ public class TdengineTimeServiceImpl {
}
@Autowired
private FanHealthIndexServiceImpl fanHealthIndexService;
public void insertMomentDataNew(String recDate) throws ParseException {
//s 489分钟 为 8小时 + 19分钟
String startTime = DateUtils.dateFormat(DateUtils.dateAddMinutes(new Date(), -489), DateUtils.DATE_TIME_PATTERN);
startTime = "2024-07-23 08:00:00";
// 子系统
List<IdxBizFanHealthLevel> levelListZxt = idxBizFanHealthLevelMapper.selectList(new LambdaQueryWrapper<IdxBizFanHealthLevel>().eq(IdxBizFanHealthLevel::getAnalysisObjType, "子系统").last("limit 4"));
List<FanHealthIndex> fanHealthIndices = fanHealthIndexService.getInfoListByGroupByZxtFan(startTime, "fan_health_index_moment", "测点");
List<FanHealthIndex> fanHealthIndicesZxt = fanHealthIndexMapper.getInfoListByGroupByZxtFan(startTime, "fan_health_index_moment", "测点");
//saveBatchFan(fanHealthIndicesZxt, "fan_health_index_moment", recDate, WarningPeriodEnum.MINUTES.getName(), levelListZxt);
// 设备
List<IdxBizFanHealthLevel> levelListSb = idxBizFanHealthLevelMapper.selectList(new LambdaQueryWrapper<IdxBizFanHealthLevel>().eq(IdxBizFanHealthLevel::getAnalysisObjType, "设备").last("limit 4"));
List<FanHealthIndex> fanHealthIndicesSb = fanHealthIndexMapper.getInfoListByGroupBySbFan(startTime, "fan_health_index_moment", "子系统");
//saveBatchFan(fanHealthIndicesSb, "fan_health_index_moment", recDate, WarningPeriodEnum.MINUTES.getName(), levelListSb);
// 场站
List<IdxBizFanHealthLevel> levelListCz = idxBizFanHealthLevelMapper.selectList(new LambdaQueryWrapper<IdxBizFanHealthLevel>().eq(IdxBizFanHealthLevel::getAnalysisObjType, "场站").last("limit 4"));
List<FanHealthIndex> fanHealthIndicesCz = fanHealthIndexMapper.getInfoListByGroupByCzFan(startTime, "fan_health_index_moment", "设备");
//saveBatchFan(fanHealthIndicesCz, "fan_health_index_moment", recDate, WarningPeriodEnum.MINUTES.getName(), levelListCz);
// 区域
List<IdxBizFanHealthLevel> levelListQy = idxBizFanHealthLevelMapper.selectList(new LambdaQueryWrapper<IdxBizFanHealthLevel>().eq(IdxBizFanHealthLevel::getAnalysisObjType, "片区").last("limit 4"));
List<FanHealthIndex> fanHealthIndicesQy = fanHealthIndexMapper.getInfoListByGroupByQyFan(startTime, "fan_health_index_moment", "场站");
//saveBatchFan(fanHealthIndicesQy, "fan_health_index_moment", recDate, WarningPeriodEnum.MINUTES.getName(), levelListQy);
// 全域【所有 / 全国】
List<IdxBizFanHealthLevel> levelListQg = idxBizFanHealthLevelMapper.selectList(new LambdaQueryWrapper<IdxBizFanHealthLevel>().eq(IdxBizFanHealthLevel::getAnalysisObjType, "全域").last("limit 4"));
List<FanHealthIndex> fanHealthIndicesQg = fanHealthIndexMapper.getInfoListByGroupByQgFan(startTime, "fan_health_index_moment", "片区");
// saveBatchFan(fanHealthIndicesQg, "fan_health_index_moment", recDate, WarningPeriodEnum.MINUTES.getName(), levelListQg);
}
/**
* 风电 - 按小时生成测点、子系统、设备、场站、区域 数据
......
......@@ -102,4 +102,9 @@ public interface FanHealthIndexMapper extends BaseMapper<FanHealthIndex> {
List<Map<String,Object>> getInfoByHour(@Param("areaCode") String areaCode, @Param("stationCode") String stationCode, @Param("list") List<String> list);
List<Map<String,Object>> getInfoByMoment(@Param("areaCode") String areaCode, @Param("stationCode") String stationCode, @Param("list") List<String> list);
List<FanHealthIndex> getInfoList(@Param("startTime") String startTime,
@Param("tableName") String tableName,
@Param("analysisObjectType") String analysisObjectType);
}
......@@ -62,4 +62,8 @@ public interface PvHealthIndexMapper extends BaseMapper<PvHealthIndex> {
List<PvHealthIndex> getInfoByPage(@Param("dto") PvHealthIndexDto dto);
Integer getInfoByPageTotal(@Param("dto") PvHealthIndexDto dto);
List<PvHealthIndex> getInfoList(@Param("startTime") String startTime,
@Param("tableName") String tableName,
@Param("analysisObjectType") String analysisObjectType);
}
......@@ -529,4 +529,24 @@
analysis_obj_type,
org_code
</select>
<select id="getInfoList" resultType="com.yeejoin.amos.boot.module.jxiop.biz.tdengine.FanHealthIndex">
select
gateway_id ,
station,
analysis_obj_type,
area,
sub_system,
equipment_name,
number,
anomaly,
org_code,
health_index
from
#{tableName}
where
analysis_obj_type = #{analysisObjectType}
and ts > #{startTime}
</select>
</mapper>
......@@ -293,4 +293,22 @@
analysis_obj_type,
org_code
</select>
<select id="getInfoList" resultType="com.yeejoin.amos.boot.module.jxiop.biz.tdengine.PvHealthIndex">
select
gateway_id ,
station,
analysis_obj_type,
area,
subarray,
equipment_name,
anomaly,
org_code,
health_index
from
#{tableName}
where
analysis_obj_type = #{analysisObjectType}
and ts > #{startTime}
</select>
</mapper>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment