refactor(853-1): M01 화면 0 서버 길 15 와 본체 걷음 — 묶음 ② 고친 파일(앞 커밋 654b75b5c 는 지운 파일만 담김)
- 길 지움(화면 TS · 다른 서버 모듈 · 시험 세 곳에서 다시 찾음 · /openapi.json 524 → 509 뜻한 15 만): GET /groups · /sections · /table/options · /logic/combos · POST /logic/new · /logic/edit · /logic/delete · /logic/draft · /logic/sheet · /logic/sheet/check · /logic/equation(+ preview · links · save) · /logic/doc/links - 본체 지움: M01_MasterData_Sheet.py · Equation.read · preview · save · Store_Make.sections · _counts · table_options · logic_edit · logic_delete · _own_only · logic_draft · Store.groups · Store_Combo.combo_preview · scripts/master_draft.py(지운 /logic/draft 만 부름) - 남김: Equation.export_row · edit_row · links(M02 Sangeun_Equation 이 부름) · Doc.candidates(M02 /doc/links) · Store_Make._all_sections(M02 Hopyo_Clause) · logic_new(복사 · 수식 저장이 씀) · combos_of_logic(Doc.users) · combo_inputs(알약 규칙 입구 · 시험) · master_combo.run(M02 시험 대조 값) · /alias/suggest(main.py 가 따로 끼움 · 승인 화면과 한 벌) - 화면 입구 지움: Api_Fetch.fetchGroups · GroupInfo · fetchSubs · Logic_Api.draftLogic + Draft 타입 6 - 시험: test_m01_draft 지움(죽은 해석기 · 길만 봄) · test_794_1 시트 길 시험 지우고 /save 다시 셈 시험만 남김 · test_796_1 수식 길 시험 지움 · test_800_2 는 살아 있는 export_row · edit_row 로 같은 셈 · test_m01_make 는 죽은 길 대신 /save · logic_new 로 같은 결과 · test_m01_combo 미리 보기 시험 지움 · /logic/combos 는 combos_of_logic 로 · test_m01_api · test_802_3 · test_799_2 · test_717_1(+helper) 죽은 길 줄만 고침 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -69,42 +69,6 @@ def _all_sections(book: str) -> list[dict]:
|
||||
return out
|
||||
|
||||
|
||||
def _counts() -> dict[tuple[str, str], list[int]]:
|
||||
"""(구분, 절 번호) → [표 수, 로직 수] — 아래 절까지 세도록 절 번호의 모든 앞마디에 얹음."""
|
||||
out: dict[tuple[str, str], list[int]] = {}
|
||||
for data in store.loaded()[0].values():
|
||||
group = data.get("그룹")
|
||||
at = 0 if group in cm.mf.TABLE_GROUPS else 1 if group == "로직" else None
|
||||
if at is None:
|
||||
continue
|
||||
for row in data.get(store.items_key(data)) or []:
|
||||
number, sub = str(row.get("원문번호") or ""), str(row.get("구분") or "")
|
||||
parts = number.split("-")
|
||||
for upto in range(1, len(parts) + 1):
|
||||
out.setdefault((sub, "-".join(parts[:upto])), [0, 0])[at] += 1
|
||||
return out
|
||||
|
||||
|
||||
def sections(book: str, division: str = "", chapter: str = "", q: str = "", limit: int = 200):
|
||||
"""원문 절 목록 — 만들기 첫 걸음(절을 고르면 그 절의 표만 보임)."""
|
||||
if book not in BOOKS:
|
||||
raise store.StoreError(404, f"없는 원문 「{book}」")
|
||||
if division and division not in cm.DIVISIONS:
|
||||
raise store.StoreError(404, f"없는 부문 「{division}」")
|
||||
counts, hits = _counts(), []
|
||||
for one in _all_sections(book):
|
||||
if division and one["division"] != division:
|
||||
continue
|
||||
if chapter and one["chapterNo"] != str(chapter).zfill(2):
|
||||
continue
|
||||
if q and q.lower() not in f"{one['section']} {one['title']}".lower():
|
||||
continue
|
||||
sub = " ".join(x for x in (book, one["division"]) if x)
|
||||
tables, logics = counts.get((sub, one["section"]), [0, 0])
|
||||
hits.append({**one, "tables": tables, "logics": logics})
|
||||
return {"total": len(hits), "sections": hits[: min(max(limit, 1), 1000)]}
|
||||
|
||||
|
||||
# ── 로직 원문(출처 글 → 품셈 본문 절) ──────────────────────────────────
|
||||
_NUMBER = re.compile(r"(?<![\d-])(\d+(?:-\d+)+)(?![\d-])(?:\s+(주[①-⑳]?|\d{1,2})(?![\d-]))?")
|
||||
_ESCAPE = re.compile(r"\\([.\-*_()#\[\]>~`])") # 마크다운 이스케이프 `\.` `\-` …
|
||||
@@ -242,30 +206,6 @@ def source(src: str) -> dict:
|
||||
return {"source": src, "found": found}
|
||||
|
||||
|
||||
# ── 표 조건 값 ─────────────────────────────────────────────────────────
|
||||
def table_options(file: str, key: str) -> dict:
|
||||
"""표 조건 칸의 값만 — 표 몸을 통째로 받지 않으려는 자리(만들기 입력 제안)."""
|
||||
table = store.table(file, key)["table"]
|
||||
conds = table.get("조건") or {}
|
||||
values: dict[str, list] = {name: [] for name in conds}
|
||||
for row in table.get("줄") or []:
|
||||
for name in conds:
|
||||
value = row.get(name)
|
||||
if value is None or value in values[name]:
|
||||
continue
|
||||
values[name].append(value)
|
||||
return {
|
||||
"file": file,
|
||||
"key": key,
|
||||
"이름": table.get("이름"),
|
||||
"조건": conds,
|
||||
"범위규칙": table.get("범위규칙"),
|
||||
"값칸": table.get("값칸") or {},
|
||||
"count": len(table.get("줄") or []),
|
||||
"값": values,
|
||||
}
|
||||
|
||||
|
||||
# ── 자체 로직 ──────────────────────────────────────────────────────────
|
||||
def _own_path() -> Path:
|
||||
return store.FOLDER / OWN
|
||||
@@ -346,11 +286,6 @@ def _find(key: str) -> tuple[str, dict]:
|
||||
return got["file"], got["logic"]
|
||||
|
||||
|
||||
def _own_only(file: str, key: str) -> None:
|
||||
if file != OWN:
|
||||
raise store.StoreError(403, f"정본 로직 「{key}」 은 못 고침 — 본뜬 뒤 고칠 것")
|
||||
|
||||
|
||||
def _clean(logic: dict, owner: str, key: str | None = None) -> dict:
|
||||
"""서버가 잡는 칸 — 키·소유·구분·상세구분. 화면이 보낸 것은 안 씀."""
|
||||
if not isinstance(logic, dict) or not str(logic.get("이름") or "").strip():
|
||||
@@ -422,16 +357,6 @@ def logic_copy(key: str, 이름: str = "", owner: str = OWNERS[0]) -> dict:
|
||||
return logic_new(copy, owner)
|
||||
|
||||
|
||||
def logic_edit(key: str, version: str, logic: dict, owner: str = "") -> dict:
|
||||
file, row = _find(key)
|
||||
_own_only(file, key)
|
||||
if store.read(OWN)[1] != version:
|
||||
raise store.StoreError(409, {"stale": [OWN]})
|
||||
fixed = _clean(logic, owner or str(row.get("소유") or OWNERS[0]), key)
|
||||
done = _write([{"op": "edit", "key": key, "row": fixed}])
|
||||
return {**done, "logic": store.logic(key)["logic"]}
|
||||
|
||||
|
||||
# ── 복사해서 만들기 ────────────────────────────────────────────────────
|
||||
def logic_formula(key: str) -> dict:
|
||||
"""로직 한 줄을 별칭 꼴 식 묶음으로 펴 보임 — 되돌릴 원문은 `별칭` 에 그대로(정본은 안 바뀜)."""
|
||||
@@ -469,41 +394,3 @@ def logic_from_formula(
|
||||
if 본뜬키:
|
||||
row["비고"] = " · ".join(x for x in (str(row.get("비고") or ""), f"{본뜬키} 를 본뜸") if x)
|
||||
return logic_new(row, owner)
|
||||
|
||||
|
||||
def logic_delete(key: str, version: str) -> dict:
|
||||
file, _ = _find(key)
|
||||
_own_only(file, key)
|
||||
if store.read(OWN)[1] != version:
|
||||
raise store.StoreError(409, {"stale": [OWN]})
|
||||
return _write([{"op": "delete", "key": key}])
|
||||
|
||||
|
||||
# ── 식으로 만들기 ──────────────────────────────────────────────────────
|
||||
def logic_draft(
|
||||
text: str,
|
||||
decided: dict | None = None,
|
||||
head: dict | None = None,
|
||||
save: bool = False,
|
||||
owner: str = OWNERS[0],
|
||||
) -> dict:
|
||||
"""줄로 적은 식 → 변수 · 검사(`_화면_계약.md` 8장).
|
||||
|
||||
`head`(이름 · 결과단위 …)가 오면 로직 한 줄까지 미리 보이고, `save` 면 다 정해진 때만
|
||||
자체 로직으로 저장(키 GX 는 서버) · 덜 정했거나 걸리면 422 로 아무것도 안 씀.
|
||||
"""
|
||||
import master_draft as draft # store 가 scripts 를 길에 올린 뒤라야 함
|
||||
|
||||
got = draft.read(text, decided, head)
|
||||
if head is None:
|
||||
return {**got, "logic": None}
|
||||
row, bad = draft.옮기기(text, decided, head)
|
||||
got["문제"] = got["문제"] + [x for x in bad if x not in got["문제"]]
|
||||
got["다됨"] = not got["문제"]
|
||||
if save and got["문제"]:
|
||||
raise store.StoreError(
|
||||
422, {"errors": [f"{x['줄']}줄 · {x['말']}" for x in got["문제"]], "문제": got["문제"]}
|
||||
)
|
||||
if not save:
|
||||
return {**got, "logic": row or None}
|
||||
return {**got, **logic_new(row, owner)}
|
||||
|
||||
Reference in New Issue
Block a user