fix: 自定义KPI计算NaN导致序列化失败
This commit is contained in:
@@ -3,6 +3,7 @@ package service
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"be.ems/src/framework/utils/date"
|
"be.ems/src/framework/utils/date"
|
||||||
@@ -91,7 +92,10 @@ func (s *KPI) saveKPIData(k oam.KPI, index int64) error {
|
|||||||
KpiValues = append(KpiValues, item)
|
KpiValues = append(KpiValues, item)
|
||||||
}
|
}
|
||||||
|
|
||||||
KpiValuesByte, _ := json.Marshal(KpiValues)
|
KpiValuesByte, err := json.Marshal(KpiValues)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// KPI 信息
|
// KPI 信息
|
||||||
kpiData := neDataModel.KpiReport{
|
kpiData := neDataModel.KpiReport{
|
||||||
@@ -180,13 +184,13 @@ func (s *KPI) saveKPIDataC(k oam.KPI, index int64) error {
|
|||||||
} else {
|
} else {
|
||||||
if v.Unit == "%" {
|
if v.Unit == "%" {
|
||||||
resultV, ok := result.(float64)
|
resultV, ok := result.(float64)
|
||||||
if !ok {
|
if !ok || math.IsNaN(resultV) {
|
||||||
resultV = 0
|
resultV = 0
|
||||||
}
|
}
|
||||||
if resultV > 100 {
|
if resultV > 100 {
|
||||||
result = 100
|
result = 100
|
||||||
}
|
}
|
||||||
if resultV < 0 {
|
if resultV <= 0 {
|
||||||
result = 0
|
result = 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -195,7 +199,10 @@ func (s *KPI) saveKPIDataC(k oam.KPI, index int64) error {
|
|||||||
}
|
}
|
||||||
KpiValues = append(KpiValues, item)
|
KpiValues = append(KpiValues, item)
|
||||||
}
|
}
|
||||||
KpiValuesByte, _ := json.Marshal(KpiValues)
|
KpiValuesByte, err := json.Marshal(KpiValues)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// KPI 信息
|
// KPI 信息
|
||||||
kpiCData := neDataModel.KpiCReport{
|
kpiCData := neDataModel.KpiCReport{
|
||||||
|
|||||||
Reference in New Issue
Block a user