Merge remote-tracking branch 'origin/main_laptop_1' into sub_laptop_3

This commit is contained in:
2026-11-16 21:28:57 +09:00
9 changed files with 464 additions and 17 deletions
@@ -33,7 +33,8 @@ EIGHT = Decimal(8)
def norm_unit(u) -> str:
t = str(u or "").strip().replace("m3", "㎥").replace("m2", "㎡")
t = re.sub(r"[mM]3", "㎥", re.sub(r"[mM]2", "㎡", str(u or "").strip())) # 848-6 대문자 꼴
t = re.sub(r"(?<![A-Za-z])(M|HR|Hr|TON|Ton)(?![A-Za-z])", lambda m: m.group(1).lower(), t)
return re.sub(r"/(시간|h|Hr|HR)$", "/hr", t)
+3 -1
View File
@@ -262,7 +262,9 @@ def test_M01_기초_고침_빌더_이어받기_되돌림(docs_tmp):
back = {NO: {"값": {"가격": float(d["값"]["가격"])}, "조종원": d["조종원"]},
SYM: {"작업량": {"방식": "일당"}}} # fmt: skip
got = _save_m01(back)
assert COVER not in got["문서"] and file.read_bytes() == orig
assert COVER not in got["문서"] and file.read_bytes().replace(b"\r", b"") == orig.replace(
b"\r", b""
) # 줄 끝(autocrlf) 무시
assert got["셈"]["계"] == before
+20 -9
View File
@@ -15,8 +15,6 @@ from __future__ import annotations
import copy
import shutil
import pytest
from M01_MasterData import M01_MasterData_Store as m01
from M02_MasterTemplete import M02_Doc_Sk_Path as path
from M02_MasterTemplete import M02_Labor_Ref as refs
@@ -31,7 +29,6 @@ CUT = (
"GC000085" # 흙깎기(기계) 보통토사 — 굴착기 1.0㎥(0201-0100) 부름 · 옵션 규모 · 지역 · 보정작업
)
PRICE = 142069 # 굴착기 1.0㎥ M01 가격
WAIT = pytest.mark.xfail(reason="M02_Doc_Sk 세 줄(848-2 a · b · c) 붙인 뒤", strict=True)
def _eq_move(monkeypatch, key: str, fn) -> None:
@@ -127,7 +124,7 @@ def test_label_only(world, monkeypatch):
def test_crew_list_kept(world, monkeypatch):
"""㉡ 목록 칸 — 기계 인력 줄 바뀜 + 인력 고침 = 지킴 알림(목록 글) · 가격 고침 칸은 알림 없음."""
"""㉡ 목록 칸 — 인력 줄 바뀜 + 인력 고침 = 지킴 알림(목록 글) · 가격 칸 알림 없음."""
me = world["personal"]
mine = [{"키": "LB:1048", "인": 2}]
key = _machine_sk(me, {"값": {"가격": 150000}, "조종원": mine})
@@ -137,9 +134,8 @@ def test_crew_list_kept(world, monkeypatch):
assert note["M01"] == ["인력 LB:1048 1인 → LB:1048 1.5인"]
@WAIT
def test_upper_only(world, monkeypatch):
"""㉣ 기초 고침(①)만 바뀜(+ 이름 글) = 따로 문서 그대로 · 내 고침 칸을 ① 이 바꾸면 지킴 알림(층 기초) ·
"""㉣ 기초 고침(①)만 바뀜(+ 이름) = 따로 문서 그대로 · ① 이 내 고침 칸을 바꿈 = 지킴(층 기초) ·
② 없는 칸(주연료)은 알림 없음."""
me = world["personal"]
key = _cut_sk(me, cover={"값": {"가격": 150000}})
@@ -156,6 +152,7 @@ def test_upper_only(world, monkeypatch):
assert got["문서"]["기계덮음"] == {DIG_NO: {"값": {"가격": 150000}}}
[note] = got["사본"]["갱신"]
assert (note["경로"], note["층"], note["전"], note["후"]) == ("값.가격", "기초", PRICE, 200000)
assert got["셈"]["계"] > was["셈"]["계"] # 안 고친 칸(주연료 ①) = 따라옴 · 가격 = 내 값
assert not got["사본"]["문서새판"]
@@ -189,7 +186,7 @@ def _grow(d: dict) -> None:
def test_structure_recopy(world, monkeypatch):
"""㉤ 기초에 줄이 더해짐 = 다시 복사(따로 아님) · 기계 고침 · 옵션 값 다시 얹음 · 알림 다시복사."""
"""㉤ 기초에 줄 더함 = 다시 복사(따로 아님) · 기계 고침 · 옵션 값 다시 얹음 · 알림 다시복사."""
me = world["personal"]
cover = {"값": {"가격": 150000}}
key = _cut_sk(me, cover=cover)
@@ -203,7 +200,6 @@ def test_structure_recopy(world, monkeypatch):
assert note["다시얹음"] == ["규모 소규모"]
@WAIT
def test_structure_recopy_saved(world, monkeypatch):
"""㉤ 다시 복사한 뒤 알림 [확인](저장) = 기계 고침 · 옵션 값 남음 · 알림 없음."""
me = world["personal"]
@@ -229,7 +225,6 @@ def test_save_keeps_base(world, monkeypatch):
assert (note["전"], note["후"]) == (PRICE, PRICE * 2)
@WAIT
def test_confirm_clears(world, monkeypatch):
"""㉥ 알림 [확인] 뒤 = 안 뜸 · 내 값 그대로 · 금액 같음."""
me = world["personal"]
@@ -288,3 +283,19 @@ def test_imported_same_rule(world, monkeypatch):
with store.at(me):
[note] = renew.notes(sk)
assert (note["처리"], note["경로"], note["후"]) == ("지킴", "값.가격", PRICE * 2)
def test_upper_cover_keeps_edited_doc(world, monkeypatch):
"""㉣ 기초 문서의 `기계덮음`(①)만 바뀜 = 그 기초로 만든 따로 SK 문서 고침 그대로 · 알림 없음
(문서 지문에서 덮음 뺌 — 848-1 이 남긴 경우)."""
from resources.tester.test_836_2_sk_auto_renew import TOOL, _base, _edit
me = world["personal"]
key = _base(me)
_edit(me, key, "노무비 × 5%")
was = _read(me, key)
_doc_move(monkeypatch, "GC001109", lambda d: d.update(기계덮음={DIG_NO: {"값": {"가격": 1}}}))
got = _read(me, key)
assert got["사본"]["따로"] is True and got["사본"]["갱신"] == []
assert got["문서"]["금액"][TOOL]["단가"] == "노무비 × 5%"
assert got["셈"]["계"] == was["셈"]["계"] and not got["사본"]["문서새판"]
+206
View File
@@ -0,0 +1,206 @@
"""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["줄"])