From c072648397bd948843526991e91f86bb416db69c Mon Sep 17 00:00:00 2001 From: Jerald-Golden-B Date: Thu, 18 Dec 2025 16:23:14 +0530 Subject: [PATCH] feat: introduce comprehensive simulation analysis module with detailed performance and material flow tracking. --- .../modules/simulation/analyzer/analyzer.tsx | 30 +++++++++++++++++++ app/src/store/simulation/useAnalysisStore.ts | 4 +-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/app/src/modules/simulation/analyzer/analyzer.tsx b/app/src/modules/simulation/analyzer/analyzer.tsx index dd27dd8..f9d6334 100644 --- a/app/src/modules/simulation/analyzer/analyzer.tsx +++ b/app/src/modules/simulation/analyzer/analyzer.tsx @@ -203,6 +203,28 @@ function Analyzer() { > >({}); + const resetAllRefs = () => { + assetCyclesRef.current = {}; + assetStateChangesRef.current = {}; + materialAdditionsRef.current = {}; + materialRemovalsRef.current = {}; + materialProcessingTimesRef.current = {}; + wipSnapshotsRef.current = {}; + throughputSnapshotsRef.current = {}; + performanceSnapshotsRef.current = {}; + bottleneckEventsRef.current = {}; + previousAssetStatesRef.current = {}; + materialLifecycleRef.current = {}; + setAnalysis(null); + setAnalyzing(false); + }; + + useEffect(() => { + if (!isPlaying) { + resetAllRefs(); + } + }, [isPlaying]); + // ============================================================================ // ENHANCED UTILITY FUNCTIONS // ============================================================================ @@ -2157,6 +2179,14 @@ function Analyzer() { performAnalysisRef.current = performAnalysis; }, [performAnalysis]); + // Trigger analysis when assets or materials change + useEffect(() => { + if (!isPlaying) return; + + // Perform analysis when any asset or material state changes + performAnalysisRef.current(); + }, [conveyors, vehicles, armBots, machines, humans, cranes, materials, isPlaying]); + // Perform initial analysis and set up interval useEffect(() => { if (!isPlaying) return; diff --git a/app/src/store/simulation/useAnalysisStore.ts b/app/src/store/simulation/useAnalysisStore.ts index f3d6c31..c8ab1f6 100644 --- a/app/src/store/simulation/useAnalysisStore.ts +++ b/app/src/store/simulation/useAnalysisStore.ts @@ -7,7 +7,7 @@ interface AnalysisStore { lastUpdateTime: string | null; // Actions - setAnalysis: (analysis: AnalysisSchema) => void; + setAnalysis: (analysis: AnalysisSchema | null) => void; updateAssetAnalysis: (assetId: string, assetAnalysis: AssetAnalysis) => void; addHistoricalDataPoint: (assetId: string, dataPoint: any) => void; clearAnalysis: () => void; @@ -29,7 +29,7 @@ export const createAnalysisStore = () => { lastUpdateTime: null, // Set complete analysis - setAnalysis: (analysis: AnalysisSchema) => { + setAnalysis: (analysis: AnalysisSchema | null) => { set((state) => { state.analysis = analysis; state.lastUpdateTime = new Date().toISOString();