enhance loading state management and add logging for production capacity and ROI summaries
This commit is contained in:
parent
db8536100c
commit
d4c15b29ec
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue