fix doc weight to show real doc instead of forcing 35-51 range and also fixed bug target weight using total days as reference for target weight instead of doc weight

This commit is contained in:
Alberto-Audrix committed 2026-09-07 10:43:54 +07:00
1 parent 4439e3b7b1
commit 75eb218558
8 files changed
+76 -34

No files matched your search

+12 -12
View File
@@ -41,34 +41,34 @@ export function formatWeight(
}
/**
* Picks the standard table whose harvest day is closest to the cycle's
* `total_days`. Every row carries values for days 1..35, so a 35-, 42- or
* 45-day cycle all map onto a matching table.
* Picks the Ross 308 standard row for a DOC (chick-in) weight.
* Table rows are keyed by DOC weight (g) 35..51; columns are age days 1..35.
* Weights outside that range use the closest available row (e.g. 20→35, 60→51).
*/
function pickStandardValues(totalDays: number): number[] {
function pickStandardValues(docWeight: number): number[] {
const rows = weightStandardData.data;
if (rows.length === 0) return [];
const exact = rows.find((row) => row.day === totalDays);
const exact = rows.find((row) => row.day === docWeight);
if (exact) return exact.values;
let closest = rows[0]!;
for (const row of rows) {
if (Math.abs(row.day - totalDays) < Math.abs(closest.day - totalDays)) {
if (Math.abs(row.day - docWeight) < Math.abs(closest.day - docWeight)) {
closest = row;
}
}
return closest.values;
}
/** Target body weight (grams) for a cycle day from the Ross 308 standard. */
export function getTargetWeightForAge(age: number, totalDays: number): number | null {
const values = pickStandardValues(totalDays);
/** Target body weight (grams) for a given age from the Ross 308 DOC-weight table. */
export function getTargetWeightForAge(age: number, docWeight: number): number | null {
const values = pickStandardValues(docWeight);
if (age < 1 || age > values.length) return null;
return values[age - 1] ?? null;
}
/** Target daily weight gain (grams/day) for a cycle day from the standard. */
export function getTargetGainForAge(age: number, totalDays: number): number | null {
const values = pickStandardValues(totalDays);
/** Target daily weight gain (grams/day) for a given age from the standard. */
export function getTargetGainForAge(age: number, docWeight: number): number | null {
const values = pickStandardValues(docWeight);
if (age < 2 || age > values.length) return null;
const current = values[age - 1];
const previous = values[age - 2];