NEZ-1768 fix:当数据返回nan的时候 取最大值 最小值 平均值不对的问题
This commit is contained in:
@@ -866,15 +866,32 @@ export function getMetricTypeValue (queryItem, type) {
|
|||||||
let copy = JSON.parse(JSON.stringify(queryItem))
|
let copy = JSON.parse(JSON.stringify(queryItem))
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 'min': {
|
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
|
return min
|
||||||
}
|
}
|
||||||
case 'max': {
|
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
|
return max
|
||||||
}
|
}
|
||||||
case 'avg': {
|
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 sum = eval(copy.join('+'))
|
||||||
const avg = sum / copy.length
|
const avg = sum / copy.length
|
||||||
return avg
|
return avg
|
||||||
@@ -888,13 +905,30 @@ export function getMetricTypeValue (queryItem, type) {
|
|||||||
return first
|
return first
|
||||||
}
|
}
|
||||||
case 'total': {
|
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('+'))
|
const total = eval(copy.join('+'))
|
||||||
return total
|
return total
|
||||||
}
|
}
|
||||||
case 'range': {
|
case 'range': {
|
||||||
const min = copy.sort((x, y) => { return parseFloat(x[1]) - parseFloat(y[1]) })[0][1]
|
let min = copy.sort((x, y) => {
|
||||||
const max = copy.sort((x, y) => { return parseFloat(y[1]) - parseFloat(x[1]) })[0][1]
|
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
|
return max - min
|
||||||
}
|
}
|
||||||
case 'different': {
|
case 'different': {
|
||||||
|
|||||||
Reference in New Issue
Block a user