81 lines
2.5 KiB
TypeScript
81 lines
2.5 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import { buildCountingInsightContext } from '../insightContextBuilders.ts';
|
|
import { scopeContextToTimeframe, scopeScalarsToTimeframe } from '../insightScope.ts';
|
|
|
|
const countingScalarScope = {
|
|
historyKey: 'tren_populasi_harian',
|
|
derive: {
|
|
populasiKini_ekor: {
|
|
field: 'populasi',
|
|
agg: 'lastValid' as const,
|
|
replaces: 'populasi_kini_ekor',
|
|
},
|
|
mortalitasKumulatif_ekor: {
|
|
field: 'mortalitas_kumulatif_ekor',
|
|
agg: 'last' as const,
|
|
replaces: 'mortalitas_kumulatif_ekor',
|
|
emptyAs: 0 as const,
|
|
},
|
|
panenKumulatif_ekor: {
|
|
field: 'panen_kumulatif_ekor',
|
|
agg: 'last' as const,
|
|
replaces: 'panen_kumulatif_ekor',
|
|
emptyAs: 0 as const,
|
|
},
|
|
beratPanenKumulatif_kg: {
|
|
field: 'berat_panen_kumulatif_kg',
|
|
agg: 'last' as const,
|
|
replaces: 'berat_panen_kumulatif_kg',
|
|
emptyAs: 0 as const,
|
|
},
|
|
mortalitasPersen: {
|
|
field: 'mortalitas_persen',
|
|
agg: 'last' as const,
|
|
replaces: 'mortalitas_persen',
|
|
},
|
|
},
|
|
drop: [
|
|
'populasi_kini_ekor',
|
|
'mortalitas_kumulatif_ekor',
|
|
'panen_kumulatif_ekor',
|
|
'berat_panen_kumulatif_kg',
|
|
'mortalitas_persen',
|
|
],
|
|
};
|
|
|
|
describe('hitung ayam insight day scope', () => {
|
|
it('does not keep full-cycle mortality/panen when day is capped', () => {
|
|
const ctx = buildCountingInsightContext({
|
|
kandangId: 1,
|
|
populasi_awal_ekor: 45_000,
|
|
// Stale full-cycle scalars — must be replaced by day-29 window.
|
|
populasi_kini_ekor: 100,
|
|
mortalitas_kumulatif_ekor: 4269,
|
|
mortalitas_persen: 9.49,
|
|
panen_kumulatif_ekor: 40_700,
|
|
berat_panen_kumulatif_kg: 57_469.4,
|
|
dailyRows: [
|
|
{ day: 0, stockAkhir: 44_800, mati: 200, panen: 0, beratPanen: 0 },
|
|
{ day: 29, stockAkhir: 42_000, mati: 100, panen: 500, beratPanen: 700 },
|
|
{ day: 48, stockAkhir: 100, mati: 3969, panen: 40_200, beratPanen: 56_769.4 },
|
|
],
|
|
});
|
|
|
|
const sliced = scopeContextToTimeframe(ctx, 'harian', 29);
|
|
const scoped = scopeScalarsToTimeframe(
|
|
sliced as Record<string, unknown>,
|
|
'harian',
|
|
countingScalarScope,
|
|
29
|
|
);
|
|
|
|
expect(scoped.populasiKini_ekor).toBe(42_000);
|
|
// Days 0+29 only: 200+100 mati, 0+500 panen, 0+700 kg
|
|
expect(scoped.mortalitasKumulatif_ekor).toBe(300);
|
|
expect(scoped.panenKumulatif_ekor).toBe(500);
|
|
expect(scoped.beratPanenKumulatif_kg).toBe(700);
|
|
expect(scoped.mortalitasPersen).toBe(0.67);
|
|
expect(scoped.periode).toBe('hari ke-0 s/d ke-29');
|
|
});
|
|
});
|