# -*- coding: utf-8 -*- """规范(2018)第6章 vs 两份 COS4 —— 最终对比汇总""" import json, re, os BASE = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) SPEC = json.load(open(os.path.join(BASE, "DBJT15-145-2018_第6章_属性表.json"), encoding="utf-8")) COS = json.load(open(os.path.join(BASE, "两份COS4_结构.json"), encoding="utf-8")) FIX = {"其他项目费明细": "SundryCostsItem"} def norm(s): return re.sub(r"\s+", "", s) spec_el, spec_tbl = {}, {} for t in SPEC: el = norm(FIX.get(norm(t["element"]), norm(t["element"]))) props = {norm(r[1]) for r in t["rows"][1:] if len(r) >= 2 and r[1] and r[1] != "属性名称"} if not el: continue spec_el.setdefault(el, set()).update(props) spec_tbl.setdefault(el, []).append(t["no"]) CONTAINERS = {"ConstructionInfo", "ConstructionSummary", "UnitWorks", "UnitWorksSummary", "DivisionalAndElementalWorks", "Preliminaries", "Sundry", "AttrInfo", "AddiInfo", "ProvisionalMaterialEquipment"} print("规范(2018)第6章:属性表 %d 张,元素 %d 个,属性定义 %d 条\n" % (len(SPEC), len(spec_el), sum(len(v) for v in spec_el.values()))) cos_els = {} for fname, ent in COS.items(): els = {} for scope in ("attrs", "unit_attrs"): for el, props in ent.get(scope, {}).items(): els.setdefault(norm(el), set()).update(props.keys()) cos_els[fname] = els for fname, els in cos_els.items(): extra = {e: p for e, p in els.items() if e not in spec_el} priv = {e: p for e, p in extra.items() if e not in CONTAINERS} cont = {e: p for e, p in extra.items() if e in CONTAINERS} print("=" * 72) print(fname) print(" 有属性元素 %d|规范内 %d|规范有属性表但COS4缺 %d|容器元素(规范无属性表) %d|★规范外 %d" % (len(els), len(set(els) & set(spec_el)), len(set(spec_el) - set(els)), len(cont), len(priv))) print(" ★规范第6章完全没有的元素:") for e in sorted(priv): print(" - %-44s %d 个属性:%s" % (e, len(priv[e]), ",".join(sorted(priv[e]))[:120])) print(" 容器元素(规范有该元素、无属性表):%s" % ",".join(sorted(cont))) # 属性名差异 diffs = [] for e in sorted(set(spec_el) & set(els)): miss, add = spec_el[e] - els[e], els[e] - spec_el[e] if miss or add: diffs.append((e, sorted(miss), sorted(add))) print(" 属性名有差异的元素 %d 个:" % len(diffs)) for e, m, a in diffs: print(" %-42s 缺:%s 多:%s" % (e, ",".join(m) or "-", ",".join(a) or "-")) print() # 两家 COS4 互比 a, b = list(cos_els.items()) print("=" * 72) print("两份 COS4 相互差异") na, nb = set(a[1]), set(b[1]) print(" 共有元素 %d 个" % len(na & nb)) print(" 仅易达有:%s" % ",".join(sorted(na - nb))) print(" 仅广联达有:%s" % ",".join(sorted(nb - na)))