fix: 修复score有时计算不准确的问题
This commit is contained in:
@@ -859,7 +859,7 @@ export function computeScore (data) {
|
||||
const scoreArr = []
|
||||
let num = 0
|
||||
Object.keys(data).forEach(t => {
|
||||
if (!data[t]) {
|
||||
if (!data[t] && data[t] !== 0) {
|
||||
num += 1
|
||||
}
|
||||
if (t === 'establishLatencyMs' || t === 'tcpLostlenPercent' || t === 'pktRetransPercent') {
|
||||
|
||||
@@ -82,6 +82,7 @@ import { urlParamsHandler, overwriteUrl, getDnsMapData, computeScore } from '@/u
|
||||
import ChartList from '@/views/charts2/ChartList'
|
||||
import { useStore } from 'vuex'
|
||||
import axios from 'axios'
|
||||
import _ from 'lodash'
|
||||
|
||||
export default {
|
||||
name: 'Panel',
|
||||
@@ -449,11 +450,11 @@ export default {
|
||||
axios.get(url, { params }).then(res => {
|
||||
if (res.status === 200) {
|
||||
const data = {
|
||||
establishLatencyMs: res.data.data.result.establishLatencyMsAvg || null,
|
||||
httpResponseLatency: res.data.data.result.httpResponseLatencyAvg || null,
|
||||
sslConLatency: res.data.data.result.sslConLatencyAvg || null,
|
||||
tcpLostlenPercent: res.data.data.result.tcpLostlenPercentAvg || null,
|
||||
pktRetransPercent: res.data.data.result.pktRetransPercentAvg || null
|
||||
establishLatencyMs: _.get(res, 'data.data.result.establishLatencyMsAvg', null),
|
||||
httpResponseLatency: _.get(res, 'data.data.result.httpResponseLatencyAvg', null),
|
||||
sslConLatency: _.get(res, 'data.data.result.sslConLatencyAvg', null),
|
||||
tcpLostlenPercent: _.get(res, 'data.data.result.tcpLostlenPercentAvg', null),
|
||||
pktRetransPercent: _.get(res, 'data.data.result.pktRetransPercentAvg', null)
|
||||
}
|
||||
this.score = computeScore(data)
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ import { storageKey } from '@/utils/constants'
|
||||
import PopoverContent from './LinkDirectionGrid/PopoverContent'
|
||||
import { computeScore } from '@/utils/tools'
|
||||
import axios from 'axios'
|
||||
import _ from 'lodash'
|
||||
|
||||
export default {
|
||||
name: 'LinkDirectionGrid',
|
||||
@@ -257,11 +258,11 @@ export default {
|
||||
localComputeScore (data) {
|
||||
let score = 0
|
||||
const dataScore = {
|
||||
establishLatencyMs: data.establishLatencyMs || null,
|
||||
httpResponseLatency: data.httpResponseLatency || null,
|
||||
sslConLatency: data.sslConLatency || null,
|
||||
tcpLostlenPercent: data.tcpLostlenPercent || null,
|
||||
pktRetransPercent: data.pktRetransPercent || null
|
||||
establishLatencyMs: _.get(data, 'establishLatencyMs', null),
|
||||
httpResponseLatency: _.get(data, 'httpResponseLatency', null),
|
||||
sslConLatency: _.get(data, 'sslConLatency', null),
|
||||
tcpLostlenPercent: _.get(data, 'tcpLostlenPercent', null),
|
||||
pktRetransPercent: _.get(data, 'pktRetransPercent', null)
|
||||
}
|
||||
score = computeScore(dataScore)
|
||||
return score
|
||||
|
||||
@@ -59,6 +59,7 @@ import { computeScore } from '@/utils/tools'
|
||||
import Loading from '@/components/common/Loading'
|
||||
import ChartError from '@/components/common/Error'
|
||||
import axios from 'axios'
|
||||
import _ from 'lodash'
|
||||
export default {
|
||||
name: 'linkTrafficList',
|
||||
mixins: [chartMixin],
|
||||
@@ -148,11 +149,11 @@ export default {
|
||||
this.showError = false
|
||||
this.isNoData = res.data.result.length === 0
|
||||
const data = {
|
||||
establishLatencyMs: res.data.result[0].establishLatencyMs || null,
|
||||
httpResponseLatency: res.data.result[0].httpResponseLatency || null,
|
||||
sslConLatency: res.data.result[0].sslConLatency || null,
|
||||
tcpLostlenPercent: res.data.result[0].tcpLostlenPercent || null,
|
||||
pktRetransPercent: res.data.result[0].pktRetransPercent || null
|
||||
establishLatencyMs: _.get(res.data.result[0], 'establishLatencyMs', null),
|
||||
httpResponseLatency: _.get(res.data.result[0], 'httpResponseLatency', null),
|
||||
sslConLatency: _.get(res.data.result[0], 'sslConLatency', null),
|
||||
tcpLostlenPercent: _.get(res.data.result[0], 'tcpLostlenPercent', null),
|
||||
pktRetransPercent: _.get(res.data.result[0], 'pktRetransPercent', null)
|
||||
}
|
||||
this.linkTrafficListData = res.data.result[0]
|
||||
this.linkTrafficListData.npmScore = computeScore(data)
|
||||
|
||||
@@ -225,11 +225,11 @@ export default {
|
||||
axios.get(this.scoreUrl, { params: this.getQueryParams() }).then(response => {
|
||||
if (response.status === 200) {
|
||||
const data = {
|
||||
establishLatencyMs: response.data.data.result.establishLatencyMsAvg || null,
|
||||
httpResponseLatency: response.data.data.result.httpResponseLatencyAvg || null,
|
||||
sslConLatency: response.data.data.result.sslConLatencyAvg || null,
|
||||
tcpLostlenPercent: response.data.data.result.tcpLostlenPercentAvg || null,
|
||||
pktRetransPercent: response.data.data.result.pktRetransPercentAvg || null
|
||||
establishLatencyMs: _.get(response, 'data.data.result.establishLatencyMsAvg', null),
|
||||
httpResponseLatency: _.get(response, 'data.data.result.httpResponseLatencyAvg', null),
|
||||
sslConLatency: _.get(response, 'data.data.result.sslConLatencyAvg', null),
|
||||
tcpLostlenPercent: _.get(response, 'data.data.result.tcpLostlenPercentAvg', null),
|
||||
pktRetransPercent: _.get(response, 'data.data.result.pktRetransPercentAvg', null)
|
||||
}
|
||||
this.score = computeScore(data)
|
||||
}
|
||||
|
||||
15
test/utils/mockData/score.js
Normal file
15
test/utils/mockData/score.js
Normal file
@@ -0,0 +1,15 @@
|
||||
export const zeroData = {
|
||||
tcpLostlenPercent: 0,
|
||||
pktRetransPercent: 0,
|
||||
sslConLatency: null,
|
||||
httpResponseLatency: 0,
|
||||
establishLatencyMs: 0
|
||||
}
|
||||
|
||||
export const undefinedData = {
|
||||
tcpLostlenPercent: undefined,
|
||||
pktRetransPercent: undefined,
|
||||
sslConLatency: undefined,
|
||||
httpResponseLatency: undefined,
|
||||
establishLatencyMs: undefined
|
||||
}
|
||||
11
test/utils/tools.test.js
Normal file
11
test/utils/tools.test.js
Normal file
@@ -0,0 +1,11 @@
|
||||
import { computeScore } from '@/utils/tools'
|
||||
import { zeroData, undefinedData } from './mockData/score'
|
||||
|
||||
describe('computeScore测试', () => {
|
||||
test('含0', () => {
|
||||
expect(computeScore(zeroData)).toEqual(6)
|
||||
})
|
||||
test('含undefined', () => {
|
||||
expect(computeScore(undefinedData)).toEqual('-')
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user