style:大屏-今日开机率/稼动率-添加lineCode展示

main
黄伟杰 1 week ago
parent f4d3a4de82
commit 4de17526dc

@ -17,7 +17,6 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref, onMounted, onUnmounted } from 'vue' import { ref, onMounted, onUnmounted } from 'vue'
import dayjs from 'dayjs'
import { useChart, colors } from '../utils' import { useChart, colors } from '../utils'
import { DeviceOperationRecordApi, type DeviceOperationRecordVO } from '@/api/iot/deviceOperationRecord' import { DeviceOperationRecordApi, type DeviceOperationRecordVO } from '@/api/iot/deviceOperationRecord'
@ -46,23 +45,26 @@ const toRateNumber = (value: unknown) => {
} }
const buildLineMetrics = (rows: DeviceOperationRecordVO[]) => { const buildLineMetrics = (rows: DeviceOperationRecordVO[]) => {
const groupMap = new Map<string, { name: string; power: number[]; util: number[] }>() const groupMap = new Map<string, { name: string; code: string; power: number[]; util: number[] }>()
rows.forEach((row) => { rows.forEach((row) => {
const name = String((row as any)?.lineName ?? (row as any)?.lineCode ?? row.deviceName ?? row.deviceCode ?? '').trim() const code = String((row as any)?.lineCode ?? '').trim()
if (!name) return const name = String((row as any)?.lineName ?? row.deviceName ?? row.deviceCode ?? code ?? '').trim()
if (!name && !code) return
const power = toRateNumber((row as any)?.powerOnRate) const power = toRateNumber((row as any)?.powerOnRate)
const util = toRateNumber((row as any)?.utilizationRate) const util = toRateNumber((row as any)?.utilizationRate)
const key = name const key = code || name
if (!groupMap.has(key)) { if (!groupMap.has(key)) {
groupMap.set(key, { name, power: [], util: [] }) groupMap.set(key, { name, code, power: [], util: [] })
} }
const g = groupMap.get(key)! const g = groupMap.get(key)!
if (!g.name) g.name = name
if (!g.code) g.code = code
if (Number.isFinite(power)) g.power.push(power) if (Number.isFinite(power)) g.power.push(power)
if (Number.isFinite(util)) g.util.push(util) if (Number.isFinite(util)) g.util.push(util)
}) })
const avg = (arr: number[]) => (arr.length ? arr.reduce((s, v) => s + v, 0) / arr.length : 0) const avg = (arr: number[]) => (arr.length ? arr.reduce((s, v) => s + v, 0) / arr.length : 0)
const list = Array.from(groupMap.values()).map((g) => ({ const list = Array.from(groupMap.values()).map((g) => ({
name: g.name, name: g.code ? `${g.name} (${g.code})` : g.name,
run: Math.round(avg(g.power) * 100) / 100, run: Math.round(avg(g.power) * 100) / 100,
avail: Math.round(avg(g.util) * 100) / 100 avail: Math.round(avg(g.util) * 100) / 100
})) }))

Loading…
Cancel
Save