|
|
|
|
@ -17,7 +17,6 @@
|
|
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
|
|
import { ref, onMounted, onUnmounted } from 'vue'
|
|
|
|
|
import dayjs from 'dayjs'
|
|
|
|
|
import { useChart, colors } from '../utils'
|
|
|
|
|
import { DeviceOperationRecordApi, type DeviceOperationRecordVO } from '@/api/iot/deviceOperationRecord'
|
|
|
|
|
|
|
|
|
|
@ -46,23 +45,26 @@ const toRateNumber = (value: unknown) => {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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) => {
|
|
|
|
|
const name = String((row as any)?.lineName ?? (row as any)?.lineCode ?? row.deviceName ?? row.deviceCode ?? '').trim()
|
|
|
|
|
if (!name) return
|
|
|
|
|
const code = String((row as any)?.lineCode ?? '').trim()
|
|
|
|
|
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 util = toRateNumber((row as any)?.utilizationRate)
|
|
|
|
|
const key = name
|
|
|
|
|
const key = code || name
|
|
|
|
|
if (!groupMap.has(key)) {
|
|
|
|
|
groupMap.set(key, { name, power: [], util: [] })
|
|
|
|
|
groupMap.set(key, { name, code, power: [], util: [] })
|
|
|
|
|
}
|
|
|
|
|
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(util)) g.util.push(util)
|
|
|
|
|
})
|
|
|
|
|
const avg = (arr: number[]) => (arr.length ? arr.reduce((s, v) => s + v, 0) / arr.length : 0)
|
|
|
|
|
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,
|
|
|
|
|
avail: Math.round(avg(g.util) * 100) / 100
|
|
|
|
|
}))
|
|
|
|
|
|