Enhance analysis components with input values integration and improve state management for production capacity and ROI calculations

This commit is contained in:
2025-05-15 18:00:07 +05:30
parent d88e93395f
commit 28e11d04b4
8 changed files with 201 additions and 173 deletions

View File

@@ -10,101 +10,107 @@ import { useConveyorStore } from '../../../../store/simulation/useConveyorStore'
import { useStorageUnitStore } from '../../../../store/simulation/useStorageUnitStore';
import { useMaterialStore } from '../../../../store/simulation/useMaterialStore';
import { usePauseButtonStore, usePlayButtonStore } from '../../../../store/usePlayButtonStore';
import { is, set } from 'immer/dist/internal';
export default function ThroughPutData() {
const { selectedProduct } = useSelectedProduct();
const { products, getProductById } = useProductStore();
const { armBots, incrementActiveTime, incrementIdleTime } = useArmBotStore();
const { armBots } = useArmBotStore();
const { vehicles } = useVehicleStore();
const { machines } = useMachineStore();
const { conveyors } = useConveyorStore();
const { storageUnits } = useStorageUnitStore();
const { materialHistory } = useMaterialStore();
const { machineCount, setMachineCount } = useMachineCount();
const { machineActiveTime, setMachineActiveTime } = useMachineUptime();
const { materialCycleTime, setMaterialCycleTime } = useMaterialCycle();
const { processBar, setProcessBar } = useProcessBar();
// const [totalActiveTime, setTotalActiveTime] = useState(0);
const { setThroughputData } = useThroughPutData() // <=== ADD THIS
const { setProcessBar } = useProcessBar();
const { setThroughputData } = useThroughPutData()
const { isPlaying } = usePlayButtonStore();
// Setting machine count
let totalItems = 0;
let totalActiveTime = 0;
useEffect(() => {
if (materialCycleTime <= 0) return
let process: any = [];
const fetchProductSequenceData = async () => {
const productData = getProductById(selectedProduct.productId);
if (productData) {
const productSequenceData = await determineExecutionMachineSequences([productData])
if (productSequenceData?.length > 0) {
let totalItems = 0;
let totalActiveTime = 0;
productSequenceData.forEach((sequence) => {
sequence.forEach((item) => {
if (!isPlaying) {
totalActiveTime = 0;
totalItems = 0;
setMachineCount(0);
setMachineActiveTime(0);
setMaterialCycleTime(0);
setProcessBar([]);
setThroughputData(0);
return;
} else {
let process: any = [];
const fetchProductSequenceData = async () => {
const productData = getProductById(selectedProduct.productId);
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 => {
if (arm.activeTime >= 0) {
process.push({ modelid: arm.modelUuid, modelName: arm.modelName, activeTime: arm?.activeTime })
totalActiveTime += arm.activeTime;
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) {
process.push({ modelid: vehicle.modelUuid, modelName: vehicle.modelName, activeTime: vehicle?.activeTime })
}
});
} else if (item.type === "vehicle") {
vehicles.filter(vehicle => vehicle.modelUuid === item.modelUuid)
.forEach(vehicle => {
if (vehicle.activeTime >= 0) {
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) {
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;
}
});
} else if (item.type === "storageUnit") {
storageUnits.filter(storage => storage.modelUuid === item.modelUuid)
.forEach(storage => {
if (storage.activeTime >= 0) {
totalActiveTime += storage.activeTime;
totalActiveTime += vehicle.activeTime;
}
});
} else if (item.type === "machine") {
machines.filter(machine => machine.modelUuid === item.modelUuid)
.forEach(machine => {
if (machine.activeTime >= 0) {
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;
}
});
} else if (item.type === "storageUnit") {
storageUnits.filter(storage => storage.modelUuid === item.modelUuid)
.forEach(storage => {
if (storage.activeTime >= 0) {
totalActiveTime += storage.activeTime;
}
});
}
}
});
}
});
totalItems += sequence.length;
});
totalItems += sequence.length;
});
setMachineCount(totalItems);
setMachineActiveTime(totalActiveTime);
let arr = process.map((item: any) => ({
name: item.modelName,
completed: Math.round((item.activeTime / totalActiveTime) * 100)
}));
setProcessBar(arr);
setMachineCount(totalItems);
setMachineActiveTime(totalActiveTime);
let arr = process.map((item: any) => ({
name: item.modelName,
completed: Math.round((item.activeTime / totalActiveTime) * 100)
}));
setProcessBar(arr);
}
}
}
};
};
fetchProductSequenceData();
fetchProductSequenceData();
}
// if (materialCycleTime <= 0) return
}, [products, selectedProduct, getProductById, setMachineCount, materialCycleTime, armBots, vehicles, machines]);
// Setting material cycle time
@@ -112,9 +118,7 @@ export default function ThroughPutData() {
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
setMaterialCycleTime(Number(totalCycleTime.toFixed(2))); // Set the material cycle time in the store
});
@@ -124,26 +128,24 @@ export default function ThroughPutData() {
useEffect(() => {
if (machineActiveTime > 0 && materialCycleTime > 0 && machineCount > 0) {
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);
const utilization = machineActiveTime / 3600; // Active time per hour
const unitsPerMachinePerHour = 3600 / materialCycleTime;
const throughput = unitsPerMachinePerHour * machineCount * utilization;
setThroughputData(throughput.toFixed(2)); // Set throughput to state/store
// console.log('---Throughput Results---');
// console.log('Machine Active Time (s):', machineActiveTime);
// console.log('Material Cycle Time (s):', materialCycleTime);
// console.log('Machine Count:', machineCount);
// console.log('Utilization:', utilization);
// console.log('Throughput (units/hr):', throughput);
}
}, [machineActiveTime, materialCycleTime, machineCount]);
return (
<>
</>