Files
Aislo/resources/tester/test_848_6_import_q.py
T
eomsangdonandClaude Opus 5.5 6f0f9be9e6 feat(848-6): 불러오기 원문 단위 · Q 값 글자 Q 부름 · STmate 기계 단위 X → 시간 · 단위 정규화 대문자
- 가져온 식 문서 derive 끝 `M02_Doc_Import_Q.tidy` (새 파일) — 원문 글줄(mid:) 단위 글 → 빈 변수 단위 (짐작 없음 · 낱말 목록 밖 안 닮) · 기계 밖 줄 나눔 자리 수 = Q 값이고 뜻 분명할 때만 Q 부름 · 아니면 「참고 · Q 값 글자」 표지
- STmate 원파일 기계 단위 기호 「X」 → 「시간」 (엑셀 내보내기와 같음 · 호표 · 자원 단위)
- `norm_unit` ↔ `normUnit` 대문자 M3 · M2 · M · HR · TON (기존 입력 결과 그대로)
- 전수 3,241 블록 — 엑셀 단가 그대로 · 우리 단가로 계 · 비목 · 검산 전후 다름 0 · 작업량 줄 블록 715 → 1,634 · Q 단위 2,324 / 2,362 · Q 글자 바꾼 블록 32 · 단위 X 667 → 0 · 그리기 규칙 지킴 전후 같음
- 세 줄 합침 · 겹분수는 안 고침 (848-7 · 화면 몫 — 보고)
- 시험 test_848_6_import_q 30

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 21:06:37 +09:00

