Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
amos-boot-zx-biz
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Jobs
Commits
Open sidebar
项目统一框架
一体化_户用光伏项目代码
amos-boot-zx-biz
Commits
be974d51
Commit
be974d51
authored
Jul 25, 2024
by
yangyang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
智慧分析 - 健康等级 片区/全国计算调整
parent
65b8929a
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
135 additions
and
84 deletions
+135
-84
FanHealthIndexServiceImpl.java
...ule/jxiop/biz/service/impl/FanHealthIndexServiceImpl.java
+62
-44
PvHealthIndexServiceImpl.java
...dule/jxiop/biz/service/impl/PvHealthIndexServiceImpl.java
+69
-32
TdengineTimeServiceImpl.java
...odule/jxiop/biz/service/impl/TdengineTimeServiceImpl.java
+4
-8
No files found.
amos-boot-system-jxiop/amos-boot-module-jxiop-analyse-biz/src/main/java/com/yeejoin/amos/boot/module/jxiop/biz/service/impl/FanHealthIndexServiceImpl.java
View file @
be974d51
...
@@ -14,12 +14,15 @@ import com.yeejoin.amos.boot.module.jxiop.biz.tdengine.PvHealthIndex;
...
@@ -14,12 +14,15 @@ import com.yeejoin.amos.boot.module.jxiop.biz.tdengine.PvHealthIndex;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
java.math.BigDecimal
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.function.Function
;
import
java.util.function.Supplier
;
import
java.util.function.Supplier
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
...
@@ -49,6 +52,9 @@ public class FanHealthIndexServiceImpl implements IFanHealthIndexService {
...
@@ -49,6 +52,9 @@ public class FanHealthIndexServiceImpl implements IFanHealthIndexService {
@Autowired
@Autowired
private
IdxBizPvWeightMapper
idxBizPvWeightMapper
;
private
IdxBizPvWeightMapper
idxBizPvWeightMapper
;
@Value
(
"${analysis.weightRounding:false}"
)
private
Boolean
weightRounding
;
@Override
@Override
public
List
<
FanHealthIndex
>
getInfoListByGroupByCdFan
(
String
startTime
,
String
tableName
,
String
analysisObjectType
)
{
public
List
<
FanHealthIndex
>
getInfoListByGroupByCdFan
(
String
startTime
,
String
tableName
,
String
analysisObjectType
)
{
List
<
FanHealthIndex
>
fanHealthIndicesZxt
=
fanHealthIndexMapper
.
getInfoList
(
startTime
,
tableName
,
analysisObjectType
);
List
<
FanHealthIndex
>
fanHealthIndicesZxt
=
fanHealthIndexMapper
.
getInfoList
(
startTime
,
tableName
,
analysisObjectType
);
...
@@ -81,11 +87,8 @@ public class FanHealthIndexServiceImpl implements IFanHealthIndexService {
...
@@ -81,11 +87,8 @@ public class FanHealthIndexServiceImpl implements IFanHealthIndexService {
// 但如果没有配置子系统的权重,如何计算?
// 但如果没有配置子系统的权重,如何计算?
try
{
try
{
// 加权平均
// 加权平均
Double
totalHealthIndex
=
v
.
stream
().
mapToDouble
(
o
->
getWeight
(()
->
o
.
getArea
()
+
o
.
getStation
()
+
o
.
getEquipmentName
()
+
o
.
getSubSystem
()
+
o
.
getPointName
(),
weightMap
)
*
o
.
getHealthIndex
()).
sum
();
Function
<
FanHealthIndex
,
String
>
assembleKey
=
o
->
o
.
getArea
()
+
o
.
getStation
()
+
o
.
getEquipmentName
()
+
o
.
getSubSystem
()
+
o
.
getPointName
();
Double
totalAnomaly
=
v
.
stream
().
mapToDouble
(
o
->
getWeight
(()
->
o
.
getArea
()
+
o
.
getStation
()
+
o
.
getEquipmentName
()
+
o
.
getSubSystem
()
+
o
.
getPointName
(),
weightMap
)
*
o
.
getAnomaly
()).
sum
();
this
.
weightedMean
(
assembleKey
,
fanHealthIndex
,
v
,
weightMap
);
Double
totalWeight
=
v
.
stream
().
mapToDouble
(
o
->
getWeight
(()
->
o
.
getArea
()
+
o
.
getStation
()
+
o
.
getEquipmentName
()
+
o
.
getSubSystem
()
+
o
.
getPointName
(),
weightMap
)).
sum
();
fanHealthIndex
.
setAnomaly
(
totalAnomaly
/
totalWeight
);
fanHealthIndex
.
setHealthIndex
(
totalHealthIndex
/
totalWeight
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
// 普通平均
// 普通平均
this
.
calculateAvg
(
fanHealthIndex
,
v
);
this
.
calculateAvg
(
fanHealthIndex
,
v
);
...
@@ -137,11 +140,8 @@ public class FanHealthIndexServiceImpl implements IFanHealthIndexService {
...
@@ -137,11 +140,8 @@ public class FanHealthIndexServiceImpl implements IFanHealthIndexService {
// 但如果没有配置子系统的权重,如何计算?
// 但如果没有配置子系统的权重,如何计算?
try
{
try
{
// 加权平均
// 加权平均
Double
totalHealthIndex
=
v
.
stream
().
mapToDouble
(
o
->
getWeight
(()
->
o
.
getArea
()
+
o
.
getStation
()
+
o
.
getEquipmentName
()
+
o
.
getSubSystem
()
+
o
.
getPointName
(),
weightMap
)
*
o
.
getHealthIndex
()).
sum
();
Function
<
FanHealthIndex
,
String
>
assembleKey
=
o
->
o
.
getArea
()
+
o
.
getStation
()
+
o
.
getEquipmentName
()
+
o
.
getSubSystem
()
+
o
.
getPointName
();
Double
totalAnomaly
=
v
.
stream
().
mapToDouble
(
o
->
getWeight
(()
->
o
.
getArea
()
+
o
.
getStation
()
+
o
.
getEquipmentName
()
+
o
.
getSubSystem
()
+
o
.
getPointName
(),
weightMap
)
*
o
.
getAnomaly
()).
sum
();
this
.
weightedMean
(
assembleKey
,
fanHealthIndex
,
v
,
weightMap
);
Double
totalWeight
=
v
.
stream
().
mapToDouble
(
o
->
getWeight
(()
->
o
.
getArea
()
+
o
.
getStation
()
+
o
.
getEquipmentName
()
+
o
.
getSubSystem
()
+
o
.
getPointName
(),
weightMap
)).
sum
();
fanHealthIndex
.
setAnomaly
(
totalAnomaly
/
totalWeight
);
fanHealthIndex
.
setHealthIndex
(
totalHealthIndex
/
totalWeight
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
// 普通平均
// 普通平均
this
.
calculateAvg
(
fanHealthIndex
,
v
);
this
.
calculateAvg
(
fanHealthIndex
,
v
);
...
@@ -192,11 +192,8 @@ public class FanHealthIndexServiceImpl implements IFanHealthIndexService {
...
@@ -192,11 +192,8 @@ public class FanHealthIndexServiceImpl implements IFanHealthIndexService {
// 但如果没有配置子系统的权重,如何计算?
// 但如果没有配置子系统的权重,如何计算?
try
{
try
{
// 加权平均
// 加权平均
Double
totalHealthIndex
=
v
.
stream
().
mapToDouble
(
o
->
getWeight
(()
->
o
.
getArea
()
+
o
.
getStation
()
+
o
.
getEquipmentName
()
+
o
.
getSubSystem
(),
weightMap
)
*
o
.
getHealthIndex
()).
sum
();
Function
<
FanHealthIndex
,
String
>
assembleKey
=
o
->
o
.
getArea
()
+
o
.
getStation
()
+
o
.
getEquipmentName
()
+
o
.
getSubSystem
();
Double
totalAnomaly
=
v
.
stream
().
mapToDouble
(
o
->
getWeight
(()
->
o
.
getArea
()
+
o
.
getStation
()
+
o
.
getEquipmentName
()
+
o
.
getSubSystem
(),
weightMap
)
*
o
.
getAnomaly
()).
sum
();
this
.
weightedMean
(
assembleKey
,
fanHealthIndex
,
v
,
weightMap
);
Double
totalWeight
=
v
.
stream
().
mapToDouble
(
o
->
getWeight
(()
->
o
.
getArea
()
+
o
.
getStation
()
+
o
.
getEquipmentName
()
+
o
.
getSubSystem
(),
weightMap
)).
sum
();
fanHealthIndex
.
setAnomaly
(
totalAnomaly
/
totalWeight
);
fanHealthIndex
.
setHealthIndex
(
totalHealthIndex
/
totalWeight
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
// 普通平均
// 普通平均
this
.
calculateAvg
(
fanHealthIndex
,
v
);
this
.
calculateAvg
(
fanHealthIndex
,
v
);
...
@@ -245,11 +242,8 @@ public class FanHealthIndexServiceImpl implements IFanHealthIndexService {
...
@@ -245,11 +242,8 @@ public class FanHealthIndexServiceImpl implements IFanHealthIndexService {
// 但如果没有配置子系统的权重,如何计算?
// 但如果没有配置子系统的权重,如何计算?
try
{
try
{
// 加权平均
// 加权平均
Double
totalHealthIndex
=
v
.
stream
().
mapToDouble
(
o
->
getWeight
(()
->
o
.
getArea
()
+
o
.
getStation
()
+
o
.
getEquipmentName
(),
weightMap
)
*
o
.
getHealthIndex
()).
sum
();
Function
<
FanHealthIndex
,
String
>
assembleKey
=
o
->
o
.
getArea
()
+
o
.
getStation
()
+
o
.
getEquipmentName
();
Double
totalAnomaly
=
v
.
stream
().
mapToDouble
(
o
->
getWeight
(()
->
o
.
getArea
()
+
o
.
getStation
()
+
o
.
getEquipmentName
(),
weightMap
)
*
o
.
getAnomaly
()).
sum
();
this
.
weightedMean
(
assembleKey
,
fanHealthIndex
,
v
,
weightMap
);
Double
totalWeight
=
v
.
stream
().
mapToDouble
(
o
->
getWeight
(()
->
o
.
getArea
()
+
o
.
getStation
()
+
o
.
getEquipmentName
(),
weightMap
)).
sum
();
fanHealthIndex
.
setAnomaly
(
totalAnomaly
/
totalWeight
);
fanHealthIndex
.
setHealthIndex
(
totalHealthIndex
/
totalWeight
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
// 普通平均
// 普通平均
this
.
calculateAvg
(
fanHealthIndex
,
v
);
this
.
calculateAvg
(
fanHealthIndex
,
v
);
...
@@ -297,11 +291,8 @@ public class FanHealthIndexServiceImpl implements IFanHealthIndexService {
...
@@ -297,11 +291,8 @@ public class FanHealthIndexServiceImpl implements IFanHealthIndexService {
// 但如果没有配置子系统的权重,如何计算?
// 但如果没有配置子系统的权重,如何计算?
try
{
try
{
// 加权平均
// 加权平均
Double
totalHealthIndex
=
v
.
stream
().
mapToDouble
(
o
->
getWeight
(()
->
o
.
getArea
()
+
o
.
getStation
(),
weightMap
)
*
o
.
getHealthIndex
()).
sum
();
Function
<
FanHealthIndex
,
String
>
assembleKey
=
o
->
o
.
getArea
()
+
o
.
getStation
();
Double
totalAnomaly
=
v
.
stream
().
mapToDouble
(
o
->
getWeight
(()
->
o
.
getArea
()
+
o
.
getStation
(),
weightMap
)
*
o
.
getAnomaly
()).
sum
();
this
.
weightedMean
(
assembleKey
,
fanHealthIndex
,
v
,
weightMap
);
Double
totalWeight
=
v
.
stream
().
mapToDouble
(
o
->
getWeight
(()
->
o
.
getArea
()
+
o
.
getStation
(),
weightMap
)).
sum
();
fanHealthIndex
.
setAnomaly
(
totalAnomaly
/
totalWeight
);
fanHealthIndex
.
setHealthIndex
(
totalHealthIndex
/
totalWeight
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
// 普通平均
// 普通平均
this
.
calculateAvg
(
fanHealthIndex
,
v
);
this
.
calculateAvg
(
fanHealthIndex
,
v
);
...
@@ -348,11 +339,8 @@ public class FanHealthIndexServiceImpl implements IFanHealthIndexService {
...
@@ -348,11 +339,8 @@ public class FanHealthIndexServiceImpl implements IFanHealthIndexService {
// 但如果没有配置子系统的权重,如何计算?
// 但如果没有配置子系统的权重,如何计算?
try
{
try
{
// 加权平均
// 加权平均
Double
totalHealthIndex
=
v
.
stream
().
mapToDouble
(
o
->
getWeight
(()
->
o
.
getArea
(),
weightMap
)
*
o
.
getHealthIndex
()).
sum
();
Function
<
FanHealthIndex
,
String
>
assembleKey
=
o
->
o
.
getArea
();
Double
totalAnomaly
=
v
.
stream
().
mapToDouble
(
o
->
getWeight
(()
->
o
.
getArea
(),
weightMap
)
*
o
.
getAnomaly
()).
sum
();
this
.
weightedMean
(
assembleKey
,
fanHealthIndex
,
v
,
weightMap
);
Double
totalWeight
=
v
.
stream
().
mapToDouble
(
o
->
getWeight
(()
->
o
.
getArea
(),
weightMap
)).
sum
();
fanHealthIndex
.
setAnomaly
(
totalAnomaly
/
totalWeight
);
fanHealthIndex
.
setHealthIndex
(
totalHealthIndex
/
totalWeight
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
// 普通平均
// 普通平均
this
.
calculateAvg
(
fanHealthIndex
,
v
);
this
.
calculateAvg
(
fanHealthIndex
,
v
);
...
@@ -393,11 +381,8 @@ public class FanHealthIndexServiceImpl implements IFanHealthIndexService {
...
@@ -393,11 +381,8 @@ public class FanHealthIndexServiceImpl implements IFanHealthIndexService {
// 但如果没有配置子系统的权重,如何计算?
// 但如果没有配置子系统的权重,如何计算?
try
{
try
{
// 加权平均
// 加权平均
Double
totalHealthIndex
=
v
.
stream
().
mapToDouble
(
o
->
getWeight
(()
->
o
.
getType
()
+
o
.
getArea
()
+
o
.
getStation
(),
weightMap
)
*
o
.
getHealthIndex
()).
sum
();
Function
<
HealthIndexDTO
,
String
>
assembleKey
=
o
->
o
.
getType
()
+
o
.
getArea
()
+
o
.
getStation
();
Double
totalAnomaly
=
v
.
stream
().
mapToDouble
(
o
->
getWeight
(()
->
o
.
getType
()
+
o
.
getArea
()
+
o
.
getStation
(),
weightMap
)
*
o
.
getAnomaly
()).
sum
();
this
.
weightedMean
(
assembleKey
,
healthIndex
,
v
,
weightMap
);
Double
totalWeight
=
v
.
stream
().
mapToDouble
(
o
->
getWeight
(()
->
o
.
getType
()
+
o
.
getArea
()
+
o
.
getStation
(),
weightMap
)).
sum
();
healthIndex
.
setAnomaly
(
totalAnomaly
/
totalWeight
);
healthIndex
.
setHealthIndex
(
totalHealthIndex
/
totalWeight
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
// 普通平均
// 普通平均
this
.
calculateAvg
(
healthIndex
,
v
);
this
.
calculateAvg
(
healthIndex
,
v
);
...
@@ -438,11 +423,8 @@ public class FanHealthIndexServiceImpl implements IFanHealthIndexService {
...
@@ -438,11 +423,8 @@ public class FanHealthIndexServiceImpl implements IFanHealthIndexService {
// 但如果没有配置子系统的权重,如何计算?
// 但如果没有配置子系统的权重,如何计算?
try
{
try
{
// 加权平均
// 加权平均
Double
totalHealthIndex
=
v
.
stream
().
mapToDouble
(
o
->
getWeight
(()
->
o
.
getType
()
+
o
.
getArea
(),
weightMap
)
*
o
.
getHealthIndex
()).
sum
();
Function
<
HealthIndexDTO
,
String
>
assembleKey
=
o
->
o
.
getType
()
+
o
.
getArea
();
Double
totalAnomaly
=
v
.
stream
().
mapToDouble
(
o
->
getWeight
(()
->
o
.
getType
()
+
o
.
getArea
(),
weightMap
)
*
o
.
getAnomaly
()).
sum
();
this
.
weightedMean
(
assembleKey
,
healthIndex
,
v
,
weightMap
);
Double
totalWeight
=
v
.
stream
().
mapToDouble
(
o
->
getWeight
(()
->
o
.
getType
()
+
o
.
getArea
(),
weightMap
)).
sum
();
healthIndex
.
setAnomaly
(
totalAnomaly
/
totalWeight
);
healthIndex
.
setHealthIndex
(
totalHealthIndex
/
totalWeight
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
// 普通平均
// 普通平均
this
.
calculateAvg
(
healthIndex
,
v
);
this
.
calculateAvg
(
healthIndex
,
v
);
...
@@ -452,14 +434,30 @@ public class FanHealthIndexServiceImpl implements IFanHealthIndexService {
...
@@ -452,14 +434,30 @@ public class FanHealthIndexServiceImpl implements IFanHealthIndexService {
return
fanHealthIndicesZxtNews
;
return
fanHealthIndicesZxtNews
;
}
}
public
void
weightedMean
(
Function
<
HealthIndexDTO
,
String
>
assembleKey
,
HealthIndexDTO
healthIndex
,
List
<
HealthIndexDTO
>
v
,
Map
<
String
,
Float
>
weightMap
)
{
Double
totalHealthIndex
=
v
.
stream
().
mapToDouble
(
o
->
getWeight
(()
->
assembleKey
.
apply
(
o
),
weightMap
)
*
o
.
getHealthIndex
()).
sum
();
Double
totalAnomaly
=
v
.
stream
().
mapToDouble
(
o
->
getWeight
(()
->
assembleKey
.
apply
(
o
),
weightMap
)
*
o
.
getAnomaly
()).
sum
();
Double
totalWeight
=
v
.
stream
().
mapToDouble
(
o
->
getWeight
(()
->
assembleKey
.
apply
(
o
),
weightMap
)).
sum
();
healthIndex
.
setAnomaly
(
division
(
totalAnomaly
,
totalWeight
));
healthIndex
.
setHealthIndex
(
division
(
totalHealthIndex
,
totalWeight
));
}
public
void
weightedMean
(
Function
<
FanHealthIndex
,
String
>
assembleKey
,
FanHealthIndex
healthIndex
,
List
<
FanHealthIndex
>
v
,
Map
<
String
,
Float
>
weightMap
)
{
Double
totalHealthIndex
=
v
.
stream
().
mapToDouble
(
o
->
getWeight
(()
->
assembleKey
.
apply
(
o
),
weightMap
)
*
o
.
getHealthIndex
()).
sum
();
Double
totalAnomaly
=
v
.
stream
().
mapToDouble
(
o
->
getWeight
(()
->
assembleKey
.
apply
(
o
),
weightMap
)
*
o
.
getAnomaly
()).
sum
();
Double
totalWeight
=
v
.
stream
().
mapToDouble
(
o
->
getWeight
(()
->
assembleKey
.
apply
(
o
),
weightMap
)).
sum
();
healthIndex
.
setAnomaly
(
division
(
totalAnomaly
,
totalWeight
));
healthIndex
.
setHealthIndex
(
division
(
totalHealthIndex
,
totalWeight
));
}
public
void
calculateAvg
(
FanHealthIndex
healthIndex
,
List
<
FanHealthIndex
>
v
)
{
public
void
calculateAvg
(
FanHealthIndex
healthIndex
,
List
<
FanHealthIndex
>
v
)
{
// 普通平均
// 普通平均
Double
avgHealthIndex
=
v
.
stream
().
mapToDouble
(
o
->
o
.
getHealthIndex
()).
sum
();
Double
avgHealthIndex
=
v
.
stream
().
mapToDouble
(
o
->
o
.
getHealthIndex
()).
sum
();
Double
avgAnomaly
=
v
.
stream
().
mapToDouble
(
o
->
o
.
getAnomaly
()).
sum
();
Double
avgAnomaly
=
v
.
stream
().
mapToDouble
(
o
->
o
.
getAnomaly
()).
sum
();
Long
totalHealthIndex
=
v
.
stream
().
filter
(
o
->
o
.
getHealthIndex
()
!=
null
).
mapToDouble
(
o
->
o
.
getHealthIndex
()).
count
();
Long
totalHealthIndex
=
v
.
stream
().
filter
(
o
->
o
.
getHealthIndex
()
!=
null
).
mapToDouble
(
o
->
o
.
getHealthIndex
()).
count
();
Long
totalAnomaly
=
v
.
stream
().
filter
(
o
->
o
.
getAnomaly
()
!=
null
).
mapToDouble
(
o
->
o
.
getAnomaly
()).
count
();
Long
totalAnomaly
=
v
.
stream
().
filter
(
o
->
o
.
getAnomaly
()
!=
null
).
mapToDouble
(
o
->
o
.
getAnomaly
()).
count
();
healthIndex
.
setAnomaly
(
avgAnomaly
/
totalHealthIndex
);
healthIndex
.
setAnomaly
(
division
(
avgAnomaly
,
totalAnomaly
.
doubleValue
())
);
healthIndex
.
setHealthIndex
(
avgHealthIndex
/
totalAnomaly
);
healthIndex
.
setHealthIndex
(
division
(
avgHealthIndex
,
totalHealthIndex
.
doubleValue
())
);
}
}
public
void
calculateAvg
(
HealthIndexDTO
healthIndex
,
List
<
HealthIndexDTO
>
v
)
{
public
void
calculateAvg
(
HealthIndexDTO
healthIndex
,
List
<
HealthIndexDTO
>
v
)
{
...
@@ -468,8 +466,8 @@ public class FanHealthIndexServiceImpl implements IFanHealthIndexService {
...
@@ -468,8 +466,8 @@ public class FanHealthIndexServiceImpl implements IFanHealthIndexService {
Double
avgAnomaly
=
v
.
stream
().
mapToDouble
(
o
->
o
.
getAnomaly
()).
sum
();
Double
avgAnomaly
=
v
.
stream
().
mapToDouble
(
o
->
o
.
getAnomaly
()).
sum
();
Long
totalHealthIndex
=
v
.
stream
().
filter
(
o
->
o
.
getHealthIndex
()
!=
null
).
mapToDouble
(
o
->
o
.
getHealthIndex
()).
count
();
Long
totalHealthIndex
=
v
.
stream
().
filter
(
o
->
o
.
getHealthIndex
()
!=
null
).
mapToDouble
(
o
->
o
.
getHealthIndex
()).
count
();
Long
totalAnomaly
=
v
.
stream
().
filter
(
o
->
o
.
getAnomaly
()
!=
null
).
mapToDouble
(
o
->
o
.
getAnomaly
()).
count
();
Long
totalAnomaly
=
v
.
stream
().
filter
(
o
->
o
.
getAnomaly
()
!=
null
).
mapToDouble
(
o
->
o
.
getAnomaly
()).
count
();
healthIndex
.
setAnomaly
(
avgAnomaly
/
totalHealthIndex
);
healthIndex
.
setAnomaly
(
division
(
avgAnomaly
,
totalAnomaly
.
doubleValue
())
);
healthIndex
.
setHealthIndex
(
avgHealthIndex
/
totalAnomaly
);
healthIndex
.
setHealthIndex
(
division
(
avgHealthIndex
,
totalHealthIndex
.
doubleValue
())
);
}
}
public
Double
getWeight
(
Supplier
<
String
>
key
,
Map
<
String
,
Float
>
weightMap
)
{
public
Double
getWeight
(
Supplier
<
String
>
key
,
Map
<
String
,
Float
>
weightMap
)
{
...
@@ -513,4 +511,24 @@ public class FanHealthIndexServiceImpl implements IFanHealthIndexService {
...
@@ -513,4 +511,24 @@ public class FanHealthIndexServiceImpl implements IFanHealthIndexService {
return
pvHealthIndex
;
return
pvHealthIndex
;
}
}
/**
* 计算的时候,会使用原始数据计算,页面显示数据会四舍五入到1位小数
*
* 启用weightRounding 配置则会四舍五入到小数点后1位
*
* @param a a
* @param b b
* @return {@link Double}
* @throws
* @author yangyang
* @date 2024/7/25 17:28
*/
private
Double
division
(
Double
a
,
Double
b
)
{
if
(
weightRounding
)
{
BigDecimal
c
=
new
BigDecimal
(
a
).
divide
(
new
BigDecimal
(
b
),
1
,
BigDecimal
.
ROUND_HALF_UP
);
return
c
.
doubleValue
();
}
return
a
/
b
;
}
}
}
amos-boot-system-jxiop/amos-boot-module-jxiop-analyse-biz/src/main/java/com/yeejoin/amos/boot/module/jxiop/biz/service/impl/PvHealthIndexServiceImpl.java
View file @
be974d51
...
@@ -9,11 +9,14 @@ import com.yeejoin.amos.boot.module.jxiop.biz.tdengine.FanHealthIndex;
...
@@ -9,11 +9,14 @@ import com.yeejoin.amos.boot.module.jxiop.biz.tdengine.FanHealthIndex;
import
com.yeejoin.amos.boot.module.jxiop.biz.tdengine.PvHealthIndex
;
import
com.yeejoin.amos.boot.module.jxiop.biz.tdengine.PvHealthIndex
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
java.math.BigDecimal
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.function.Function
;
import
java.util.function.Supplier
;
import
java.util.function.Supplier
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
...
@@ -37,6 +40,9 @@ public class PvHealthIndexServiceImpl implements IPvHealthIndexService {
...
@@ -37,6 +40,9 @@ public class PvHealthIndexServiceImpl implements IPvHealthIndexService {
@Autowired
@Autowired
private
IdxBizPvWeightMapper
idxBizPvWeightMapper
;
private
IdxBizPvWeightMapper
idxBizPvWeightMapper
;
@Value
(
"${analysis.weightRounding:false}"
)
private
Boolean
weightRounding
;
@Override
@Override
public
List
<
PvHealthIndex
>
getInfoListByGroupByCdPv
(
String
startTime
,
String
tableName
,
String
analysisObjectType
)
{
public
List
<
PvHealthIndex
>
getInfoListByGroupByCdPv
(
String
startTime
,
String
tableName
,
String
analysisObjectType
)
{
List
<
PvHealthIndex
>
pvHealthIndices
=
pvHealthIndexMapper
.
getInfoList
(
startTime
,
tableName
,
analysisObjectType
);
List
<
PvHealthIndex
>
pvHealthIndices
=
pvHealthIndexMapper
.
getInfoList
(
startTime
,
tableName
,
analysisObjectType
);
...
@@ -70,11 +76,8 @@ public class PvHealthIndexServiceImpl implements IPvHealthIndexService {
...
@@ -70,11 +76,8 @@ public class PvHealthIndexServiceImpl implements IPvHealthIndexService {
// 但如果没有配置子系统的权重,如何计算?
// 但如果没有配置子系统的权重,如何计算?
try
{
try
{
// 加权平均
// 加权平均
Double
totalHealthIndex
=
v
.
stream
().
mapToDouble
(
o
->
getWeight
(()
->
o
.
getArea
()
+
o
.
getStation
()
+
o
.
getEquipmentName
()
+
o
.
getSubarray
()
+
o
.
getPointName
(),
weightMap
)
*
o
.
getHealthIndex
()).
sum
();
Function
<
PvHealthIndex
,
String
>
assembleKey
=
o
->
o
.
getArea
()
+
o
.
getStation
()
+
o
.
getEquipmentName
()
+
o
.
getSubarray
()
+
o
.
getPointName
();
Double
totalAnomaly
=
v
.
stream
().
mapToDouble
(
o
->
getWeight
(()
->
o
.
getArea
()
+
o
.
getStation
()
+
o
.
getEquipmentName
()
+
o
.
getSubarray
()
+
o
.
getPointName
(),
weightMap
)
*
o
.
getAnomaly
()).
sum
();
this
.
weightedMean
(
assembleKey
,
pvHealthIndex
,
v
,
weightMap
);
Double
totalWeight
=
v
.
stream
().
mapToDouble
(
o
->
getWeight
(()
->
o
.
getArea
()
+
o
.
getStation
()
+
o
.
getEquipmentName
()
+
o
.
getSubarray
()
+
o
.
getPointName
(),
weightMap
)).
sum
();
pvHealthIndex
.
setAnomaly
(
totalAnomaly
/
totalWeight
);
pvHealthIndex
.
setHealthIndex
(
totalHealthIndex
/
totalWeight
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
// 普通平均
// 普通平均
this
.
calculateAvg
(
pvHealthIndex
,
v
);
this
.
calculateAvg
(
pvHealthIndex
,
v
);
...
@@ -127,11 +130,8 @@ public class PvHealthIndexServiceImpl implements IPvHealthIndexService {
...
@@ -127,11 +130,8 @@ public class PvHealthIndexServiceImpl implements IPvHealthIndexService {
// 但如果没有配置子系统的权重,如何计算?
// 但如果没有配置子系统的权重,如何计算?
try
{
try
{
// 加权平均
// 加权平均
Double
totalHealthIndex
=
v
.
stream
().
mapToDouble
(
o
->
getWeight
(()
->
o
.
getArea
()
+
o
.
getStation
()
+
o
.
getEquipmentName
()
+
o
.
getSubarray
()
+
o
.
getPointName
(),
weightMap
)
*
o
.
getHealthIndex
()).
sum
();
Function
<
PvHealthIndex
,
String
>
assembleKey
=
o
->
o
.
getArea
()
+
o
.
getStation
()
+
o
.
getEquipmentName
()
+
o
.
getSubarray
()
+
o
.
getPointName
();
Double
totalAnomaly
=
v
.
stream
().
mapToDouble
(
o
->
getWeight
(()
->
o
.
getArea
()
+
o
.
getStation
()
+
o
.
getEquipmentName
()
+
o
.
getSubarray
()
+
o
.
getPointName
(),
weightMap
)
*
o
.
getAnomaly
()).
sum
();
this
.
weightedMean
(
assembleKey
,
pvHealthIndex
,
v
,
weightMap
);
Double
totalWeight
=
v
.
stream
().
mapToDouble
(
o
->
getWeight
(()
->
o
.
getArea
()
+
o
.
getStation
()
+
o
.
getEquipmentName
()
+
o
.
getSubarray
()
+
o
.
getPointName
(),
weightMap
)).
sum
();
pvHealthIndex
.
setAnomaly
(
totalAnomaly
/
totalWeight
);
pvHealthIndex
.
setHealthIndex
(
totalHealthIndex
/
totalWeight
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
// 普通平均
// 普通平均
this
.
calculateAvg
(
pvHealthIndex
,
v
);
this
.
calculateAvg
(
pvHealthIndex
,
v
);
...
@@ -183,11 +183,8 @@ public class PvHealthIndexServiceImpl implements IPvHealthIndexService {
...
@@ -183,11 +183,8 @@ public class PvHealthIndexServiceImpl implements IPvHealthIndexService {
// 但如果没有配置子系统的权重,如何计算?
// 但如果没有配置子系统的权重,如何计算?
try
{
try
{
// 加权平均
// 加权平均
Double
totalHealthIndex
=
v
.
stream
().
mapToDouble
(
o
->
getWeight
(()
->
o
.
getArea
()
+
o
.
getStation
()
+
o
.
getEquipmentName
()
+
o
.
getSubarray
(),
weightMap
)
*
o
.
getHealthIndex
()).
sum
();
Function
<
PvHealthIndex
,
String
>
assembleKey
=
o
->
o
.
getArea
()
+
o
.
getStation
()
+
o
.
getEquipmentName
()
+
o
.
getSubarray
();
Double
totalAnomaly
=
v
.
stream
().
mapToDouble
(
o
->
getWeight
(()
->
o
.
getArea
()
+
o
.
getStation
()
+
o
.
getEquipmentName
()
+
o
.
getSubarray
(),
weightMap
)
*
o
.
getAnomaly
()).
sum
();
this
.
weightedMean
(
assembleKey
,
pvHealthIndex
,
v
,
weightMap
);
Double
totalWeight
=
v
.
stream
().
mapToDouble
(
o
->
getWeight
(()
->
o
.
getArea
()
+
o
.
getStation
()
+
o
.
getEquipmentName
()
+
o
.
getSubarray
(),
weightMap
)).
sum
();
pvHealthIndex
.
setAnomaly
(
totalAnomaly
/
totalWeight
);
pvHealthIndex
.
setHealthIndex
(
totalHealthIndex
/
totalWeight
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
// 普通平均
// 普通平均
this
.
calculateAvg
(
pvHealthIndex
,
v
);
this
.
calculateAvg
(
pvHealthIndex
,
v
);
...
@@ -238,11 +235,8 @@ public class PvHealthIndexServiceImpl implements IPvHealthIndexService {
...
@@ -238,11 +235,8 @@ public class PvHealthIndexServiceImpl implements IPvHealthIndexService {
// 但如果没有配置子系统的权重,如何计算?
// 但如果没有配置子系统的权重,如何计算?
try
{
try
{
// 加权平均
// 加权平均
Double
totalHealthIndex
=
v
.
stream
().
mapToDouble
(
o
->
getWeight
(()
->
o
.
getArea
()
+
o
.
getStation
()
+
o
.
getEquipmentName
(),
weightMap
)
*
o
.
getHealthIndex
()).
sum
();
Function
<
PvHealthIndex
,
String
>
assembleKey
=
o
->
o
.
getArea
()
+
o
.
getStation
()
+
o
.
getEquipmentName
();
Double
totalAnomaly
=
v
.
stream
().
mapToDouble
(
o
->
getWeight
(()
->
o
.
getArea
()
+
o
.
getStation
()
+
o
.
getEquipmentName
(),
weightMap
)
*
o
.
getAnomaly
()).
sum
();
this
.
weightedMean
(
assembleKey
,
pvHealthIndex
,
v
,
weightMap
);
Double
totalWeight
=
v
.
stream
().
mapToDouble
(
o
->
getWeight
(()
->
o
.
getArea
()
+
o
.
getStation
()
+
o
.
getEquipmentName
(),
weightMap
)).
sum
();
pvHealthIndex
.
setAnomaly
(
totalAnomaly
/
totalWeight
);
pvHealthIndex
.
setHealthIndex
(
totalHealthIndex
/
totalWeight
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
// 普通平均
// 普通平均
this
.
calculateAvg
(
pvHealthIndex
,
v
);
this
.
calculateAvg
(
pvHealthIndex
,
v
);
...
@@ -291,11 +285,8 @@ public class PvHealthIndexServiceImpl implements IPvHealthIndexService {
...
@@ -291,11 +285,8 @@ public class PvHealthIndexServiceImpl implements IPvHealthIndexService {
// 但如果没有配置子系统的权重,如何计算?
// 但如果没有配置子系统的权重,如何计算?
try
{
try
{
// 加权平均
// 加权平均
Double
totalHealthIndex
=
v
.
stream
().
mapToDouble
(
o
->
getWeight
(()
->
o
.
getArea
()
+
o
.
getStation
(),
weightMap
)
*
o
.
getHealthIndex
()).
sum
();
Function
<
PvHealthIndex
,
String
>
assembleKey
=
o
->
o
.
getArea
()
+
o
.
getStation
();
Double
totalAnomaly
=
v
.
stream
().
mapToDouble
(
o
->
getWeight
(()
->
o
.
getArea
()
+
o
.
getStation
(),
weightMap
)
*
o
.
getAnomaly
()).
sum
();
this
.
weightedMean
(
assembleKey
,
pvHealthIndex
,
v
,
weightMap
);
Double
totalWeight
=
v
.
stream
().
mapToDouble
(
o
->
getWeight
(()
->
o
.
getArea
()
+
o
.
getStation
(),
weightMap
)).
sum
();
pvHealthIndex
.
setAnomaly
(
totalAnomaly
/
totalWeight
);
pvHealthIndex
.
setHealthIndex
(
totalHealthIndex
/
totalWeight
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
// 普通平均
// 普通平均
this
.
calculateAvg
(
pvHealthIndex
,
v
);
this
.
calculateAvg
(
pvHealthIndex
,
v
);
...
@@ -343,11 +334,8 @@ public class PvHealthIndexServiceImpl implements IPvHealthIndexService {
...
@@ -343,11 +334,8 @@ public class PvHealthIndexServiceImpl implements IPvHealthIndexService {
// 但如果没有配置子系统的权重,如何计算?
// 但如果没有配置子系统的权重,如何计算?
try
{
try
{
// 加权平均
// 加权平均
Double
totalHealthIndex
=
v
.
stream
().
mapToDouble
(
o
->
getWeight
(()
->
o
.
getArea
(),
weightMap
)
*
o
.
getHealthIndex
()).
sum
();
Function
<
PvHealthIndex
,
String
>
assembleKey
=
o
->
o
.
getArea
();
Double
totalAnomaly
=
v
.
stream
().
mapToDouble
(
o
->
getWeight
(()
->
o
.
getArea
(),
weightMap
)
*
o
.
getAnomaly
()).
sum
();
this
.
weightedMean
(
assembleKey
,
pvHealthIndex
,
v
,
weightMap
);
Double
totalWeight
=
v
.
stream
().
mapToDouble
(
o
->
getWeight
(()
->
o
.
getArea
(),
weightMap
)).
sum
();
pvHealthIndex
.
setAnomaly
(
totalAnomaly
/
totalWeight
);
pvHealthIndex
.
setHealthIndex
(
totalHealthIndex
/
totalWeight
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
// 普通平均
// 普通平均
this
.
calculateAvg
(
pvHealthIndex
,
v
);
this
.
calculateAvg
(
pvHealthIndex
,
v
);
...
@@ -357,15 +345,44 @@ public class PvHealthIndexServiceImpl implements IPvHealthIndexService {
...
@@ -357,15 +345,44 @@ public class PvHealthIndexServiceImpl implements IPvHealthIndexService {
return
pvHealthIndexList
;
return
pvHealthIndexList
;
}
}
/**
* 加权平均
*
* @param assembleKey assembleKey
* @param healthIndex healthIndex
* @param v v
* @param weightMap weightMap
* @return {@link }
* @throws
* @author yangyang
* @date 2024/7/25 17:36
*/
public
void
weightedMean
(
Function
<
PvHealthIndex
,
String
>
assembleKey
,
PvHealthIndex
healthIndex
,
List
<
PvHealthIndex
>
v
,
Map
<
String
,
Float
>
weightMap
)
{
Double
totalHealthIndex
=
v
.
stream
().
mapToDouble
(
o
->
getWeight
(()
->
assembleKey
.
apply
(
o
),
weightMap
)
*
o
.
getHealthIndex
()).
sum
();
Double
totalAnomaly
=
v
.
stream
().
mapToDouble
(
o
->
getWeight
(()
->
assembleKey
.
apply
(
o
),
weightMap
)
*
o
.
getAnomaly
()).
sum
();
Double
totalWeight
=
v
.
stream
().
mapToDouble
(
o
->
getWeight
(()
->
assembleKey
.
apply
(
o
),
weightMap
)).
sum
();
healthIndex
.
setAnomaly
(
division
(
totalAnomaly
,
totalWeight
));
healthIndex
.
setHealthIndex
(
division
(
totalHealthIndex
,
totalWeight
));
}
/**
* 普通平均
*
* @param healthIndex healthIndex
* @param v v
* @return {@link }
* @throws
* @author yangyang
* @date 2024/7/25 17:37
*/
public
void
calculateAvg
(
PvHealthIndex
healthIndex
,
List
<
PvHealthIndex
>
v
)
{
public
void
calculateAvg
(
PvHealthIndex
healthIndex
,
List
<
PvHealthIndex
>
v
)
{
// 普通平均
// 普通平均
Double
avgHealthIndex
=
v
.
stream
().
mapToDouble
(
o
->
o
.
getHealthIndex
()).
sum
();
Double
avgHealthIndex
=
v
.
stream
().
mapToDouble
(
o
->
o
.
getHealthIndex
()).
sum
();
Double
avgAnomaly
=
v
.
stream
().
mapToDouble
(
o
->
o
.
getAnomaly
()).
sum
();
Double
avgAnomaly
=
v
.
stream
().
mapToDouble
(
o
->
o
.
getAnomaly
()).
sum
();
Long
totalHealthIndex
=
v
.
stream
().
filter
(
o
->
o
.
getHealthIndex
()
!=
null
).
mapToDouble
(
o
->
o
.
getHealthIndex
()).
count
();
Long
totalHealthIndex
=
v
.
stream
().
filter
(
o
->
o
.
getHealthIndex
()
!=
null
).
mapToDouble
(
o
->
o
.
getHealthIndex
()).
count
();
Long
totalAnomaly
=
v
.
stream
().
filter
(
o
->
o
.
getAnomaly
()
!=
null
).
mapToDouble
(
o
->
o
.
getAnomaly
()).
count
();
Long
totalAnomaly
=
v
.
stream
().
filter
(
o
->
o
.
getAnomaly
()
!=
null
).
mapToDouble
(
o
->
o
.
getAnomaly
()).
count
();
healthIndex
.
setAnomaly
(
avgAnomaly
/
totalHealthIndex
);
healthIndex
.
setAnomaly
(
division
(
avgAnomaly
,
totalAnomaly
.
doubleValue
())
);
healthIndex
.
setHealthIndex
(
avgHealthIndex
/
totalAnomaly
);
healthIndex
.
setHealthIndex
(
division
(
avgHealthIndex
,
totalHealthIndex
.
doubleValue
())
);
}
}
public
Double
getWeight
(
Supplier
<
String
>
key
,
Map
<
String
,
Float
>
weightMap
)
{
public
Double
getWeight
(
Supplier
<
String
>
key
,
Map
<
String
,
Float
>
weightMap
)
{
...
@@ -377,4 +394,24 @@ public class PvHealthIndexServiceImpl implements IPvHealthIndexService {
...
@@ -377,4 +394,24 @@ public class PvHealthIndexServiceImpl implements IPvHealthIndexService {
return
weight
.
doubleValue
();
return
weight
.
doubleValue
();
}
}
/**
* 计算的时候,会使用原始数据计算,页面显示数据会四舍五入到1位小数
*
* 启用weightRounding 配置则会四舍五入到小数点后1位
*
* @param a a
* @param b b
* @return {@link Double}
* @throws
* @author yangyang
* @date 2024/7/25 17:28
*/
private
Double
division
(
Double
a
,
Double
b
)
{
if
(
weightRounding
)
{
BigDecimal
c
=
new
BigDecimal
(
a
).
divide
(
new
BigDecimal
(
b
),
1
,
BigDecimal
.
ROUND_HALF_UP
);
return
c
.
doubleValue
();
}
return
a
/
b
;
}
}
}
amos-boot-system-jxiop/amos-boot-module-jxiop-analyse-biz/src/main/java/com/yeejoin/amos/boot/module/jxiop/biz/service/impl/TdengineTimeServiceImpl.java
View file @
be974d51
...
@@ -474,14 +474,10 @@ public class TdengineTimeServiceImpl {
...
@@ -474,14 +474,10 @@ public class TdengineTimeServiceImpl {
}
}
public
void
printPv
(
String
desc
,
List
<
PvHealthIndex
>
olds
,
List
<
PvHealthIndex
>
news
)
{
public
void
printPv
(
String
desc
,
List
<
PvHealthIndex
>
olds
,
List
<
PvHealthIndex
>
news
)
{
try
{
olds
.
sort
(
Comparator
.
comparing
(
PvHealthIndex:
:
getArea
).
thenComparing
(
PvHealthIndex:
:
getStation
).
thenComparing
(
PvHealthIndex:
:
getSubarray
).
thenComparing
(
PvHealthIndex:
:
getEquipmentName
).
thenComparing
(
PvHealthIndex:
:
getPointName
));
olds
.
sort
(
Comparator
.
comparing
(
PvHealthIndex:
:
getArea
).
thenComparing
(
PvHealthIndex:
:
getStation
).
thenComparing
(
PvHealthIndex:
:
getEquipmentName
).
thenComparing
(
PvHealthIndex:
:
getSubarray
).
thenComparing
(
PvHealthIndex:
:
getPointName
));
news
.
sort
(
Comparator
.
comparing
(
PvHealthIndex:
:
getArea
).
thenComparing
(
PvHealthIndex:
:
getStation
).
thenComparing
(
PvHealthIndex:
:
getSubarray
).
thenComparing
(
PvHealthIndex:
:
getEquipmentName
).
thenComparing
(
PvHealthIndex:
:
getPointName
));
news
.
sort
(
Comparator
.
comparing
(
PvHealthIndex:
:
getArea
).
thenComparing
(
PvHealthIndex:
:
getStation
).
thenComparing
(
PvHealthIndex:
:
getEquipmentName
).
thenComparing
(
PvHealthIndex:
:
getSubarray
).
thenComparing
(
PvHealthIndex:
:
getPointName
));
log
.
info
(
"对比{} old => {}"
,
desc
,
olds
);
log
.
info
(
"对比{} old => {}"
,
desc
,
olds
);
log
.
info
(
"对比{} news => {}"
,
desc
,
news
);
log
.
info
(
"对比{} news => {}"
,
desc
,
news
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
}
public
void
insertMomentDataAll
(
String
recDate
)
throws
ParseException
{
public
void
insertMomentDataAll
(
String
recDate
)
throws
ParseException
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment