feat(m02-df): 36-0b 선 조건 여러 줄(그리고 · 또는) · 값 목록
- CfRule gate conds[{from · op · value}] · join 그리고/또는 · 옛 한 줄 꼴(from · op · value)도 읽음 — 옛 칸은 첫 조건과 같게 둠(makeGate)
- gateConds · makeGate · valueChoices(변수 고르기 · 재료 규격 · 표 칸 값 · 수 · 함수 결과는 null)
- 규칙 → 받는 칸 엑셀 식 IF(AND/OR(...),A1,NA()) · 선 이름표 「지반 = 토사 그리고 높이 ≥ 3 일 때만」 · 겹침 · 안 맞음은 조건 알약 묶음끼리
- 조건 값 열쇠 「상자|알약」 먼저(이름 겹침 막음) · M02_DF_Compute.py gate 같은 뜻(서버 = 화면 시험)
- 시험 test_m02_df_model 30개
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VBToTCGk5dqDKeXCEP3vhk
This commit is contained in:
@@ -12,7 +12,7 @@ import { currentLanguageIndex } from "@ui/ui_template_locale";
|
||||
import { colName } from "../../A00_Common/spreadsheet/spreadsheet_address";
|
||||
import { recalcWorkbook } from "../../A00_Common/spreadsheet/spreadsheet_recalc";
|
||||
import type { CalcValue, Cell } from "../../A00_Common/spreadsheet/spreadsheet_types";
|
||||
import type { CfGateOp, CfRound, CfRule } from "./M02_DF_Model";
|
||||
import { gateConds, type CfGateOp, type CfRound, type CfRule } from "./M02_DF_Model";
|
||||
|
||||
type Scalar = number | string | boolean | null;
|
||||
|
||||
@@ -27,6 +27,8 @@ export interface CfRuleResult {
|
||||
const TEXT = {
|
||||
Lookup: ["표에서 찾기", "Look up in table"],
|
||||
Gate: ["일 때만", "only when"],
|
||||
And: ["그리고", "and"],
|
||||
Or: ["또는", "or"],
|
||||
Places: ["소수 {n}자리", "{n} decimals"],
|
||||
Round: ["반올림", "round"],
|
||||
Up: ["올림", "round up"],
|
||||
@@ -57,8 +59,11 @@ export function ruleLabel(rule: CfRule): string {
|
||||
const conds = rule.conds.map((c) => `${c.col} = ${c.from.name}`).join(" · ");
|
||||
return `${tl("Lookup")}${conds ? ` (${conds})` : ""} → ${rule.col}`;
|
||||
}
|
||||
case "gate":
|
||||
return `${rule.from.name} ${rule.op} ${rule.value} ${tl("Gate")}`;
|
||||
case "gate": {
|
||||
const g = gateConds(rule);
|
||||
const join = g.join === "또는" ? tl("Or") : tl("And");
|
||||
return `${g.conds.map((c) => `${c.from.name} ${c.op} ${c.value}`).join(` ${join} `)} ${tl("Gate")}`;
|
||||
}
|
||||
case "scale":
|
||||
return rule.op === "+%" || rule.op === "-%"
|
||||
? `${rule.op[0]}${rule.value}%`
|
||||
@@ -109,6 +114,10 @@ const lit = (v: number | string): string =>
|
||||
|
||||
/* ── 규칙 ───────────────────────────────────────────────────────────────── */
|
||||
|
||||
/** 조건 알약 값 — 열쇠 「상자|알약」 이 먼저 · 없으면 알약 이름 */
|
||||
const condOf = (conds: Record<string, unknown>, p: { box: string; name: string }): unknown =>
|
||||
`${p.box}|${p.name}` in conds ? conds[`${p.box}|${p.name}`] : conds[p.name];
|
||||
|
||||
/** 규칙 적용 — value = 보낸 알약 값(표면 머리 줄 포함 칸 덩어리) · conds = 조건 알약 이름 → 값(lookup · gate) */
|
||||
export function applyRule(
|
||||
rule: CfRule,
|
||||
@@ -121,9 +130,17 @@ export function applyRule(
|
||||
if (a1) 칸.A1 = a1;
|
||||
let formula: string;
|
||||
if (rule.kind === "gate") {
|
||||
const c1 = cellOf(conds[rule.from.name]);
|
||||
if (c1) 칸.C1 = c1;
|
||||
formula = `IF(C1${OP[rule.op]}${lit(rule.value)},A1,NA())`;
|
||||
// 조건 값 = C1 · D1 · E1 … · 여러 줄은 AND / OR
|
||||
const g = gateConds(rule);
|
||||
const tests = g.conds.map((c, i) => {
|
||||
const at = `${colName(2 + i)}1`;
|
||||
const cv = cellOf(condOf(conds, c.from));
|
||||
if (cv) 칸[at] = cv;
|
||||
return `${at}${OP[c.op]}${lit(c.value)}`;
|
||||
});
|
||||
const test =
|
||||
tests.length > 1 ? `${g.join === "또는" ? "OR" : "AND"}(${tests.join(",")})` : tests[0];
|
||||
formula = `IF(${test},A1,NA())`;
|
||||
} else if (rule.kind === "scale") {
|
||||
const v = rule.value;
|
||||
formula =
|
||||
@@ -169,7 +186,7 @@ function lookup(
|
||||
let bad = !out || rows < 1;
|
||||
rule.conds.forEach((c, i) => {
|
||||
const ref = `$${colName(W + 1 + i)}$1`;
|
||||
const cv = cellOf(conds[c.from.name]);
|
||||
const cv = cellOf(condOf(conds, c.from));
|
||||
if (cv) 칸[`${colName(W + 1 + i)}1`] = cv;
|
||||
const same = at(c.col);
|
||||
const low = at(`${c.col}·아래`);
|
||||
|
||||
Reference in New Issue
Block a user