enhance loading state management and streamline throughput data handling

This commit is contained in:
Gomathi 2025-06-10 11:54:57 +05:30
parent 6884ffd562
commit e0736b26b9
3 changed files with 82 additions and 35 deletions

View File

@ -86,8 +86,9 @@ const ROISummary = ({
useEffect(() => {
if (roiSummary.productName) {
// If productName is set, assume data is loaded
setTimeout(() => {
setIsLoading(false);
}, 4000)
} else {
// If productName is empty, assume still loading
setIsLoading(true);

View File

@ -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()
@ -30,14 +27,10 @@ const ProductionCapacity = ({
const [isLoading, setIsLoading] = useState(false);
useEffect(() => {
console.log('typeof throughputData:', typeof throughputData);
console.log('throughputData > 0: ', throughputData > 0);
if (throughputData > 0) {
// console.log('machineActiveTime: ', machineActiveTime);
// console.log('materialCycleTime: ', materialCycleTime);
// console.log('throughputData: ', throughputData);
// console.log('productionCapacityData: ', productionCapacityData);
setTimeout(() => {
setIsLoading(false);
}, 3000)
} else {
setIsLoading(true);
}
@ -60,7 +53,7 @@ const ProductionCapacity = ({
<ThroughputSummaryIcon />
</div>
</div>
{isLoading ? (
{!isLoading ? (
<>
<div className="process-container">
<div className="throughput-value">

View File

@ -16,7 +16,7 @@ export default function ThroughPutData() {
const { machines } = machineStore();
const { conveyors } = conveyorStore();
const { storageUnits } = storageUnitStore();
const { materialHistory } = materialStore();
const { materialHistory, materials } = materialStore();
const { machineCount, setMachineCount } = useMachineCount();
const { machineActiveTime, setMachineActiveTime } = useMachineUptime();
const { materialCycleTime, setMaterialCycleTime } = useMaterialCycle();
@ -109,39 +109,92 @@ export default function ThroughPutData() {
// if (materialCycleTime <= 0) return
}, [products, selectedProduct, getProductById, setMachineCount, materialCycleTime, armBots, vehicles, machines]);
// Setting material cycle time
useEffect(() => {
async function getMachineActive() {
const productData = getProductById(selectedProduct.productUuid);
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 => {
if (arm.isActive) {
anyArmActive = true;
} else {
anyArmActive = false;
}
});
}
if (item.type === "vehicle") {
vehicles
.filter(vehicle => vehicle.modelUuid === item.modelUuid)
.forEach(vehicle => {
if (vehicle.isActive) {
anyVehicleActive = true;
} else {
anyVehicleActive = false;
}
});
}
if (item.type === "machine") {
machines
.filter(machine => machine.modelUuid === item.modelUuid)
.forEach(machine => {
if (machine.isActive) {
anyMachineActive = true;
} else {
anyMachineActive = false;
}
});
}
});
});
}
}
const allInactive = !anyArmActive && !anyVehicleActive && !anyMachineActive;
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
setMaterialCycleTime(Number(totalCycleTime.toFixed(2))); // Set the material cycle time in the store
totalCycleTimeSum += totalCycleTime;
cycleCount++;
});
}, [materialHistory]);
if (cycleCount > 0) {
const averageCycleTime = totalCycleTimeSum / cycleCount;
setMaterialCycleTime(Number(averageCycleTime.toFixed(2)));
}
}
}
getMachineActive();
}, [armBots, materials, materialHistory, machines, vehicles, selectedProduct])
useEffect(() => {
if (machineActiveTime > 0 && materialCycleTime > 0 && machineCount > 0) {
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);
setThroughputData(Number(throughput.toFixed(2))); // Keep as number
// console.log('throughput ', Number(throughput.toFixed(2)));
}
}, [machineActiveTime, materialCycleTime, machineCount]);
return (
<>
</>