"""내 기계 저장 전 영향(PLAN 848-5 · 요구서 889 6 장) — 기계 보기 [저장] 전에 확인창이 부름 · 쓰기 없음. 고친 줄 = 저장과 같은 손질(`M02_MyMachine.clean` — 틀리면 400) · 바뀐 칸 = 값 칸 · 방식 · 시간당. 쓰는 단가산출 = 이 층(`store.root()`) SK 가운데 사본 단가에 그 키 · 덮음에 「개인 키」 가 있는 것 (색인 = `M01_MasterData_Machine_Uses.sk_index` — 파일 자국 기억) · 따로 고쳐 둔 곳 = 덮음이 바뀐 칸을 덮음 (② 내 고침 · ① 위 층 고침 따로). 이름은 이 층 것만 냄. """ from __future__ import annotations from pathlib import Path from typing import Any from M01_MasterData import M01_MasterData_Machine_Impact as mi from M01_MasterData import M01_MasterData_Machine_Uses as mu from M02_MasterTemplete import M02_MasterTemplete_Store as store from M02_MasterTemplete import M02_MyMachine as mym def impact(key: str, raw: Any) -> dict[str, Any]: """{칸, 쓰는곳: [{키, 이름, 고침, 위층}], 고침, 위층}.""" old = next((r for r in mym.rows() if r["키"] == key), None) if old is None: raise store.StoreError(404, f"없는 내 기계 「{key}」") new = mym.clean(raw) fields = mi.changed_fields(old.get("값"), new.get("값")) fields += [k for k in ("방식", "시간당") if not mi.same(old.get(k), new.get(k))] here = (store.root() / "sangeun").resolve() names = (f"{mym.NO}{key}", key) used = [ { "키": r["키"], "이름": r["이름"], "고침": mi.cover_hits(r["덮음"], names, fields), "위층": mi.cover_hits(r["위덮음"], names, fields), } for r in mu.sk_index() if Path(r["파일"]).parent.resolve() == here and (key in r["기계"] or any(n in r[c] for c in mu.COVERS for n in names)) ] return { "칸": fields, "쓰는곳": used, "고침": sum(1 for u in used if u["고침"]), "위층": sum(1 for u in used if u["위층"]), }