feat(M01): 조합 알약 물량 길 GET /combo/{키}/inputs
- 담은 로직 결과단위 분모(원/㎥ → ㎥)가 물량 하나 · 설계 조건은 안 넣음(조건 자리만) - 이름 = 로직 이름 끝 괄호 뗀 것 · 같은 이름·단위는 합침 · 원/10㎡ 은 배 10 - 시험 test_m01_combo_inputs.py(UA000004 · 031 · 002 · 없는 조합 404) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TULoa94ZFL26KU6ZqVpjkF
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
from datetime import date
|
||||
from pathlib import Path
|
||||
|
||||
@@ -141,6 +142,40 @@ def combo(key: str) -> dict:
|
||||
}
|
||||
|
||||
|
||||
_PER = re.compile(r"원\s*/\s*(\d*\.?\d*)\s*([^\s·(]+)")
|
||||
_TAIL = re.compile(r"\s*\([^()]*\)\s*$")
|
||||
|
||||
|
||||
def combo_inputs(key: str) -> dict:
|
||||
"""조합 알약 — 담은 로직마다 결과단위 분모(원/㎥ → ㎥)가 물량 하나.
|
||||
|
||||
이름 = 로직 이름 끝 괄호 뗀 것(「(인력)」·「(장비)」 한 알약) · 같은 이름 · 단위면 합침 ·
|
||||
키 = 그 알약 첫 로직 키 · `배` = 분모 앞 수(원/10㎡ → 10 · 1 이면 안 줌) · 돈 아닌 로직은 빠짐.
|
||||
`조건` 은 자리만(설계 조건 고르기 · 범위는 알약에 안 넣음).
|
||||
"""
|
||||
row = _find(_read()[0], key)
|
||||
whole = store.loaded()[1]
|
||||
pills: dict[tuple[str, str], dict] = {}
|
||||
for one in mcb.items(row):
|
||||
code = str(one.get("로직") or "") if isinstance(one, dict) else ""
|
||||
try:
|
||||
got = whole.logic(code)
|
||||
except cm.mf.FormulaError:
|
||||
continue
|
||||
per = _PER.findall(str(got.get("결과단위") or ""))
|
||||
if not per:
|
||||
continue
|
||||
# ponytail: 분모가 여럿(「원/㎡ · 원/㎥(단위당 따름)」)이면 「㎡ · ㎥」 한 글 — 입력이 고름
|
||||
unit = " · ".join(dict.fromkeys(u for _, u in per))
|
||||
name = _TAIL.sub("", str(got.get("이름") or code)) or code
|
||||
pill = pills.setdefault((name, unit), {"키": code, "이름": name, "단위": unit, "로직": []})
|
||||
pill["로직"].append(code)
|
||||
times = per[0][0]
|
||||
if len(per) == 1 and times and float(times) != 1:
|
||||
pill["배"] = float(times) if "." in times else int(times)
|
||||
return {"키": row.get("키"), "이름": row.get("이름"), "물량": list(pills.values()), "조건": []}
|
||||
|
||||
|
||||
def combos_of_logic(key: str) -> dict:
|
||||
"""「이 로직을 쓰는 조합」 — 로직 화면이 거꾸로 볼 때(소요량 「용도」 와 같은 결)."""
|
||||
files, _ = store.loaded()
|
||||
|
||||
Reference in New Issue
Block a user