import React, { useEffect, useMemo, useState } from 'react'; import { cobbStandardPerformance } from '../mockData/cobbStandard.ts'; import { useFarm } from '../context/FarmContext.tsx'; import { formatNumber, formatRatio } from '../utils/format.ts'; const CobbStandardPage: React.FC = () => { const { selectedCycle } = useFarm(); const [initialBw, setInitialBw] = useState(selectedCycle?.chick_in_weight || 42); const [capacity, setCapacity] = useState(selectedCycle?.doc_in_count || 50000); useEffect(() => { if (selectedCycle?.chick_in_weight) setInitialBw(selectedCycle.chick_in_weight); if (selectedCycle?.doc_in_count) setCapacity(selectedCycle.doc_in_count); }, [selectedCycle?.chick_in_weight, selectedCycle?.doc_in_count]); const calculatedData = useMemo(() => { const results = []; let lastBw = Number(initialBw); let lastCumFeed = 0; for (const standard of cobbStandardPerformance) { const currentBw = lastBw * (1 + standard.dailyGainPercent); const dailyGainG = currentBw - lastBw; const cumFeedG = currentBw * standard.fcr; const dailyFeedG = cumFeedG - lastCumFeed; const feedKg = (dailyFeedG * capacity) / 1000; const feedBag = feedKg / 50; results.push({ day: standard.day, bw: Math.round(currentBw), dailyGainG: Math.round(dailyGainG), dailyGainPercent: standard.dailyGainPercent, dailyFeedG: Math.round(dailyFeedG), cumFeedG: Math.round(cumFeedG), fcr: standard.fcr, feedKg: Math.round(feedKg), feedBag: Math.round(feedBag), }); lastBw = currentBw; lastCumFeed = cumFeedG; } return results; }, [initialBw, capacity]); return (

Kalkulator Standar Performa

Hitung proyeksi pertumbuhan dan kebutuhan pakan berdasarkan bobot awal dan kapasitas kandang.

setInitialBw(Number(e.target.value))} className="mt-1 block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:ring-red-500 focus:border-red-500 text-lg font-semibold" />
setCapacity(Number(e.target.value))} className="mt-1 block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:ring-red-500 focus:border-red-500 text-lg font-semibold" />
{calculatedData.map((row) => { const isSeventhDay = row.day > 0 && row.day % 7 === 0; const rowClass = `hover:bg-red-50 ${isSeventhDay ? 'font-bold bg-blue-100' : 'even:bg-gray-100/50'}`; const cellBorderClass = isSeventhDay ? 'border-b-[3px] border-double border-blue-400' : 'border-gray-200'; return ( ); })}
Umur BW (g) Daily Gain Feed Consumption FCR Kebutuhan Pakan
(g) (%) Daily (g) Cum (g) (Kg) (Bag)
0 {initialBw}
{row.day} {formatNumber(row.bw)} {formatNumber(row.dailyGainG)} {(row.dailyGainPercent * 100).toFixed(0)}% {formatNumber(row.dailyFeedG)} {formatNumber(row.cumFeedG)} {formatRatio(row.fcr)} {formatNumber(row.feedKg)} {formatNumber(row.feedBag)}
Standar Performa COBB (2018)
); }; export default CobbStandardPage;