207 lines
9.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""848-6 불러오기 — 원문 단위 · Q 값 글자 · STmate 기계 단위 X(서버 단독 · 금액 그대로).
① 원문 글줄 단위 글 읽기(EST · STmate 꼴 · 못 읽음 = 빈 글) ② 단위 정규화 대문자 꼴 파이썬 = TS 거울
③ Q 값 글자 → Q 부름(값 같고 뜻 분명할 때만 · 아니면 「참고 · …」 표지) ④ 실제 원파일 견본 셋 —
Q 단위 · 시간당 작업량 줄 · 기계 줄 단위 「시간」 · 엑셀 단가 그대로 계 = 원파일 · 검산 같음.
원파일 없으면 ④ 만 skip(다른 PC).
"""
from __future__ import annotations
import json
import subprocess
import sys
from decimal import Decimal as D
from pathlib import Path
import pytest
ROOT = Path(__file__).resolve().parents[2]
HERE = Path(__file__).resolve().parent
for p in (ROOT, HERE):
if str(p) not in sys.path:
sys.path.insert(0, str(p))
import test_810_2_native_doc as nd # noqa: E402
from M02_MasterTemplete import M02_Doc_FromNative as fn # noqa: E402
from M02_MasterTemplete import M02_Doc_Import as dim # noqa: E402
from M02_MasterTemplete import M02_Doc_Import_Q as qt # noqa: E402
from M02_MasterTemplete import M02_Sangeun_Imported as imp # noqa: E402
# ── ① 원문 단위 글 ───────────────────────────────────────────────────────
@pytest.mark.parametrize(
"text, n, want",
[
(" Q = ────────── = ─────────────── = 23.39 ㎥/hr", 1, ["㎥/hr"]),
(" E = 0.45 Cm = 20sec (135˚)", 2, ["", "sec"]),
(" Q = 560㎥ / 8hr = 70㎥/hr", 1, ["㎥/hr"]),
(" Q = 8. hr / (63. ㎥×0.5) = 0.254 hr/㎥", 1, ["hr/㎥"]),
("Q = 3600*q*k*E*f/Cm ='m3/hr'", 1, ["㎥/hr"]),
(" Q1 = 60 * q1 * F * E / Cm ='M3/HR'", 1, ["㎥/hr"]),
("Cm = 20 'sec(135)'", 1, ["sec"]),
(" t3 = 1.5 , t4 = 0.7", 2, ["", ""]),
("q'(버킷용량)' = 1.0 , k'(버킷계수)' = 0.55 , E'(작업효율)' = 0.45", 3, ["", "", ""]),
(" Cm = 20'sec (135˚)', E = 0.75", 2, ["sec", ""]),
(" Q=3.5'㎥/hr''연암'", 1, ["㎥/hr"]),
(" Q = Qt / t / 100㎡ = 1.95 / 0.05 / 100 = 0.39 a/hr", 1, ["a/hr"]),
(" L = 0.5km {작업능력}", 1, ["km"]),
(" '□ 시간당 시공량 :' Q = 63'm3/일r'", 1, [""]), # 원문 오타 = 못 읽음(짐작 안 함)
("K = 0.9 '보통'", 1, [""]),
(" Q = 17개 ÷ 8hr = 2.13", 1, [""]), # 값 뒤 단위 글 없음
],
)
def test_원문_단위_글(text, n, want):
segs = qt._segments(text, n)
assert segs is not None and [qt._tail(s) for s in segs] == want
def test_대입_수_안_맞으면_안_닮():
assert qt._segments("q = 0.7 K = 0.55", 3) is None
def _var(name, link, unit=""):
return {"열쇠": name, "기호": name, "아래": "", "이름": name, "단위": unit, "연결": link}
def test_단위_닮_빈_칸만():
doc = {"변수": [_var("Q", {"갈래": "식"}), _var("Cm", {"갈래": "숫자", "값": D(20)}, "초")]}
lines = [{"글": " E = 0.45 Cm = 20sec", "자리": "mid:E", "자리들": ["mid:E", "mid:Cm"]},
{"글": " Q = ── = 23.39 ㎥/hr", "자리": "mid:Q"}] # fmt: skip
assert qt.units(doc, lines) == 1
assert [v["단위"] for v in doc["변수"]] == ["㎥/hr", "초"] # 이미 있는 단위 그대로
# ── ② 정규화 거울 ────────────────────────────────────────────────────────
NORM = [
"M3/HR",
"m3/hr",
"M2/Hr",
"M/HR",
"TON/HR",
"Ton",
"㎥/hr",
"m/시간",
"100m2",
"MIN",
"EA/hr",
]
_JS = r"""
const fs = require("fs"), path = require("path");
const ts = require(path.join(process.argv[1], "config", "node_modules", "typescript"));
const cache = new Map();
function load(at) {
if (cache.has(at)) return cache.get(at);
const js = ts.transpileModule(fs.readFileSync(at, "utf8"), {
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 },
}).outputText;
const box = { exports: {} };
cache.set(at, box.exports);
const need = (p) => (p.startsWith(".") ? load(path.resolve(path.dirname(at), `${p}.ts`)) : require(p));
new Function("exports", "module", "require", js)(box.exports, box, need);
return box.exports;
}
const work = load(path.join(process.argv[1], "common_util", "common_util_formula_doc_work.ts"));
const xs = JSON.parse(fs.readFileSync(0, "utf8"));
process.stdout.write(JSON.stringify(xs.map(work.normUnit)));
"""
def test_정규화_대문자_파이썬_TS_같음():
want = [qt.mw.norm_unit(x) for x in NORM]
assert want == ["㎥/hr", "㎥/hr", "㎡/hr", "m/hr", "ton/hr", "ton", "㎥/hr", "m/hr", "100㎡", "MIN", "EA/hr"] # fmt: skip
proc = subprocess.run(["node", "-e", _JS, str(ROOT)], input=json.dumps(NORM), capture_output=True,
text=True, encoding="utf-8", check=True) # fmt: skip
assert json.loads(proc.stdout) == want
# ── ③ Q 값 글자 ─────────────────────────────────────────────────────────
def _doc(vars_, crew, defs=()):
return {
"키": "SK-999999", "이름": "시험", "결과단위": "원/㎥",
"변수": [*vars_, _var("P_굴", {"갈래": "숫자", "값": {"노무비": D(1), "재료비": D(1), "경비": D(1)}}),
_var("P_인", {"갈래": "숫자", "값": D(100)})],
"식": [{"기호": k, "식": v} for k, v in defs],
"금액": [{"이름": "굴삭기", "비목": "묶음", "수량": "1 ÷ Q", "단가": "P_굴"},
{"이름": "보통인부", "비목": "노무비", "수량": crew, "단가": "P_인"}],
"가져온": {"기계": [{"기호": "P_굴"}]},
} # fmt: skip
NUM = {"갈래": "숫자", "값": D("23.39")}
@pytest.mark.parametrize(
"crew, want",
[("1 ÷ 8 ÷ 23.39 × 0.1", "1 ÷ 8 ÷ Q × 0.1"), ("3 ÷ (23.39 ÷ 2)", "3 ÷ (Q ÷ 2)")],
)
def test_Q_글자_값_같으면_Q_부름(crew, want):
doc = _doc([_var("Q", NUM)], crew)
assert qt.literals(doc) == []
assert doc["금액"][1]["수량"] == want
@pytest.mark.parametrize(
"vars_, crew, defs, why",
[
([_var("Q", NUM), _var("t", NUM)], "1 ÷ 8 ÷ 23.39", (), "같은 값 변수 t"),
([_var("Qd", {"갈래": "숫자", "값": D(20)}), _var("Q", {"갈래": "식"})], "1 ÷ Qd ÷ 2.5",
(("Q", "Qd ÷ 8"),), "뜻 불분명"), # 줄이 Q 사슬(Qd)을 부름 · 2.5 = 길이
([_var("Q", {"갈래": "숫자", "값": D(8)})], "1 ÷ 8", (), "뜻 불분명"), # 8 = 시간
([_var("Q", {"갈래": "숫자", "값": D("23.389")})], "1 ÷ 8 ÷ 23.39", (), "끝수 다름"),
([_var("Q", NUM)], "23.39 ÷ 23.39", (), "같은 글자 여럿"),
],
) # fmt: skip
def test_Q_글자_못_가르면_그대로_표지(vars_, crew, defs, why):
doc = _doc(vars_, crew, defs)
notes = qt.literals(doc)
assert doc["금액"][1]["수량"] == crew
assert len(notes) == 1 and notes[0].startswith("참고 · ") and why in notes[0]
def test_Q_글자_금액_같음():
a = _doc([_var("Q", NUM)], "1 ÷ 8 ÷ 23.39")
b = _doc([_var("Q", NUM)], "1 ÷ 8 ÷ 23.39")
qt.literals(b)
assert b["금액"][1]["수량"] == "1 ÷ 8 ÷ Q"
x, y = qt.dc.mc.calc(a, None), qt.dc.mc.calc(b, None)
assert x["셈됨"] and [z["금액"] for z in x["줄"]] == [z["금액"] for z in y["줄"]]
assert x["계"] == y["계"]
# ── ④ 실제 원파일 견본 ───────────────────────────────────────────────────
def _block(kind, tag, no):
out = fn.emit(nd.native(kind, tag), no)
sk = nd.sk_of(out)
doc = dim.derive(sk, None, nd.whole())
ours = {**sk, imp.KEY: {**sk[imp.KEY], "단가기준": "우리"}}
return out, sk, doc, dim.run(doc, sk, nd.whole()), dim.run(doc, ours, nd.whole())
def _unit(doc, name):
return next(v["단위"] for v in doc["변수"] if v["열쇠"] == name)
def test_EST_굴착기형_Q_단위_보조인부_Q_부름():
out, sk, doc, xl, ours = _block("EST", "거창", 1)
assert _unit(doc, "Q") == "㎥/hr" and _unit(doc, "Cm") == "sec"
assert doc["금액"][1]["수량"] == "1 ÷ 8 ÷ Q"
assert xl["계"] == D(str(out["원본"]["엑셀금액"]["계"])) == 5323
assert ours["줄"][0]["작업량"]["값"] == D("23.39") and ours["줄"][0]["작업량"]["식들"]
assert imp.check(sk, nd.whole())["같음"]
def test_EST_일당_꼴_단위만_달아_문서_식():
out, sk, doc, xl, ours = _block("EST", "main", 96)
assert doc["식"] == [{"기호": "Q", "식": "560 ÷ 8"}] and _unit(doc, "Q") == "㎥/hr"
assert xl["계"] == 1884 and ours["줄"][0]["작업량"]["값"] == 70
def test_STmate_덤프_60형_작업량_줄_기계_단위_시간():
out, sk, doc, xl, ours = _block("STC", "봉화", 109)
assert {x["단위"] for x in out["로직"]["호표"]} == {"시간"} # 원파일 기호 「X」 → 시간
assert _unit(doc, "q1_2") == "㎥/hr" and _unit(doc, "t1") == "분"
assert xl["계"] == 3796 and imp.check(sk, nd.whole())["같음"]
assert all(z.get("작업량") for z in ours["줄"])