diff --git a/apps/web/src/lib/componentInspector.ts b/apps/web/src/lib/componentInspector.ts index 4230acc..8a010f1 100644 --- a/apps/web/src/lib/componentInspector.ts +++ b/apps/web/src/lib/componentInspector.ts @@ -6,7 +6,7 @@ import type { Edge, Node } from "@xyflow/react"; import type { EntropykNodeData } from "./configBuilder"; import { COMPONENT_BY_TYPE, isSecondaryPort } from "./componentMeta"; -import type { SimulationResult } from "./api"; +import type { SimulationResult, SolvedVariable } from "./api"; export interface PortVariable { port: string; @@ -225,3 +225,21 @@ function streamDutyKw( function fmt(v: number, digits: number): string { return Number.isFinite(v) ? v.toFixed(digits) : "—"; } + +/** + * Returns the solver-computed unknowns (free actuators + calibration factors) + * attached to a given component, filtered out of `result.solved_variables`. + * + * Returns an empty array when there is no result or the component owns no + * solved variable. Globals (component === null) are excluded here — they are + * not tied to a specific diagram node. + */ +export function getSolvedVariablesForComponent( + result: SimulationResult | null, + componentName: string, +): SolvedVariable[] { + if (!result?.solved_variables?.length) return []; + return result.solved_variables.filter( + (sv) => sv.component != null && sv.component === componentName, + ); +}