Refactor loading state management and enhance data handling in analysis components
This commit is contained in:
@@ -3,7 +3,7 @@ import { useSelectedProduct } from '../../../../store/simulation/useSimulationSt
|
||||
import { useProductStore } from '../../../../store/simulation/useProductStore';
|
||||
import { determineExecutionMachineSequences } from '../../simulator/functions/determineExecutionMachineSequences';
|
||||
import { useArmBotStore } from '../../../../store/simulation/useArmBotStore';
|
||||
import { useMachineCount, useMachineUptime, useMaterialCycle, useThroughPutData } from '../../../../store/builder/store';
|
||||
import { useMachineCount, useMachineUptime, useMaterialCycle, useProcessBar, useThroughPutData } from '../../../../store/builder/store';
|
||||
import { useVehicleStore } from '../../../../store/simulation/useVehicleStore';
|
||||
import { useMachineStore } from '../../../../store/simulation/useMachineStore';
|
||||
import { useConveyorStore } from '../../../../store/simulation/useConveyorStore';
|
||||
@@ -25,6 +25,7 @@ export default function ThroughPutData() {
|
||||
const { machineActiveTime, setMachineActiveTime } = useMachineUptime();
|
||||
|
||||
const { materialCycleTime, setMaterialCycleTime } = useMaterialCycle();
|
||||
const { processBar, setProcessBar } = useProcessBar();
|
||||
|
||||
// const [totalActiveTime, setTotalActiveTime] = useState(0);
|
||||
const { setThroughputData } = useThroughPutData() // <=== ADD THIS
|
||||
@@ -32,7 +33,8 @@ export default function ThroughPutData() {
|
||||
|
||||
// Setting machine count
|
||||
useEffect(() => {
|
||||
if (materialCycleTime < 0) return
|
||||
if (materialCycleTime <= 0) return
|
||||
let process: any = [];
|
||||
const fetchProductSequenceData = async () => {
|
||||
const productData = getProductById(selectedProduct.productId);
|
||||
if (productData) {
|
||||
@@ -42,45 +44,45 @@ export default function ThroughPutData() {
|
||||
let totalActiveTime = 0;
|
||||
productSequenceData.forEach((sequence) => {
|
||||
sequence.forEach((item) => {
|
||||
|
||||
if (item.type === "roboticArm") {
|
||||
armBots.filter(arm => arm.modelUuid === item.modelUuid)
|
||||
.forEach(arm => {
|
||||
|
||||
if (arm.activeTime >= 0) {
|
||||
process.push({ modelid: arm.modelUuid, modelName: arm.modelName, activeTime: arm?.activeTime })
|
||||
totalActiveTime += arm.activeTime;
|
||||
}
|
||||
});
|
||||
} else if (item.type === "vehicle") {
|
||||
vehicles.filter(vehicle => vehicle.modelUuid === item.modelUuid)
|
||||
.forEach(vehicle => {
|
||||
|
||||
if (vehicle.activeTime >= 0) {
|
||||
// totalActiveTime += vehicle.activeTime;
|
||||
totalActiveTime += 34;
|
||||
process.push({ modelid: vehicle.modelUuid, modelName: vehicle.modelName, activeTime: vehicle?.activeTime })
|
||||
|
||||
totalActiveTime += vehicle.activeTime;
|
||||
}
|
||||
});
|
||||
} else if (item.type === "machine") {
|
||||
machines.filter(machine => machine.modelUuid === item.modelUuid)
|
||||
.forEach(machine => {
|
||||
if (machine.activeTime >= 0) {
|
||||
// totalActiveTime += machine.activeTime;
|
||||
totalActiveTime += 12;
|
||||
process.push({ modelid: machine.modelUuid, modelName: machine.modelName, activeTime: machine?.activeTime })
|
||||
totalActiveTime += machine.activeTime;
|
||||
}
|
||||
});
|
||||
} else if (item.type === "transfer") {
|
||||
conveyors.filter(conveyor => conveyor.modelUuid === item.modelUuid)
|
||||
.forEach(conveyor => {
|
||||
if (conveyor.activeTime >= 0) {
|
||||
// totalActiveTime += conveyor.activeTime;
|
||||
totalActiveTime += 89;
|
||||
totalActiveTime += conveyor.activeTime;
|
||||
}
|
||||
});
|
||||
} else if (item.type === "storageUnit") {
|
||||
storageUnits.filter(storage => storage.modelUuid === item.modelUuid)
|
||||
.forEach(storage => {
|
||||
if (storage.activeTime >= 0) {
|
||||
// totalActiveTime += storage.activeTime;
|
||||
totalActiveTime += 45;
|
||||
totalActiveTime += storage.activeTime;
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -90,13 +92,20 @@ export default function ThroughPutData() {
|
||||
|
||||
setMachineCount(totalItems);
|
||||
setMachineActiveTime(totalActiveTime);
|
||||
let arr = process.map((item: any) => ({
|
||||
name: item.modelName,
|
||||
completed: Math.round((item.activeTime / totalActiveTime) * 100)
|
||||
}));
|
||||
setProcessBar(arr);
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
fetchProductSequenceData();
|
||||
}, [products, selectedProduct, getProductById, setMachineCount, isPlaying, armBots, materialCycleTime]);
|
||||
}, [products, selectedProduct, getProductById, setMachineCount, materialCycleTime, armBots, vehicles, machines]);
|
||||
|
||||
// Setting material cycle time
|
||||
useEffect(() => {
|
||||
@@ -106,8 +115,8 @@ export default function ThroughPutData() {
|
||||
|
||||
if (start === 0 || end === 0) return;
|
||||
|
||||
const totalCycleTime = end - start;
|
||||
setMaterialCycleTime(totalCycleTime.toFixed(2)); // Set the material cycle time in the store
|
||||
const totalCycleTime = (end - start) / 1000; // Convert milliseconds to seconds
|
||||
setMaterialCycleTime(Number(totalCycleTime.toFixed(2))); // Set the material cycle time in the store
|
||||
});
|
||||
}, [materialHistory]);
|
||||
|
||||
@@ -115,16 +124,21 @@ export default function ThroughPutData() {
|
||||
|
||||
useEffect(() => {
|
||||
if (machineActiveTime > 0 && materialCycleTime > 0 && machineCount > 0) {
|
||||
const avgProcessTime = (machineActiveTime / materialCycleTime) * 100; // % value
|
||||
const throughput = (3600 / materialCycleTime) * machineCount * (avgProcessTime / 100); // ✅ division by 100
|
||||
const avgProcessTime = (machineActiveTime / materialCycleTime) * 100;
|
||||
const throughput = (3600 / materialCycleTime) * machineCount * (avgProcessTime / 100);
|
||||
setThroughputData(throughput.toFixed(2)); // Set the throughput data in the store
|
||||
|
||||
|
||||
console.log('---Throughput Results---');
|
||||
console.log('Total Active Time:', machineActiveTime);
|
||||
console.log('Material Cycle Time:', materialCycleTime);
|
||||
console.log('Machine Count:', machineCount);
|
||||
console.log('Average Process Time (%):', avgProcessTime);
|
||||
console.log('Calculated Throughput:', throughput);
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}, [machineActiveTime, materialCycleTime, machineCount]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user