fix day 1 target weight bug and chicken counting row not showed before publish cutoff
This commit is contained in:
1 parent
05465b0382
commit
3fe6b05258
5 files changed
+28
-11
No files matched your search
@@ -6,7 +6,6 @@ import { Banner, EmptyFarm, PageHeader, Spinner } from '../ui/Feedback.tsx';
|
|||||||
import {
|
import {
|
||||||
addDaysIso,
|
addDaysIso,
|
||||||
cycleDayForDate,
|
cycleDayForDate,
|
||||||
cycleLastDayIndex,
|
|
||||||
formatDateId,
|
formatDateId,
|
||||||
formatDateRange,
|
formatDateRange,
|
||||||
formatNumber,
|
formatNumber,
|
||||||
@@ -116,8 +115,11 @@ const DataManagementPage: React.FC<{ onSettings: () => void }> = ({ onSettings }
|
|||||||
const kpiByDate = new Map(kpis.map((k) => [k.date, k]));
|
const kpiByDate = new Map(kpis.map((k) => [k.date, k]));
|
||||||
|
|
||||||
const lastCycleDay = Math.max(0, (selectedCycle.total_days || 1) - 1);
|
const lastCycleDay = Math.max(0, (selectedCycle.total_days || 1) - 1);
|
||||||
const endDay = cycleLastDayIndex(selectedCycle);
|
|
||||||
const calendarDay = cycleDayForDate(selectedCycle.start_date, todayIso());
|
const calendarDay = cycleDayForDate(selectedCycle.start_date, todayIso());
|
||||||
|
// Closed cycles stop at end_date; active / open cycles build daily rows through calendar today.
|
||||||
|
const endDay = selectedCycle.end_date
|
||||||
|
? cycleDayForDate(selectedCycle.start_date, selectedCycle.end_date)
|
||||||
|
: calendarDay;
|
||||||
const maxDay = Math.min(calendarDay, lastCycleDay, endDay);
|
const maxDay = Math.min(calendarDay, lastCycleDay, endDay);
|
||||||
const today = todayIso();
|
const today = todayIso();
|
||||||
|
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ vi.mock('../../../context/FarmContext.tsx', () => ({
|
|||||||
current_day: 1,
|
current_day: 1,
|
||||||
visible_through_date: '2026-08-10',
|
visible_through_date: '2026-08-10',
|
||||||
start_date: '2026-08-10',
|
start_date: '2026-08-10',
|
||||||
end_date: '2026-09-13',
|
end_date: null,
|
||||||
chick_in_weight: 45,
|
chick_in_weight: 45,
|
||||||
doc_in_count: 20000,
|
doc_in_count: 20000,
|
||||||
doc_in_weight: 45,
|
doc_in_weight: 45,
|
||||||
|
|||||||
@@ -25,8 +25,9 @@ describe('getTargetWeightForAge', () => {
|
|||||||
expect(getTargetWeightForAge(7, 60)).toBe(row.values[6]);
|
expect(getTargetWeightForAge(7, 60)).toBe(row.values[6]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns null for ages outside 1..35', () => {
|
it('returns docWeight for age 0 and null for ages outside 0..35', () => {
|
||||||
expect(getTargetWeightForAge(0, 42)).toBeNull();
|
expect(getTargetWeightForAge(0, 42)).toBe(42);
|
||||||
|
expect(getTargetWeightForAge(-1, 42)).toBeNull();
|
||||||
expect(getTargetWeightForAge(36, 42)).toBeNull();
|
expect(getTargetWeightForAge(36, 42)).toBeNull();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -37,7 +38,15 @@ describe('getTargetGainForAge', () => {
|
|||||||
expect(getTargetGainForAge(2, 40)).toBe(row.values[1]! - row.values[0]!);
|
expect(getTargetGainForAge(2, 40)).toBe(row.values[1]! - row.values[0]!);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns null for age 1', () => {
|
it('calculates target gain for age 1 relative to docWeight', () => {
|
||||||
expect(getTargetGainForAge(1, 40)).toBeNull();
|
const row = rowForDoc(40);
|
||||||
|
expect(getTargetGainForAge(1, 40)).toBe(row.values[0]! - 40);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns null for ages outside 1..35 or invalid docWeight', () => {
|
||||||
|
expect(getTargetGainForAge(0, 40)).toBeNull();
|
||||||
|
expect(getTargetGainForAge(36, 40)).toBeNull();
|
||||||
|
expect(getTargetGainForAge(1, 0)).toBeNull();
|
||||||
|
expect(getTargetGainForAge(1, -5)).toBeNull();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { ChickenCounting, Cycle, KPI, ManualInput } from '../types/api.ts';
|
import type { ChickenCounting, Cycle, KPI, ManualInput } from '../types/api.ts';
|
||||||
import { addDaysIso, cycleDayForDate, cycleLastDayIndex } from './format.ts';
|
import { addDaysIso, cycleDayForDate, todayIso } from './format.ts';
|
||||||
import { stockAkhirFromKpi } from './kpiStock.ts';
|
import { stockAkhirFromKpi } from './kpiStock.ts';
|
||||||
|
|
||||||
export const COUNTING_ACCURACY_WARNING_THRESHOLD = 95;
|
export const COUNTING_ACCURACY_WARNING_THRESHOLD = 95;
|
||||||
@@ -39,8 +39,9 @@ function stockAkhirByDate(
|
|||||||
const manualByDate = new Map(manualInputs.map((m) => [m.date, m]));
|
const manualByDate = new Map(manualInputs.map((m) => [m.date, m]));
|
||||||
|
|
||||||
const lastCycleDay = Math.max(0, (cycle.total_days || 1) - 1);
|
const lastCycleDay = Math.max(0, (cycle.total_days || 1) - 1);
|
||||||
const endDay = cycleLastDayIndex(cycle);
|
const calendarDay = cycleDayForDate(cycle.start_date, todayIso());
|
||||||
const maxDay = Math.min(lastCycleDay, endDay);
|
const endDay = cycle.end_date ? cycleDayForDate(cycle.start_date, cycle.end_date) : calendarDay;
|
||||||
|
const maxDay = Math.min(calendarDay, lastCycleDay, endDay);
|
||||||
|
|
||||||
const result = new Map<string, number>();
|
const result = new Map<string, number>();
|
||||||
let previousStockAkhir = 0;
|
let previousStockAkhir = 0;
|
||||||
|
|||||||
+6
-1
@@ -70,7 +70,12 @@ export function getTargetWeightForAge(age: number, docWeight: number): number |
|
|||||||
/** Target daily weight gain (grams/day) for a given age from the standard. */
|
/** Target daily weight gain (grams/day) for a given age from the standard. */
|
||||||
export function getTargetGainForAge(age: number, docWeight: number): number | null {
|
export function getTargetGainForAge(age: number, docWeight: number): number | null {
|
||||||
const values = pickStandardValues(docWeight);
|
const values = pickStandardValues(docWeight);
|
||||||
if (age < 2 || age > values.length) return null;
|
if (age < 1 || age > values.length) return null;
|
||||||
|
if (age === 1) {
|
||||||
|
const current = values[0];
|
||||||
|
if (current == null || docWeight <= 0) return null;
|
||||||
|
return current - docWeight;
|
||||||
|
}
|
||||||
const current = values[age - 1];
|
const current = values[age - 1];
|
||||||
const previous = values[age - 2];
|
const previous = values[age - 2];
|
||||||
if (current == null || previous == null) return null;
|
if (current == null || previous == null) return null;
|
||||||
|
|||||||
Reference in new issue
Block a user