feat(dashboard): 接入预测结果聚合
This commit is contained in:
@@ -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}
|
||||
|
||||
Reference in New Issue
Block a user