Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 仪表盘计算不准确 #3855

Merged
merged 1 commit into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"cron-parser": "^4.0.0",
"crypto-js": "^4.1.1",
"css-color-function": "^1.3.3",
"decimal.js": "^10.4.3",
"deepmerge": "^4.2.2",
"echarts": "4.7.0",
"element-ui": "2.13.2",
Expand Down
21 changes: 15 additions & 6 deletions src/views/dashboard/Audit/DataSummary.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

<script>
import DataCard from '../components/DataCard.vue'
import Decimal from 'decimal.js'
export default {
components: {
DataCard
Expand Down Expand Up @@ -76,22 +77,30 @@ export default {
&total_count_commands=1
&total_count_commands_danger=1
`)
const LoginSucceeded = data.total_count_user_login_success_logs === 0 ? 0 : ((data.total_count_user_login_success_logs / data.total_count_user_login_logs) * 100).toFixed(0)
const userLoginSuccessCountDecimal = data.total_count_user_login_success_logs ? new Decimal(data.total_count_user_login_success_logs) : new Decimal(0)
const userLoginCountDecimal = data.total_count_user_login_logs ? new Decimal(data.total_count_user_login_logs) : new Decimal(0)

let LoginSucceeded = userLoginSuccessCountDecimal.dividedBy(userLoginCountDecimal).times(100)
LoginSucceeded = isNaN(LoginSucceeded) ? 0 : LoginSucceeded
const LoginFailed = LoginSucceeded === 100 ? 0 : 100 - LoginSucceeded
const logs = [
{ name: this.$t('dashboard.LoginSucceeded'), value: LoginSucceeded },
{ name: this.$t('dashboard.LoginFailed'), value: LoginFailed }
{ name: this.$t('dashboard.LoginSucceeded'), value: LoginSucceeded.toString() },
{ name: this.$t('dashboard.LoginFailed'), value: LoginFailed.toString() }
]
this.$set(this.logConfig, 'data', logs)
this.$set(this.logConfig, 'total', data.total_count_user_login_logs)
this.$set(this.logConfig, 'active', data.total_count_user_login_success_logs)
this.$set(this.logConfig, 'weekAdd', data.total_count_user_login_success_logs)

const dangerCommand = data.total_count_commands_danger === 0 ? 0 : ((data.total_count_commands_danger / data.total_count_commands) * 100).toFixed(0)
const dangerCommandCountDecimal = data.total_count_commands_danger ? new Decimal(data.total_count_commands_danger) : new Decimal(0)
const commandCountDecimal = data.total_count_commands ? new Decimal(data.total_count_commands) : new Decimal(0)

let dangerCommand = dangerCommandCountDecimal.dividedBy(commandCountDecimal).times(100)
dangerCommand = isNaN(dangerCommand) ? 0 : dangerCommand
const SafeCommand = dangerCommand === 100 ? 0 : 100 - dangerCommand
const commandCounts = [
{ name: this.$t('dashboard.DangerCommand'), value: dangerCommand },
{ name: this.$t('dashboard.SafeCommand'), value: SafeCommand }
{ name: this.$t('dashboard.DangerCommand'), value: dangerCommand.toString() },
{ name: this.$t('dashboard.SafeCommand'), value: SafeCommand.toString() }
]
this.$set(this.assetConfig, 'data', commandCounts)
this.$set(this.assetConfig, 'total', data.total_count_commands)
Expand Down
22 changes: 16 additions & 6 deletions src/views/dashboard/Console/DataSummary.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

<script>
import DataCard from '../components/DataCard.vue'
import Decimal from 'decimal.js'
export default {
components: {
DataCard
Expand Down Expand Up @@ -56,22 +57,31 @@ export default {
&total_count_assets_this_week=1
&total_count_today_active_assets=1
`)
const userActive = data.total_count_login_users === 0 ? 0 : ((data.total_count_login_users / data.total_count_users) * 100).toFixed(0)

const loginUserCountDecimal = data.total_count_login_users ? new Decimal(data.total_count_login_users) : new Decimal(0)
const userCountDecimal = data.total_count_users ? new Decimal(data.total_count_users) : new Decimal(0)

let userActive = loginUserCountDecimal.dividedBy(userCountDecimal).times(100)
userActive = isNaN(userActive) ? 0 : userActive
const userTotal = userActive === 100 ? 0 : 100 - userActive
const users = [
{ name: this.$t('dashboard.ActiveUser'), value: userActive },
{ name: this.$t('dashboard.InActiveUser'), value: userTotal }
{ name: this.$t('dashboard.ActiveUser'), value: userActive.toString() },
{ name: this.$t('dashboard.InActiveUser'), value: userTotal.toString() }
]
this.$set(this.userConfig, 'data', users)
this.$set(this.userConfig, 'total', data.total_count_users)
this.$set(this.userConfig, 'active', data.total_count_login_users)
this.$set(this.userConfig, 'weekAdd', data.total_count_users_this_week)

const assetActive = data.total_count_today_active_assets === 0 ? 0 : ((data.total_count_today_active_assets / data.total_count_assets) * 100).toFixed(0)
const ActiveAssetCountDecimal = data.total_count_today_active_assets ? new Decimal(data.total_count_today_active_assets) : new Decimal(0)
const AssetCountDecimal = data.total_count_assets ? new Decimal(data.total_count_assets) : new Decimal(0)

let assetActive = ActiveAssetCountDecimal.dividedBy(AssetCountDecimal).times(100)
assetActive = isNaN(assetActive) ? 0 : assetActive
const assetTotal = assetActive === 100 ? 0 : 100 - assetActive
const assets = [
{ name: this.$t('dashboard.ActiveAsset'), value: assetActive },
{ name: this.$t('dashboard.InActiveAsset'), value: assetTotal }
{ name: this.$t('dashboard.ActiveAsset'), value: assetActive.toString() },
{ name: this.$t('dashboard.InActiveAsset'), value: assetTotal.toString() }
]
this.$set(this.assetConfig, 'data', assets)
this.$set(this.assetConfig, 'total', data.total_count_assets)
Expand Down
10 changes: 8 additions & 2 deletions src/views/dashboard/components/RingChart.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import 'echarts/lib/chart/line'
import 'echarts/lib/component/legend'

import Decimal from 'decimal.js'

export default {
components: {

Expand All @@ -28,8 +30,12 @@ export default {
},
computed: {
options() {
const { total, active = 0, title, color } = this.config
const percentage = active === 0 ? 0 : ((active / total) * 100).toFixed(0)
const { total = 0, active = 0, title, color } = this.config
const activeDecimal = new Decimal(active)
const totalDecimal = new Decimal(total)

let percentage = activeDecimal.dividedBy(totalDecimal).times(100)
percentage = isNaN(percentage) ? 0 : percentage
return {
title: [
{
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4153,6 +4153,11 @@ decamelize@^1.1.1, decamelize@^1.2.0:
resolved "https://registry.npmmirror.com/decamelize/-/decamelize-1.2.0.tgz#f6534d15148269b20352e7bee26f501f9a191290"
integrity sha512-z2S+W9X73hAUUki+N+9Za2lBlun89zigOyGrsax+KUQ6wKW4ZoWpEYBkGhQjwAjjDCkWxhY0VKEhk8wzY7F5cA==

decimal.js@^10.4.3:
version "10.4.3"
resolved "https://registry.yarnpkg.com/decimal.js/-/decimal.js-10.4.3.tgz#1044092884d245d1b7f65725fa4ad4c6f781cc23"
integrity sha512-VBBaLc1MgL5XpzgIP7ny5Z6Nx3UrRkIViUkPUdtl9aya5amy3De1gsUUSB1g3+3sExYNjCAsAznmukyxCb1GRA==

decode-uri-component@^0.2.0:
version "0.2.2"
resolved "https://registry.npmmirror.com/decode-uri-component/-/decode-uri-component-0.2.2.tgz#e69dbe25d37941171dd540e024c444cd5188e1e9"
Expand Down
Loading