🐛 平均值计算剔除0

This commit is contained in:
hi2hi 2024-12-12 17:42:06 +00:00
parent d580f5fc81
commit 5a771a4932

View File

@ -255,12 +255,16 @@ const monitorChartData = computed(() => {
if (!validate.hasOwn(showCates.value, id)) { if (!validate.hasOwn(showCates.value, id)) {
showCates.value[id] = true; showCates.value[id] = true;
} }
//
const validAvgs = avgs.filter((a) => a[1] !== 0);
const avg = validAvgs.reduce((a, b) => a + b[1], 0) / validAvgs.length;
const over = avgs.filter((a) => a[1] !== 0).length / avgs.length;
const cateItem = { const cateItem = {
id, id,
name: i, name: i,
color, color,
avg: (avgs.reduce((a, b) => a + b[1], 0) / avgs.length).toFixed(2) * 1, avg: avg.toFixed(2) * 1,
over: ((avgs.filter((o) => o[1] > 0).length / avgs.length) * 100).toFixed(2) * 1, over: (over * 100).toFixed(2) * 1,
}; };
if (Number.isNaN(cateItem.avg)) { if (Number.isNaN(cateItem.avg)) {
cateItem.avg = 0; cateItem.avg = 0;