diff --git a/src/utils/tools.js b/src/utils/tools.js index 4a504573..c8de0fef 100644 --- a/src/utils/tools.js +++ b/src/utils/tools.js @@ -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') { diff --git a/src/views/charts2/Panel.vue b/src/views/charts2/Panel.vue index 1cb1b2c4..17941650 100644 --- a/src/views/charts2/Panel.vue +++ b/src/views/charts2/Panel.vue @@ -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) } diff --git a/src/views/charts2/charts/linkMonitor/LinkDirectionGrid.vue b/src/views/charts2/charts/linkMonitor/LinkDirectionGrid.vue index 85d24b3d..5d87f8b0 100644 --- a/src/views/charts2/charts/linkMonitor/LinkDirectionGrid.vue +++ b/src/views/charts2/charts/linkMonitor/LinkDirectionGrid.vue @@ -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 diff --git a/src/views/charts2/charts/linkMonitor/localComponents/LinkTrafficDrillDownList.vue b/src/views/charts2/charts/linkMonitor/localComponents/LinkTrafficDrillDownList.vue index f08952a8..b66336ba 100644 --- a/src/views/charts2/charts/linkMonitor/localComponents/LinkTrafficDrillDownList.vue +++ b/src/views/charts2/charts/linkMonitor/localComponents/LinkTrafficDrillDownList.vue @@ -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) diff --git a/src/views/entityExplorer/entityList/entityListMixin.js b/src/views/entityExplorer/entityList/entityListMixin.js index 629c7d7e..29060f4b 100644 --- a/src/views/entityExplorer/entityList/entityListMixin.js +++ b/src/views/entityExplorer/entityList/entityListMixin.js @@ -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) } diff --git a/test/utils/mockData/score.js b/test/utils/mockData/score.js new file mode 100644 index 00000000..a1eff77c --- /dev/null +++ b/test/utils/mockData/score.js @@ -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 +} diff --git a/test/utils/tools.test.js b/test/utils/tools.test.js new file mode 100644 index 00000000..552bfe85 --- /dev/null +++ b/test/utils/tools.test.js @@ -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('-') + }) +})