refactor(api): extract computation graph project snapshot

This commit is contained in:
2026-03-31 10:12:05 +02:00
parent f24d8deacf
commit 45c90438ba
4 changed files with 470 additions and 449 deletions
@@ -0,0 +1,46 @@
type Domain =
| "INPUT" | "SAH" | "ALLOCATION" | "RULES" | "CHARGEABILITY" | "BUDGET"
| "ESTIMATE" | "COMMERCIAL" | "EXPERIENCE" | "EFFORT" | "SPREAD";
export interface GraphNode {
id: string;
label: string;
value: number | string;
unit: string;
domain: Domain;
description: string;
formula?: string;
level: number;
}
export interface GraphLink {
source: string;
target: string;
formula: string;
weight: number;
}
export function n(
id: string,
label: string,
value: number | string,
unit: string,
domain: Domain,
description: string,
level: number,
formula?: string,
): GraphNode {
return { id, label, value, unit, domain, description, level, ...(formula ? { formula } : {}) };
}
export function l(source: string, target: string, formula: string, weight = 1): GraphLink {
return { source, target, formula, weight };
}
export function fmtPct(ratio: number): string {
return `${(ratio * 100).toFixed(1)}%`;
}
export function fmtNum(value: number, decimals = 1): string {
return value.toFixed(decimals);
}