NEZ-1768 fix:当数据返回nan的时候 取最大值 最小值 平均值不对的问题

This commit is contained in:
zhangyu
2022-04-01 17:44:02 +08:00
parent d3715114fb
commit cf98a31414

View File

@@ -866,15 +866,32 @@ export function getMetricTypeValue (queryItem, type) {
let copy = JSON.parse(JSON.stringify(queryItem))
switch (type) {
case 'min': {
const min = copy.sort((x, y) => { return parseFloat(x[1]) - parseFloat(y[1]) })[0][1]
let min = copy.sort((x, y) => {
const x1 = isNaN(x[1]) ? 0 : x[1]
const y1 = isNaN(x[1]) ? 0 : y[1]
return x1 - y1
})[0][1]
if (isNaN(min)) {
min = 0
}
return min
}
case 'max': {
const max = copy.sort((x, y) => { return parseFloat(y[1]) - parseFloat(x[1]) })[0][1]
let max = copy.sort((x, y) => {
const x1 = isNaN(x[1]) ? 0 : x[1]
const y1 = isNaN(x[1]) ? 0 : y[1]
return y1 - x1
})[0][1]
if (isNaN(max)) {
max = 0
}
return max
}
case 'avg': {
copy = copy.map(t => parseFloat(t[1]))
copy = copy.map(t => {
const t1 = isNaN(t[1]) ? 0 : t[1]
return parseFloat(t1)
})
const sum = eval(copy.join('+'))
const avg = sum / copy.length
return avg
@@ -888,13 +905,30 @@ export function getMetricTypeValue (queryItem, type) {
return first
}
case 'total': {
copy = copy.map(t => parseFloat(t[1]))
copy = copy.map(t => {
const t1 = isNaN(t[1]) ? 0 : t[1]
return parseFloat(t1)
})
const total = eval(copy.join('+'))
return total
}
case 'range': {
const min = copy.sort((x, y) => { return parseFloat(x[1]) - parseFloat(y[1]) })[0][1]
const max = copy.sort((x, y) => { return parseFloat(y[1]) - parseFloat(x[1]) })[0][1]
let min = copy.sort((x, y) => {
const x1 = isNaN(x[1]) ? 0 : x[1]
const y1 = isNaN(x[1]) ? 0 : y[1]
return x1 - y1
})[0][1]
if (isNaN(min)) {
min = 0
}
let max = copy.sort((x, y) => {
const x1 = isNaN(x[1]) ? 0 : x[1]
const y1 = isNaN(x[1]) ? 0 : y[1]
return y1 - x1
})[0][1]
if (isNaN(max)) {
max = 0
}
return max - min
}
case 'different': {