From d4c15b29ecbcf61b0d9204eb1b1d087dcd03895d Mon Sep 17 00:00:00 2001 From: Gomathi9520 Date: Tue, 10 Jun 2025 10:59:53 +0530 Subject: [PATCH] enhance loading state management and add logging for production capacity and ROI summaries --- .../ui/analysis/ProductionCapacity.tsx | 3 +- app/src/components/ui/analysis/ROISummary.tsx | 4 +- .../ui/analysis/ThroughputSummary.tsx | 3 - .../analysis/throughPut/throughPutData.tsx | 87 ++++++++++++++++++- 4 files changed, 89 insertions(+), 8 deletions(-) diff --git a/app/src/components/ui/analysis/ProductionCapacity.tsx b/app/src/components/ui/analysis/ProductionCapacity.tsx index 2733827..185e8bf 100644 --- a/app/src/components/ui/analysis/ProductionCapacity.tsx +++ b/app/src/components/ui/analysis/ProductionCapacity.tsx @@ -92,11 +92,10 @@ const ThroughputSummary: React.FC = () => { useEffect(() => { if (productionCapacityData >0) { + console.log("productionCapacityData: ", productionCapacityData); setTimeout(() => { - setIsLoading(false); }, 3000); - console.log("productionCapacityData: ", productionCapacityData); } else { setIsLoading(true); } diff --git a/app/src/components/ui/analysis/ROISummary.tsx b/app/src/components/ui/analysis/ROISummary.tsx index e7cfc52..2aab7cb 100644 --- a/app/src/components/ui/analysis/ROISummary.tsx +++ b/app/src/components/ui/analysis/ROISummary.tsx @@ -85,11 +85,11 @@ const ROISummary = ({ useEffect(() => { if (roiSummary.productName) { + console.log('roiSummary.productName: ', roiSummary.productName); // If productName is set, assume data is loaded setTimeout(() => { - setIsLoading(false); - }, 3000); + }, 4000); // setIsLoading(false); } else { // If productName is empty, assume still loading diff --git a/app/src/components/ui/analysis/ThroughputSummary.tsx b/app/src/components/ui/analysis/ThroughputSummary.tsx index 254efd3..df1eb77 100644 --- a/app/src/components/ui/analysis/ThroughputSummary.tsx +++ b/app/src/components/ui/analysis/ThroughputSummary.tsx @@ -11,9 +11,6 @@ const ProductionCapacity = ({ throughputValue = 128, timeRange = { startTime: "08:00 AM", endTime: "09:00 AM" }, }) => { - - - const { machineActiveTime } = useMachineUptime(); const { materialCycleTime } = useMaterialCycle(); const { throughputData } = useThroughPutData() diff --git a/app/src/modules/simulation/analysis/throughPut/throughPutData.tsx b/app/src/modules/simulation/analysis/throughPut/throughPutData.tsx index 19d8fd8..91815c8 100644 --- a/app/src/modules/simulation/analysis/throughPut/throughPutData.tsx +++ b/app/src/modules/simulation/analysis/throughPut/throughPutData.tsx @@ -19,7 +19,7 @@ export default function ThroughPutData() { const { machines } = useMachineStore(); const { conveyors } = useConveyorStore(); const { storageUnits } = useStorageUnitStore(); - const { materialHistory } = useMaterialStore(); + const { materialHistory, materials } = useMaterialStore(); const { machineCount, setMachineCount } = useMachineCount(); const { machineActiveTime, setMachineActiveTime } = useMachineUptime(); const { materialCycleTime, setMaterialCycleTime } = useMaterialCycle(); @@ -112,8 +112,93 @@ export default function ThroughPutData() { // if (materialCycleTime <= 0) return }, [products, selectedProduct, getProductById, setMachineCount, materialCycleTime, armBots, vehicles, machines]); + + useEffect(() => { + async function getMachineActive() { + const productData = getProductById(selectedProduct.productId); + let anyArmActive; + let anyVehicleActive; + let anyMachineActive; + + if (productData) { + const productSequenceData = await determineExecutionMachineSequences([productData]); + if (productSequenceData?.length > 0) { + productSequenceData.forEach(sequence => { + sequence.forEach(item => { + if (item.type === "roboticArm") { + armBots + .filter(arm => arm.modelUuid === item.modelUuid) + .forEach(arm => { + // console.log("arm: ", arm); + if (arm.isActive) { + anyArmActive = true; + } else { + anyArmActive = false; + } + }); + } + + if (item.type === "vehicle") { + vehicles + .filter(vehicle => vehicle.modelUuid === item.modelUuid) + .forEach(vehicle => { + // console.log("vehicle: ", vehicle); + if (vehicle.isActive) { + anyVehicleActive = true; + } else { + anyVehicleActive = false; + } + }); + } + + if (item.type === "machine") { + machines + .filter(machine => machine.modelUuid === item.modelUuid) + .forEach(machine => { + // console.log("machine: ", machine); + if (machine.isActive) { + anyMachineActive = true; + } else { + anyMachineActive = false; + } + }); + } + }); + }); + } + } + + const allInactive = !anyArmActive && !anyVehicleActive && !anyMachineActive; + console.log('allInactive: ', allInactive); + + if (allInactive && materials.length === 0 && materialHistory.length > 0) { + console.log("inside allInactive condition"); + let totalCycleTimeSum = 0; + let cycleCount = 0; + + materialHistory.forEach((material) => { + const start = material.material.startTime ?? 0; + const end = material.material.endTime ?? 0; + if (start === 0 || end === 0) return; + + const totalCycleTime = (end - start) / 1000; // Convert milliseconds to seconds + totalCycleTimeSum += totalCycleTime; + cycleCount++; + }); + + if (cycleCount > 0) { + const averageCycleTime = totalCycleTimeSum / cycleCount; + setMaterialCycleTime(Number(averageCycleTime.toFixed(2))); + } + } + } + + getMachineActive(); + }, [armBots, materials, materialHistory, machines, vehicles, selectedProduct]); + // Setting material cycle time useEffect(() => { + materialHistory.forEach((material) => { const start = material.material.startTime ?? 0; const end = material.material.endTime ?? 0;