50 lines
1.4 KiB
TypeScript
50 lines
1.4 KiB
TypeScript
import type { KpiStatus } from '../components/KpiCard.tsx';
|
|
|
|
/**
|
|
* Daily mortality % of DOC thresholds (manager operational rules):
|
|
* - <= 0.05%: Normal / OK (green)
|
|
* - > 0.05% and < 0.10%: Warning (yellow)
|
|
* - >= 0.10%: Critical (red)
|
|
*/
|
|
export const DAILY_MORTALITY_DOC_THRESHOLDS = {
|
|
warning_pct: 0.05,
|
|
critical_pct: 0.1,
|
|
} as const;
|
|
|
|
/**
|
|
* Calculates daily mortality percentage relative to initial DOC count.
|
|
*/
|
|
export function getDailyMortalityPct(
|
|
mortalityToday: number | null | undefined,
|
|
docInCount: number | null | undefined
|
|
): number | null {
|
|
if (mortalityToday == null || docInCount == null || docInCount <= 0) {
|
|
return null;
|
|
}
|
|
return (mortalityToday / docInCount) * 100;
|
|
}
|
|
|
|
/**
|
|
* Evaluates the KPI status for daily mortality based on DOC thresholds.
|
|
* - 'na' when data is unavailable
|
|
* - 'critical' when daily mortality >= 0.10%
|
|
* - 'warning' when daily mortality > 0.05%
|
|
* - 'ok' when daily mortality <= 0.05%
|
|
*/
|
|
export function getDailyMortalityStatus(
|
|
mortalityToday: number | null | undefined,
|
|
docInCount: number | null | undefined
|
|
): KpiStatus {
|
|
if (mortalityToday == null) return 'na';
|
|
if (docInCount == null || docInCount <= 0) return 'ok';
|
|
|
|
const dailyPct = (mortalityToday / docInCount) * 100;
|
|
if (dailyPct >= DAILY_MORTALITY_DOC_THRESHOLDS.critical_pct) {
|
|
return 'critical';
|
|
}
|
|
if (dailyPct > DAILY_MORTALITY_DOC_THRESHOLDS.warning_pct) {
|
|
return 'warning';
|
|
}
|
|
return 'ok';
|
|
}
|