fix day 0 insight main dashboard page

This commit is contained in:
Alberto-Audrix committed 2026-10-01 15:55:09 +07:00
1 parent e1987d6999
commit bc2b260065
6 files changed
+165 -36

No files matched your search

+6 -4
View File
@@ -654,7 +654,7 @@ export function buildDashboardInsightMetrics(
>();
for (const row of args.weights) {
const hari = num(row.age);
if (hari === null || hari <= 0) continue;
if (hari === null || hari < 0) continue;
const actual = positiveNum(row.average_weight);
const doc = num(row.doc_weight) ?? 40;
const target = getTargetWeightForAge(hari, doc);
@@ -672,7 +672,7 @@ export function buildDashboardInsightMetrics(
const kpiByAge = new Map<number, DashboardInsightKpiPoint>();
for (const row of args.kpis) {
const hari = num(row.age);
if (hari === null || hari <= 0) continue;
if (hari === null || hari < 0) continue;
const iotWeight = positiveNum(row.iot_weight);
const weightFromSeries = weightByAge.get(hari)?.actual ?? null;
const bobot = iotWeight !== null ? iotWeight : weightFromSeries;
@@ -714,7 +714,9 @@ export function buildDashboardInsightMetrics(
const hari_ke =
latestKpi?.hari ??
latestWeight?.hari ??
(num(args.currentDay) != null && (args.currentDay as number) > 0 ? num(args.currentDay) : null);
(num(args.currentDay) != null && (args.currentDay as number) >= 0
? num(args.currentDay)
: null);
const docIn =
num(args.docInCount) != null && (args.docInCount as number) > 0 ? num(args.docInCount) : null;
@@ -958,7 +960,7 @@ export function scopeDashboardInsightMetrics(
metrics: DashboardInsightMetrics,
upToDay: number | null
): DashboardInsightMetrics {
if (upToDay === null || !Number.isFinite(upToDay) || upToDay <= 0) {
if (upToDay === null || !Number.isFinite(upToDay) || upToDay < 0) {
return metrics;
}
+1
View File
@@ -61,6 +61,7 @@ function pickStandardValues(docWeight: number): number[] {
/** Target body weight (grams) for a given age from the Ross 308 DOC-weight table. */
export function getTargetWeightForAge(age: number, docWeight: number): number | null {
if (age === 0) return docWeight > 0 ? docWeight : null;
const values = pickStandardValues(docWeight);
if (age < 1 || age > values.length) return null;
return values[age - 1] ?? null;