Enhance analysis components with new state management for production capacity and ROI data

This commit is contained in:
2025-05-14 14:25:54 +05:30
parent 3ccfc54922
commit e4be4505a9
8 changed files with 131 additions and 142 deletions

View File

@@ -1,10 +1,12 @@
import React, { useEffect } from 'react'
import { useInputValues, useProductionCapacityData } from '../../../../store/builder/store';
import React, { useEffect, useState } from 'react'
import { useInputValues, useProductionCapacityData, useROISummaryData } from '../../../../store/builder/store';
export default function ROIData() {
const { inputValues } = useInputValues();
const { productionCapacityData } = useProductionCapacityData()
const { setRoiSummaryData } = useROISummaryData();
useEffect(() => {
if (inputValues === undefined) return;
@@ -53,6 +55,7 @@ export default function ROIData() {
let TotalAnnualCost = MaterialCost + LaborCost + EnergyCost + MaintenceCost;
console.log('TotalAnnualCost: ', TotalAnnualCost);
//Profit for Year
let ProfitforYear = RevenueForYear - TotalAnnualCost;
console.log('ProfitforYear: ', ProfitforYear);
@@ -70,7 +73,16 @@ export default function ROIData() {
// Payback Period
const paybackPeriod = initialInvestment / ProfitforYear;
console.log('paybackPeriod: ', paybackPeriod);
setRoiSummaryData({
roiPercentage: ROIData,
paybackPeriod,
totalCost: TotalAnnualCost,
revenueGenerated: RevenueForYear,
netProfit: NetProfit > 0 ? NetProfit : 0,
netLoss: NetProfit < 0 ? -NetProfit : 0
});
}

View File

@@ -19,7 +19,7 @@ export default function ProductionCapacityData() {
// console.log('yieldRate: ', yieldRate);
if (!isNaN(shiftLength) && !isNaN(shiftsPerDay) && !isNaN(workingDaysPerYear) && !isNaN(yieldRate) && throughputData > 0) {
if (!isNaN(shiftLength) && !isNaN(shiftsPerDay) && !isNaN(workingDaysPerYear) && !isNaN(yieldRate) && throughputData >= 0) {
//Daily Output
const dailyProduction = throughputData * shiftLength * shiftsPerDay;
console.log("DailyProduction: ", dailyProduction.toFixed(2));

View File

@@ -19,7 +19,7 @@ export default function ThroughPutData() {
const { machines } = useMachineStore();
const { conveyors } = useConveyorStore();
const { storageUnits } = useStorageUnitStore();
const { materials } = useMaterialStore();
const { materialHistory } = useMaterialStore();
const { machineCount, setMachineCount } = useMachineCount();
const { machineActiveTime, setMachineActiveTime } = useMachineUptime();
@@ -33,20 +33,14 @@ export default function ThroughPutData() {
// Setting machine count
useEffect(() => {
if (materialCycleTime < 0) return
// console.log('materialCycleTime: ', materialCycleTime);
const fetchProductSequenceData = async () => {
const productData = getProductById(selectedProduct.productId);
if (productData) {
const productSequenceData = await determineExecutionMachineSequences([productData]);
// console.log('productSequenceData: ', productSequenceData);
const productSequenceData = await determineExecutionMachineSequences([productData])
if (productSequenceData?.length > 0) {
let totalItems = 0;
let totalActiveTime = 0;
productSequenceData.forEach((sequence) => {
// console.log('sequence: ', sequence);
sequence.forEach((item) => {
if (item.type === "roboticArm") {
armBots.filter(arm => arm.modelUuid === item.modelUuid)
@@ -62,7 +56,7 @@ export default function ThroughPutData() {
if (vehicle.activeTime >= 0) {
// totalActiveTime += vehicle.activeTime;
// totalActiveTime += 10;
totalActiveTime += 34;
}
});
} else if (item.type === "machine") {
@@ -70,7 +64,7 @@ export default function ThroughPutData() {
.forEach(machine => {
if (machine.activeTime >= 0) {
// totalActiveTime += machine.activeTime;
// totalActiveTime += 12;
totalActiveTime += 12;
}
});
} else if (item.type === "transfer") {
@@ -78,7 +72,7 @@ export default function ThroughPutData() {
.forEach(conveyor => {
if (conveyor.activeTime >= 0) {
// totalActiveTime += conveyor.activeTime;
// totalActiveTime += 7;
totalActiveTime += 89;
}
});
} else if (item.type === "storageUnit") {
@@ -86,12 +80,11 @@ export default function ThroughPutData() {
.forEach(storage => {
if (storage.activeTime >= 0) {
// totalActiveTime += storage.activeTime;
// totalActiveTime += 9;
totalActiveTime += 45;
}
});
}
});
totalItems += sequence.length;
});
@@ -107,16 +100,17 @@ export default function ThroughPutData() {
// Setting material cycle time
useEffect(() => {
materials.map((material) => {
// console.log('material: ', material);
// const totalCycleTime = material.endTime - material.startTime;//dynamic
const staticStartTime = 50;
const staticEndTime = 100;
const totalCycleTime = staticEndTime - staticStartTime;
setMaterialCycleTime(totalCycleTime)
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;
setMaterialCycleTime(totalCycleTime.toFixed(2)); // Set the material cycle time in the store
});
}, [materialHistory]);
})
}, [materials]);
useEffect(() => {
@@ -125,12 +119,12 @@ export default function ThroughPutData() {
const throughput = (3600 / materialCycleTime) * machineCount * (avgProcessTime / 100); // ✅ division by 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);
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]);
@@ -141,68 +135,3 @@ export default function ThroughPutData() {
</>
);
}
// useEffect(() => {
// if (!isPlaying) return;
// const intervalMs = 1000
// if (!armBot.isActive && armBot.state == "idle" && (currentPhase == "rest" || currentPhase == "init") && !isIdleRef.current) {
// isIdleRef.current = true
// // Stop the timer
// // 🚨 1. Clear Active Timer
// if (activeTimerId.current) {
// clearInterval(activeTimerId.current);
// activeTimerId.current = null;
// }
// incrementActiveTime(armBot.modelUuid, activeSecondsElapsed.current)
// console.log(`✅ Active Cycle completed in ${activeSecondsElapsed.current} seconds`);
// // 🚨 2. Reset active timer seconds after logging
// // activeSecondsElapsed.current = 0;
// // 🚨 3. Start Idle Timer (clean old idle timer first)
// if (idleTimerId.current) {
// clearInterval(idleTimerId.current);
// idleTimerId.current = null;
// }
// idleSecondsElapsed.current = 0;
// idleTimerId.current = setInterval(() => {
// if (!isPausedRef.current) {
// idleSecondsElapsed.current += 1;
// console.log(`🕒 Idle Timer: ${idleSecondsElapsed.current} seconds`);
// }
// }, intervalMs);
// }
// if (armBot.isActive && armBot.state != "idle" && currentPhase !== "rest" && armBot.currentAction && isIdleRef.current) {
// isIdleRef.current = false
// if (armBot.currentAction) {
// // 🚨 Clear Idle Timer
// if (idleTimerId.current) {
// clearInterval(idleTimerId.current);
// idleTimerId.current = null;
// }
// incrementIdleTime(armBot.modelUuid, idleSecondsElapsed.current)
// console.log(`🕒 Idle Cycle completed in: ${idleSecondsElapsed.current} seconds`);
// idleSecondsElapsed.current = 0;
// // 🚨 Start Active Timer
// if (activeTimerId.current) {
// clearInterval(activeTimerId.current);
// }
// // activeSecondsElapsed.current = 0;
// activeTimerId.current = setInterval(() => {
// if (!isPausedRef.current) {
// activeSecondsElapsed.current += 1
// console.log(`🕒 Active Timer: ${activeSecondsElapsed.current} seconds`);
// }
// }, intervalMs);
// }
// }
// }, [armBot, currentPhase, isPlaying])