|
@@ -42,22 +42,28 @@ public class LocalBusDeviceHistoryService extends BaseService<BusDeviceHistoryMa
|
|
|
return this.baseMapper.pageQuery(query.getPage(),query);
|
|
return this.baseMapper.pageQuery(query.getPage(),query);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
- public BigDecimal computeLossRate(List<BusDeviceHistoryEntity> sources) {
|
|
|
|
|
- if(CollectionUtil.isEmpty(sources)){
|
|
|
|
|
|
|
+ public BigDecimal computeLossRate(long totalCount,List<BusDeviceHistoryEntity> sources) {
|
|
|
|
|
+ if(totalCount==0){
|
|
|
return BigDecimal.ZERO;
|
|
return BigDecimal.ZERO;
|
|
|
}
|
|
}
|
|
|
- long count = sources.stream().map(BusDeviceHistoryEntity::getDataNumber).distinct().count();
|
|
|
|
|
AtomicReference<BigDecimal> result = new AtomicReference<>(BigDecimal.ZERO);
|
|
AtomicReference<BigDecimal> result = new AtomicReference<>(BigDecimal.ZERO);
|
|
|
if (CollectionUtil.isNotEmpty(sources)) {
|
|
if (CollectionUtil.isNotEmpty(sources)) {
|
|
|
sources.stream().map(BusDeviceHistoryEntity::getDataNumber)
|
|
sources.stream().map(BusDeviceHistoryEntity::getDataNumber)
|
|
|
.max(Comparator.comparing(Integer::valueOf))
|
|
.max(Comparator.comparing(Integer::valueOf))
|
|
|
.map(max -> {
|
|
.map(max -> {
|
|
|
- BigDecimal proportionRate = BigDecimal.valueOf(count).divide(BigDecimal.valueOf(max), 2, BigDecimal.ROUND_HALF_UP);
|
|
|
|
|
|
|
+ BigDecimal proportionRate = BigDecimal.valueOf(totalCount).divide(BigDecimal.valueOf(max), 2, BigDecimal.ROUND_HALF_UP);
|
|
|
result.set(BigDecimal.ONE.subtract(proportionRate).multiply(BigDecimal.valueOf(100)));
|
|
result.set(BigDecimal.ONE.subtract(proportionRate).multiply(BigDecimal.valueOf(100)));
|
|
|
return max;
|
|
return max;
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
return result.get();
|
|
return result.get();
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ public BigDecimal computeLossRate(List<BusDeviceHistoryEntity> sources) {
|
|
|
|
|
+ if(CollectionUtil.isEmpty(sources)){
|
|
|
|
|
+ return BigDecimal.ZERO;
|
|
|
|
|
+ }
|
|
|
|
|
+ long count = sources.stream().map(BusDeviceHistoryEntity::getDataNumber).distinct().count();
|
|
|
|
|
+ return computeLossRate(count,sources);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|