Files
goldenChart/frontend/src/utils/strategyEvaluationParams.ts
T
2026-06-17 21:49:15 +09:00

42 lines
1.5 KiB
TypeScript

/**
* 전략 평가 — 전략에 포함된 지표 파라미터 맵
*/
import type { StrategyDto } from './backendApi';
import { collectIndicatorRefs } from './strategyToChartIndicators';
import { applyStrategyRefToParams } from './strategyIndicatorSync';
export type EvalIndicatorParams = Record<string, Record<string, number | string | boolean>>;
export function buildEvalParamsFromStrategy(
strategy: StrategyDto | null | undefined,
getParams: (type: string) => Record<string, number | string | boolean>,
): EvalIndicatorParams {
if (!strategy) return {};
const out: EvalIndicatorParams = {};
for (const ref of collectIndicatorRefs(strategy)) {
const base = { ...getParams(ref.registryType) };
const merged = applyStrategyRefToParams(ref, base);
out[ref.registryType] = { ...(out[ref.registryType] ?? {}), ...merged };
}
return out;
}
export function mergeEvalGetParams(
baseGetParams: (type: string, defaults?: Record<string, number | string | boolean>) => Record<string, number | string | boolean>,
applied: EvalIndicatorParams | null | undefined,
) {
return (type: string, defaults?: Record<string, number | string | boolean>) => {
const base = baseGetParams(type, defaults);
const override = applied?.[type];
return override ? { ...base, ...override } : base;
};
}
export function hasEvalParamsDiff(
draft: EvalIndicatorParams,
applied: EvalIndicatorParams | null | undefined,
): boolean {
return JSON.stringify(draft) !== JSON.stringify(applied ?? {});
}