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