// server/lib/metrics.ts // Pure KPI metric definitions. All return 0 when there is no data (no divide-by-zero). /** Cancellation rate: cancelled / total, rounded to 1 decimal (percent). */ export function cancelRate(cancelled: number, total: number): number { if (total <= 0) return 0; return Math.round((cancelled / total) * 1000) / 10; } /** No-show rate: noShow / total, rounded to 1 decimal (percent). */ export function noShowRate(noShow: number, total: number): number { if (total <= 0) return 0; return Math.round((noShow / total) * 1000) / 10; } /** Completion rate: completed / total, rounded to the nearest whole percent. */ export function completionRate(completed: number, total: number): number { if (total <= 0) return 0; return Math.round((completed / total) * 100); }