import { computeDateRange } from './dateRange.uts' import { rpcOrEmptyArray } from './rpc.uts' export type DeliveryAnalysisData = { trendList: Array topList: Array startIso: string endIso: string } export async function fetchDeliveryAnalysis(period: string): Promise { const { startIso, endIso } = computeDateRange(period) const trendList = await rpcOrEmptyArray('rpc_delivery_efficiency_daily', { p_start: startIso, p_end: endIso } as any) const topList = await rpcOrEmptyArray('rpc_delivery_efficiency_top_drivers', { p_start: startIso, p_end: endIso, p_limit: 10 } as any) return { trendList, topList, startIso, endIso } }