merged and added the layout
This commit is contained in:
@@ -7,7 +7,110 @@ import useModuleStore from "../../../store/ui/useModuleStore";
|
|||||||
import CompareLayOut from "../../ui/compareVersion/CompareLayOut";
|
import CompareLayOut from "../../ui/compareVersion/CompareLayOut";
|
||||||
import ComparisonResult from "../../ui/compareVersion/ComparisonResult";
|
import ComparisonResult from "../../ui/compareVersion/ComparisonResult";
|
||||||
import RegularDropDown from "../../ui/inputs/RegularDropDown";
|
import RegularDropDown from "../../ui/inputs/RegularDropDown";
|
||||||
|
import { useSimulationManager } from "../../../store/rough/useSimulationManagerStore";
|
||||||
|
import { useParams } from "react-router-dom";
|
||||||
|
type AssetData = {
|
||||||
|
activeTime: number;
|
||||||
|
idleTime: number;
|
||||||
|
type: string;
|
||||||
|
assetId: string;
|
||||||
|
};
|
||||||
|
export interface CompareProduct {
|
||||||
|
productUuid: string;
|
||||||
|
productName: string;
|
||||||
|
// simulationData: {
|
||||||
|
// // costPerUnit: number;
|
||||||
|
// // workingDaysPerYear: number;
|
||||||
|
// // shiftLength: number;
|
||||||
|
// // shiftsPerDay: number;
|
||||||
|
// roiPercentage: number;
|
||||||
|
// // paybackPeriod: number;
|
||||||
|
// // totalCost: number;
|
||||||
|
// // revenueGenerated: number;
|
||||||
|
// netProfit: number;
|
||||||
|
// productionCapacity: number;
|
||||||
|
// paybackPeriod: number;
|
||||||
|
// // netLoss: number;
|
||||||
|
// machineIdleTime: number;
|
||||||
|
// machineActiveTime: number;
|
||||||
|
// throughputData: number;
|
||||||
|
// };
|
||||||
|
simulationData: {
|
||||||
|
roiPercentage: number;
|
||||||
|
netProfit: number;
|
||||||
|
productionCapacity: number;
|
||||||
|
paybackPeriod: number;
|
||||||
|
machineIdleTime: number;
|
||||||
|
machineActiveTime: number;
|
||||||
|
throughputData: number;
|
||||||
|
simulationTime?: number;
|
||||||
|
simulationCost?: number;
|
||||||
|
efficiencyScore?: number;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
const calculateSimulationData = (assets: AssetData[]) => {
|
||||||
|
let totalActiveTime = 0;
|
||||||
|
let totalIdleTime = 0;
|
||||||
|
let throughput = 0;
|
||||||
|
let productionCapacity = 0;
|
||||||
|
let simulationCost = 0;
|
||||||
|
|
||||||
|
// Cost weight per type (example values, adjust as needed)
|
||||||
|
const costWeight: Record<string, number> = {
|
||||||
|
roboticArm: 50,
|
||||||
|
machine: 100,
|
||||||
|
human: 30,
|
||||||
|
transfer: 20,
|
||||||
|
storageUnit: 10,
|
||||||
|
};
|
||||||
|
const energyUsage = assets.filter((a) => a.type === "human").reduce((sum, a) => sum + a.activeTime * 1, 0);
|
||||||
|
|
||||||
|
assets.forEach((asset) => {
|
||||||
|
totalActiveTime += asset.activeTime;
|
||||||
|
totalIdleTime += asset.idleTime;
|
||||||
|
|
||||||
|
if (asset.activeTime > 0) throughput += 1;
|
||||||
|
|
||||||
|
productionCapacity += asset.activeTime;
|
||||||
|
simulationCost += asset.activeTime * (costWeight[asset.type] || 10);
|
||||||
|
});
|
||||||
|
|
||||||
|
const machineActiveTime = assets.filter((a) => a.type === "machine").reduce((acc, a) => acc + a.activeTime, 0);
|
||||||
|
|
||||||
|
const machineIdleTime = assets.filter((a) => a.type === "machine").reduce((acc, a) => acc + a.idleTime, 0);
|
||||||
|
|
||||||
|
const simulationTime = totalActiveTime + totalIdleTime;
|
||||||
|
|
||||||
|
// --- Efficiency Score ---
|
||||||
|
// Weighted formula: lower cost + lower time => higher score
|
||||||
|
// Example formula (normalize to 0–100):
|
||||||
|
const efficiencyScore = Math.max(
|
||||||
|
0,
|
||||||
|
100 -
|
||||||
|
(simulationTime / 1000) * 0.5 - // weight 0.5 for time
|
||||||
|
(simulationCost / 1000) * 0.5 // weight 0.5 for cost
|
||||||
|
);
|
||||||
|
|
||||||
|
return {
|
||||||
|
throughputData: throughput,
|
||||||
|
machineActiveTime,
|
||||||
|
machineIdleTime,
|
||||||
|
productionCapacity,
|
||||||
|
netProfit: 0, // placeholder
|
||||||
|
roiPercentage: 0, // placeholder
|
||||||
|
paybackPeriod: 0, // placeholder
|
||||||
|
simulationTime,
|
||||||
|
simulationCost,
|
||||||
|
efficiencyScore,
|
||||||
|
energyUsage,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export const createCompareProduct = (productUuid: string, productName: string, assets: AssetData[]): CompareProduct => ({
|
||||||
|
productUuid,
|
||||||
|
productName,
|
||||||
|
simulationData: calculateSimulationData(assets),
|
||||||
|
});
|
||||||
function ComparisonScene() {
|
function ComparisonScene() {
|
||||||
const { isPlaying } = usePlayButtonStore();
|
const { isPlaying } = usePlayButtonStore();
|
||||||
const { productStore, versionStore } = useSceneContext();
|
const { productStore, versionStore } = useSceneContext();
|
||||||
@@ -18,8 +121,10 @@ function ComparisonScene() {
|
|||||||
const { comparisonProduct, setComparisonProduct } = useComparisonProduct();
|
const { comparisonProduct, setComparisonProduct } = useComparisonProduct();
|
||||||
const { mainProduct } = useMainProduct();
|
const { mainProduct } = useMainProduct();
|
||||||
const { loadingProgress } = useLoadingProgress();
|
const { loadingProgress } = useLoadingProgress();
|
||||||
const { compareProductsData } = useCompareProductDataStore();
|
const { projectId } = useParams();
|
||||||
|
const { compareProductsData, setCompareProductsData } = useCompareProductDataStore();
|
||||||
const [shouldShowComparisonResult, setShouldShowComparisonResult] = useState(false);
|
const [shouldShowComparisonResult, setShouldShowComparisonResult] = useState(false);
|
||||||
|
console.log("shouldShowComparisonResult: ", shouldShowComparisonResult);
|
||||||
|
|
||||||
const handleSelectVersion = (option: string) => {
|
const handleSelectVersion = (option: string) => {
|
||||||
const version = versionHistory.find((version) => version.versionName === option);
|
const version = versionHistory.find((version) => version.versionName === option);
|
||||||
@@ -35,19 +140,43 @@ function ComparisonScene() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// useEffect(() => {
|
||||||
|
// if (mainProduct && comparisonProduct && compareProductsData.length > 1) {
|
||||||
|
// const hasMain = compareProductsData.some((val) => val.productUuid === mainProduct.productUuid);
|
||||||
|
// const hasComparison = compareProductsData.some((val) => val.productUuid === comparisonProduct.productUuid);
|
||||||
|
// if (hasMain && hasComparison && mainProduct.productUuid !== comparisonProduct.productUuid) {
|
||||||
|
// setShouldShowComparisonResult(true);
|
||||||
|
// } else {
|
||||||
|
// setShouldShowComparisonResult(false);
|
||||||
|
// }
|
||||||
|
// } else {
|
||||||
|
// setShouldShowComparisonResult(false);
|
||||||
|
// }
|
||||||
|
// }, [compareProductsData, mainProduct, comparisonProduct]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (mainProduct && comparisonProduct && compareProductsData.length > 1) {
|
// const selectedProductData = getProductById(selectedProduct.productUuid);
|
||||||
const hasMain = compareProductsData.some((val) => val.productUuid === mainProduct.productUuid);
|
if (mainProduct && comparisonProduct && selectedVersion) {
|
||||||
const hasComparison = compareProductsData.some((val) => val.productUuid === comparisonProduct.productUuid);
|
const product1 = useSimulationManager.getState().getProductById(projectId, selectedVersion?.versionId, mainProduct.productUuid);
|
||||||
if (hasMain && hasComparison && mainProduct.productUuid !== comparisonProduct.productUuid) {
|
|
||||||
|
const product2 = useSimulationManager.getState().getProductById(projectId, selectedVersion?.versionId, comparisonProduct.productUuid);
|
||||||
|
|
||||||
|
const compareProduct1 = createCompareProduct(product1?.productId ?? "", mainProduct.productName, product1?.simulateData || []);
|
||||||
|
const compareProduct2 = createCompareProduct(product2?.productId ?? "", comparisonProduct.productName, product2?.simulateData || []);
|
||||||
|
|
||||||
|
const comparedArray = [compareProduct1, compareProduct2];
|
||||||
|
console.log("comparedArray: ", comparedArray);
|
||||||
|
|
||||||
|
if (product1 === undefined || product2 === undefined) {
|
||||||
|
setShouldShowComparisonResult(false);
|
||||||
|
} else if (comparedArray.length === 2) {
|
||||||
|
setCompareProductsData(comparedArray);
|
||||||
setShouldShowComparisonResult(true);
|
setShouldShowComparisonResult(true);
|
||||||
} else {
|
|
||||||
setShouldShowComparisonResult(false);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
setShouldShowComparisonResult(false);
|
setShouldShowComparisonResult(false);
|
||||||
}
|
}
|
||||||
}, [compareProductsData, mainProduct, comparisonProduct]);
|
}, [mainProduct, comparisonProduct, selectedVersion, projectId, setCompareProductsData]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|||||||
@@ -13,11 +13,12 @@ import { deleteProductApi } from "../../../../services/simulation/products/delet
|
|||||||
import { renameProductApi } from "../../../../services/simulation/products/renameProductApi";
|
import { renameProductApi } from "../../../../services/simulation/products/renameProductApi";
|
||||||
import { determineExecutionMachineSequences } from "../../../../modules/simulation/simulator/functions/determineExecutionMachineSequences";
|
import { determineExecutionMachineSequences } from "../../../../modules/simulation/simulator/functions/determineExecutionMachineSequences";
|
||||||
import ComparePopUp from "../../../ui/compareVersion/Compare";
|
import ComparePopUp from "../../../ui/compareVersion/Compare";
|
||||||
import { useCompareStore, useIsComparing } from "../../../../store/builder/store";
|
import { useCompareStore, useIsComparing, useSimulateId } from "../../../../store/builder/store";
|
||||||
import { useToggleStore } from "../../../../store/ui/useUIToggleStore";
|
import { useToggleStore } from "../../../../store/ui/useUIToggleStore";
|
||||||
import { useParams } from "react-router-dom";
|
import { useParams } from "react-router-dom";
|
||||||
import { useSceneContext } from "../../../../modules/scene/sceneContext";
|
import { useSceneContext } from "../../../../modules/scene/sceneContext";
|
||||||
import { getSimulationData, updateSimulateData } from "../../scenes/functions/simulationStorage";
|
import { getSimulationData, updateSimulateData } from "../../scenes/functions/simulationStorage";
|
||||||
|
import { get } from "http";
|
||||||
|
|
||||||
interface Event {
|
interface Event {
|
||||||
modelName: string;
|
modelName: string;
|
||||||
@@ -38,11 +39,21 @@ const Simulations: React.FC = () => {
|
|||||||
const { selectedVersion } = versionStore();
|
const { selectedVersion } = versionStore();
|
||||||
const { comparePopUp, setComparePopUp } = useCompareStore();
|
const { comparePopUp, setComparePopUp } = useCompareStore();
|
||||||
const { setIsComparing } = useIsComparing();
|
const { setIsComparing } = useIsComparing();
|
||||||
|
const { simulateId } = useSimulateId();
|
||||||
|
|
||||||
const handleSaveVersion = () => {
|
const handleSaveVersion = async () => {
|
||||||
setIsComparing(true);
|
setIsComparing(true);
|
||||||
setComparePopUp(false);
|
setComparePopUp(false);
|
||||||
setToggleUI(false, false);
|
setToggleUI(false, false);
|
||||||
|
const singleData = {
|
||||||
|
projectId: projectId,
|
||||||
|
versionId: selectedVersion?.versionId || "",
|
||||||
|
productUuid: selectedProduct?.productUuid || "",
|
||||||
|
simulatedId: simulateId,
|
||||||
|
};
|
||||||
|
console.log("singleData: ", singleData);
|
||||||
|
const getData = await updateSimulateData(singleData);
|
||||||
|
echo.log(getData.message);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleAddProduct = () => {
|
const handleAddProduct = () => {
|
||||||
|
|||||||
@@ -7,15 +7,18 @@ import SimulationHandler from "./SimulationHandler";
|
|||||||
import { useParams } from "react-router-dom";
|
import { useParams } from "react-router-dom";
|
||||||
import { getSimulationData, saveSimulationData } from "../../../components/layout/scenes/functions/simulationStorage";
|
import { getSimulationData, saveSimulationData } from "../../../components/layout/scenes/functions/simulationStorage";
|
||||||
import { useSimulationManager } from "../../../store/rough/useSimulationManagerStore";
|
import { useSimulationManager } from "../../../store/rough/useSimulationManagerStore";
|
||||||
|
import { useSimulateId } from "../../../store/builder/store";
|
||||||
|
|
||||||
function Simulator() {
|
function Simulator() {
|
||||||
const { productStore,versionStore } = useSceneContext();
|
const { productStore, versionStore } = useSceneContext();
|
||||||
const { products, getProductById, selectedProduct } = productStore();
|
const { products, getProductById, selectedProduct } = productStore();
|
||||||
const { handleAction } = useActionHandler();
|
const { handleAction } = useActionHandler();
|
||||||
const { isPlaying } = usePlayButtonStore();
|
const { isPlaying } = usePlayButtonStore();
|
||||||
const { isReset } = useResetButtonStore();
|
const { isReset } = useResetButtonStore();
|
||||||
const { projectId } = useParams();
|
const { projectId } = useParams();
|
||||||
const { selectedVersion } = versionStore();
|
const { selectedVersion } = versionStore();
|
||||||
|
const { setSimulateId } = useSimulateId();
|
||||||
|
const { addSimulationRecords } = useSimulationManager();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!isPlaying || isReset || !selectedProduct.productUuid) return;
|
if (!isPlaying || isReset || !selectedProduct.productUuid) return;
|
||||||
@@ -37,7 +40,17 @@ function Simulator() {
|
|||||||
if (!product) return;
|
if (!product) return;
|
||||||
const products: productsSchema = [product];
|
const products: productsSchema = [product];
|
||||||
const getSimulate = getData?.data;
|
const getSimulate = getData?.data;
|
||||||
|
console.log("getSimulate: ", getSimulate);
|
||||||
if (getData && getSimulate && getSimulate.productTimestamp === products[0]?.timestamp) {
|
if (getData && getSimulate && getSimulate.productTimestamp === products[0]?.timestamp) {
|
||||||
|
setSimulateId(getSimulate._id);
|
||||||
|
console.log(" getSimulate.data: ", getSimulate.data);
|
||||||
|
addSimulationRecords(
|
||||||
|
projectId,
|
||||||
|
selectedVersion?.versionId || "",
|
||||||
|
selectedProduct?.productUuid || "",
|
||||||
|
getSimulate.data // ✅ this is already an array
|
||||||
|
);
|
||||||
|
echo.log("Simulation data is up to date");
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
//call create API
|
//call create API
|
||||||
|
|||||||
@@ -4,12 +4,7 @@ import * as CONSTANTS from "../../types/world/worldConstants";
|
|||||||
|
|
||||||
export const useSocketStore = create<any>((set: any, get: any) => ({
|
export const useSocketStore = create<any>((set: any, get: any) => ({
|
||||||
socket: null,
|
socket: null,
|
||||||
initializeSocket: (
|
initializeSocket: (email?: string, organization?: string, token?: string, refreshToken?: string) => {
|
||||||
email?: string,
|
|
||||||
organization?: string,
|
|
||||||
token?: string,
|
|
||||||
refreshToken?: string
|
|
||||||
) => {
|
|
||||||
const existingSocket = get().socket;
|
const existingSocket = get().socket;
|
||||||
if (existingSocket) {
|
if (existingSocket) {
|
||||||
return;
|
return;
|
||||||
@@ -322,8 +317,7 @@ export const useTileDistance = create<any>((set: any) => ({
|
|||||||
|
|
||||||
export const usePlayAgv = create<any>((set, get) => ({
|
export const usePlayAgv = create<any>((set, get) => ({
|
||||||
PlayAgv: [],
|
PlayAgv: [],
|
||||||
setPlayAgv: (updateFn: (prev: any[]) => any[]) =>
|
setPlayAgv: (updateFn: (prev: any[]) => any[]) => set({ PlayAgv: updateFn(get().PlayAgv) }),
|
||||||
set({ PlayAgv: updateFn(get().PlayAgv) }),
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// Define the Asset type
|
// Define the Asset type
|
||||||
@@ -522,22 +516,34 @@ function getInitialViewSceneLabels(): boolean {
|
|||||||
export interface CompareProduct {
|
export interface CompareProduct {
|
||||||
productUuid: string;
|
productUuid: string;
|
||||||
productName: string;
|
productName: string;
|
||||||
simulationData: {
|
// simulationData: {
|
||||||
// costPerUnit: number;
|
// // costPerUnit: number;
|
||||||
// workingDaysPerYear: number;
|
// // workingDaysPerYear: number;
|
||||||
// shiftLength: number;
|
// // shiftLength: number;
|
||||||
// shiftsPerDay: number;
|
// // shiftsPerDay: number;
|
||||||
roiPercentage: number;
|
// roiPercentage: number;
|
||||||
|
// // paybackPeriod: number;
|
||||||
|
// // totalCost: number;
|
||||||
|
// // revenueGenerated: number;
|
||||||
|
// netProfit: number;
|
||||||
|
// productionCapacity: number;
|
||||||
// paybackPeriod: number;
|
// paybackPeriod: number;
|
||||||
// totalCost: number;
|
// // netLoss: number;
|
||||||
// revenueGenerated: number;
|
// machineIdleTime: number;
|
||||||
|
// machineActiveTime: number;
|
||||||
|
// throughputData: number;
|
||||||
|
// };
|
||||||
|
simulationData: {
|
||||||
|
roiPercentage: number;
|
||||||
netProfit: number;
|
netProfit: number;
|
||||||
productionCapacity: number;
|
productionCapacity: number;
|
||||||
paybackPeriod: number;
|
paybackPeriod: number;
|
||||||
// netLoss: number;
|
|
||||||
machineIdleTime: number;
|
machineIdleTime: number;
|
||||||
machineActiveTime: number;
|
machineActiveTime: number;
|
||||||
throughputData: number;
|
throughputData: number;
|
||||||
|
simulationTime?: number;
|
||||||
|
simulationCost?: number;
|
||||||
|
efficiencyScore?: number;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ interface SimulationManagerStore {
|
|||||||
simulationRecords: ProjectSimulation[];
|
simulationRecords: ProjectSimulation[];
|
||||||
setSimulationRecords: (simulateData: ProjectSimulation[]) => void;
|
setSimulationRecords: (simulateData: ProjectSimulation[]) => void;
|
||||||
addSimulationRecord: (projectId: string | undefined, versionId: string, productId: string, record: SimulationUsageRecord) => void;
|
addSimulationRecord: (projectId: string | undefined, versionId: string, productId: string, record: SimulationUsageRecord) => void;
|
||||||
|
addSimulationRecords: (projectId: string | undefined, versionId: string, productId: string, records: SimulationUsageRecord[]) => void;
|
||||||
resetProductRecords: (projectId: string, versionId: string, productId: string) => void;
|
resetProductRecords: (projectId: string, versionId: string, productId: string) => void;
|
||||||
getProjectById: (projectId: string | undefined) => ProjectSimulation | undefined;
|
getProjectById: (projectId: string | undefined) => ProjectSimulation | undefined;
|
||||||
getVersionById: (projectId: string | undefined, versionId: string) => VersionSimulation | undefined;
|
getVersionById: (projectId: string | undefined, versionId: string) => VersionSimulation | undefined;
|
||||||
@@ -85,6 +85,52 @@ export const useSimulationManager = create<SimulationManagerStore>((set, get) =>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return { simulationRecords: projects };
|
||||||
|
}),
|
||||||
|
addSimulationRecords: (projectId, versionId, productId, records) =>
|
||||||
|
set((state) => {
|
||||||
|
const projects = state.simulationRecords.map((project) => {
|
||||||
|
if (project.projectId !== projectId) return project;
|
||||||
|
|
||||||
|
return {
|
||||||
|
...project,
|
||||||
|
versions: project.versions.map((version) => {
|
||||||
|
if (version.versionId !== versionId) return version;
|
||||||
|
|
||||||
|
return {
|
||||||
|
...version,
|
||||||
|
products: version.products.map((product) => (product.productId === productId ? { ...product, simulateData: [...product.simulateData, ...records] } : product)),
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
// same creation logic for new project/version/product
|
||||||
|
if (!state.simulationRecords.find((p) => p.projectId === projectId)) {
|
||||||
|
projects.push({
|
||||||
|
projectId,
|
||||||
|
versions: [
|
||||||
|
{
|
||||||
|
versionId,
|
||||||
|
products: [{ productId, simulateData: [...records] }],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
const project = projects.find((p) => p.projectId === projectId)!;
|
||||||
|
if (!project.versions.find((v) => v.versionId === versionId)) {
|
||||||
|
project.versions.push({
|
||||||
|
versionId,
|
||||||
|
products: [{ productId, simulateData: [...records] }],
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
const version = project.versions.find((v) => v.versionId === versionId)!;
|
||||||
|
if (!version.products.find((p) => p.productId === productId)) {
|
||||||
|
version.products.push({ productId, simulateData: [...records] });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return { simulationRecords: projects };
|
return { simulationRecords: projects };
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user