feat(dashboard): 接入预测结果聚合

This commit is contained in:
2026-05-11 22:21:57 +08:00
parent b11d37e9d8
commit 1a2ff19cf4
4 changed files with 125 additions and 12 deletions
+16
View File
@@ -4,6 +4,7 @@ import { type BatteryInfo, type BatteryInfoSourceRow, toBatteryInfo } from '@/do
import { env } from '@/env'
const historyLimit = 500
const predictionHistoryLimit = 10
type BatteryInfoMysqlRow = RowDataPacket & BatteryInfoSourceRow
@@ -55,6 +56,21 @@ export async function getBatteryHistory(mac: string): Promise<BatteryInfo[]> {
return rows.map(toBatteryInfo)
}
export async function getBatteryPredictionHistory(mac: string): Promise<BatteryInfo[]> {
const [rows] = await getBatteryPool().query<BatteryInfoMysqlRow[]>(
`
SELECT ${sourceColumns}
FROM ls_battery_info
WHERE mac = :mac
ORDER BY create_time DESC, id DESC
LIMIT :limit
`,
{ mac, limit: predictionHistoryLimit },
)
return rows.map(toBatteryInfo).reverse()
}
export async function getLatestBatteryPerDevice(): Promise<BatteryInfo[]> {
const [rows] = await getBatteryPool().query<BatteryInfoMysqlRow[]>(`
SELECT ${sourceColumns}