Skip to content

Commit

Permalink
fix(overview): filter out invalid data
Browse files Browse the repository at this point in the history
  • Loading branch information
Kinplemelon authored and ysfscream committed Oct 12, 2024
1 parent f7f4ea6 commit b37e75b
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/views/Dashboard/components/PolylineCards.vue
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ import { ChartType } from '@/types/enum'
import useI18nTl from '@/hooks/useI18nTl'
import useSyncPolling from '@/hooks/useSyncPolling'
import { FullScreen } from '@element-plus/icons-vue'
import { isNumber } from 'lodash'
import InfoTooltip from '@/components/InfoTooltip.vue'

const POLLING_INTERVAL = 60000
Expand Down Expand Up @@ -307,11 +308,15 @@ const openedFullScreen = async () => {
fullScreenChart.value?.chart?.resize()
}

const calculateStatistics = (data: number[]) => {
const max = Math.max(...data)
const min = Math.min(...data)
const sum = data.reduce((acc, val) => acc + val, 0)
const avg = Math.round(sum / data.length)
const calculateStatistics = (data: Array<number | null>) => {
const validData: Array<number> = data.filter(
(item) => isNumber(item) && item !== -1,
) as Array<number>
const validDataLength = validData.length
const max = Math.max(...validData)
const min = Math.min(...validData)
const sum = validData.reduce((acc, val) => acc + val, 0)
const avg = Math.round(sum / validDataLength)
const last = data[data.length - 1]
return { max, min, avg, last }
}
Expand Down

0 comments on commit b37e75b

Please sign in to comment.