직접입력값 평가오류 수정
This commit is contained in:
@@ -3,35 +3,21 @@ import type { ConditionDSL, LogicNode } from './strategyTypes';
|
||||
import type { DefType } from './strategyEditorShared';
|
||||
import { getDefaultConditionFields } from './strategyEditorShared';
|
||||
import {
|
||||
canonicalizeConditionThreshold,
|
||||
ensureDirectThresholdSnapshot,
|
||||
isThresholdOverridden,
|
||||
isValuePeriodOverridden,
|
||||
parseThresholdField,
|
||||
usesValuePeriodField,
|
||||
VALUE_FIELD_PREFIX,
|
||||
} from './conditionPeriods';
|
||||
import {
|
||||
defaultInheritedThresholdField,
|
||||
inferThresholdRoleForValue,
|
||||
inferThresholdSymbolFromLegacy,
|
||||
inferThresholdSymbolFromLegacyExact,
|
||||
isThresholdFieldOrSymbol,
|
||||
isThresholdSymbol,
|
||||
THRESHOLD_HL_MID,
|
||||
THRESHOLD_HL_OVER,
|
||||
} from './thresholdSymbols';
|
||||
import { repairPriceExtremePairForest } from './priceExtremeBreakoutPair';
|
||||
|
||||
function coerceTargetValue(raw: unknown): number | null {
|
||||
if (raw == null) return null;
|
||||
if (typeof raw === 'number') return Number.isFinite(raw) ? raw : null;
|
||||
if (typeof raw === 'string') {
|
||||
const n = parseFloat(raw.trim());
|
||||
return Number.isFinite(n) ? n : null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function isConditionCarrier(node: LogicNode): node is LogicNode & { condition: ConditionDSL } {
|
||||
return !!node.condition && (node.type === 'CONDITION' || node.type == null || node.type === undefined);
|
||||
}
|
||||
@@ -41,22 +27,8 @@ function migrateConditionThreshold(
|
||||
def: DefType,
|
||||
signalType: 'buy' | 'sell',
|
||||
): ConditionDSL {
|
||||
// 직접입력(K_55 등) — 숫자 스냅샷 유지, HL_* 로 접지 않음
|
||||
if (isThresholdOverridden(cond)) {
|
||||
const val = coerceTargetValue(cond.targetValue) ?? parseThresholdField(cond.rightField);
|
||||
if (val != null) {
|
||||
const role = inferThresholdRoleForValue(val, cond.indicatorType, {});
|
||||
if (role != null) {
|
||||
const { targetValue: _t, ...rest } = cond;
|
||||
return migrateConditionPeriod({ ...rest, rightField: role, thresholdOverride: false });
|
||||
}
|
||||
}
|
||||
if (cond.rightField?.startsWith('K_')) {
|
||||
const role = inferThresholdSymbolFromLegacyExact(cond.rightField, cond.indicatorType, {});
|
||||
if (role != null) {
|
||||
const { targetValue: _t, ...rest } = cond;
|
||||
return migrateConditionPeriod({ ...rest, rightField: role, thresholdOverride: false });
|
||||
}
|
||||
}
|
||||
return cond;
|
||||
}
|
||||
|
||||
@@ -138,9 +110,9 @@ export function migrateLogicRootForEditor(
|
||||
return repairPriceExtremePairForest(migrated.root, migrated.orphans);
|
||||
}
|
||||
|
||||
/** 저장·표시·평가 공통 — K_50 등을 HL_MID 로 접기 */
|
||||
/** 저장·표시·평가 공통 — K_* 직접입력 스냅샷 보강 (HL_* 치환 없음) */
|
||||
export function normalizeConditionForPersistence(cond: ConditionDSL): ConditionDSL {
|
||||
let next = canonicalizeConditionThreshold(cond);
|
||||
let next = ensureDirectThresholdSnapshot(cond);
|
||||
|
||||
if (!isValuePeriodOverridden(next)) {
|
||||
const prefix = VALUE_FIELD_PREFIX[next.indicatorType];
|
||||
|
||||
Reference in New Issue
Block a user